Skip to content

Commit

Permalink
Merge pull request #2436 from jorisv/topic/numpy2
Browse files Browse the repository at this point in the history
Numpy 2 compatibility
  • Loading branch information
jcarpent authored Sep 25, 2024
2 parents e6c1399 + ed3439c commit bc7e4a8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Default visualizer can be changed with `PINOCCHIO_VIEWER` environment variable ([#2419](https://github.com/stack-of-tasks/pinocchio/pull/2419))
- Add more Python and C++ examples related to inverse kinematics with 3d tasks ([#2428](https://github.com/stack-of-tasks/pinocchio/pull/2428))
- Add parsing of equality/connect tag for closed-loop chains for MJCF format ([#2413](https://github.com/stack-of-tasks/pinocchio/pull/2413))
- Add compatibility with NumPy 2 `__array__` API ([#2436](https://github.com/stack-of-tasks/pinocchio/pull/2436))

### Fixed
- Fix linkage of Boost.Serialization on Windows ([#2400](https://github.com/stack-of-tasks/pinocchio/pull/2400))
Expand Down
8 changes: 6 additions & 2 deletions include/pinocchio/bindings/python/spatial/force.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ namespace pinocchio
"__array__", bp::make_function(
(typename Force::ToVectorReturnType(Force::*)()) & Force::toVector,
bp::return_internal_reference<>()))
.def("__array__", &__array__, bp::return_internal_reference<>())
.def(
"__array__", &__array__,
(bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object()),
bp::return_internal_reference<>())
#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
.def_pickle(Pickle())
#endif
Expand Down Expand Up @@ -197,7 +200,8 @@ namespace pinocchio
}

private:
static typename Force::ToVectorConstReturnType __array__(const Force & self, bp::object)
static typename Force::ToVectorConstReturnType
__array__(const Force & self, bp::object, bp::object)
{
return self.toVector();
}
Expand Down
6 changes: 4 additions & 2 deletions include/pinocchio/bindings/python/spatial/inertia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ namespace pinocchio
.staticmethod("FromCapsule")

.def("__array__", (Matrix6(Inertia::*)() const) & Inertia::matrix)
.def("__array__", &__array__)
.def(
"__array__", &__array__,
(bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object()))
#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
.def_pickle(Pickle())
#endif
Expand Down Expand Up @@ -273,7 +275,7 @@ namespace pinocchio
}

private:
static Matrix6 __array__(const Inertia & self, bp::object)
static Matrix6 __array__(const Inertia & self, bp::object, bp::object)
{
return self.matrix();
}
Expand Down
8 changes: 6 additions & 2 deletions include/pinocchio/bindings/python/spatial/motion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ namespace pinocchio
"__array__", bp::make_function(
(typename Motion::ToVectorReturnType(Motion::*)()) & Motion::toVector,
bp::return_internal_reference<>()))
.def("__array__", &__array__, bp::return_internal_reference<>())
.def(
"__array__", &__array__,
(bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object()),
bp::return_internal_reference<>())
#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
.def_pickle(Pickle())
#endif
Expand Down Expand Up @@ -220,7 +223,8 @@ namespace pinocchio
}

private:
static typename Motion::ToVectorConstReturnType __array__(const Motion & self, bp::object)
static typename Motion::ToVectorConstReturnType
__array__(const Motion & self, bp::object, bp::object)
{
return self.toVector();
}
Expand Down
6 changes: 4 additions & 2 deletions include/pinocchio/bindings/python/spatial/se3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ namespace pinocchio
.staticmethod("Interpolate")

.def("__array__", &SE3::toHomogeneousMatrix)
.def("__array__", &__array__)
.def(
"__array__", &__array__,
(bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object()))

#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
.def_pickle(Pickle())
Expand Down Expand Up @@ -230,7 +232,7 @@ namespace pinocchio
}

private:
static Matrix4 __array__(const SE3 & self, bp::object)
static Matrix4 __array__(const SE3 & self, bp::object, bp::object)
{
return self.toHomogeneousMatrix();
}
Expand Down

0 comments on commit bc7e4a8

Please sign in to comment.