Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/spatial/inertia.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 211 | 226 | 93.4% |
Branches: | 287 | 577 | 49.7% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2015-2024 CNRS INRIA | ||
3 | // Copyright (c) 2016 Wandercraft, 86 rue de Paris 91400 Orsay, France. | ||
4 | // | ||
5 | |||
6 | #ifndef __pinocchio_python_spatial_inertia_hpp__ | ||
7 | #define __pinocchio_python_spatial_inertia_hpp__ | ||
8 | |||
9 | #include <eigenpy/exception.hpp> | ||
10 | #include <eigenpy/eigenpy.hpp> | ||
11 | #include <eigenpy/memory.hpp> | ||
12 | #include <boost/python/tuple.hpp> | ||
13 | |||
14 | #include "pinocchio/spatial/inertia.hpp" | ||
15 | |||
16 | #include "pinocchio/bindings/python/utils/cast.hpp" | ||
17 | #include "pinocchio/bindings/python/utils/copyable.hpp" | ||
18 | #include "pinocchio/bindings/python/utils/printable.hpp" | ||
19 | |||
20 | #if EIGENPY_VERSION_AT_MOST(2, 8, 1) | ||
21 | EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::Inertia) | ||
22 | EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::PseudoInertiaTpl) | ||
23 | EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(pinocchio::LogCholeskyParametersTpl) | ||
24 | #endif | ||
25 | |||
26 | namespace pinocchio | ||
27 | { | ||
28 | namespace python | ||
29 | { | ||
30 | namespace bp = boost::python; | ||
31 | |||
32 | template<typename Inertia> | ||
33 | struct InertiaPythonVisitor : public boost::python::def_visitor<InertiaPythonVisitor<Inertia>> | ||
34 | { | ||
35 | enum | ||
36 | { | ||
37 | Options = Inertia::Options | ||
38 | }; | ||
39 | typedef typename Inertia::Scalar Scalar; | ||
40 | typedef typename Inertia::Vector3 Vector3; | ||
41 | typedef typename Inertia::Matrix3 Matrix3; | ||
42 | typedef typename Inertia::Vector6 Vector6; | ||
43 | typedef typename Inertia::Matrix6 Matrix6; | ||
44 | |||
45 | typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> VectorXs; | ||
46 | typedef MotionTpl<Scalar, Options> Motion; | ||
47 | typedef ForceTpl<Scalar, Options> Force; | ||
48 | |||
49 | public: | ||
50 | template<class PyClass> | ||
51 | 69 | void visit(PyClass & cl) const | |
52 | { | ||
53 |
3/8✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
4 | static const Scalar dummy_precision = Eigen::NumTraits<Scalar>::dummy_precision(); |
54 |
2/4✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
69 | cl.def( |
55 | "__init__", | ||
56 | bp::make_constructor( | ||
57 | 69 | &InertiaPythonVisitor::makeFromMCI, bp::default_call_policies(), | |
58 | bp::args("mass", "lever", "inertia")), | ||
59 | "Initialize from mass, lever and 3d inertia.") | ||
60 | |||
61 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
|
138 | .def(bp::init<>(bp::arg("self"), "Default constructor.")) |
62 |
5/10✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 69 times.
✗ Branch 14 not taken.
|
138 | .def(bp::init<const Inertia &>((bp::arg("self"), bp::arg("clone")), "Copy constructor")) |
63 | |||
64 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .add_property( |
65 | "mass", &InertiaPythonVisitor::getMass, &InertiaPythonVisitor::setMass, | ||
66 | "Mass of the Spatial Inertia.") | ||
67 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
69 | .add_property( |
68 | "lever", | ||
69 | bp::make_function( | ||
70 | (typename Inertia::Vector3 & (Inertia::*)()) & Inertia::lever, | ||
71 | 69 | bp::return_internal_reference<>()), | |
72 | &InertiaPythonVisitor::setLever, | ||
73 | "Center of mass location of the Spatial Inertia. It corresponds to the location of the " | ||
74 | "center of mass regarding to the frame where the Spatial Inertia is expressed.") | ||
75 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .add_property( |
76 | "inertia", &InertiaPythonVisitor::getInertia, &InertiaPythonVisitor::setInertia, | ||
77 | "Rotational part of the Spatial Inertia, i.e. a symmetric matrix " | ||
78 | "representing the rotational inertia around the center of mass.") | ||
79 | |||
80 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | .def("matrix", (Matrix6(Inertia::*)() const)&Inertia::matrix, bp::arg("self")) |
81 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def("inverse", (Matrix6(Inertia::*)() const)&Inertia::inverse, bp::arg("self")) |
82 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
83 | "se3Action", &Inertia::template se3Action<Scalar, Options>, bp::args("self", "M"), | ||
84 | "Returns the result of the action of M on *this.") | ||
85 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
86 | "se3ActionInverse", &Inertia::template se3ActionInverse<Scalar, Options>, | ||
87 | bp::args("self", "M"), "Returns the result of the action of the inverse of M on *this.") | ||
88 | |||
89 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
90 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "setIdentity", &Inertia::setIdentity, bp::arg("self"), |
91 | "Set *this to be the Identity inertia.") | ||
92 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
93 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "setZero", &Inertia::setZero, bp::arg("self"), |
94 | "Set all the components of *this to zero.") | ||
95 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
96 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "setRandom", &Inertia::setRandom, bp::arg("self"), |
97 | "Set all the components of *this to random values.") | ||
98 | |||
99 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
69 | .def(bp::self + bp::self) |
100 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self += bp::self) |
101 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self - bp::self) |
102 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self -= bp::self) |
103 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self * bp::other<Motion>()) |
104 | |||
105 | 138 | .add_property("np", (Matrix6(Inertia::*)() const)&Inertia::matrix) | |
106 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
107 | "vxiv", &Inertia::template vxiv<Motion>, bp::args("self", "v"), | ||
108 | "Returns the result of v x Iv.") | ||
109 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
110 | "vtiv", &Inertia::template vtiv<Motion>, bp::args("self", "v"), | ||
111 | "Returns the result of v.T * Iv.") | ||
112 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
113 | "vxi", | ||
114 | (Matrix6(Inertia::*)(const MotionDense<Motion> &) const)&Inertia::template vxi<Motion>, | ||
115 | bp::args("self", "v"), "Returns the result of v x* I, a 6x6 matrix.") | ||
116 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
117 | "ivx", | ||
118 | (Matrix6(Inertia::*)(const MotionDense<Motion> &) const)&Inertia::template ivx<Motion>, | ||
119 | bp::args("self", "v"), "Returns the result of I vx, a 6x6 matrix.") | ||
120 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
|
138 | .def( |
121 | "variation", | ||
122 | (Matrix6(Inertia::*)(const MotionDense<Motion> &) | ||
123 | const)&Inertia::template variation<Motion>, | ||
124 | bp::args("self", "v"), "Returns the time derivative of the inertia.") | ||
125 | |||
126 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
127 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self == bp::self) |
128 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self != bp::self) |
129 | #endif | ||
130 | |||
131 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
132 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
133 | "isApprox", &Inertia::isApprox, | ||
134 |
5/10✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 65 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 65 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 65 times.
✗ Branch 14 not taken.
|
195 | (bp::arg("self"), bp::arg("other"), bp::arg("prec") = dummy_precision), |
135 | "Returns true if *this is approximately equal to other, within the precision given " | ||
136 | "by prec.") | ||
137 | |||
138 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
139 |
4/8✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 65 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 65 times.
✗ Branch 11 not taken.
|
130 | "isZero", &Inertia::isZero, (bp::arg("self"), bp::arg("prec") = dummy_precision), |
140 | "Returns true if *this is approximately equal to the zero Inertia, within the " | ||
141 | "precision given by prec.") | ||
142 | #endif | ||
143 | |||
144 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
69 | .def("Identity", &Inertia::Identity, "Returns the identity Inertia.") |
145 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("Identity") |
146 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def("Zero", &Inertia::Zero, "Returns the zero Inertia.") |
147 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("Zero") |
148 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def("Random", &Inertia::Random, "Returns a random Inertia.") |
149 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("Random") |
150 | |||
151 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
152 | "toDynamicParameters", &InertiaPythonVisitor::toDynamicParameters_proxy, | ||
153 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | bp::arg("self"), |
154 | "Returns the representation of the matrix as a vector of dynamic parameters." | ||
155 | "\nThe parameters are given as v = [m, mc_x, mc_y, mc_z, I_{xx}, I_{xy}, I_{yy}, " | ||
156 | "I_{xz}, I_{yz}, I_{zz}]^T " | ||
157 | "where I = I_C + mS^T(c)S(c) and I_C has its origin at the barycenter") | ||
158 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
159 | "FromDynamicParameters", &InertiaPythonVisitor::fromDynamicParameters_proxy, | ||
160 | bp::args("dynamic_parameters"), | ||
161 | "Builds and inertia matrix from a vector of dynamic parameters." | ||
162 | "\nThe parameters are given as dynamic_parameters = [m, mc_x, mc_y, mc_z, I_{xx}, " | ||
163 | "I_{xy}, I_{yy}, I_{xz}, I_{yz}, I_{zz}]^T " | ||
164 | "where I = I_C + mS^T(c)S(c) and I_C has its origin at the barycenter.") | ||
165 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromDynamicParameters") |
166 | |||
167 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
168 | "FromSphere", &Inertia::FromSphere, bp::args("mass", "radius"), | ||
169 | "Returns the Inertia of a sphere defined by a given mass and radius.") | ||
170 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromSphere") |
171 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
172 | "FromEllipsoid", &Inertia::FromEllipsoid, | ||
173 | bp::args("mass", "length_x", "length_y", "length_z"), | ||
174 | "Returns the Inertia of an ellipsoid shape defined by a mass and given dimensions " | ||
175 | "the semi-axis of values length_{x,y,z}.") | ||
176 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromEllipsoid") |
177 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
178 | "FromCylinder", &Inertia::FromCylinder, bp::args("mass", "radius", "length"), | ||
179 | "Returns the Inertia of a cylinder defined by its mass, radius and length along the " | ||
180 | "Z axis.") | ||
181 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromCylinder") |
182 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
183 | "FromBox", &Inertia::FromBox, bp::args("mass", "length_x", "length_y", "length_z"), | ||
184 | "Returns the Inertia of a box shape with a mass and of dimension the semi axis of " | ||
185 | "length_{x,y,z}.") | ||
186 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromBox") |
187 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
188 | "FromCapsule", &Inertia::FromCapsule, bp::args("mass", "radius", "height"), | ||
189 | "Computes the Inertia of a capsule defined by its mass, radius and length along the " | ||
190 | "Z axis. Assumes a uniform density.") | ||
191 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromCapsule") |
192 | |||
193 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
194 | "FromPseudoInertia", &Inertia::FromPseudoInertia, bp::args("pseudo_inertia"), | ||
195 | "Returns the Inertia created from a pseudo inertia object.") | ||
196 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromPseudoInertia") |
197 | |||
198 | 138 | .def( | |
199 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "toPseudoInertia", &Inertia::toPseudoInertia, bp::arg("self"), |
200 | "Returns the pseudo inertia representation of the inertia.") | ||
201 | |||
202 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
|
138 | .def( |
203 | "FromLogCholeskyParameters", &Inertia::FromLogCholeskyParameters, | ||
204 | bp::args("log_cholesky_parameters"), | ||
205 | "Returns the Inertia created from log Cholesky parameters.") | ||
206 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromLogCholeskyParameters") |
207 | |||
208 | 138 | .def("__array__", (Matrix6(Inertia::*)() const)&Inertia::matrix) | |
209 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
210 | "__array__", &__array__, | ||
211 |
9/18✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 69 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 69 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 69 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 69 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 69 times.
✗ Branch 26 not taken.
|
138 | (bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object())) |
212 | #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION | ||
213 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_pickle(Pickle()) |
214 | #endif | ||
215 | ; | ||
216 | 69 | } | |
217 | |||
218 | 92 | static Scalar getMass(const Inertia & self) | |
219 | { | ||
220 | 92 | return self.mass(); | |
221 | } | ||
222 | 1 | static void setMass(Inertia & self, Scalar mass) | |
223 | { | ||
224 | 1 | self.mass() = mass; | |
225 | 1 | } | |
226 | |||
227 | 1 | static void setLever(Inertia & self, const Vector3 & lever) | |
228 | { | ||
229 | 1 | self.lever() = lever; | |
230 | 1 | } | |
231 | |||
232 | 7 | static Matrix3 getInertia(const Inertia & self) | |
233 | { | ||
234 | 7 | return self.inertia().matrix(); | |
235 | } | ||
236 | // static void setInertia(Inertia & self, const Vector6 & minimal_inertia) { | ||
237 | // self.inertia().data() = minimal_inertia; } | ||
238 | 1 | static void setInertia(Inertia & self, const Matrix3 & symmetric_inertia) | |
239 | { | ||
240 | 2 | if (!check_expression_if_real<Scalar>( | |
241 |
5/11✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
|
1 | isZero(symmetric_inertia - symmetric_inertia.transpose()))) |
242 | ✗ | throw eigenpy::Exception("The 3d inertia should be symmetric."); | |
243 |
2/4✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | self.inertia().data() << symmetric_inertia(0, 0), symmetric_inertia(1, 0), |
244 |
6/12✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
|
1 | symmetric_inertia(1, 1), symmetric_inertia(0, 2), symmetric_inertia(1, 2), |
245 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | symmetric_inertia(2, 2); |
246 | 1 | } | |
247 | |||
248 | 32 | static VectorXs toDynamicParameters_proxy(const Inertia & self) | |
249 | { | ||
250 |
1/2✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
|
32 | return self.toDynamicParameters(); |
251 | } | ||
252 | |||
253 | 2 | static Inertia fromDynamicParameters_proxy(const VectorXs & params) | |
254 | { | ||
255 |
5/6✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
|
2 | if (params.rows() != 10 || params.cols() != 1) |
256 | { | ||
257 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | std::ostringstream shape; |
258 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
|
1 | shape << "(" << params.rows() << ", " << params.cols() << ")"; |
259 |
4/8✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
|
1 | throw std::invalid_argument( |
260 | "Wrong size: params" + shape.str() + " but should have the following shape (10, 1)"); | ||
261 | 1 | } | |
262 | 1 | return Inertia::FromDynamicParameters(params); | |
263 | } | ||
264 | |||
265 | static Inertia * | ||
266 | 2 | makeFromMCI(const Scalar & mass, const Vector3 & lever, const Matrix3 & inertia) | |
267 | { | ||
268 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
269 |
3/6✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
|
2 | if (!inertia.isApprox(inertia.transpose())) |
270 | ✗ | throw eigenpy::Exception("The 3d inertia should be symmetric."); | |
271 | 2 | if ( | |
272 |
6/12✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
|
2 | (Vector3::UnitX().transpose() * inertia * Vector3::UnitX() < 0) |
273 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
|
2 | || (Vector3::UnitY().transpose() * inertia * Vector3::UnitY() < 0) |
274 |
9/18✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 2 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 2 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 2 times.
|
4 | || (Vector3::UnitZ().transpose() * inertia * Vector3::UnitZ() < 0)) |
275 | ✗ | throw eigenpy::Exception("The 3d inertia should be positive."); | |
276 | #endif | ||
277 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | return new Inertia(mass, lever, inertia); |
278 | } | ||
279 | |||
280 | 69 | static void expose() | |
281 | { | ||
282 | #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 6 && EIGENPY_VERSION_AT_LEAST(2, 9, 0) | ||
283 | typedef PINOCCHIO_SHARED_PTR_HOLDER_TYPE(Inertia) HolderType; | ||
284 | #else | ||
285 | typedef ::boost::python::detail::not_specified HolderType; | ||
286 | #endif | ||
287 | 69 | bp::class_<Inertia, HolderType>( | |
288 | "Inertia", | ||
289 | "This class represenses a sparse version of a Spatial Inertia and its is defined by its " | ||
290 | "mass, its center of mass location and the rotational inertia expressed around this " | ||
291 | "center of mass.\n\n" | ||
292 | "Supported operations ...", | ||
293 | bp::no_init) | ||
294 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(InertiaPythonVisitor<Inertia>()) |
295 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CastVisitor<Inertia>()) |
296 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(ExposeConstructorByCastVisitor<Inertia, ::pinocchio::Inertia>()) |
297 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CopyableVisitor<Inertia>()) |
298 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(PrintableVisitor<Inertia>()); |
299 | 69 | } | |
300 | |||
301 | private: | ||
302 | 1 | static Matrix6 __array__(const Inertia & self, bp::object, bp::object) | |
303 | { | ||
304 | 1 | return self.matrix(); | |
305 | } | ||
306 | |||
307 | struct Pickle : bp::pickle_suite | ||
308 | { | ||
309 | 1 | static boost::python::tuple getinitargs(const Inertia & I) | |
310 | { | ||
311 |
2/4✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | return bp::make_tuple(I.mass(), (Vector3)I.lever(), I.inertia().matrix()); |
312 | } | ||
313 | |||
314 | 65 | static bool getstate_manages_dict() | |
315 | { | ||
316 | 65 | return true; | |
317 | } | ||
318 | }; | ||
319 | |||
320 | }; // struct InertiaPythonVisitor | ||
321 | |||
322 | template<typename PseudoInertia> | ||
323 | struct PseudoInertiaPythonVisitor | ||
324 | : public boost::python::def_visitor<PseudoInertiaPythonVisitor<PseudoInertia>> | ||
325 | { | ||
326 | enum | ||
327 | { | ||
328 | Options = PseudoInertia::Options | ||
329 | }; | ||
330 | typedef typename PseudoInertia::Scalar Scalar; | ||
331 | typedef typename PseudoInertia::Vector3 Vector3; | ||
332 | typedef typename PseudoInertia::Matrix3 Matrix3; | ||
333 | typedef typename PseudoInertia::Vector10 Vector10; | ||
334 | typedef typename PseudoInertia::Matrix4 Matrix4; | ||
335 | typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> VectorXs; | ||
336 | |||
337 | public: | ||
338 | template<class PyClass> | ||
339 | 69 | void visit(PyClass & cl) const | |
340 | { | ||
341 |
5/10✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 69 times.
✗ Branch 14 not taken.
|
207 | cl.def(bp::init<const Scalar &, const Vector3 &, const Matrix3 &>( |
342 |
3/6✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 69 times.
✗ Branch 9 not taken.
|
276 | (bp::arg("self"), bp::arg("mass"), bp::arg("h"), bp::arg("sigma")), |
343 | "Initialize from mass, vector part of the pseudo inertia and matrix part of the " | ||
344 | "pseudo inertia.")) | ||
345 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
|
69 | .def(bp::init<const PseudoInertia &>( |
346 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | (bp::arg("self"), bp::arg("clone")), "Copy constructor")) |
347 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .add_property( |
348 | "mass", &PseudoInertiaPythonVisitor::getMass, &PseudoInertiaPythonVisitor::setMass, | ||
349 | "Mass of the Pseudo Inertia.") | ||
350 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .add_property( |
351 | "h", &PseudoInertiaPythonVisitor::getH, &PseudoInertiaPythonVisitor::setH, | ||
352 | "Vector part of the Pseudo Inertia.") | ||
353 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .add_property( |
354 | "sigma", &PseudoInertiaPythonVisitor::getSigma, &PseudoInertiaPythonVisitor::setSigma, | ||
355 | "Matrix part of the Pseudo Inertia.") | ||
356 | |||
357 | 138 | .def( | |
358 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "toMatrix", &PseudoInertia::toMatrix, bp::arg("self"), |
359 | "Returns the pseudo inertia as a 4x4 matrix.") | ||
360 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
361 | "toDynamicParameters", &PseudoInertiaPythonVisitor::toDynamicParameters_proxy, | ||
362 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | bp::arg("self"), "Returns the dynamic parameters representation.") |
363 | 138 | .def( | |
364 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "toInertia", &PseudoInertia::toInertia, bp::arg("self"), |
365 | "Returns the inertia representation.") | ||
366 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
|
138 | .def( |
367 | "FromDynamicParameters", &PseudoInertiaPythonVisitor::fromDynamicParameters_proxy, | ||
368 | bp::args("dynamic_parameters"), | ||
369 | "Builds a pseudo inertia matrix from a vector of dynamic parameters." | ||
370 | "\nThe parameters are given as dynamic_parameters = [m, h_x, h_y, h_z, I_{xx}, " | ||
371 | "I_{xy}, I_{yy}, I_{xz}, I_{yz}, I_{zz}]^T.") | ||
372 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromDynamicParameters") |
373 | |||
374 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
375 | "FromMatrix", &PseudoInertia::FromMatrix, bp::args("pseudo_inertia_matrix"), | ||
376 | "Returns the Pseudo Inertia from a 4x4 matrix.") | ||
377 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromMatrix") |
378 | |||
379 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
380 | "FromInertia", &PseudoInertia::FromInertia, bp::args("inertia"), | ||
381 | "Returns the Pseudo Inertia from an Inertia object.") | ||
382 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("FromInertia") |
383 | |||
384 | 138 | .def("__array__", &PseudoInertia::toMatrix) | |
385 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
386 | "__array__", &__array__, | ||
387 |
9/18✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 69 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 69 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 69 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 69 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 69 times.
✗ Branch 26 not taken.
|
138 | (bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object())) |
388 | #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION | ||
389 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_pickle(Pickle()) |
390 | #endif | ||
391 | ; | ||
392 | 69 | } | |
393 | |||
394 | 9 | static Scalar getMass(const PseudoInertia & self) | |
395 | { | ||
396 | 9 | return self.mass; | |
397 | } | ||
398 | ✗ | static void setMass(PseudoInertia & self, Scalar mass) | |
399 | { | ||
400 | ✗ | self.mass = mass; | |
401 | } | ||
402 | |||
403 | 9 | static Vector3 getH(const PseudoInertia & self) | |
404 | { | ||
405 | 9 | return self.h; | |
406 | } | ||
407 | ✗ | static void setH(PseudoInertia & self, const Vector3 & h) | |
408 | { | ||
409 | ✗ | self.h = h; | |
410 | } | ||
411 | |||
412 | 9 | static Matrix3 getSigma(const PseudoInertia & self) | |
413 | { | ||
414 | 9 | return self.sigma; | |
415 | } | ||
416 | ✗ | static void setSigma(PseudoInertia & self, const Matrix3 & sigma) | |
417 | { | ||
418 | ✗ | self.sigma = sigma; | |
419 | } | ||
420 | |||
421 | 1 | static VectorXs toDynamicParameters_proxy(const PseudoInertia & self) | |
422 | { | ||
423 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | return self.toDynamicParameters(); |
424 | } | ||
425 | |||
426 | 2 | static PseudoInertia fromDynamicParameters_proxy(const VectorXs & params) | |
427 | { | ||
428 |
5/6✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
|
2 | if (params.rows() != 10 || params.cols() != 1) |
429 | { | ||
430 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | std::ostringstream shape; |
431 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
|
1 | shape << "(" << params.rows() << ", " << params.cols() << ")"; |
432 |
4/8✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
|
1 | throw std::invalid_argument( |
433 | "Wrong size: params" + shape.str() + " but should have the following shape (10, 1)"); | ||
434 | 1 | } | |
435 | 1 | return PseudoInertia::FromDynamicParameters(params); | |
436 | } | ||
437 | |||
438 | 69 | static void expose() | |
439 | { | ||
440 | #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 6 && EIGENPY_VERSION_AT_LEAST(2, 9, 0) | ||
441 | typedef PINOCCHIO_SHARED_PTR_HOLDER_TYPE(PseudoInertia) HolderType; | ||
442 | #else | ||
443 | typedef ::boost::python::detail::not_specified HolderType; | ||
444 | #endif | ||
445 | 69 | bp::class_<PseudoInertia, HolderType>( | |
446 | "PseudoInertia", | ||
447 | "This class represents a pseudo inertia matrix and it is defined by its mass, vector " | ||
448 | "part, and 3x3 matrix part.\n\n" | ||
449 | "Supported operations ...", | ||
450 | bp::no_init) | ||
451 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(PseudoInertiaPythonVisitor<PseudoInertia>()) |
452 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CopyableVisitor<PseudoInertia>()) |
453 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(PrintableVisitor<PseudoInertia>()) |
454 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CastVisitor<PseudoInertia>()) |
455 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(ExposeConstructorByCastVisitor<PseudoInertia, ::pinocchio::PseudoInertia>()); |
456 | 69 | } | |
457 | |||
458 | private: | ||
459 | 1 | static Matrix4 __array__(const PseudoInertia & self, bp::object, bp::object) | |
460 | { | ||
461 | 1 | return self.toMatrix(); | |
462 | } | ||
463 | |||
464 | struct Pickle : bp::pickle_suite | ||
465 | { | ||
466 | ✗ | static boost::python::tuple getinitargs(const PseudoInertia & pi) | |
467 | { | ||
468 | ✗ | return bp::make_tuple(pi.mass, pi.h, pi.sigma); | |
469 | } | ||
470 | |||
471 | 65 | static bool getstate_manages_dict() | |
472 | { | ||
473 | 65 | return true; | |
474 | } | ||
475 | }; | ||
476 | |||
477 | }; // struct PseudoInertiaPythonVisitor | ||
478 | |||
479 | template<typename LogCholeskyParameters> | ||
480 | struct LogCholeskyParametersPythonVisitor | ||
481 | : public boost::python::def_visitor<LogCholeskyParametersPythonVisitor<LogCholeskyParameters>> | ||
482 | { | ||
483 | enum | ||
484 | { | ||
485 | Options = LogCholeskyParameters::Options | ||
486 | }; | ||
487 | typedef typename LogCholeskyParameters::Scalar Scalar; | ||
488 | typedef typename LogCholeskyParameters::Vector10 Vector10; | ||
489 | typedef typename LogCholeskyParameters::Matrix10 Matrix10; | ||
490 | typedef Eigen::Matrix<Scalar, Eigen::Dynamic, 1, Options> VectorXs; | ||
491 | typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options> MatrixXs; | ||
492 | |||
493 | public: | ||
494 | template<class PyClass> | ||
495 | 69 | void visit(PyClass & cl) const | |
496 | { | ||
497 |
2/4✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
69 | cl.def( |
498 | "__init__", | ||
499 | bp::make_constructor( | ||
500 | 69 | &LogCholeskyParametersPythonVisitor::makeFromParameters, bp::default_call_policies(), | |
501 | bp::args("log_cholesky_parameters")), | ||
502 | "Initialize from log cholesky parameters.") | ||
503 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
|
69 | .def(bp::init<const LogCholeskyParameters &>( |
504 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | (bp::arg("self"), bp::arg("clone")), "Copy constructor")) |
505 | |||
506 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .add_property( |
507 | "parameters", &LogCholeskyParametersPythonVisitor::getParameters, | ||
508 | &LogCholeskyParametersPythonVisitor::setParameters, "Log Cholesky parameters.") | ||
509 | |||
510 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
511 | "toDynamicParameters", &LogCholeskyParametersPythonVisitor::toDynamicParameters_proxy, | ||
512 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | bp::arg("self"), "Returns the dynamic parameters representation.") |
513 | 138 | .def( | |
514 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "toPseudoInertia", &LogCholeskyParameters::toPseudoInertia, bp::arg("self"), |
515 | "Returns the Pseudo Inertia representation.") | ||
516 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
517 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "toInertia", &LogCholeskyParameters::toInertia, bp::arg("self"), |
518 | "Returns the Inertia representation.") | ||
519 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
520 | "calculateJacobian", &LogCholeskyParametersPythonVisitor::calculateJacobian_proxy, | ||
521 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | bp::arg("self"), "Calculates the Jacobian of the log Cholesky parameters.") |
522 | |||
523 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def("__array__", &LogCholeskyParametersPythonVisitor::getParameters) |
524 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
525 | "__array__", &__array__, | ||
526 |
9/18✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 69 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 69 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 69 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 69 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 69 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 69 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 69 times.
✗ Branch 26 not taken.
|
138 | (bp::arg("self"), bp::arg("dtype") = bp::object(), bp::arg("copy") = bp::object())) |
527 | #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION | ||
528 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def_pickle(Pickle()) |
529 | #endif | ||
530 | ; | ||
531 | 69 | } | |
532 | |||
533 | 2 | static LogCholeskyParameters * makeFromParameters(const VectorXs & params) | |
534 | { | ||
535 |
5/6✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
|
2 | if (params.rows() != 10 || params.cols() != 1) |
536 | { | ||
537 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | std::ostringstream shape; |
538 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
|
1 | shape << "(" << params.rows() << ", " << params.cols() << ")"; |
539 |
4/8✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
|
1 | throw std::invalid_argument( |
540 | "Wrong size: params" + shape.str() + " but should have the following shape (10, 1)"); | ||
541 | 1 | } | |
542 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | return new LogCholeskyParameters(params); |
543 | } | ||
544 | |||
545 | 2 | static VectorXs getParameters(const LogCholeskyParameters & self) | |
546 | { | ||
547 | 2 | return self.parameters; | |
548 | } | ||
549 | ✗ | static void setParameters(LogCholeskyParameters & self, const Vector10 & parameters) | |
550 | { | ||
551 | ✗ | self.parameters = parameters; | |
552 | } | ||
553 | |||
554 | 1 | static VectorXs toDynamicParameters_proxy(const LogCholeskyParameters & self) | |
555 | { | ||
556 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | return self.toDynamicParameters(); |
557 | } | ||
558 | |||
559 | 1 | static MatrixXs calculateJacobian_proxy(const LogCholeskyParameters & self) | |
560 | { | ||
561 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | return self.calculateJacobian(); |
562 | } | ||
563 | |||
564 | 69 | static void expose() | |
565 | { | ||
566 | #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 6 && EIGENPY_VERSION_AT_LEAST(2, 9, 0) | ||
567 | typedef PINOCCHIO_SHARED_PTR_HOLDER_TYPE(LogCholeskyParameters) HolderType; | ||
568 | #else | ||
569 | typedef ::boost::python::detail::not_specified HolderType; | ||
570 | #endif | ||
571 | 69 | bp::class_<LogCholeskyParameters, HolderType>( | |
572 | "LogCholeskyParameters", | ||
573 | "This class represents log Cholesky parameters.\n\n" | ||
574 | "Supported operations ...", | ||
575 | bp::no_init) | ||
576 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(LogCholeskyParametersPythonVisitor<LogCholeskyParameters>()) |
577 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CopyableVisitor<LogCholeskyParameters>()) |
578 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(PrintableVisitor<LogCholeskyParameters>()) |
579 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CastVisitor<LogCholeskyParameters>()) |
580 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(ExposeConstructorByCastVisitor< |
581 | LogCholeskyParameters, ::pinocchio::LogCholeskyParameters>()); | ||
582 | 69 | } | |
583 | |||
584 | private: | ||
585 | 1 | static VectorXs __array__(const LogCholeskyParameters & self, bp::object, bp::object) | |
586 | { | ||
587 | 1 | return self.parameters; | |
588 | } | ||
589 | |||
590 | struct Pickle : bp::pickle_suite | ||
591 | { | ||
592 | ✗ | static boost::python::tuple getinitargs(const LogCholeskyParameters & lcp) | |
593 | { | ||
594 | ✗ | return bp::make_tuple(lcp.parameters); | |
595 | } | ||
596 | |||
597 | 65 | static bool getstate_manages_dict() | |
598 | { | ||
599 | 65 | return true; | |
600 | } | ||
601 | }; | ||
602 | |||
603 | }; // struct LogCholeskyParametersPythonVisitor | ||
604 | |||
605 | } // namespace python | ||
606 | } // namespace pinocchio | ||
607 | |||
608 | #endif // ifndef __pinocchio_python_spatial_inertia_hpp__ | ||
609 |