Ask Your Question

# Revision history [back]

What about :

sage: import numpy
sage: my_exp=integral(sin(x),x)
sage: f=fast_callable(my_exp.substitute_function({sin:numpy.sin, cos:numpy.cos}), vars=[x])
sage: z=numpy.linspace(0,10,5)
sage: %time f(z)
CPU times: user 47 µs, sys: 0 ns, total: 47 µs
Wall time: 51.5 µs
array([-1.        ,  0.80114362, -0.28366219, -0.34663532,  0.83907153])
sage: lz=list(map(SR, z))
sage: time list(map(sin, lz))
CPU times: user 154 µs, sys: 0 ns, total: 154 µs
Wall time: 159 µs
[0,
0.5984721441039564,
-0.9589242746631385,
0.9379999767747389,
-0.5440211108893698]


A "general sage-numpy dictionary" could be prepared and used at will (could even be packaged or Sage patched to include it).

Alternativelty, fast_callable could be adapted to accept sage's equivalent of standard numpy functions...

HTH,

What about :

sage: import numpy
sage: my_exp=integral(sin(x),x)
sage: f=fast_callable(my_exp.substitute_function({sin:numpy.sin, cos:numpy.cos}), vars=[x])
sage: z=numpy.linspace(0,10,5)
sage: %time f(z)
CPU times: user 47 µs, sys: 0 ns, total: 47 µs
Wall time: 51.5 µs
array([-1.        ,  0.80114362, -0.28366219, -0.34663532,  0.83907153])
sage: lz=list(map(SR, z))
sage: time list(map(sin, lz))
CPU times: user 154 µs, sys: 0 ns, total: 154 µs
Wall time: 159 µs
[0,
0.5984721441039564,
-0.9589242746631385,
0.9379999767747389,
-0.5440211108893698]


A "general sage-numpy dictionary" could be prepared and used at will (could even be packaged or Sage patched to include it).

Alternativelty, fast_callable could be adapted to accept sage's equivalent of standard numpy functions...functions, for example by buildind a Sage->numpy [ExpressionTreeWalker](https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression_conversions.html. (a reveres numpy->Sage converter might be harder to build...)...

HTH,