On Nov 26, 2007, at 8:23 PM, William Stein wrote: >> >> See >> >> http://sagetrac.org/sage_trac/attachment/ticket/1189/sympy- >> coerce.patch >> >> This on top of 2.8.14 + sympy.patch works great. (I wasn't able to >> cleanly apply sympy2.patch which looks like it had some useful non- >> coercion stuff in there as well.) I'm curious about your infinite >> recursion bug for looking up the _sage_ attribute... > > This is getting discussed to death but wouldn't it make more sense > to replace: > > if not PY_TYPE_CHECK(x, SageObject) or not PY_TYPE_CHECK(y, > SageObject): > x = x._sage_() > y = y._sage_() > return self.canonical_coercion_c(x, y) > > by > > cdef bint tx = PY_TYPE_CHECK(x, SageObject) > cdef bint ty = PY_TYPE_CHECK(y, SageObject) > > if not tx or not ty: > x = x if tx else x._sage_() > y = y if ty else x._sage_() > return self.canonical_coercion_c(x, y) > > Since otherwise you're very likely calling _sage_() on a sage > object (in your > version of the code).
Yes, this would be a bit faster, and could even be optimized further knowing that exactly one of x and y is a non-sage object. However, for sage objects the _sage_ method is fairly fast (return self, though it is a python call), probably dwarfed by the other's _sage_ method. --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---