| Directory: | ./ |
|---|---|
| File: | include/pinocchio/bindings/python/math/tridiagonal-matrix.hpp |
| Date: | 2025-02-12 21:03:38 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 35 | 35 | 100.0% |
| Branches: | 47 | 96 | 49.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2024 INRIA | ||
| 3 | // | ||
| 4 | |||
| 5 | #ifndef __pinocchio_python_math_tridiagonal_matrix_hpp__ | ||
| 6 | #define __pinocchio_python_math_tridiagonal_matrix_hpp__ | ||
| 7 | |||
| 8 | #include "pinocchio/bindings/python/fwd.hpp" | ||
| 9 | #include "pinocchio/math/tridiagonal-matrix.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 TridiagonalSymmetricMatrix> | ||
| 21 | struct TridiagonalSymmetricMatrixPythonVisitor | ||
| 22 | : public boost::python::def_visitor< | ||
| 23 | TridiagonalSymmetricMatrixPythonVisitor<TridiagonalSymmetricMatrix>> | ||
| 24 | { | ||
| 25 | typedef typename TridiagonalSymmetricMatrix::Scalar Scalar; | ||
| 26 | typedef typename TridiagonalSymmetricMatrix::CoeffVectorType CoeffVectorType; | ||
| 27 | typedef typename TridiagonalSymmetricMatrix::PlainMatrixType PlainMatrixType; | ||
| 28 | |||
| 29 | public: | ||
| 30 | template<class PyClass> | ||
| 31 | 69 | void visit(PyClass & cl) const | |
| 32 | { | ||
| 33 |
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(); |
| 34 | |||
| 35 |
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 | cl.def(bp::init<Eigen::DenseIndex>( |
| 36 |
1/2✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
|
138 | (bp::arg("self"), bp::arg("size")), "Default constructor from a given size.")) |
| 37 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
| 38 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self == bp::self) |
| 39 |
1/2✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
|
65 | .def(bp::self != bp::self) |
| 40 | #endif | ||
| 41 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
| 42 | "diagonal", | ||
| 43 | (CoeffVectorType & (TridiagonalSymmetricMatrix::*)()) | ||
| 44 | & TridiagonalSymmetricMatrix::diagonal, | ||
| 45 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | bp::arg("self"), |
| 46 | "Reference of the diagonal elements of the symmetric tridiagonal matrix.", | ||
| 47 | 69 | bp::return_internal_reference<>()) | |
| 48 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
| 49 | "subDiagonal", | ||
| 50 | (CoeffVectorType & (TridiagonalSymmetricMatrix::*)()) | ||
| 51 | & TridiagonalSymmetricMatrix::subDiagonal, | ||
| 52 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | bp::arg("self"), |
| 53 | "Reference of the sub diagonal elements of the symmetric tridiagonal matrix.", | ||
| 54 | 69 | bp::return_internal_reference<>()) | |
| 55 | |||
| 56 | 138 | .def( | |
| 57 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "setIdentity", &TridiagonalSymmetricMatrix::setIdentity, bp::arg("self"), |
| 58 | "Set the current tridiagonal matrix to identity.") | ||
| 59 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
| 60 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "setZero", &TridiagonalSymmetricMatrix::setZero, bp::arg("self"), |
| 61 | "Set the current tridiagonal matrix to zero.") | ||
| 62 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def( |
| 63 | "setDiagonal", &TridiagonalSymmetricMatrix::template setDiagonal<CoeffVectorType>, | ||
| 64 | bp::args("self", "diagonal"), | ||
| 65 | "Set the current tridiagonal matrix to a diagonal matrix given by the entry vector " | ||
| 66 | "diagonal.") | ||
| 67 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def( |
| 68 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
138 | "setRandom", &TridiagonalSymmetricMatrix::setRandom, bp::arg("self"), |
| 69 | "Set the current tridiagonal matrix to random.") | ||
| 70 | #ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
| 71 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
| 72 | "isIdentity", &TridiagonalSymmetricMatrix::isIdentity, | ||
| 73 |
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 | (bp::arg("self"), bp::arg("prec") = dummy_precision), |
| 74 | "Returns true if *this is approximately equal to the identity matrix, within the " | ||
| 75 | "precision given by prec.") | ||
| 76 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
| 77 | "isZero", &TridiagonalSymmetricMatrix::isZero, | ||
| 78 |
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 | (bp::arg("self"), bp::arg("prec") = dummy_precision), |
| 79 | "Returns true if *this is approximately equal to the zero matrix, within the " | ||
| 80 | "precision given by prec.") | ||
| 81 |
1/2✓ Branch 1 taken 65 times.
✗ Branch 2 not taken.
|
65 | .def( |
| 82 | "isDiagonal", &TridiagonalSymmetricMatrix::isDiagonal, | ||
| 83 |
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 | (bp::arg("self"), bp::arg("prec") = dummy_precision), |
| 84 | "Returns true if *this is approximately equal to the a diagonal matrix, within the " | ||
| 85 | "precision given by prec.") | ||
| 86 | #endif // PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS | ||
| 87 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def("rows", &TridiagonalSymmetricMatrix::rows, bp::arg("self")) |
| 88 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def("cols", &TridiagonalSymmetricMatrix::cols, bp::arg("self")) |
| 89 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
|
138 | .def("matrix", &TridiagonalSymmetricMatrix::matrix, bp::arg("self")) |
| 90 | |||
| 91 |
3/6✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 69 times.
✗ Branch 9 not taken.
|
138 | .def(bp::self * PlainMatrixType()) |
| 92 |
2/4✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 69 times.
✗ Branch 6 not taken.
|
69 | .def(PlainMatrixType() * bp::self); |
| 93 | 69 | } | |
| 94 | |||
| 95 | 69 | static void expose() | |
| 96 | { | ||
| 97 | #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION == 6 && EIGENPY_VERSION_AT_LEAST(2, 9, 0) | ||
| 98 | typedef PINOCCHIO_SHARED_PTR_HOLDER_TYPE(TridiagonalSymmetricMatrix) HolderType; | ||
| 99 | #else | ||
| 100 | typedef ::boost::python::detail::not_specified HolderType; | ||
| 101 | #endif | ||
| 102 | 69 | bp::class_<TridiagonalSymmetricMatrix, HolderType>( | |
| 103 | "TridiagonalSymmetricMatrix", "Tridiagonal symmetric matrix.", bp::no_init) | ||
| 104 |
1/2✓ Branch 1 taken 69 times.
✗ Branch 2 not taken.
|
69 | .def(TridiagonalSymmetricMatrixPythonVisitor()); |
| 105 | 69 | } | |
| 106 | }; | ||
| 107 | |||
| 108 | } // namespace python | ||
| 109 | } // namespace pinocchio | ||
| 110 | |||
| 111 | #endif // ifndef __pinocchio_python_math_tridiagonal_matrix_hpp__ | ||
| 112 |