Ask Your Question
0

Using MPolynomial_libsingular in Cython code

asked 2016-05-02 14:15:08 +0100

B r u n o gravatar image

updated 2016-05-04 11:09:49 +0100

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>
        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
    
  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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-05-11 15:06:49 +0100

vdelecroix gravatar image

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.

edit flag offensive delete link more

Comments

Thanks. I'll try with a fresher install.

B r u n o gravatar imageB r u n o ( 2016-05-12 17:10:10 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-05-02 14:15:08 +0100

Seen: 663 times

Last updated: May 11 '16