Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/spatial/symmetric3.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 68 | 74 | 91.9% |
Branches: | 104 | 210 | 49.5% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2022 INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_python_spatial_symmetric3_hpp__ | ||
6 | #define __pinocchio_python_spatial_symmetric3_hpp__ | ||
7 | |||
8 | #include <eigenpy/exception.hpp> | ||
9 | #include <eigenpy/memory.hpp> | ||
10 | #include <eigenpy/eigen-to-python.hpp> | ||
11 | #include <boost/python/tuple.hpp> | ||
12 | |||
13 | #include "pinocchio/spatial/symmetric3.hpp" | ||
14 | |||
15 | #include "pinocchio/bindings/python/utils/cast.hpp" | ||
16 | #include "pinocchio/bindings/python/utils/copyable.hpp" | ||
17 | #include "pinocchio/bindings/python/utils/printable.hpp" | ||
18 | |||
19 | namespace pinocchio | ||
20 | { | ||
21 | namespace python | ||
22 | { | ||
23 | namespace bp = boost::python; | ||
24 | |||
25 | template<typename Symmetric3> | ||
26 | struct Symmetric3PythonVisitor | ||
27 | : public boost::python::def_visitor<Symmetric3PythonVisitor<Symmetric3>> | ||
28 | { | ||
29 | enum | ||
30 | { | ||
31 | Options = Symmetric3::Options | ||
32 | }; | ||
33 | typedef typename Symmetric3::Scalar Scalar; | ||
34 | typedef typename Symmetric3::Vector3 Vector3; | ||
35 | typedef typename Symmetric3::Vector6 Vector6; | ||
36 | typedef typename Symmetric3::Matrix3 Matrix3; | ||
37 | typedef typename Symmetric3::Matrix2 Matrix2; | ||
38 | typedef typename Symmetric3::Matrix32 Matrix32; | ||
39 | |||
40 | typedef Eigen::Matrix<Scalar, 3, 1, Options> Vector3Like; | ||
41 | typedef Eigen::Matrix<Scalar, 3, 3, Options> Matrix3Like; | ||
42 | typedef typename Symmetric3::SkewSquare SkewSquare; | ||
43 | typedef typename Symmetric3::AlphaSkewSquare AlphaSkewSquare; | ||
44 | |||
45 | public: | ||
46 | template<class PyClass> | ||
47 | 69 | void visit(PyClass & cl) const | |
48 | { | ||
49 |
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(); |
50 | PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH | ||
51 | PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED | ||
52 |
2/4✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
69 | cl.def(bp::init<>((bp::arg("self")), "Default constructor.")) |
53 |
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 Matrix3 &>( |
54 |
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("I")), "Initialize from symmetrical matrix I of size 3x3.")) |
55 |
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 Vector6 &>( |
56 |
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("I")), "Initialize from vector I of size 6.")) |
57 |
8/16✓ 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.
|
414 | .def(bp::init< |
58 | const Scalar &, const Scalar &, const Scalar &, const Scalar &, const Scalar &, | ||
59 | const Scalar &>( | ||
60 |
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.
|
345 | (bp::arg("self"), bp::arg("a0"), bp::arg("a1"), bp::arg("a2"), bp::arg("a3"), |
61 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
207 | bp::arg("a4"), bp::arg("a5")), |
62 | "Initialize from 6 scalar values.")) | ||
63 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
64 |
4/8✓ 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.
|
138 | bp::init<const Symmetric3 &>((bp::arg("self"), bp::arg("other")), "Copy constructor.")) |
65 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def("Zero", &Symmetric3::Zero, "Returns a zero 3x3 matrix.") |
66 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("Zero") |
67 | 138 | .def( | |
68 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "setZero", &Symmetric3::setZero, bp::arg("self"), |
69 | "Set all the components of *this to zero.") | ||
70 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
69 | .def("Random", &Symmetric3::Random, "Returns a random symmetric 3x3 matrix.") |
71 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("Random") |
72 | 138 | .def( | |
73 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "setRandom", &Symmetric3::setRandom, bp::arg("self"), |
74 | "Set all the components of *this randomly.") | ||
75 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
69 | .def("Identity", &Symmetric3::Identity, "Returns identity matrix.") |
76 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("Identity") |
77 | 138 | .def( | |
78 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "setIdentity", &Symmetric3::setIdentity, bp::arg("self"), |
79 | "Set the components of *this to identity.") | ||
80 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
81 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
|
65 | .def(bp::self == bp::self) |
82 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self != bp::self) |
83 | #endif | ||
84 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
85 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
86 | "isApprox", &Symmetric3::isApprox, | ||
87 |
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), |
88 | "Returns true if *this is approximately equal to other, within the precision given " | ||
89 | "by prec.") | ||
90 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
91 |
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", &Symmetric3::isZero, (bp::arg("self"), bp::arg("prec") = dummy_precision), |
92 | "Returns true if *this is approximately equal to the zero matrix, within the " | ||
93 | "precision given by prec.") | ||
94 | #endif | ||
95 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
96 | "setDiagonal", &Symmetric3::template setDiagonal<Vector3Like>, bp::args("self", "diag"), | ||
97 | "Set the diagonal elements of 3x3 matrix.") | ||
98 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
99 | "inverse", &Symmetric3::template inverse<Matrix3Like>, bp::args("self", "res"), | ||
100 | "Invert the symmetrical 3x3 matrix.") | ||
101 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def("fill", &Symmetric3::fill, bp::args("self", "value")) |
102 |
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::other<SkewSquare>()) |
103 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self -= bp::other<SkewSquare>()) |
104 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self - bp::other<AlphaSkewSquare>()) |
105 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self -= bp::other<AlphaSkewSquare>()) |
106 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .add_property( |
107 | "data", &Symmetric3PythonVisitor::getData, &Symmetric3PythonVisitor::setData, | ||
108 | "6D vector containing the data of the symmetric 3x3 matrix.") | ||
109 | 138 | .def( | |
110 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "matrix", &Symmetric3::matrix, bp::arg("self"), |
111 | "Returns a matrix representation of the data.") | ||
112 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def("vtiv", &Symmetric3::vtiv, bp::args("self", "v")) |
113 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
114 | "vxs", &Symmetric3::template vxs<Vector3>, bp::args("v", "S3"), | ||
115 | "Performs the operation \f$ M = [v]_{\times} S_{3} \f$., Apply the cross product of " | ||
116 | "v on each column of S and return result matrix M.") | ||
117 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
69 | .staticmethod("vxs") |
118 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | .def( |
119 | "svx", &Symmetric3::template vxs<Vector3>, bp::args("v", "S3"), | ||
120 | "Performs the operation \f$ M = S_{3} [v]_{\times} \f$.") | ||
121 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
69 | .staticmethod("svx") |
122 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
123 | "rhsMult", &Symmetric3::template rhsMult<Vector3, Vector3>, | ||
124 | bp::args("SE3", "vin", "vout")) | ||
125 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .staticmethod("rhsMult") |
126 | |||
127 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self + bp::self) |
128 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self += bp::self) |
129 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self - bp::self) |
130 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self -= bp::self) |
131 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self *= bp::other<Scalar>()) |
132 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self * bp::other<Vector3Like>()) |
133 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self - bp::other<Matrix3Like>()) |
134 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
69 | .def(bp::self + bp::other<Matrix3Like>()) |
135 | |||
136 | 138 | .def( | |
137 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "decomposeltI", &Symmetric3::decomposeltI, bp::arg("self"), |
138 | "Computes L for a symmetric matrix S.") | ||
139 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
|
134 | .def( |
140 | "rotate", &Symmetric3::template rotate<Matrix3>, bp::args("self", "R"), | ||
141 | "Computes R*S*R'") | ||
142 | |||
143 | #ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION | ||
144 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
65 | .def_pickle(Pickle()) |
145 | #endif | ||
146 | ; | ||
147 | PINOCCHIO_COMPILER_DIAGNOSTIC_POP | ||
148 | 69 | } | |
149 | |||
150 | ✗ | static Vector6 getData(const Symmetric3 & self) | |
151 | { | ||
152 | ✗ | return self.data(); | |
153 | } | ||
154 | ✗ | static void setData(Symmetric3 & self, Vector6 data) | |
155 | { | ||
156 | ✗ | self.data() = data; | |
157 | } | ||
158 | |||
159 | 69 | static void expose() | |
160 | { | ||
161 | 69 | bp::class_<Symmetric3>( | |
162 | "Symmetric3", | ||
163 | "This class represents symmetric 3x3 matrices.\n\n" | ||
164 | "Supported operations ...", | ||
165 | bp::no_init) | ||
166 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(Symmetric3PythonVisitor<Symmetric3>()) |
167 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CastVisitor<Symmetric3>()) |
168 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(ExposeConstructorByCastVisitor<Symmetric3, ::pinocchio::Symmetric3>()) |
169 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(CopyableVisitor<Symmetric3>()) |
170 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(PrintableVisitor<Symmetric3>()); |
171 | 69 | } | |
172 | |||
173 | private: | ||
174 | struct Pickle : bp::pickle_suite | ||
175 | { | ||
176 | ✗ | static boost::python::tuple getinitargs(const Symmetric3 & I) | |
177 | { | ||
178 | ✗ | return bp::make_tuple(I); | |
179 | } | ||
180 | }; | ||
181 | |||
182 | }; // struct Symmetric3PythonVisitor | ||
183 | |||
184 | } // namespace python | ||
185 | } // namespace pinocchio | ||
186 | |||
187 | #endif // __pinocchio_python_spatial_symmetric3_hpp__ | ||
188 |