mred.sage 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import numeric_monoid as nm
  2. from sage.parallel.map_reduce import RESetMapReduce as MR
  3. class CGenCount(MR):
  4. def __init__(self, g):
  5. MR.__init__(self)
  6. self._g = g
  7. def roots(self):
  8. return [nm.Full]
  9. def children(self, x):
  10. return x.children() if x.genus() < self._g else []
  11. def post_process(self, x):
  12. return 1 if x.genus() == self._g else None
  13. class CGenCountMixed(MR):
  14. def __init__(self, seuil, g):
  15. MR.__init__(self)
  16. self._seuil = seuil
  17. self._g = g
  18. def reduce_init(self):
  19. return vector(ZZ, self._g)
  20. def roots(self):
  21. return [nm.Full]
  22. def children(self, x):
  23. return x.children() if x.genus() < self._seuil else []
  24. def map_function(self, x):
  25. if x.genus() < self._seuil:
  26. res = vector(ZZ, self._g)
  27. res[x.genus()] = 1
  28. return res
  29. # print "start"
  30. res = x.walk_children(self._g)
  31. # print "end"
  32. return vector(ZZ, res)
  33. class CGen(CGenCount):
  34. def __init__(self, g):
  35. MR.__init__(self)
  36. self._g = g
  37. def roots(self):
  38. return [nm.Full]
  39. def children(self, x):
  40. return x.children() if x.genus() < self._g else []
  41. def post_process(self, x):
  42. return x if x.genus() == self._g else None
  43. def reduce_init(self):
  44. return []
  45. def map_function(self, x):
  46. return [x]
  47. # def cgen(g):
  48. # calc = MR(
  49. # roots=[nm.Full],
  50. # children=lambda x : x.children() if x.genus() < g else [],
  51. # post_process=lambda x : x if x.genus() == g else None,
  52. # reduce_init=[],
  53. # map_function=lambda x : [x]
  54. # )
  55. # return calc.run()