Hi Luis, On 18 Mai, 00:45, Luis Finotti <luis.fino...@gmail.com> wrote: > The problem is that it seems that it creates a loop, as in > witt_element.py I need witt.py and vice-versa. That's why at the > bottom of witt_element I had > > class RingOfWittVectors(RingOfWittVectors): > # def _call_(self,data,parent,coerce=True): > # return WittVector(data,parent,coerce) > Element=WittVector
I see. But then, when you create your R, you should at least import RingOfWittVectors from witt_element, not from witt. Not sure if that would solve the problem. In any case, I think there are better ways of doing the same. For example, if you want to do source inspection (like R??), you wouldn't just like to see the few lines above, but you would like to see the actual definition of the class (namely the one in witt.py). > If I follow your advice, I get: > > ImportError Traceback (most recent call last) > > /usr/local/sage-5.0.beta4/local/lib/python2.7/site-packages/IPython/ipmaker.pyc > in force_import(modname, force_reload) > 61 reload(sys.modules[modname]) > 62 else: > ---> 63 __import__(modname) > 64 > 65 > > /usr/local/sage-5.0.beta4/local/bin/ipy_profile_sage.py in <module>() > 5 preparser(True) > 6 > ----> 7 import sage.all_cmdline > 8 sage.all_cmdline._init_cmdline(globals()) > 9 > > /usr/local/sage-5.0.beta4/local/lib/python2.7/site-packages/sage/all_cmdline.py > in <module>() > 12 try: > 13 > ---> 14 from sage.all import * > 15 from sage.calculus.predefined import x > 16 preparser(on=True) > > /usr/local/sage-5.0.beta4/local/lib/python2.7/site-packages/sage/all.py > in <module>() > 72 from sage.libs.all import * > 73 > ---> 74 from sage.rings.all import * > 75 from sage.matrix.all import * > 76 > > /usr/local/sage-5.0.beta4/local/lib/python2.7/site-packages/sage/rings/all.py > in <module>() > 72 > 73 # p-adic field > ---> 74 from padics.all import * > 75 from padics.padic_printing import _printer_defaults as padic_printing > 76 > > /usr/local/sage-5.0.beta4/local/lib/python2.7/site-packages/sage/rings/padics/all.py > in <module>() > 8 #from sage.rings.padics.witt import Big_Witt_Ring > 9 #from sage.rings.padics.witt_element import Big_Witt_Vector > ---> 10 from sage.rings.padics.witt import RingOfWittVectors > 11 from sage.rings.padics.witt_element import WittVector > 12 > > /usr/local/sage-5.0.beta4/local/lib/python2.7/site-packages/sage/rings/padics/witt.py > in <module>() > 24 #from sage.structure.factory import UniqueFactory > 25 from sage.categories.commutative_rings import CommutativeRings > ---> 26 from witt_element import WittVector > 27 > 28 class RingOfWittVectors(CommutativeRing): > > /usr/local/sage-5.0.beta4/local/lib/python2.7/site-packages/sage/rings/padics/witt_element.py > in <module>() > 23 from sage.structure.element import CommutativeRingElement > 24 # from sage.structure.factory import UniqueFactory > ---> 25 from sage.rings.padics.witt import RingOfWittVectors > 26 > 27 > > ImportError: cannot import name RingOfWittVectors > Error importing ipy_profile_sage - perhaps you should run %upgrade? > WARNING: Loading of ipy_profile_sage failed. As David says, in order to avoid the circular import error, one should try to break the import cycle. It seems to me that there is no need to import RingOfWittVectors into witt_element.py, and so it would easily possible to import WittVector into witt.py and use it to provide RingOfWittVectors.Element. Details. In witt_element.py, you use RingOfWittVectors in several ways: 1. def is_witt_vector(x): return isinstance(x,RingOfWittVectors) What is that supposed to do? If you want to test if x is a Witt vector, shouldn't you test whether isinstance(x, WittVector)? The RingOfWittVectors is certainly not a Witt vector by itself, isn't it? And if that function really does the right thing, why don't you define the function is_witt_vector in witt.py, rather than in witt_element.py? 2. In WittVector.__init__: if isinstance(data, RingOfWittVectors): data = data._list So, you really want to create a single vector out of some data obtained from a *ring* of vectors? Let R be a ring of witt vectors. With your current code, you seem to allow WittVector(R) which is supposed to create a particular, canonical, element of R. Is that intended (sorry, I don't know the mathematics behind Witt vectors)? Then, why not work the other way around and define a method of RingOfWittVectors returning that canonical element, perhaps even with caching? Hence, in witt.py: class RingOfWittVectors(CommutativeRing): Element = WittVector ... @cached_method def canonical_element(self): return self(self._list) (of course, you need to "from sage.misc.cachefunc import cached_method") It thus seems that you only need to import WittVector into witt.py, but you don't need to import RingOfWittVectors into witt_element.py. And, by the why, if you would import RingOfWittVectors in WittVector.__init__ (not on module level), there would be a slow-down. Best regards, Simon -- 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