Ask Your Question
0

Saving compiled expressions

asked 2013-02-21 18:40:52 -0500

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
1

answered 2013-02-21 20:05:25 -0500

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 http://docs.python.org/2/library/pick...).

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:

http://ask.sagemath.org/question/366/...

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

Stats

Asked: 2013-02-21 18:40:52 -0500

Seen: 74 times

Last updated: Feb 21 '13