What about not-the-notebook? :-) For example, I have the following
file, called test_rational.pyx:
from sage.rings.rational import Rational
cpdef Rational add(a, b):
return a + b
When I try to attach it to sage, I get: [lots of output removed]
_home_perry_test_rational_pyx_1.pyx:8:6: 'Rational' is not a type
identifier
I get the same error with
from sage.rings.rational import Rational
cpdef Rational add(a, b):
cdef Rational c
c = a + b
return c
john
On Jul 24, 7:53 pm, William Stein <[email protected]> wrote:
> On Sun, Jul 24, 2011 at 5:47 PM, john_perry_usm <[email protected]> wrote:
> > I want to declare c to be of the type defined by the class Rational.
> > I'm sure this is easy, but what I want to do is this:
>
> > from sage.rings.rational import Rational
> > cdef Rational c
>
> > but that doesn't work. Neither does cimport (which I found in a file
> > somewhere, albeit commented out, and now I know why).
>
> Actually,
>
> from sage.rings.rational cimport Rational
>
> *does* work, but you have to put it in the right place. As an illustration,
> try this in the notebook:
>
> %cython
>
> from sage.rings.rational cimport Rational
>
> def f(Rational c, s):
> cdef Rational dummy = Rational('2/3') # just for illustrative purposes
> print dummy
> mpq_set_str(c.value, s, 10)
>
> Then in the next cell put this:
>
> c = 8/7
> f(c, '5/3')
> print c
>
> -- William
>
>
>
> > regards
> > john perry
>
> > --
> > 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
>
> --
> William Stein
> Professor of Mathematics
> University of Washingtonhttp://wstein.org
--
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