Improve bindings for mjd_subQuat.
- Accept `None` for optional arguments. - Accept 3x3 matrices for matrix arguments. PiperOrigin-RevId: 611000820 Change-Id: Id28cdb2ae574f372ff251f94ab4557d9d2eaa80b
This commit is contained in:
committed by
Copybara-Service
parent
a5ea87b0e6
commit
982760a63b
@@ -1205,10 +1205,16 @@ Euler integrator, semi-implicit in velocity.
|
||||
|
||||
def test_mjd_sub_quat(self):
|
||||
quat1 = np.array((0.2, 0.3, 0.3, 0.4))
|
||||
quat2 = np.array((0.2, 0.3, 0.3, 0.4))
|
||||
quat2 = np.array((0.1, 0.2, 0.4, 0.5))
|
||||
d1 = np.empty(9, np.float64)
|
||||
d2 = np.empty(9, np.float64)
|
||||
mujoco.mjd_subQuat(quat1, quat2, d1, d2)
|
||||
d3 = np.empty((3, 3), np.float64)
|
||||
d4 = np.empty((3, 3), np.float64)
|
||||
mujoco.mjd_subQuat(quat1, quat2, None, d3)
|
||||
mujoco.mjd_subQuat(quat1, quat2, d4, None)
|
||||
np.testing.assert_array_equal(d2, d3.flatten())
|
||||
np.testing.assert_array_equal(d1, d4.flatten())
|
||||
|
||||
def test_mjd_quat_intergrate(self):
|
||||
scale = 0.1
|
||||
|
||||
@@ -1353,7 +1353,28 @@ PYBIND11_MODULE(_functions, pymodule) {
|
||||
DsDa.has_value() ? DsDa->data() : nullptr,
|
||||
DmDq.has_value() ? DmDq->data() : nullptr);
|
||||
});
|
||||
Def<traits::mjd_subQuat>(pymodule);
|
||||
Def<traits::mjd_subQuat>(
|
||||
pymodule,
|
||||
[](Eigen::Ref<const EigenVectorX> qa, Eigen::Ref<const EigenVectorX> qb,
|
||||
std::optional<Eigen::Ref<EigenArrayXX>> Da,
|
||||
std::optional<Eigen::Ref<EigenArrayXX>> Db) {
|
||||
if (qa.size() != 4) {
|
||||
throw py::type_error("qa must have size 4");
|
||||
}
|
||||
if (qb.size() != 4) {
|
||||
throw py::type_error("qb must have size 4");
|
||||
}
|
||||
if (Da.has_value() && Da->size() != 9) {
|
||||
throw py::type_error("Da must have size 9");
|
||||
}
|
||||
if (Db.has_value() && Db->size() != 9) {
|
||||
throw py::type_error("Db must have size 9");
|
||||
}
|
||||
return InterceptMjErrors(::mjd_subQuat)(
|
||||
qa.data(), qb.data(),
|
||||
Da.has_value() ? Da->data() : nullptr,
|
||||
Db.has_value() ? Db->data() : nullptr);
|
||||
});
|
||||
Def<traits::mjd_quatIntegrate>(pymodule);
|
||||
|
||||
pymodule.def(
|
||||
|
||||
Reference in New Issue
Block a user