Thanks, William.
I don't know why I didn't try cimport on that other example; that
certainly works with Rational.
But I shouldn't have simplified the example to that level. What I
*really* want to cdef is MPolynomial_libsingular. Something like this:
from sage.rings.polynomial.multi_polynomial_libsingular cimport
MPolynomial_libsingular
cpdef MPolynomial_libsingular add(MPolynomial_libsingular a,
MPolynomial_libsingular b):
return a+b
But I get all kinds of errors. First a bunch like this:
-------------------------
In file included from _Users_user_test_import_pyx_1.c:206:
/Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/
local/include/factory.h:29:20: error: iostream: No such file or
directory
In file included from /Applications/Sage-4.6.2-OSX-64bit-10.6.app/
Contents/Resources/sage/local/include/factory.h:51,
from _Users_user_test_import_pyx_1.c:206:
/Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/
local/include/templates/ftmpl_array.h:19: error: expected ‘=’, ‘,’,
‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
/Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/
local/include/templates/ftmpl_array.h:43: error: expected ‘=’, ‘,’,
‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
-------------------------
then more of other types.
john
On Jul 24, 10:34 pm, William Stein <[email protected]> wrote:
> On Sunday, July 24, 2011, john_perry_usm <[email protected]> wrote:
> > What about not-the-notebook? :-) For example, I have the following
> > file, called test_rational.pyx:
>
> > from sage.rings.rational import Rational
>
> import ---> cimport ?!
>
>
>
>
>
>
>
>
>
>
>
> > 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
>
> --
> 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