Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/spatial/symmetric3.hpp |
Date: | 2024-08-27 18:20:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 67 | 73 | 91.8% |
Branches: | 100 | 200 | 50.0% |
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 | 20 | void visit(PyClass & cl) const | |
48 | { | ||
49 | 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 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
|
20 | cl.def(bp::init<>((bp::arg("self")), "Default constructor.")) |
53 |
3/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
|
20 | .def(bp::init<const Matrix3 &>( |
54 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | (bp::arg("self"), bp::arg("I")), "Initialize from symmetrical matrix I of size 3x3.")) |
55 |
3/6✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
|
20 | .def(bp::init<const Vector6 &>( |
56 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | (bp::arg("self"), bp::arg("I")), "Initialize from vector I of size 6.")) |
57 |
8/16✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 20 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 20 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 20 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 20 times.
✗ Branch 23 not taken.
|
120 | .def(bp::init< |
58 | const Scalar &, const Scalar &, const Scalar &, const Scalar &, const Scalar &, | ||
59 | const Scalar &>( | ||
60 |
5/10✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 20 times.
✗ Branch 14 not taken.
|
100 | (bp::arg("self"), bp::arg("a0"), bp::arg("a1"), bp::arg("a2"), bp::arg("a3"), |
61 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
60 | bp::arg("a4"), bp::arg("a5")), |
62 | "Initialize from 6 scalar values.")) | ||
63 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def( |
64 |
4/8✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
|
40 | bp::init<const Symmetric3 &>((bp::arg("self"), bp::arg("other")), "Copy constructor.")) |
65 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def("Zero", &Symmetric3::Zero, "Returns a zero 3x3 matrix.") |
66 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .staticmethod("Zero") |
67 | 40 | .def( | |
68 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | "setZero", &Symmetric3::setZero, bp::arg("self"), |
69 | "Set all the components of *this to zero.") | ||
70 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
20 | .def("Random", &Symmetric3::Random, "Returns a random symmetric 3x3 matrix.") |
71 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .staticmethod("Random") |
72 | 40 | .def( | |
73 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | "setRandom", &Symmetric3::setRandom, bp::arg("self"), |
74 | "Set all the components of *this randomly.") | ||
75 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
20 | .def("Identity", &Symmetric3::Identity, "Returns identity matrix.") |
76 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .staticmethod("Identity") |
77 | 40 | .def( | |
78 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | "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 20 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
|
20 | .def(bp::self == bp::self) |
82 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self != bp::self) |
83 | #endif | ||
84 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
85 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def( |
86 | "isApprox", &Symmetric3::isApprox, | ||
87 |
5/10✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 20 times.
✗ Branch 14 not taken.
|
60 | (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 20 times.
✗ Branch 2 not taken.
|
20 | .def( |
91 |
4/8✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
|
40 | "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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .def( |
99 | "inverse", &Symmetric3::template inverse<Matrix3Like>, bp::args("self", "res"), | ||
100 | "Invert the symmetrical 3x3 matrix.") | ||
101 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .def("fill", &Symmetric3::fill, bp::args("self", "value")) |
102 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
|
20 | .def(bp::self - bp::other<SkewSquare>()) |
103 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self -= bp::other<SkewSquare>()) |
104 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self - bp::other<AlphaSkewSquare>()) |
105 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self -= bp::other<AlphaSkewSquare>()) |
106 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .add_property( |
107 | "data", &Symmetric3PythonVisitor::getData, &Symmetric3PythonVisitor::setData, | ||
108 | "6D vector containing the data of the symmetric 3x3 matrix.") | ||
109 | 40 | .def( | |
110 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | "matrix", &Symmetric3::matrix, bp::arg("self"), |
111 | "Returns a matrix representation of the data.") | ||
112 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .def("vtiv", &Symmetric3::vtiv, bp::args("self", "v")) |
113 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
20 | .staticmethod("vxs") |
118 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
20 | .staticmethod("svx") |
122 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .def( |
123 | "rhsMult", &Symmetric3::template rhsMult<Vector3, Vector3>, | ||
124 | bp::args("SE3", "vin", "vout")) | ||
125 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .staticmethod("rhsMult") |
126 | |||
127 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self + bp::self) |
128 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self += bp::self) |
129 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self - bp::self) |
130 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self -= bp::self) |
131 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self *= bp::other<Scalar>()) |
132 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self * bp::other<Vector3Like>()) |
133 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self - bp::other<Matrix3Like>()) |
134 |
1/2✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
|
20 | .def(bp::self + bp::other<Matrix3Like>()) |
135 | |||
136 | 40 | .def( | |
137 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | "decomposeltI", &Symmetric3::decomposeltI, bp::arg("self"), |
138 | "Computes L for a symmetric matrix S.") | ||
139 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
40 | .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 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
20 | .def_pickle(Pickle()) |
145 | #endif | ||
146 | ; | ||
147 | PINOCCHIO_COMPILER_DIAGNOSTIC_POP | ||
148 | 20 | } | |
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 | 20 | static void expose() | |
160 | { | ||
161 | 20 | 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 20 times.
✗ Branch 2 not taken.
|
20 | .def(Symmetric3PythonVisitor<Symmetric3>()) |
167 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def(CastVisitor<Symmetric3>()) |
168 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def(ExposeConstructorByCastVisitor<Symmetric3, ::pinocchio::Symmetric3>()) |
169 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def(CopyableVisitor<Symmetric3>()) |
170 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 | .def(PrintableVisitor<Symmetric3>()); |
171 | 20 | } | |
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 |