File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ if(NOT NUMPY_WITH_BROKEN_UFUNC_SUPPORT)
3838 add_lib_unit_test(user_type)
3939endif ()
4040add_lib_unit_test(std_vector)
41+ add_lib_unit_test(user_struct)
4142
4243add_python_unit_test("py-matrix" "unittest/python/test_matrix.py" "unittest" )
4344
@@ -92,3 +93,7 @@ endif(NOT WIN32)
9293add_python_unit_test("py-std-vector" "unittest/python/test_std_vector.py"
9394 "python;unittest" )
9495set_tests_properties ("py-std-vector" PROPERTIES DEPENDS ${PYWRAP} )
96+
97+ add_python_unit_test("py-user-struct" "unittest/python/test_user_struct.py"
98+ "python;unittest" )
99+ set_tests_properties ("py-std-vector" PROPERTIES DEPENDS ${PYWRAP} )
Original file line number Diff line number Diff line change 1+ import numpy as np
2+ from user_struct import *
3+
4+
5+ x = np .ones (3 )
6+ y = np .ones (4 )
7+ ms = MyStruct (x , y )
8+ print (ms .x )
9+ print (ms .y )
10+
11+ ms .x [0 ] = 0.0
12+
13+ ms .x = x # ok
14+ assert np .allclose (ms .x , x )
15+
16+ ms .y [:] = y
17+ ms .y = y # segfault
Original file line number Diff line number Diff line change 1+ #include " eigenpy/eigenpy.hpp"
2+
3+ struct mystruct {
4+ Eigen::Vector3d x_;
5+ Eigen::Vector4d y_;
6+
7+ mystruct (const Eigen::Vector3d& x, const Eigen::Vector4d& y) : x_(x), y_(y) {}
8+ };
9+
10+ BOOST_PYTHON_MODULE (user_struct) {
11+ using namespace Eigen ;
12+ namespace bp = boost::python;
13+ eigenpy::enableEigenPy ();
14+ bp::class_<mystruct>(" MyStruct" , bp::init<const Vector3d&, const Vector4d&>())
15+ .add_property (
16+ " x" ,
17+ bp::make_getter (&mystruct::x_, bp::return_internal_reference<>()),
18+ bp::make_setter (&mystruct::x_))
19+ .add_property (
20+ " y" ,
21+ bp::make_getter (&mystruct::y_, bp::return_internal_reference<>()),
22+ bp::make_setter (&mystruct::y_));
23+ }
You can’t perform that action at this time.
0 commit comments