Ask Your Question

Revision history [back]

You can try using the fast_callable function which converts a symbolic function to a python (or Cython? or C?) function that takes advantage of the fast routines for compute (for example) sin(x) where the input x is a float.

Try:

sage: x,y,z = var('x,y,z')
sage: import numpy as np
sage: X=np.linspace(-1,1,10)
sage: Y,Z=X,X
sage: f(x,y,z)=x^2*sin(y)*z
sage: ff = fast_callable(f, vars=[x,y,z])
sage: ff(1,2,3)
3*sin(2)
sage: ff(X,Y,Z)
array([  8.41470985e-01,   3.30154145e-01,   9.04347369e-02,
         1.21183221e-02,   1.52102371e-04,   1.52102371e-04,
         1.21183221e-02,   9.04347369e-02,   3.30154145e-01,
         8.41470985e-01])

My first thought was to use fast_float instead, but that doesn't seem to work. Maybe someone more knowledgable can point out why.

You can try using the fast_callable function which converts a symbolic function to a python (or Cython? or C?) function that takes advantage of the fast routines for compute (for example) sin(x) where the input x is a float.

Try:

sage: x,y,z = var('x,y,z')
sage: import numpy as np
sage: X=np.linspace(-1,1,10)
sage: Y,Z=X,X
sage: f(x,y,z)=x^2*sin(y)*z
sage: ff = fast_callable(f, vars=[x,y,z])
sage: ff(1,2,3)
3*sin(2)
sage: ff(X,Y,Z)
array([  8.41470985e-01,   3.30154145e-01,   9.04347369e-02,
         1.21183221e-02,   1.52102371e-04,   1.52102371e-04,
         1.21183221e-02,   9.04347369e-02,   3.30154145e-01,
         8.41470985e-01])

My first thought was to use fast_float instead, but that doesn't seem to work. Maybe someone more knowledgable knowledgeable can point out why.