loading programs created by Cython into notebook

1 view
Skip to first unread message

pong

unread,
Apr 24, 2008, 8:29:18 PM4/24/08
to sage-support
I have followed the SAGE program guide and create the function
sumsquares (one of the examples there). It works for the same session
of the notebook. My question is how can I use this faster version of
sumsquares in the future?

At the moment, I just want when I type, e.g. sumsquares(1000), in a
notebook cell, SAGE will run the complied code that was created.

I looked around from the reference manual and find something like
sage.server.support.cython_import... but it asks for a .pyx file. I
couldn't locate where it is. All I see are a .c and a .pyx.html files.

Please help
Thanks in advance

pong

unread,
Apr 26, 2008, 4:49:50 AM4/26/08
to sage-support
After digging around a little bit more I found something that works.

To load a python program into a worksheet, one can use

load "filename.py"

assuming your code is stored in the file with name filename.py.
Certainly you may need to specify the path where you save filename.py

To compile and then load a Python or C program to a notebook, one can

cython(open("home/sage/.sage/filename.spyx").read())

here assuming the file with name filename.spyx is located at the
directory home/sage/.sage/

note that filename.spyx can contain code in either C or python.

The SAGE tutorial describes the use of load and the use of
cython(open(...))
was discussed in this group under the title Problem to access C code

pong

unread,
Apr 27, 2008, 1:36:03 AM4/27/08
to sage-support
There is a typo in my previous post.

It should be /home/sage/.sage/filename.spyx

I forgot the / before home.
Reply all
Reply to author
Forward
0 new messages