Skip to content

Commit bc7e4a8

Browse files
authored
Merge pull request #2436 from jorisv/topic/numpy2
Numpy 2 compatibility
2 parents e6c1399 + ed3439c commit bc7e4a8

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1111
- Default visualizer can be changed with `PINOCCHIO_VIEWER` environment variable ([#2419](https://github.com/stack-of-tasks/pinocchio/pull/2419))
1212
- Add more Python and C++ examples related to inverse kinematics with 3d tasks ([#2428](https://github.com/stack-of-tasks/pinocchio/pull/2428))
1313
- Add parsing of equality/connect tag for closed-loop chains for MJCF format ([#2413](https://github.com/stack-of-tasks/pinocchio/pull/2413))
14+
- Add compatibility with NumPy 2 `__array__` API ([#2436](https://github.com/stack-of-tasks/pinocchio/pull/2436))
1415

1516
### Fixed
1617
- Fix linkage of Boost.Serialization on Windows ([#2400](https://github.com/stack-of-tasks/pinocchio/pull/2400))

include/pinocchio/bindings/python/spatial/force.hpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ namespace pinocchio
161161
"__array__", bp::make_function(
162162
(typename Force::ToVectorReturnType(Force::*)()) & Force::toVector,
163163
bp::return_internal_reference<>()))
164-
.def("__array__", &__array__, bp::return_internal_reference<>())
164+
.def(
165+
"__array__", &__array__,
166+
(bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object()),
167+
bp::return_internal_reference<>())
165168
#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
166169
.def_pickle(Pickle())
167170
#endif
@@ -197,7 +200,8 @@ namespace pinocchio
197200
}
198201

199202
private:
200-
static typename Force::ToVectorConstReturnType __array__(const Force & self, bp::object)
203+
static typename Force::ToVectorConstReturnType
204+
__array__(const Force & self, bp::object, bp::object)
201205
{
202206
return self.toVector();
203207
}

include/pinocchio/bindings/python/spatial/inertia.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ namespace pinocchio
193193
.staticmethod("FromCapsule")
194194

195195
.def("__array__", (Matrix6(Inertia::*)() const) & Inertia::matrix)
196-
.def("__array__", &__array__)
196+
.def(
197+
"__array__", &__array__,
198+
(bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object()))
197199
#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
198200
.def_pickle(Pickle())
199201
#endif
@@ -273,7 +275,7 @@ namespace pinocchio
273275
}
274276

275277
private:
276-
static Matrix6 __array__(const Inertia & self, bp::object)
278+
static Matrix6 __array__(const Inertia & self, bp::object, bp::object)
277279
{
278280
return self.matrix();
279281
}

include/pinocchio/bindings/python/spatial/motion.hpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ namespace pinocchio
184184
"__array__", bp::make_function(
185185
(typename Motion::ToVectorReturnType(Motion::*)()) & Motion::toVector,
186186
bp::return_internal_reference<>()))
187-
.def("__array__", &__array__, bp::return_internal_reference<>())
187+
.def(
188+
"__array__", &__array__,
189+
(bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object()),
190+
bp::return_internal_reference<>())
188191
#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
189192
.def_pickle(Pickle())
190193
#endif
@@ -220,7 +223,8 @@ namespace pinocchio
220223
}
221224

222225
private:
223-
static typename Motion::ToVectorConstReturnType __array__(const Motion & self, bp::object)
226+
static typename Motion::ToVectorConstReturnType
227+
__array__(const Motion & self, bp::object, bp::object)
224228
{
225229
return self.toVector();
226230
}

include/pinocchio/bindings/python/spatial/se3.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ namespace pinocchio
197197
.staticmethod("Interpolate")
198198

199199
.def("__array__", &SE3::toHomogeneousMatrix)
200-
.def("__array__", &__array__)
200+
.def(
201+
"__array__", &__array__,
202+
(bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object()))
201203

202204
#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
203205
.def_pickle(Pickle())
@@ -230,7 +232,7 @@ namespace pinocchio
230232
}
231233

232234
private:
233-
static Matrix4 __array__(const SE3 & self, bp::object)
235+
static Matrix4 __array__(const SE3 & self, bp::object, bp::object)
234236
{
235237
return self.toHomogeneousMatrix();
236238
}

0 commit comments

Comments
 (0)