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
:
With
import
:Compiling essai.spyx... Traceback (most recent call last): File "/home/bruno/Software/sage/src/bin/sage-run-cython", line 8, in <module> s = load_cython(sys.argv.pop(1)) File "/home/bruno/Software/sage/local/lib/python2.7/site-packages/sage/repl/load.py", line 65, in load_cython 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
With
cimport
, I get also aRuntimeError
, 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)?