# Using MPolynomial_libsingular in Cython code

I wrote some Sage code to deal with multivariate polynomials (over QQ say). In order to increase performances, I tried to cythonize the file, and in particular to add static types. I was able to add types for basic types (such as int or list¹) but I am not able to use the type MPolynomial_libsingular. I tried to import Mpolynomial_libsingular with either import or cimport. A minimal example (file named essai.spyx):

from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomial_libsingular # or cimport
cpdef MPolynomial_libsingular dummy(MPolynomial_libsingular p):
return p


I give below the result I get when I call sage essai.spyx, first with import and then with cimport:

1. With import:

Compiling essai.spyx...
Traceback (most recent call last):
File "/home/bruno/Software/sage/src/bin/sage-run-cython", line 8, in <module>
mod, dir = cython(name, compile_message=True, use_cache=True)
File "/home/bruno/Software/sage/local/lib/python2.7/site-packages/sage/misc/cython.py", line 469, in cython
raise RuntimeError("Error converting {} to C:\n{}\n{}".format(filename, log, err))
RuntimeError: Error converting essai.spyx to C:

Error compiling Cython file:
------------------------------------------------------------
...
include "cysignals/signals.pxi"  # ctrl-c interrupt block support
include "stdsage.pxi"

include "cdefs.pxi"
from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomial_libsingular
cpdef MPolynomial_libsingular dummy(MPolynomial_libsingular p):
^
------------------------------------------------------------

_home_bruno_Recherche_Sage_LinearFactors_essai_spyx_0.pyx:7:6: 'MPolynomial_libsingular' is not a type identifier

Error compiling Cython file:
------------------------------------------------------------
...
include "cysignals/signals.pxi"  # ctrl-c interrupt block support
include "stdsage.pxi"

include "cdefs.pxi"
from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomial_libsingular
cpdef MPolynomial_libsingular dummy(MPolynomial_libsingular p):
^
------------------------------------------------------------

_home_bruno_Recherche_Sage_LinearFactors_essai_spyx_0.pyx:7:36: 'MPolynomial_libsingular' is not a type identifier

2. With cimport, I get also a RuntimeError, but with many more errors. You can read the complete log file. Here is an excerpt:

In file included from /home/bruno/Software/sage/local/include/factory/factory.h:45:0,
from /home/bruno/Software/sage/local/include/factor.h:8,
from _home_bruno_Recherche_Sage_LinearFactors_essai_spyx_0.c:249:
/home/bruno/Software/sage/local/include/factory/templates/ftmpl_array.h:19:10: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
template <class T>
^


Question: What am I doing wrong, and what is the correct way of cythonizing such a file?

¹ An aside question: Is there a way to specify the type of elements in a list? Something like list<int> (this does not work)?

edit retag close merge delete

Sort by » oldest newest most voted

It should be a cimport and it works perfectly fine on my computer. From your log it seems that you have some weird things going on because of gmp.

For your aside question, you can not type the elements of a list. You can try arrays. Though they are more limited than lists.

more

Thanks. I'll try with a fresher install.

( 2016-05-12 10:10:10 -0600 )edit