Directory: | ./ |
---|---|
File: | src/matrix/operator-python-module-py.cc |
Date: | 2024-08-13 12:13:25 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 88 | 91 | 96.7% |
Branches: | 16 | 32 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "dynamic-graph/python/module.hh" | ||
2 | #include "operator.hh" | ||
3 | |||
4 | namespace dg = dynamicgraph; | ||
5 | namespace dgs = dynamicgraph::sot; | ||
6 | namespace bp = boost::python; | ||
7 | |||
8 | typedef bp::return_value_policy<bp::reference_existing_object> | ||
9 | reference_existing_object; | ||
10 | |||
11 | template <typename Operator> | ||
12 | 70 | void exposeUnaryOp() { | |
13 | typedef dgs::UnaryOp<Operator> O_t; | ||
14 | dg::python::exposeEntity<O_t, bp::bases<dg::Entity>, | ||
15 | dg::python::AddCommands>() | ||
16 |
1/2✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
|
70 | .def_readonly("sin", &O_t::SIN) |
17 |
1/2✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
|
70 | .def_readonly("sout", &O_t::SOUT); |
18 | 70 | } | |
19 | |||
20 | template <typename Operator> | ||
21 | 30 | void exposeBinaryOp() { | |
22 | typedef dgs::BinaryOp<Operator> O_t; | ||
23 | dg::python::exposeEntity<O_t, bp::bases<dg::Entity>, | ||
24 | dg::python::AddCommands>() | ||
25 |
1/2✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
|
30 | .def_readonly("sin1", &O_t::SIN1) |
26 |
1/2✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
|
30 | .def_readonly("sin2", &O_t::SIN2) |
27 |
1/2✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
|
30 | .def_readonly("sout", &O_t::SOUT); |
28 | 30 | } | |
29 | |||
30 | template <typename Operator> | ||
31 | 26 | auto exposeVariadicOpBase() { | |
32 | typedef dgs::VariadicOp<Operator> O_t; | ||
33 | typedef typename O_t::Base B_t; | ||
34 | return dg::python::exposeEntity<O_t, bp::bases<dg::Entity>, | ||
35 | dg::python::AddCommands>() | ||
36 |
1/2✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
|
52 | .def_readonly("sout", &O_t::SOUT) |
37 | ✗ | .def("sin", &B_t::getSignalIn, reference_existing_object()) | |
38 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
26 | .add_property("n_sin", &B_t::getSignalNumber, &B_t::setSignalNumber, |
39 | "the number of input signal.") | ||
40 | |||
41 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
26 | .def("setSignalNumber", &B_t::setSignalNumber, |
42 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
52 | "set the number of input signal.", bp::arg("size")) |
43 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
26 | .def("getSignalNumber", &B_t::getSignalNumber, |
44 |
3/6✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 13 times.
✗ Branch 8 not taken.
|
78 | "get the number of input signal.", bp::arg("size")); |
45 | } | ||
46 | |||
47 | template <typename Operator> | ||
48 | struct exposeVariadicOpImpl { | ||
49 | 20 | static void run() { exposeVariadicOpBase<Operator>(); } | |
50 | }; | ||
51 | |||
52 | template <typename T> | ||
53 | struct exposeVariadicOpImpl<dgs::AdderVariadic<T> > { | ||
54 | 6 | static void run() { | |
55 | typedef dgs::VariadicOp<dgs::AdderVariadic<T> > E_t; | ||
56 |
1/2✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
6 | exposeVariadicOpBase<dgs::AdderVariadic<T> >().add_property( |
57 | ✗ | "coeffs", +[](E_t &e) { return e.op.coeffs; }, | |
58 | ✗ | +[](E_t &e, const dg::Vector &c) { e.op.setCoeffs(c); }, | |
59 | "the multipliers."); | ||
60 | 6 | } | |
61 | }; | ||
62 | |||
63 | template <typename Operator> | ||
64 | 26 | void exposeVariadicOp() { | |
65 | 26 | exposeVariadicOpImpl<Operator>::run(); | |
66 | 26 | } | |
67 | |||
68 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
4 | BOOST_PYTHON_MODULE(wrap) { |
69 | using namespace dynamicgraph; | ||
70 | using namespace dynamicgraph::sot; | ||
71 | |||
72 | 2 | exposeUnaryOp<VectorSelecter>(); | |
73 | 2 | exposeUnaryOp<VectorComponent>(); | |
74 | 2 | exposeUnaryOp<MatrixSelector>(); | |
75 | 2 | exposeUnaryOp<MatrixColumnSelector>(); | |
76 | 2 | exposeUnaryOp<MatrixTranspose>(); | |
77 | 2 | exposeUnaryOp<Diagonalizer>(); | |
78 | |||
79 | /* ---------------------------------------------------------------------- */ | ||
80 | /* --- INVERSION -------------------------------------------------------- */ | ||
81 | /* ---------------------------------------------------------------------- */ | ||
82 | 2 | exposeUnaryOp<Inverser<Matrix> >(); | |
83 | 2 | exposeUnaryOp<Inverser<MatrixHomogeneous> >(); | |
84 | 2 | exposeUnaryOp<Inverser<MatrixTwist> >(); | |
85 | 2 | exposeUnaryOp<Normalize>(); | |
86 | 2 | exposeUnaryOp<InverserRotation>(); | |
87 | 2 | exposeUnaryOp<InverserQuaternion>(); | |
88 | |||
89 | /* ----------------------------------------------------------------------- */ | ||
90 | /* --- SE3/SO3 conversions ----------------------------------------------- */ | ||
91 | /* ----------------------------------------------------------------------- */ | ||
92 | |||
93 | 2 | exposeUnaryOp<SkewSymToVector>(); | |
94 | 2 | exposeUnaryOp<PoseUThetaToMatrixHomo>(); | |
95 | 2 | exposeUnaryOp<MatrixHomoToPoseUTheta>(); | |
96 | 2 | exposeUnaryOp<MatrixHomoToSE3Vector>(); | |
97 | 2 | exposeUnaryOp<SE3VectorToMatrixHomo>(); | |
98 | 2 | exposeUnaryOp<PoseQuaternionToMatrixHomo>(); | |
99 | 2 | exposeUnaryOp<MatrixHomoToPoseQuaternion>(); | |
100 | 2 | exposeUnaryOp<MatrixHomoToPoseRollPitchYaw>(); | |
101 | 2 | exposeUnaryOp<PoseRollPitchYawToMatrixHomo>(); | |
102 | 2 | exposeUnaryOp<PoseRollPitchYawToPoseUTheta>(); | |
103 | 2 | exposeUnaryOp<HomoToMatrix>(); | |
104 | 2 | exposeUnaryOp<MatrixToHomo>(); | |
105 | 2 | exposeUnaryOp<HomoToTwist>(); | |
106 | 2 | exposeUnaryOp<HomoToRotation>(); | |
107 | 2 | exposeUnaryOp<MatrixHomoToPose>(); | |
108 | 2 | exposeUnaryOp<RPYToMatrix>(); | |
109 | 2 | exposeUnaryOp<MatrixToRPY>(); | |
110 | 2 | exposeUnaryOp<RPYToQuaternion>(); | |
111 | 2 | exposeUnaryOp<QuaternionToRPY>(); | |
112 | 2 | exposeUnaryOp<QuaternionToMatrix>(); | |
113 | 2 | exposeUnaryOp<MatrixToQuaternion>(); | |
114 | 2 | exposeUnaryOp<MatrixToUTheta>(); | |
115 | 2 | exposeUnaryOp<UThetaToQuaternion>(); | |
116 | |||
117 | /* --- MULTIPLICATION --------------------------------------------------- */ | ||
118 | |||
119 | 2 | exposeBinaryOp<Multiplier_double_vector>(); | |
120 | 2 | exposeBinaryOp<Multiplier_matrix_vector>(); | |
121 | 2 | exposeBinaryOp<Multiplier_matrixHomo_vector>(); | |
122 | 2 | exposeBinaryOp<Multiplier_matrixTwist_vector>(); | |
123 | |||
124 | /* --- SUBSTRACTION ----------------------------------------------------- */ | ||
125 | 2 | exposeBinaryOp<Substraction<dynamicgraph::Matrix> >(); | |
126 | 2 | exposeBinaryOp<Substraction<dynamicgraph::Vector> >(); | |
127 | 2 | exposeBinaryOp<Substraction<double> >(); | |
128 | |||
129 | /* --- STACK ------------------------------------------------------------ */ | ||
130 | 2 | exposeBinaryOp<VectorStack>(); | |
131 | |||
132 | /* ---------------------------------------------------------------------- */ | ||
133 | 2 | exposeBinaryOp<Composer>(); | |
134 | |||
135 | /* --- CONVOLUTION PRODUCT ---------------------------------------------- */ | ||
136 | 2 | exposeBinaryOp<ConvolutionTemporal>(); | |
137 | |||
138 | /* --- BOOLEAN REDUCTION ------------------------------------------------ */ | ||
139 | 2 | exposeBinaryOp<Comparison<double> >(); | |
140 | 2 | exposeBinaryOp<MatrixComparison<Vector> >(); | |
141 | |||
142 | 2 | exposeBinaryOp<WeightedAdder<dynamicgraph::Matrix> >(); | |
143 | 2 | exposeBinaryOp<WeightedAdder<dynamicgraph::Vector> >(); | |
144 | 2 | exposeBinaryOp<WeightedAdder<double> >(); | |
145 | |||
146 | /* --- VectorMix ------------------------------------------------------------ | ||
147 | */ | ||
148 | 2 | exposeVariadicOp<VectorMix>(); | |
149 | |||
150 | /* --- ADDITION --------------------------------------------------------- */ | ||
151 | 2 | exposeVariadicOp<AdderVariadic<Matrix> >(); | |
152 | 2 | exposeVariadicOp<AdderVariadic<Vector> >(); | |
153 | 2 | exposeVariadicOp<AdderVariadic<double> >(); | |
154 | |||
155 | /* --- MULTIPLICATION --------------------------------------------------- */ | ||
156 | 2 | exposeVariadicOp<Multiplier<Matrix> >(); | |
157 | 2 | exposeVariadicOp<Multiplier<Vector> >(); | |
158 | 2 | exposeVariadicOp<Multiplier<MatrixRotation> >(); | |
159 | 2 | exposeVariadicOp<Multiplier<MatrixHomogeneous> >(); | |
160 | 2 | exposeVariadicOp<Multiplier<MatrixTwist> >(); | |
161 | 2 | exposeVariadicOp<Multiplier<VectorQuaternion> >(); | |
162 | 2 | exposeVariadicOp<Multiplier<double> >(); | |
163 | |||
164 | /* --- BOOLEAN --------------------------------------------------------- */ | ||
165 | 2 | exposeVariadicOp<BoolOp<0> >(); | |
166 | 2 | exposeVariadicOp<BoolOp<1> >(); | |
167 | 2 | } | |
168 |