11#include <boost/python/extract.hpp>
15#define PY_ARRAY_UNIQUE_SYMBOL CORE_ARRAY_API
16#define NO_IMPORT_ARRAY
17#include <numpy/arrayobject.h>
19using boost::python::extract;
20using boost::python::handle;
21using boost::python::len;
22using boost::python::object;
34 extract<Kernel::V3D> converter(p);
35 if (converter.check()) {
41 const size_t length = len(p);
43 throw std::invalid_argument(
"Incorrect length for conversion to V3D");
46 p.attr(
"__getitem__")(0);
47 }
catch (boost::python::error_already_set &) {
48 throw std::invalid_argument(std::string(
"Cannot convert object to V3D. Expected a python sequence found ") +
49 p.ptr()->ob_type->tp_name);
61 return extract<Kernel::V3D>(
m_obj)();
63 auto toDouble = [](
const object &
obj) {
return extract<double>(
object(handle<>(PyNumber_Float(
obj.ptr()))))(); };
double obj
the value of the quadratic function
const boost::python::object & m_obj
A reference to the object.
PyObjectToV3D(const boost::python::object &p)
Construct the converter object with the given Python object.
Kernel::V3D operator()()
Produces a V3D object from the given PyObject.
bool m_alreadyV3D
Is the object a wrapped instance of V3D.