Skip to content
Snippets Groups Projects
Unverified Commit 79ced4de authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #350 from ManifoldFR/wj/add-test-user-struct

Tests: add user-struct test
parents 04e3c68a e0c0ebd3
No related branches found
No related tags found
No related merge requests found
Pipeline #26082 passed with warnings
......@@ -38,6 +38,7 @@ if(NOT NUMPY_WITH_BROKEN_UFUNC_SUPPORT)
add_lib_unit_test(user_type)
endif()
add_lib_unit_test(std_vector)
add_lib_unit_test(user_struct)
add_python_unit_test("py-matrix" "unittest/python/test_matrix.py" "unittest")
......@@ -92,3 +93,7 @@ endif(NOT WIN32)
add_python_unit_test("py-std-vector" "unittest/python/test_std_vector.py"
"python;unittest")
set_tests_properties("py-std-vector" PROPERTIES DEPENDS ${PYWRAP})
add_python_unit_test("py-user-struct" "unittest/python/test_user_struct.py"
"python;unittest")
set_tests_properties("py-std-vector" PROPERTIES DEPENDS ${PYWRAP})
import numpy as np
from user_struct import *
x = np.ones(3)
y = np.ones(4)
ms = MyStruct(x, y)
print(ms.x)
print(ms.y)
ms.x[0] = 0.0
ms.x = x # ok
assert np.allclose(ms.x, x)
ms.y[:] = y
ms.y = y # segfault
#include "eigenpy/eigenpy.hpp"
struct mystruct {
Eigen::Vector3d x_;
Eigen::Vector4d y_;
mystruct(const Eigen::Vector3d& x, const Eigen::Vector4d& y) : x_(x), y_(y) {}
};
BOOST_PYTHON_MODULE(user_struct) {
using namespace Eigen;
namespace bp = boost::python;
eigenpy::enableEigenPy();
bp::class_<mystruct>("MyStruct", bp::init<const Vector3d&, const Vector4d&>())
.add_property(
"x",
bp::make_getter(&mystruct::x_, bp::return_internal_reference<>()),
bp::make_setter(&mystruct::x_))
.add_property(
"y",
bp::make_getter(&mystruct::y_, bp::return_internal_reference<>()),
bp::make_setter(&mystruct::y_));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment