Opened 9 years ago
Last modified 6 years ago
#13098 new enhancement
Issue with NumPy, SciPy, cvxopt
Reported by: | kheyfboris | Owned by: | jason, jkantor |
---|---|---|---|
Priority: | major | Milestone: | sage-6.4 |
Component: | numerical | Keywords: | |
Cc: | Merged in: | ||
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
When You type in numbers into Sage, the pre-processor converts them to a base ring, which is unknown to NumPy?, SciPy? and cvxopt. The best solution to this is to redefine the types:
RealNumber=float Integer=int
But this solution only works in interpreter - since in a script - all numbers got converted to _sage_consts despite the claim of:
RealNumber=float Integer=int
So the following sage script:
#!/usr/bin/sage RealNumber=float Integer=int from cvxopt.base import matrix as m from cvxopt import solvers c = m([-4., -5.]) G = m([[2., 1., -1., 0.], [1., 2., 0., -1.]]) h = m([3., 3., 0., 0.]) sol = solvers.lp(c,G,h) print sol['x']
is converted to the following python script
# This file was *autogenerated* from the file ./1.sage. from sage.all_cmdline import * # import sage library _sage_const_4p = RealNumber('4.'); _sage_const_1p = RealNumber('1.'); _sage_const_0p = RealNumber('0.'); _sage_const_3p = RealNumber('3.'); _sage_const_2p = RealNumber('2.'); _sage_const_5p = RealNumber('5.')#!/usr/bin/sage RealNumber=float Integer=int from cvxopt.base import matrix as m from cvxopt import solvers c = m([-_sage_const_4p , -_sage_const_5p ]) G = m([[_sage_const_2p , _sage_const_1p , -_sage_const_1p , _sage_const_0p ], [_sage_const_1p , _sage_const_2p , _sage_const_0p , -_sage_const_1p ]]) h = m([_sage_const_3p , _sage_const_3p , _sage_const_0p , _sage_const_0p ]) sol = solvers.lp(c,G,h) print sol['x']
which gives error:
Traceback (most recent call last): File "./1.py", line 11, in <module> c = m([-_sage_const_4p , -_sage_const_5p ]) TypeError: invalid type in list
Change History (7)
comment:1 Changed 9 years ago by
comment:2 Changed 8 years ago by
- Milestone changed from sage-5.11 to sage-5.12
comment:3 Changed 7 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:4 Changed 7 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:5 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
comment:6 Changed 6 years ago by
Ah, this must be the thing that causes Brian to have problems too.
comment:7 Changed 6 years ago by
Note that for some reason this is actually in the FAQ. I don't know if that is good or bad.
Note: See
TracTickets for help on using
tickets.
So the solution:
for
NumPy
/SciPy
type issues (see here) doesn't work in a script executed bysage
. But it does in a script executed bysage -python
. But in a script executed bysage -python
– none of sage is working: for example^
does not stand for exponentiation any more. So this solution is no good for scripts.