On Wed, Sep 14, 2011 at 3:01 PM, Rajeev Singh <[email protected]> wrote:
> Hi,
>
> The following examples compiles from the notebook
>
> %cython
> cimport sage.gsl.ode
> import sage.gsl.ode
> include 'gsl.pxi'
>
> cdef class van_der_pol(sage.gsl.ode.ode_system):
>    cdef double beta
>    def __cinit__(self, double beta=1.0):
>        self.beta = beta
>    cdef int c_f(self,double t, double *y,double *dydt):
>        dydt[0]=y[1]
>        dydt[1]=-y[0]-self.beta*y[1]*(y[0]*y[0]-1)
>        return GSL_SUCCESS
>    cdef int c_j(self, double t,double *y,double *dfdy,double *dfdt):
>        dfdy[0]=0
>        dfdy[1]=1.0
>        dfdy[2]=-2.0*10*y[0]*y[1]-1.0
>        dfdy[3]=-10*(y[0]*y[0]-1.0)
>        dfdt[0]=0
>        dfdt[1]=0
>        return GSL_SUCCESS
>
> However if I put it in a file vander.pyx (say) and use the following setup.py 
> -
>
> from distutils.core import setup
> from distutils.extension import Extension
> from Cython.Distutils import build_ext
>
> ext = Extension("vander", ["vander.pyx"],
>    include_dirs = ['/home/rajeev/bin/sage/devel/sage-main/sage/gsl/'])
>
> setup(ext_modules=[ext],
>      cmdclass = {'build_ext': build_ext})
>
>
> I get the following error -
>
> cdef class van_der_pol(sage.gsl.ode.ode_system):
>    ^
> ------------------------------------------------------------
>
> vander.pyx:10:5: 'ode_system' is not declared
>
>
> I guess the problem is with the setup.py. Can someone tell me how to do this?
>
> Thanks in advance.
> Rajeev
>

Hi,

Going through few source codes in Sage I was able to hack a small
script which does the job. The script is -


#!/home/rajeev/bin/sage/sage

import os
import sys

SAGE_ROOT = os.environ['SAGE_ROOT']

if len(sys.argv) != 2:
    sys.exit('commad usage: cython_sage_compile <filename>.pyx')

fname = sys.argv[1][:-4] #dropping the pyx subscript

cmd = """sage -cython -p --pre-import sage.all \\
-I'%(SAGE_ROOT)s/local/include/csage/' \\
-I'%(SAGE_ROOT)s/local/include/' \\
-I'%(SAGE_ROOT)s/local/include/python2.6/' \\
-I'%(SAGE_ROOT)s/local/lib/python2.6/site-packages/numpy/core/include' \\
-I'%(SAGE_ROOT)s/devel/sage/sage/ext/' \\
-I'%(SAGE_ROOT)s/devel/sage/' \\
-I'%(SAGE_ROOT)s/devel/sage/sage/gsl/' \\
%(fname)s.pyx""" %vars()
print cmd
print
os.system(cmd)

cmd = """gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -O3 -Wall \\
-Wstrict-prototypes -fPIC \\
-I'%(SAGE_ROOT)s/local/include/csage/' \\
-I'%(SAGE_ROOT)s/local/include/' \\
-I'%(SAGE_ROOT)s/local/include/python2.6/' \\
-I'%(SAGE_ROOT)s/local/lib/python2.6/site-packages/numpy/core/include' \\
-I'%(SAGE_ROOT)s/devel/sage/sage/ext/' \\
-I'%(SAGE_ROOT)s/devel/sage/' \\
-I'%(SAGE_ROOT)s/devel/sage/sage/gsl/' \\
-c %(fname)s.c -o %(fname)s.o -w -O2""" %vars()
print cmd
print
os.system(cmd)

cmd = """gcc -pthread -shared %(fname)s.o \
-L'%(SAGE_ROOT)s/local/lib' \
-lmpfr -lgmp -lgmpxx -lstdc++ -lpari -lm -lcurvesntl -lg0nntl -ljcntl \
-lrankntl -lgsl -lgslcblas -latlas -lntl -lcsage -lpython2.6 \
-o %(fname)s.so """ %vars()
print cmd
print
os.system(cmd)


This is for future reference.

Rajeev

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to