4

I have the following class:

class PyWav {

   public:

     static inline boost::python::object sdVecToNumpyArray(std::vector<double> const& vec)
    {
        npy_intp size = vec.size();

        double * data = size ? const_cast<double *>(&vec[0]) : static_cast<double *>(NULL);
        PyObject * pyObj = PyArray_SimpleNewFromData(1, &size, NPY_DOUBLE, data);
        boost::python::handle<> handle ( pyObj );
        boost::python::numeric::array arr(handle);

        return arr.copy();

    }

   // Access function 
   inline boost::python::numeric::array toNumPy()
   {
        std::vector<double> v = Signal(); // get the vector 
        boost::python::numeric::array arr = Lib::python::PyWav::sdVecToNumpyArray(
                                                                                  v);
        return arr;
   }

}; 

The problem is I do not know how to access the stdVecToNumpyArray and pass through the vector? I want the method "toNumPy()" to be open to the user, but, not the sdVecToNumpyArray

I get the following error:

error: conversion from ‘boost::python::api::object’ to non-scalar type ‘boost::python::numeric::array’ requested v);

Anyone have any ideas?

1 Answer 1

2

You may need an explicit cast, like here: https://mail.python.org/pipermail/cplusplus-sig/2009-January/014194.html

boost::python::numeric::array arr(static_cast<boost::python::numeric::array>(handle));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.