On Saturday, January 4, 2014 11:29:33 AM UTC-8, vdelecroix wrote: > > I do not see how we can make the coercion numpy int/Sage Integer works > if numpy is not loaded at startup time...
It seems more an issue of *ensuring* that coercion does *not* work, because we're communicating with a non-sage type here. An indication that there is probably some special case that is foiling correct behaviour comes from the fact that np.float32, np.float and np.float128 all do seem to work. Compare: sage: c=get_coercion_model() sage: import numpy as np sage: c.canonical_coercion(1j,np.float(1)) (1.00000000000000*I, 1.00000000000000) sage: c.canonical_coercion(1j,np.float32(1)) TypeError: no common canonical parent for objects with parents: ... sage: c.canonical_coercion(1j,np.float64(1)) (0.0, 1.0) sage: c.canonical_coercion(1j,np.float128(1)) TypeError: no common canonical parent for objects with parents: ... As you can see, it's just float64 that does the bad thing: sage: parent(1j+np.float32(1)) <type 'numpy.complex128'> sage: parent(1j+np.float128(1)) <type 'numpy.complex256'> sage: parent(1j+np.float64(1)) <type 'numpy.float64'> sage: parent(1j+np.float(1)) Complex Field with 53 bits of precision As you can see, sage does seem to know how to coerce np.float into its own complex field. The ones where no coercion is known end up using __radd__ on the numpy type. It's just that somewhere in sage, numpy.float64 apparently is deemed to be an appropriate parent for 1j to be coerced in. So it seems float64 is recognized *too much* (and in the wrong way), not too little. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/groups/opt_out.