Ask Your Question
3

failure to compile cython .pyx when cimporting some function from sage

asked 2021-08-24 17:17:33 +0100

pierre gravatar image

updated 2021-08-25 09:47:21 +0100

Hello,

I am working on a Sage graph project, and for optimization, I have chosen to move it to Cython. The code compiles just fine as is, but for further optimization I will need to use a union find data structure in my cdef function. So far, I was using DisjointSet from sage.sets.disjoint_set in a separate function: my issue is I do not know how to cdef such an object.

My initial attempt to solve this was to cimport the disjoint set class from the sage/sets/disjoint_set.pyx file, and use it to cdef.

This would in summary be something like this :

...

from sage.sets.disjoint_set cimport DisjointSet_of_hashables

cdef DisjointSet_of_hashables D

D = DisjointSet(10)

...

Though this does not compile : I get an error related to a library (that I assumed was included in the install of Sage). Just in case it was not, I manually installed GAP (which did not solve the problem).

/usr/bin/ld : ne peut trouver -lgap
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-g++' failed with exit status 1

This message is partly in French but it translates exactly to

/usr/bin/ld: cannot find -lgap

I believe this is mostly likely due to me misunderstanding how to import a class from the Sage Cython files. I had a similar problem when trying to work with bitsets (although the error was on the library PARI instead of GAP).

In case it is relevant, I am working on Ubuntu 20.04, installed Sage with apt (Sage version is 9.0).

Thank you in advance for any help.

Pierre

edit retag flag offensive close merge delete

Comments

1

Welcome to Ask Sage! Thank you for your question!

slelievre gravatar imageslelievre ( 2021-08-24 17:45:41 +0100 )edit

On ne peut pas cimporter quelque chose qui est une def. Ca marche seulement pour les cdef.

FrédéricC gravatar imageFrédéricC ( 2021-08-24 18:18:58 +0100 )edit

Merci pour votre réponse Frédéric, effectivement j'ai mal renseigné mon exemple ; mais même si j'utilise ... cimport DisjointSet_Class (qui est bien cdef dans le fichier source) ou DisjointSet_of_hashables j'ai la même erreur.

Est-il possible de cdef un DisjointSet ?

pierre gravatar imagepierre ( 2021-08-25 09:46:27 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2021-08-25 15:24:47 +0100

pierre gravatar image

updated 2021-08-25 15:25:42 +0100

As an update, I have decided to make my own union find class in my code considering it is a fairly simple object - but I would still like an answer to this slighty more general question : was "from xyz cimport some_cdef_class" not the correct way to import a class from a sage cython file [included in the source code] ? Do I need to specify something more in my setup.py file perhaps ?

And most importantly, is this error due to my installation or to my code ?

edit flag offensive delete link more

Comments

Ca serait bien de ré-essayer avec une nouvelle installation propre de sage 9.4.

FrédéricC gravatar imageFrédéricC ( 2021-08-25 17:04:38 +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: 2021-08-24 17:17:33 +0100

Seen: 299 times

Last updated: Aug 25 '21