Hi all, I am trying to clean up, categorify and upload my old code for wrapping GAP conjugacy classes into Sage. Following the suggestion from Nicolas Thiery, I have two main classes ConjugacyClass(Parent) for the generic methods and ConjugacyClassGAP(ConjugacyClass) for wrapping GAP methods. In particular, the generic method for computing the set of all the elements in a conjugacy class gets overridden by the fastest GAP method when available.
As of now, the GAP wrapper for computing this sets may fail due to some issues when converting GAP matrix groups into Sage groups, so I would like the ConjugacyClassGAP.set() method to fall back to ConjugacyClass.set() method, but this fails when the method in the base category is cached. Here is a stripped down version of my code (I only include the __init__ and set methods): class ConjugacyClass(Parent): def __init__(self, group, element): self._parent = group self._representative = element Parent.__init__(self) @cached_method def set(self): from sage.sets.set import Set if self._parent.is_finite(): g = self._representative G = self._parent return Set(x*g*x**(-1) for x in G) else: raise NotImplementedError, "Listing the elements of conjugacy \ classes is not implemented for infinite groups!" class ConjugacyClassGAP(ConjugacyClass): def __init__(self, group, element): try: self._gap_group = group._gap_() self._gap_representative = element._gap_() ConjugacyClass.__init__(self,group, element) except: raise TypeError, "The group %s cannot be defined as a GAP group"%group @cached_method def set(self): """ from sage.sets.set import Set try: cc = self._gap_group.ConjugacyClass(self._gap_representative).AsList().sage() return Set([self._parent(x) for x in cc]) except NotImplementedError: # If GAP doesn't work, fall back to naive method return ConjugacyClass.set(self) # <-- THIS IS THE TROUBLING CALL! the problem is with the last line (the fallback method). If I leave it like this then sage complains about the number of arguments in the set method: sage: F = GF(5) sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] sage: H = MatrixGroup(gens) sage: h = H(matrix(F,2,[1,2, -1, 1])) sage: C = ConjugacyClassGAP(H,h) sage: C.set() ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (396, 0)) ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (396, 0)) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /Users/javier/<ipython console> in <module>() /Applications/sage/local/lib/python2.6/site-packages/sage/misc/ cachefunc.pyc in __call__(self, *args, **kwds) 553 return self.cache[k] 554 except KeyError: --> 555 w = self._cachedmethod._instance_call(self._instance, *args, **kwds) 556 self.cache[k] = w 557 return w /Applications/sage/local/lib/python2.6/site-packages/sage/misc/ cachefunc.pyc in _instance_call(self, inst, *args, **kwds) 776 777 """ --> 778 return self._cachedfunc.f(inst, *args, **kwds) 779 780 def _get_instance_cache(self, inst): /Applications/sage/local/lib/python2.6/site-packages/sage/groups/ conjugacy_classes.pyc in set(self) 300 try: 301 cc = self._gap_group.ConjugacyClass(self._gap_representative).AsList().sage() 302 return Set([self._parent(x) for x in cc]) 303 except NotImplementedError: # If GAP doesn't work, fall back to naive method --> 304 return ConjugacyClass.set(self) /Applications/sage/local/lib/python2.6/site-packages/sage/misc/ cachefunc.pyc in __call__(self, *args, **kwds) 553 return self.cache[k] 554 except KeyError: --> 555 w = self._cachedmethod._instance_call(self._instance, *args, **kwds) 556 self.cache[k] = w 557 return w /Applications/sage/local/lib/python2.6/site-packages/sage/misc/ cachefunc.pyc in _instance_call(self, inst, *args, **kwds) 776 777 """ --> 778 return self._cachedfunc.f(inst, *args, **kwds) 779 780 def _get_instance_cache(self, inst): TypeError: set() takes exactly 1 argument (2 given) If I remove the @cached_method decorator from the base class (ConjugacyClass) then the fallback works perfectly: age: F = GF(5) sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] sage: H = MatrixGroup(gens) sage: h = H(matrix(F,2,[1,2, -1, 1])) sage: C = ConjugacyClassGAP(H,h) sage: C.set() {[3 2] [2 4], [0 1] [2 2], [3 4] [1 4], [0 3] [4 2], [1 2] [4 1], [2 1] [2 0], [4 1] [4 3], [4 4] [1 3], [2 4] [3 0], [1 4] [2 1], [3 3] [3 4], [2 3] [4 0], [0 2] [1 2], [1 3] [1 1], [4 3] [3 3], [4 2] [2 3], [0 4] [3 2], [1 1] [3 1], [2 2] [1 0], [3 1] [4 4]} All my testing has been done in Sage 4.7.2 in a Mac OS-X 10.6.8 Is this a (known) problem with the cached_method decorator, or am I doing something wrong? Cheers, Javier -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org