Segmentierungsfehler bei Verwendung von boost :: numpy :: ndarray

Ich bekomme das, was ich für einen seltsamen Seg-Fehler halte, wenn ich versuche zu bestehenboost::numpy::ndarray als Argument:

#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;
    def("say_hello", say_hello);

}

Ich weiß, dass das Beispiel albern ist, aber ich sollte dort keinen Seg-Fehler bekommen, und dies ist das kleinste Beispiel, auf das ich das Problem reduzieren konnte. Vielleicht muss ich das angebenndarray Art oder Anzahl der Dimensionen, aber ich konnte keine Dokumentation finden. Ich habe geschautdiese, aber es schien nicht sehr hilfreich. Mein Bauchgefühl ist, dass ich etwas Einfaches vermisse, aber ich sehe es einfach nicht.

Wenn ich das laufen lasse:

In [1]: from hello_ext import *

In [2]: import numpy as np

In [3]: say_hello(np.array([3,4,5]))
Segmentation fault (core dumped)

Mein Makefile:

PYTHON_VERSION = 2.7
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)


BOOST_INC = /usr/include
BOOST_LIB = /usr/lib

TARGET = hello_ext

$(TARGET).so: $(TARGET).o
    g++ -std=c++11 -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -lboost_python -lboost_numpy -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o $(TARGET).so

$(TARGET).o: $(TARGET).cpp
    g++ -std=c++11 -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cp

Antworten auf die Frage(1)

Ihre Antwort auf die Frage