sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.3k stars 449 forks source link

symbolic functions dont work with numpy.int32 #8949

Closed a8806e44-c4d4-4baf-918e-1f2679b05e2d closed 9 years ago

a8806e44-c4d4-4baf-918e-1f2679b05e2d commented 14 years ago
sage: import numpy
sage: a = numpy.array([1,2])
sage: type(a[0])
<type 'numpy.int32'>
sage: f(x) = x^2
sage: f(a[0])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
./sage-4.4.2/<ipython console> in <module>()

./sage-4.4.2/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.__call__ (sage/symbolic/expression.cpp:15476)()

./sage-4.4.2/local/lib/python2.6/site-packages/sage/symbolic/callable.pyc in _call_element_(self, _the_element, *args, **kwds)
    454         d = dict(zip(map(repr, self.arguments()), args))
    455         d.update(kwds)
--> 456         return SR(_the_element.substitute(**d))
    457
    458

./sage-4.4.2/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.substitute (sage/symbolic/expression.cpp:14850)()

./sage-4.4.2/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.coerce_in (sage/symbolic/expression.cpp:10193)()

./sage-4.4.2/local/lib/python2.6/site-packages/sage/structure/parent_old.so in sage.structure.parent_old.Parent._coerce_ (sage/structure/parent_old.c:3288)()

./sage-4.4.2/local/lib/python2.6/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.coerce (sage/structure/parent.c:6970)()

TypeError: no canonical coercion from <type 'numpy.int32'> to Callable function ring with arguments (x,)

CC: @jasongrout

Component: symbolics

Reviewer: Jeroen Demeyer

Issue created by migration from https://trac.sagemath.org/ticket/8949

jasongrout commented 14 years ago
comment:2

I think #8824 may have the solution for this.

5e15749f-ac25-4a4f-8d4a-caceb6ae86a4 commented 14 years ago
comment:3

computer pictures

videlec commented 9 years ago
comment:8

Hello,

I propose to close this as duplicates because of #18076. With the branch applied

sage: import numpy
sage: cos(numpy.float('12'))
0.8438539587324921

Though it is not perfect since the result is a Python float and not a numpy float.

Vincent

jdemeyer commented 9 years ago

Reviewer: Jeroen Demeyer