Segmentation fault when using boost::numpy::ndarray

前端 未结 1 1601
温柔的废话
温柔的废话 2021-02-20 17:33

I am getting what I think is a strange seg fault when I am trying to pass boost::numpy::ndarray as an argument:

#include 
#include &         


        
相关标签:
1条回答
  • 2021-02-20 17:59

    I knew it was something simple. I needed to add these two lines:

    Py_Initialize();
    boost::numpy::initialize();
    

    as explained : here seg fault results after any attempt to use boost::numpy::ndarray if the above lines are not ran.

    Therefore: my file becomes:

    #include <iostream>
    #include <boost/python.hpp>
    #include <boost/numpy.hpp>
    
    
    void say_hello(boost::numpy::ndarray& my_array)
    //void say_hello(int x) This works fine
    {
      std::cout<<"Hello"<<std::endl;
    }
    
    BOOST_PYTHON_MODULE(hello_ext)
    {
        using namespace boost::python;
        Py_Initialize();
        boost::numpy::initialize();
        def("say_hello", say_hello);
    }
    
    0 讨论(0)
提交回复
热议问题