Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

symbolic function do not work with numpy.int64 arguments #9769

Closed
sagetrac-maldun mannequin opened this issue Aug 19, 2010 · 7 comments
Closed

symbolic function do not work with numpy.int64 arguments #9769

sagetrac-maldun mannequin opened this issue Aug 19, 2010 · 7 comments

Comments

@sagetrac-maldun
Copy link
Mannequin

sagetrac-maldun mannequin commented Aug 19, 2010

There seems to be some problems with the coercion of some datatypes to the symbolic ring:

sage: cos(MatrixSpace(ZZ, 2)([1, 2, -4, 7]))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
.......
TypeError: cannot coerce arguments: no canonical coercion from Full MatrixSpace of 2 by 2 dense matrices over Integer Ring to Symbolic Ring

sage: import numpy
sage: vec = numpy.array([1,2])
sage: sin(vec)
array([ 0.84147098,  0.90929743])
sage: sin(vec[0])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
....
TypeError: cannot coerce arguments: no canonical coercion from <type 'numpy.int64'> to Symbolic Ring

Component: symbolics

Reviewer: Jeroen Demeyer

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

@sagetrac-maldun

This comment has been minimized.

@burcin
Copy link

burcin commented May 10, 2011

comment:2

Note that there is no coercion when you call

sage: import numpy
sage: vec = numpy.array([1,2])
sage: sin(vec)
array([ 0.84147098,  0.90929743])

The __call__() function for sin checks if the argument is a numpy array and calls the right numpy function on this input. See line 349 of sage/symbolic/function.pyx. We can handle other numpy types there.

We cannot work with matrices as numeric objects in symbolics. I suppose you expect the sin() function to be applied to each entry of the matrix. The apply_map() method should be used for this purpose:

sage: t = Matrix(ZZ, 2,2)
sage: t.randomize()
sage: t.apply_map(lambda x: sin(x))
[      0 -sin(1)]
[ sin(4)       0]

sage: x = PolynomialRing(RR, 'x').gen()
sage: sin(x)
<boom>

The problem here is really coercion, but it should be copied to another ticket (in the basic_arithmetic component):

The __call__() function of RR[x] doesn't conform to the generic definition. You should be able to give the parameters as a keyword argument as well. This should be made to work:

sage: R.<x> = RR[]
sage: (x^2+1)(x=5)
11

@burcin burcin added this to the sage-4.7.1 milestone May 10, 2011
@burcin burcin changed the title Coercon problems to symbolic ring symbolic function do not work with numpy.int64 arguments May 10, 2011
@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@rwst
Copy link

rwst commented Apr 22, 2014

comment:5

Replying to @burcin:

sage: x = PolynomialRing(RR, 'x').gen()
sage: sin(x)
<boom>

The problem here is really coercion, but it should be copied to another ticket (in the basic_arithmetic component):

Incidentally the same with power series is part of #16197.

The __call__() function of RR[x] doesn't conform to the generic definition. You should be able to give the parameters as a keyword argument as well. This should be made to work:

sage: R.<x> = RR[]
sage: (x^2+1)(x=5)
11

Edit: confused poly with series, sorry

@rwst

This comment has been minimized.

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@rwst
Copy link

rwst commented Nov 10, 2014

comment:8

Replying to @burcin:

The __call__() function of RR[x] doesn't conform to the generic definition. You should be able to give the parameters as a keyword argument as well. This should be made to work:

sage: R.<x> = RR[]
sage: (x^2+1)(x=5)
11

This is now #17311

@videlec
Copy link
Contributor

videlec commented Mar 28, 2015

comment:9

Hello,

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

sage: import numpy
sage: cos(numpy.int32('12'))
cos(12)
sage: cos(numpy.float32('1.1'))
0.453596100177538

@videlec videlec removed this from the sage-6.4 milestone Mar 28, 2015
@jdemeyer
Copy link

Reviewer: Jeroen Demeyer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants