I'm using Python 2.7.10 on a Mac (10.12.6). Apologies in advance for any silly comments: I am a Python newbie and also am not that experienced with C++.
I need to compile an old C++-based code that interfaces with Python. A couple of the .cpp files use the deprecated "boost/python/numeric.hpp" as an include and for making arrays:
#include <boost/python/numeric.hpp>
const py::numeric::array& X
I have spent a couple of days now on trying to figure out how to deal with this, but just can't turn up any documentation that makes sense as a newbie. I would be very grateful if someone would please point me in the right direction. One thing I did come across was this post:
where one suggestion involves using
#include <numpy/ndarrayobject.h>
However, I just cannot figure out how to use it to translate my old code.
Thank you for any help.
Edit in response to sehe: The code is too large to post in its entirety, but the errors all seem to be related to:
#include <boost/python/numeric.hpp>
I'm pretty sure I need to use:
#include <numpy/ndarrayobject.h>
However, I can't figure out how to change the code that refers to the arrays. This seems like such a simple thing, but I haven't been able to find any documentation. Below are specific examples of where the deprecated code is an issue (please let me know if I can make this more understandable)
In the main() file "PyMain.cpp":
// Include from Boost
#include <boost/python.hpp>
namespace py = boost::python;
// Other includes for the code PyCalculator
# XXX...
# XXX...
BOOST_PYTHON_MODULE(PyCalculator)
{
// Set numpy as the numeric::array engine
py::numeric::array::set_module_and_type("numpy", "ndarray");
XXX // (Other non-problematic code
}
Here's an example of another file, "Auxiliary .cpp"
The error shown in the terminal is:
PyAux.cpp: fatal error:
'boost/python/numeric.hpp' file not found
#include "PyAux.hpp"
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <Python.h>
#include <numpy/ndarrayobject.h>
// Boost includes
#include <boost/python.hpp>
#include <boost/python/numeric.hpp>
#include <boost/python/slice.hpp>
#include <boost/smart_ptr.hpp>
namespace py = boost::python;
// Other includes
#include <PyAux/Math/Other/Core>
namespace PyCalculator {
... XXX
// There are functions like:
static auto initializeWithArray(const py::numeric::array& array) -> boost::shared_ptr<VectorType>
{ //...XXX
const py::numeric::array& X
}
}
ahuge code" then clearly it's beyond the scope of your question. Your question is specifically about the interface code, which should be doable <40 LoC – sehe Sep 15 '17 at 12:11