Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/math/lanczos-decomposition.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 20 | 20 | 100.0% |
Branches: | 19 | 38 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2024 INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_python_math_lanczos_decomposition_hpp__ | ||
6 | #define __pinocchio_python_math_lanczos_decomposition_hpp__ | ||
7 | |||
8 | #include "pinocchio/bindings/python/fwd.hpp" | ||
9 | #include "pinocchio/math/lanczos-decomposition.hpp" | ||
10 | |||
11 | #include <eigenpy/eigenpy.hpp> | ||
12 | #include <eigenpy/memory.hpp> | ||
13 | |||
14 | namespace pinocchio | ||
15 | { | ||
16 | namespace python | ||
17 | { | ||
18 | namespace bp = boost::python; | ||
19 | |||
20 | template<typename LanczosDecomposition> | ||
21 | struct LanczosDecompositionPythonVisitor | ||
22 | : public boost::python::def_visitor<LanczosDecompositionPythonVisitor<LanczosDecomposition>> | ||
23 | { | ||
24 | typedef typename LanczosDecomposition::Scalar Scalar; | ||
25 | typedef typename LanczosDecomposition::TridiagonalMatrix TridiagonalMatrix; | ||
26 | typedef typename LanczosDecomposition::PlainMatrix PlainMatrix; | ||
27 | |||
28 | public: | ||
29 | template<class PyClass> | ||
30 | 65 | void visit(PyClass & cl) const | |
31 | { | ||
32 | // static const Scalar dummy_precision = Eigen::NumTraits<Scalar>::dummy_precision(); | ||
33 | |||
34 |
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 | cl.def(bp::init<const context::MatrixXs &, const Eigen::DenseIndex>( |
35 |
2/4✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 65 times.
✗ Branch 6 not taken.
|
195 | (bp::arg("self"), bp::arg("mat"), bp::arg("decomposition_size")), |
36 | "Default constructor from a given matrix and a given decomposition size.")) | ||
37 | |||
38 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | .def( |
39 | "compute", &LanczosDecomposition::template compute<context::MatrixXs>, | ||
40 | bp::args("self", "mat"), | ||
41 | "Computes the Lanczos decomposition for the given input matrix.") | ||
42 | |||
43 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
44 | "Ts", (TridiagonalMatrix & (LanczosDecomposition::*)()) & LanczosDecomposition::Ts, | ||
45 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | bp::arg("self"), |
46 | "Returns the tridiagonal matrix associated with the Lanczos decomposition.", | ||
47 | 65 | bp::return_internal_reference<>()) | |
48 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
49 | "Qs", (PlainMatrix & (LanczosDecomposition::*)()) & LanczosDecomposition::Qs, | ||
50 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | bp::arg("self"), |
51 | "Returns the orthogonal basis associated with the Lanczos decomposition.", | ||
52 | 65 | bp::return_internal_reference<>()) | |
53 | |||
54 | 130 | .def( | |
55 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
130 | "rank", &LanczosDecomposition::rank, bp::arg("self"), |
56 | "Returns the rank of the decomposition.") | ||
57 | |||
58 |
2/4✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 65 times.
✗ Branch 5 not taken.
|
130 | .def( |
59 | "computeDecompositionResidual", | ||
60 | &LanczosDecomposition::template computeDecompositionResidual<context::MatrixXs>, | ||
61 | bp::args("self", "mat"), | ||
62 | "Computes the residual associated with the decomposition, namely, the quantity \f$ " | ||
63 | "A Q_s - Q_s T_s \f$") | ||
64 | |||
65 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
66 |
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) |
67 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self != bp::self) |
68 | #endif | ||
69 | |||
70 | ; | ||
71 | 65 | } | |
72 | |||
73 | 65 | static void expose() | |
74 | { | ||
75 | #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 6 && EIGENPY_VERSION_AT_LEAST(2, 9, 0) | ||
76 | typedef PINOCCHIO_SHARED_PTR_HOLDER_TYPE(LanczosDecomposition) HolderType; | ||
77 | #else | ||
78 | typedef ::boost::python::detail::not_specified HolderType; | ||
79 | #endif | ||
80 | 65 | bp::class_<LanczosDecomposition, HolderType>( | |
81 | "LanczosDecomposition", "Lanczos decomposition.", bp::no_init) | ||
82 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def(LanczosDecompositionPythonVisitor()); |
83 | 65 | } | |
84 | }; | ||
85 | |||
86 | } // namespace python | ||
87 | } // namespace pinocchio | ||
88 | |||
89 | #endif // ifndef __pinocchio_python_math_lanczos_decomposition_hpp__ | ||
90 |