ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 25 Aug 2021 17:04:38 +0200failure to compile cython .pyx when cimporting some function from sagehttps://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/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.
PierreTue, 24 Aug 2021 17:17:33 +0200https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/Comment by pierre for <p>Hello,</p>
<p>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 <code>cdef</code> function.
So far, I was using <code>DisjointSet</code> from <code>sage.sets.disjoint_set</code>
in a separate function: my issue is I do not know
how to <code>cdef</code> such an object.</p>
<p>My initial attempt to solve this was to <code>cimport</code>
the disjoint set class from the <code>sage/sets/disjoint_set.pyx</code> file,
and use it to <code>cdef</code>.</p>
<p>This would in summary be something like this : </p>
<pre><code>...
from sage.sets.disjoint_set cimport DisjointSet_of_hashables
cdef DisjointSet_of_hashables D
D = DisjointSet(10)
...
</code></pre>
<p>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).</p>
<pre><code>/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
</code></pre>
<p>This message is partly in French but it translates exactly to</p>
<pre><code>/usr/bin/ld: cannot find -lgap
</code></pre>
<p>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).</p>
<p>In case it is relevant, I am working on Ubuntu 20.04,
installed Sage with apt (Sage version is 9.0).</p>
<p>Thank you in advance for any help.</p>
<p>Pierre</p>
https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?comment=58675#post-id-58675Merci 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 ?Wed, 25 Aug 2021 09:46:27 +0200https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?comment=58675#post-id-58675Comment by FrédéricC for <p>Hello,</p>
<p>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 <code>cdef</code> function.
So far, I was using <code>DisjointSet</code> from <code>sage.sets.disjoint_set</code>
in a separate function: my issue is I do not know
how to <code>cdef</code> such an object.</p>
<p>My initial attempt to solve this was to <code>cimport</code>
the disjoint set class from the <code>sage/sets/disjoint_set.pyx</code> file,
and use it to <code>cdef</code>.</p>
<p>This would in summary be something like this : </p>
<pre><code>...
from sage.sets.disjoint_set cimport DisjointSet_of_hashables
cdef DisjointSet_of_hashables D
D = DisjointSet(10)
...
</code></pre>
<p>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).</p>
<pre><code>/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
</code></pre>
<p>This message is partly in French but it translates exactly to</p>
<pre><code>/usr/bin/ld: cannot find -lgap
</code></pre>
<p>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).</p>
<p>In case it is relevant, I am working on Ubuntu 20.04,
installed Sage with apt (Sage version is 9.0).</p>
<p>Thank you in advance for any help.</p>
<p>Pierre</p>
https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?comment=58663#post-id-58663On ne peut pas cimporter quelque chose qui est une def. Ca marche seulement pour les cdef.Tue, 24 Aug 2021 18:18:58 +0200https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?comment=58663#post-id-58663Comment by slelievre for <p>Hello,</p>
<p>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 <code>cdef</code> function.
So far, I was using <code>DisjointSet</code> from <code>sage.sets.disjoint_set</code>
in a separate function: my issue is I do not know
how to <code>cdef</code> such an object.</p>
<p>My initial attempt to solve this was to <code>cimport</code>
the disjoint set class from the <code>sage/sets/disjoint_set.pyx</code> file,
and use it to <code>cdef</code>.</p>
<p>This would in summary be something like this : </p>
<pre><code>...
from sage.sets.disjoint_set cimport DisjointSet_of_hashables
cdef DisjointSet_of_hashables D
D = DisjointSet(10)
...
</code></pre>
<p>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).</p>
<pre><code>/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
</code></pre>
<p>This message is partly in French but it translates exactly to</p>
<pre><code>/usr/bin/ld: cannot find -lgap
</code></pre>
<p>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).</p>
<p>In case it is relevant, I am working on Ubuntu 20.04,
installed Sage with apt (Sage version is 9.0).</p>
<p>Thank you in advance for any help.</p>
<p>Pierre</p>
https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?comment=58661#post-id-58661Welcome to Ask Sage! Thank you for your question!Tue, 24 Aug 2021 17:45:41 +0200https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?comment=58661#post-id-58661Answer by pierre for <p>Hello,</p>
<p>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 <code>cdef</code> function.
So far, I was using <code>DisjointSet</code> from <code>sage.sets.disjoint_set</code>
in a separate function: my issue is I do not know
how to <code>cdef</code> such an object.</p>
<p>My initial attempt to solve this was to <code>cimport</code>
the disjoint set class from the <code>sage/sets/disjoint_set.pyx</code> file,
and use it to <code>cdef</code>.</p>
<p>This would in summary be something like this : </p>
<pre><code>...
from sage.sets.disjoint_set cimport DisjointSet_of_hashables
cdef DisjointSet_of_hashables D
D = DisjointSet(10)
...
</code></pre>
<p>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).</p>
<pre><code>/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
</code></pre>
<p>This message is partly in French but it translates exactly to</p>
<pre><code>/usr/bin/ld: cannot find -lgap
</code></pre>
<p>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).</p>
<p>In case it is relevant, I am working on Ubuntu 20.04,
installed Sage with apt (Sage version is 9.0).</p>
<p>Thank you in advance for any help.</p>
<p>Pierre</p>
https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?answer=58678#post-id-58678As 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 ?Wed, 25 Aug 2021 15:24:47 +0200https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?answer=58678#post-id-58678Comment by FrédéricC for <p>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 ? </p>
<p>And most importantly, is this error due to my installation or to my code ?</p>
https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?comment=58681#post-id-58681Ca serait bien de ré-essayer avec une nouvelle installation propre de sage 9.4.Wed, 25 Aug 2021 17:04:38 +0200https://ask.sagemath.org/question/58659/failure-to-compile-cython-pyx-when-cimporting-some-function-from-sage/?comment=58681#post-id-58681