Compilation error with Weave inline
Hi, I recently moved from NetworkX to graph-tool and I am very impressed with the performance increase, good job! A bit for learning and also for speeding up a code that creates a graph dynamically, I am trying to implement a batch insertion function with Weave, but I am running into a compilation error. My knowledge of C++ is sketchy at best so please forgive if I am asking something really dumb -- though I suspect that the problem is more in the way graph_tool interacts with the BGL. Anyway, the code is here: https://gist.github.com/junkieDolphin/5868934 The error I get is:
/home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:822:13: error: ‘adjacency_list’ does not name a type
(full trace below) So I suspect the problem is in how I tell run_inline to include the proper header files in the generated source. Putting them before the loop is clearly not an option, because it would put the #includes in the middle of a scope. Any idea? Alternatively, how do I get to call BGL's add_edge with the wrapped graph type, i.e. the one typedef'd automatically by inline? Thanks! Giovanni
In [33]: %run graph_utils.py Python mode Python mode added 100 edges in 0.0191810131073 seconds Weave mode In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1728:0, from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17, from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:15, from /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:22: /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp: In function ‘PyObject* compiled_func(PyObject*, PyObject*)’: /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:822:13: error: ‘adjacency_list’ does not name a type /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:826:27: warning: left operand of comma operator has no effect [-Wunused-value] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:826:40: warning: left operand of comma operator has no effect [-Wunused-value] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:826:44: error: ‘_graph’ was not declared in this scope /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:747:15: warning: unused variable ‘Nedges’ [-Wunused-variable] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:748:15: warning: unused variable ‘Sedges’ [-Wunused-variable] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:749:9: warning: unused variable ‘Dedges’ [-Wunused-variable] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp: At global scope: /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:713:18: warning: unused parameter ‘self’ [-Wunused-parameter] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:885:1: warning: missing initializer for member ‘PyMethodDef::ml_doc’ [-Wmissing-field-initializers] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:885:1: warning: missing initializer for member ‘PyMethodDef::ml_flags’ [-Wmissing-field-initializers] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:885:1: warning: missing initializer for member ‘PyMethodDef::ml_doc’ [-Wmissing-field-initializers] In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1728:0, from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17, from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:15, from /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:22: /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_deprecated_api.h:11:2: warning: #warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp: In function ‘PyObject* compiled_func(PyObject*, PyObject*)’: /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:822:13: error: ‘adjacency_list’ does not name a type /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:826:27: warning: left operand of comma operator has no effect [-Wunused-value] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:826:40: warning: left operand of comma operator has no effect [-Wunused-value] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:826:44: error: ‘_graph’ was not declared in this scope /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:747:15: warning: unused variable ‘Nedges’ [-Wunused-variable] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:748:15: warning: unused variable ‘Sedges’ [-Wunused-variable] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:749:9: warning: unused variable ‘Dedges’ [-Wunused-variable] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp: At global scope: /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:713:18: warning: unused parameter ‘self’ [-Wunused-parameter] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:885:1: warning: missing initializer for member ‘PyMethodDef::ml_doc’ [-Wmissing-field-initializers] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:885:1: warning: missing initializer for member ‘PyMethodDef::ml_flags’ [-Wmissing-field-initializers] /home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:885:1: warning: missing initializer for member ‘PyMethodDef::ml_doc’ [-Wmissing-field-initializers]
-- Giovanni Luca Ciampaglia Postdoctoral fellow Center for Complex Networks and Systems Research Indiana University ✎ 910 E 10th St ∙ Bloomington ∙ IN 47408 ☞ http://cnets.indiana.edu/ ✉ gciampag@indiana.edu
On 06/26/2013 06:41 PM, Giovanni Luca Ciampaglia wrote:
Hi,
I recently moved from NetworkX to graph-tool and I am very impressed with the performance increase, good job!
A bit for learning and also for speeding up a code that creates a graph dynamically, I am trying to implement a batch insertion function with Weave, but I am running into a compilation error. My knowledge of C++ is sketchy at best so please forgive if I am asking something really dumb -- though I suspect that the problem is more in the way graph_tool interacts with the BGL. Anyway, the code is here:
https://gist.github.com/junkieDolphin/5868934
The error I get is:
/home/giovanni/.python27_compiled/sc_d9500bfc215fd29698821c3db4d6aeb81.cpp:822:13: error: ‘adjacency_list’ does not name a type
(full trace below)
So I suspect the problem is in how I tell run_inline to include the proper header files in the generated source. Putting them before the loop is clearly not an option, because it would put the #includes in the middle of a scope. Any idea?
The code you're trying to run is not valid C++ (you cannot mix typedefs and variable definitions). Furthermore you should not try to guess the type of the graph, and instead you should use the pre-defined typedefs. You have to use the following code: _add_code = ''' using namespace boost; typedef graph_traits<graph_graph_t>::vertex_descriptor vertex_t; for (int i = 0; i < n; ++i) { add_edge(vertex_t(edges[i, 0]), vertex_t(edges[i, 1]), graph); } ''' Modifying your script with the above code worked for me. Note that you have to use the development version of graph-tool in git, since the current version has a bug in the run_action module. I think that a function to add several edges at once is a useful one. If you open a ticket for it, I'll implement it when I find some time.
Alternatively, how do I get to call BGL's add_edge with the wrapped graph type, i.e. the one typedef'd automatically by inline?
Everything should work fine with the properly overloaded functions... I.e., whenever you call add_edge(), it should select the appropriately overloaded function for the correct type. Cheers, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
participants (2)
-
Giovanni Luca Ciampaglia -
Tiago de Paula Peixoto