を作成します。ブースト:: Pythonとアイゲン/高密度のは、私がこのような構造に固有/高密度のオブジェクトを使用するセグメンテーションフォールト
#include <boost/python.hpp>
#include <Eigen/Dense>
#include <iostream>
#include <vector>
struct data_t {
Eigen::Matrix2f matrix;
//std::vector<float> matrix;
};
data_t init_data() {
data_t result;
result.matrix(0, 0) = 1.0f;
result.matrix(0, 1) = 2.0f;
result.matrix(1, 0) = 3.0f;
result.matrix(1, 1) = 4.0f;
//result.matrix.push_back(1.0f);
//result.matrix.push_back(2.0f);
//result.matrix.push_back(3.0f);
//result.matrix.push_back(4.0f);
return result;
}
BOOST_PYTHON_MODULE(python_test) {
boost::python::class_<data_t>("DataType")
.def("from_init", &init_data)
.staticmethod("from_init")
;
}
Pythonのコードは次のようになります。
import python_test
def init_data():
return python_test.DataType.from_init()
sample = init_data()
実行によりセグメンテーションフォルトが発生します。私の質問は:なぜですか? Eigenオブジェクトをstd :: vectorに置き換えると、コードはうまく動作します。
follwong作品: 構造体data_t {固有:: MatrixXfマトリックス;}; および: data_t init_data(){ data_t result; result.matrix = Eigen :: Matrix2f(); result.matrix(0、0)= 1.0f; result.matrix(0、1)= 2.0f; result.matrix(1,0)= 3.0f; result.matrix(1,1)= 4.0f;戻り値: ; } – Michael
私は、固定サイズのEigenオブジェクトが内部的に値によってboost :: python関数にreturn文の間渡されるという問題があると思います。 (http://eigen.tuxfamily.org/dox-devel/group__TopicPassingByValue.html) – Michael
'-D EIGEN_MAX_STATIC_ALIGN_BYTES = 0'を使って静的アラインメントを無効にすることができます – chtz