How to compile sparse graph backend with c++

28 views
Skip to first unread message

jonatha...@googlemail.com

unread,
Jan 8, 2021, 10:31:48 AM1/8/21
to sage-devel
Prepending
# distutils: language = c++
to src/sage/graphs/base/sparse_graph.pyx makes my compilation crash.

Does anyone know, how to fix it. I'm on develop and I'm getting the following compilation error. Does anyone know how to resolve this? Thank you.

Jonathan

(I want to see whether cpp set would be a reasonable alternative to our private tree implementation.)

[sagelib-9.3.beta5] [3/3] gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wno-unused -march=native -O2 -g -march=native -O3 -g -fPIC -I./sage/data_structures -I/srv/public/kliem/sage/local/lib/python3.8/site-packages/cysignals -I./sage/cpython -Isage/data_structures -I/srv/public/kliem/sage/build/pkgs/sagelib/src -I/srv/public/kliem/sage/local/include/python3.8 -I/srv/public/kliem/sage/local/lib/python3.8/site-packages/numpy/core/include -Ibuild/cythonized -I/srv/public/kliem/sage/local/include/python3.8 -c build/cythonized/sage/graphs/base/sparse_graph.cpp -o build/temp.linux-x86_64-3.8/build/cythonized/sage/graphs/base/sparse_graph.o -fno-strict-aliasing -DCYTHON_CLINE_IN_TRACEBACK=1 -std=c++11
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp: In function ‘PyObject* __pyx_f_4sage_6graphs_4base_12sparse_graph_11SparseGraph_add_arc_label(__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraph*, int, int, int, __pyx_opt_args_4sage_6graphs_4base_12sparse_graph_11SparseGraph_add_arc_label*)’:
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:6543:94: error: cannot convert ‘__pyx_obj_4sage_6graphs_4base_7c_graph_CGraph*’ to ‘__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraph*’
[sagelib-9.3.beta5]    __pyx_t_6 = __pyx_f_4sage_6graphs_4base_12sparse_graph_11SparseGraph_add_arc_label_unsafe(((struct __pyx_obj_4sage_6graphs_4base_7c_graph_CGraph *)__pyx_v_self), __pyx_v_u, __pyx_v_v, __pyx_v_l); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 917, __pyx_L1_error)
[sagelib-9.3.beta5]                                                                                              ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:6280:155: note:   initializing argument 1 of ‘int __pyx_f_4sage_6graphs_4base_12sparse_graph_11SparseGraph_add_arc_label_unsafe(__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraph*, int, int, int)’
[sagelib-9.3.beta5]  static int __pyx_f_4sage_6graphs_4base_12sparse_graph_11SparseGraph_add_arc_label_unsafe(struct __pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraph *__pyx_v_self, int __pyx_v_u, int __pyx_v_v, int __pyx_v_l) {
[sagelib-9.3.beta5]                                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp: In function ‘PyObject* __pyx_pf_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend_4has_edge(__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend*, PyObject*, PyObject*, PyObject*)’:
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:10771:105: error: cannot convert ‘__pyx_obj_4sage_6graphs_4base_7c_graph_CGraphBackend*’ to ‘__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend*’
[sagelib-9.3.beta5]    __pyx_t_2 = __pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend__has_labeled_edge_unsafe(((struct __pyx_obj_4sage_6graphs_4base_7c_graph_CGraphBackend *)__pyx_v_self), __pyx_v_u_int, __pyx_v_v_int, __pyx_v_l); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 1348, __pyx_L1_error)
[sagelib-9.3.beta5]                                                                                                         ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:2013:173: note:   initializing argument 1 of ‘int __pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend__has_labeled_edge_unsafe(__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend*, int, int, PyObject*)’
[sagelib-9.3.beta5]  static int __pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend__has_labeled_edge_unsafe(struct __pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend *__pyx_v_self, int __pyx_v_u_int, int __pyx_v_v_int, PyObject *__pyx_v_l); /* proto*/
[sagelib-9.3.beta5]                                                                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp: In function ‘int __pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend__has_labeled_edge_unsafe(__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend*, int, int, PyObject*)’:
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:10828:96: error: cannot convert ‘__pyx_obj_4sage_6graphs_4base_7c_graph_CGraphBackend*’ to ‘__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend*’
[sagelib-9.3.beta5]    __pyx_t_1 = ((PyObject *)__pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend_cg(((struct __pyx_obj_4sage_6graphs_4base_7c_graph_CGraphBackend *)__pyx_v_self))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1355, __pyx_L1_error)
[sagelib-9.3.beta5]                                                                                                ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:2023:201: note:   initializing argument 1 of ‘__pyx_obj_4sage_6graphs_4base_7c_graph_CGraph* __pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend_cg(__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend*)’
[sagelib-9.3.beta5]  static struct __pyx_obj_4sage_6graphs_4base_7c_graph_CGraph *__pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend_cg(struct __pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend *__pyx_v_self); /* proto*/
[sagelib-9.3.beta5]                                                                                                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp: In function ‘PyObject* __pyx_pf_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend_8set_edge_label(__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend*, PyObject*, PyObject*, PyObject*, int)’:
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:11440:97: error: cannot convert ‘__pyx_obj_4sage_6graphs_4base_7c_graph_CGraphBackend*’ to ‘__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend*’
[sagelib-9.3.beta5]      __pyx_t_4 = __pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend_new_edge_label(((struct __pyx_obj_4sage_6graphs_4base_7c_graph_CGraphBackend *)__pyx_v_self), __pyx_v_l); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 1429, __pyx_L1_error)
[sagelib-9.3.beta5]                                                                                                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:9841:163: note:   initializing argument 1 of ‘int __pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend_new_edge_label(__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend*, PyObject*)’
[sagelib-9.3.beta5]  static int __pyx_f_4sage_6graphs_4base_12sparse_graph_18SparseGraphBackend_new_edge_label(struct __pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraphBackend *__pyx_v_self, PyObject *__pyx_v_l) {
[sagelib-9.3.beta5]                                                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:11503:90: error: cannot convert ‘__pyx_obj_4sage_6graphs_4base_7c_graph_CGraph*’ to ‘__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraph*’
[sagelib-9.3.beta5]    __pyx_t_4 = __pyx_f_4sage_6graphs_4base_12sparse_graph_11SparseGraph_arc_label_unsafe(((struct __pyx_obj_4sage_6graphs_4base_7c_graph_CGraph *)((struct __pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraph *)__pyx_v_self->_cg)), __pyx_v_u_int, __pyx_v_v_int); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 1434, __pyx_L1_error)
[sagelib-9.3.beta5]                                                                                          ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[sagelib-9.3.beta5] build/cythonized/sage/graphs/base/sparse_graph.cpp:6689:151: note:   initializing argument 1 of ‘int __pyx_f_4sage_6graphs_4base_12sparse_graph_11SparseGraph_arc_label_unsafe(__pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraph*, int, int)’
[sagelib-9.3.beta5]  static int __pyx_f_4sage_6graphs_4base_12sparse_graph_11SparseGraph_arc_label_unsafe(struct __pyx_obj_4sage_6graphs_4base_12sparse_graph_SparseGraph *__pyx_v_self, int __pyx_v_u, int __pyx_v_v) {
[sagelib-9.3.beta5]                                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
[sagelib-9.3.beta5] error: command 'gcc' failed with exit status 1

jonatha...@googlemail.com

unread,
Jan 11, 2021, 5:28:47 AM1/11/21
to sage-devel
Super weird. I think it is a cython bug, but I'm not sure.

The problem seems to be that the parent class has the same method. I need to enforce the correct method
by

self.foo(u) -> SparseGraph.foo(self, u)

This seems to work (compiles and the doctests pass).

David Coudert

unread,
Jan 12, 2021, 3:56:19 AM1/12/21
to sage-devel
I have not tried yet, but isn't it due to the fact that some parts are compiled with C and others with C++ ?

jonatha...@googlemail.com

unread,
Jan 12, 2021, 4:05:16 AM1/12/21
to sage-devel
I tried to compile more things with C++ and things just got worse. But maybe I did it wrong, that is also possible.

Anyway, using sets as an alternative wasn't really sucessfull. It is a bit slower. Turns out the data structure is pretty good.
Reply all
Reply to author
Forward
0 new messages