Opened 9 years ago
Closed 5 years ago
#9769 closed defect (duplicate)
symbolic function do not work with numpy.int64 arguments
Reported by: | maldun | Owned by: | burcin |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | symbolics | Keywords: | |
Cc: | Merged in: | ||
Authors: | Reviewers: | Jeroen Demeyer | |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
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
Change History (11)
comment:1 Changed 9 years ago by
- Description modified (diff)
comment:2 follow-ups: ↓ 5 ↓ 8 Changed 9 years ago by
- Milestone set to sage-4.7.1
- Summary changed from Coercon problems to symbolic ring to symbolic function do not work with numpy.int64 arguments
comment:3 Changed 6 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:4 Changed 6 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:5 in reply to: ↑ 2 Changed 6 years ago by
- Description modified (diff)
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
comment:6 Changed 6 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:7 Changed 5 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:8 in reply to: ↑ 2 Changed 5 years ago by
comment:9 Changed 5 years ago by
- Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
- Status changed from new to needs_review
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
comment:10 Changed 5 years ago by
- Reviewers set to Jeroen Demeyer
- Status changed from needs_review to positive_review
comment:11 Changed 5 years ago by
- Resolution set to duplicate
- Status changed from positive_review to closed
Note that there is no coercion when you call
The
__call__()
function forsin
checks if the argument is a numpy array and calls the right numpy function on this input. See line 349 ofsage/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: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: