On Saturday, April 22, 2017 at 10:47:48 AM UTC+1, Volker Braun wrote:
>
> There is this:
>
> sage: import numpy as np
> sage: cm = sage.structure.element.coercion_model
> sage: cm.explain(polygen(RR), np.float32('1.5'), operator.mul)
> Action discovered.
>     Right scalar multiplication by Real Double Field on Univariate 
> Polynomial Ring in x over Real Field with 53 bits of precision
>     with precomposition on right by Native morphism:
>       From: Set of Python objects of type 'numpy.float32'
>       To:   Real Double Field
> Result lives in Univariate Polynomial Ring in x over Real Field with 53 
> bits of precision
> Univariate Polynomial Ring in x over Real Field with 53 bits of precision
>

Thanks! It seems that cm.explain() lies in this case, i.e., the action is 
actually computed in a different way!!!
Indeed:

sage: import numpy as np
sage: x=polygen(RealField())
sage: np.float32('1.5')*x
/usr/home/dima/Sage/sage/src/bin/sage-ipython:1: RuntimeWarning: invalid 
value encountered in multiply
  #!/usr/bin/env python
1.50000000000000*x
sage: cm = sage.structure.element.get_coercion_model()
sage: cm.explain(np.float32('1.5'), x, operator.mul)
Action discovered.
    Left scalar multiplication by Real Double Field on Univariate 
Polynomial Ring in x over Real Field with 53 bits of precision
    with precomposition on left by Native morphism:
      From: Set of Python objects of type 'numpy.float32'
      To:   Real Double Field
Result lives in Univariate Polynomial Ring in x over Real Field with 53 
bits of precision
Univariate Polynomial Ring in x over Real Field with 53 bits of precision
sage: RDF(np.float32('1.5'))*x
1.50000000000000*x

that is, cm.explain tells me that   np.float32('1.5')*x is computed by doing
RDF(np.float32('1.5'))*x

But this is not the case, as RDF(np.float32('1.5'))*x does not produce any 
numpy warnings, whereas
np.float32('1.5')*x does.

Then I went digging for  the place which is supposed to do apply RDF(), and 
tried to break  it:

--- a/src/sage/structure/coerce.pyx
+++ b/src/sage/structure/coerce.pyx
@@ -231,7 +231,8 @@ cpdef py_scalar_to_element(x):
             return Integer(x)
         elif isinstance(x, numpy.floating):
             from sage.rings.real_double import RDF
-            return RDF(x)
+           # return RDF(x)
+            return RDF(42)
         elif isinstance(x, numpy.complexfloating):
             from sage.rings.complex_double import CDF
             return CDF(x)

but to no avail, 1.5 does not get replaced by 42.0 in the answer.

It seems that this part of coersion is broken in the sense that it does 
something rogue,
not prescribed by the framework---and it has nothing to do with clang (I 
also tried this "patch" in
a usual configuration).





>
> On Saturday, April 22, 2017 at 11:01:52 AM UTC+2, Dima Pasechnik wrote:
>>
>> Is there a "normal" way to trace all the coersion/conversion steps for a 
>> given Sage expression?
>> If not, there should be one, IMHO (otherwise it's always a huge guessing 
>> game for this sort of issues)
>>
>

-- 
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 https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to