Ask Your Question

Saving compiled expressions

asked 2013-02-22 01:40:52 +0100

bolverk gravatar image

I have a large symbolic expression, such that converting it to fast callable takes more than a minute. After the conversion, evaluation is much faster than the symbolic evaluation. However, I don't know how to save the fast_callable so I could use it in other scripts. When I tried pickling it, I got the following error:

AttributeError: 'sage.ext.interpreters.wrapper_cdf.Wrapper_cdf' object has no attribute 'write'

Using sage's save and load methods, I was able to load it to another scipt, but when I tried to call it I got the ValueError.

Any help would be welcome.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-02-22 03:05:25 +0100

benjaminfjones gravatar image

I believe that fast_callable produces, and then compiles, C code under the hood; the object you get back from fast_callableis a wrapper around a foreign function call and hence can't be saved and restored by Python/Sage (see

On the other hand, you can have Sage (via sympy) generate C code for a function that provides evaluation of your expression on C doubles. I gave a short example of this on this question:

It may also be possible to convert your expression into a python function and send that through the Cython compiler to produce compiled C code with a direct interface in Sage... I don't know if that's possible in your situation or not.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-02-22 01:40:52 +0100

Seen: 240 times

Last updated: Feb 22 '13