pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
tridiagonal-matrix.hpp
1//
2// Copyright (c) 2024 INRIA
3//
4
5#pragma once
6
7#include "pinocchio/bindings/python/fwd.hpp"
8#include "pinocchio/math.hpp"
9
10#include <eigenpy/eigenpy.hpp>
11#include <eigenpy/memory.hpp>
12
13namespace pinocchio
14{
15 namespace python
16 {
17 namespace bp = boost::python;
18
19 template<typename TridiagonalSymmetricMatrix>
21 : public boost::python::def_visitor<
22 TridiagonalSymmetricMatrixPythonVisitor<TridiagonalSymmetricMatrix>>
23 {
24 typedef typename TridiagonalSymmetricMatrix::Scalar Scalar;
25 typedef typename TridiagonalSymmetricMatrix::CoeffVectorType CoeffVectorType;
26 typedef typename TridiagonalSymmetricMatrix::PlainMatrixType PlainMatrixType;
27
28 public:
29 template<class PyClass>
30 void visit(PyClass & cl) const
31 {
32 static const Scalar dummy_precision = Eigen::NumTraits<Scalar>::dummy_precision();
33
34 cl.def(
35 bp::init<Eigen::Index>(
36 (bp::arg("self"), bp::arg("size")), "Default constructor from a given size."))
37#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
38 .def(bp::self == bp::self)
39 .def(bp::self != bp::self)
40#endif
41 .def(
42 "diagonal",
43 (CoeffVectorType & (TridiagonalSymmetricMatrix::*)())
44 & TridiagonalSymmetricMatrix::diagonal,
45 bp::arg("self"),
46 "Reference of the diagonal elements of the symmetric tridiagonal matrix.",
47 bp::return_internal_reference<>())
48 .def(
49 "subDiagonal",
50 (CoeffVectorType & (TridiagonalSymmetricMatrix::*)())
51 & TridiagonalSymmetricMatrix::subDiagonal,
52 bp::arg("self"),
53 "Reference of the sub diagonal elements of the symmetric tridiagonal matrix.",
54 bp::return_internal_reference<>())
55
56 .def(
57 "setIdentity", &TridiagonalSymmetricMatrix::setIdentity, bp::arg("self"),
58 "Set the current tridiagonal matrix to identity.")
59 .def(
60 "setZero", &TridiagonalSymmetricMatrix::setZero, bp::arg("self"),
61 "Set the current tridiagonal matrix to zero.")
62 .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 .def(
68 "setRandom", &TridiagonalSymmetricMatrix::setRandom, bp::arg("self"),
69 "Set the current tridiagonal matrix to random.")
70#ifndef PINOCCHIO_PYTHON_SKIP_COMPARISON_OPERATIONS
71 .def(
72 "isIdentity", &TridiagonalSymmetricMatrix::isIdentity,
73 (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 .def(
77 "isZero", &TridiagonalSymmetricMatrix::isZero,
78 (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 .def(
82 "isDiagonal", &TridiagonalSymmetricMatrix::isDiagonal,
83 (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 .def("rows", &TridiagonalSymmetricMatrix::rows, bp::arg("self"))
88 .def("cols", &TridiagonalSymmetricMatrix::cols, bp::arg("self"))
89 .def("matrix", &TridiagonalSymmetricMatrix::matrix, bp::arg("self"))
90
91 .def(
92 "computeEigenvalue", &TridiagonalSymmetricMatrix::computeEigenvalue,
93 (bp::arg("self"), bp::arg("eigenvalue_index"), bp::arg("eps") = 1e-8),
94 "Computes the kth eigenvalue associated with the input tridiagonal matrix up to "
95 "precision eps.")
96
97 .def(
98 "computeSpectrum", &TridiagonalSymmetricMatrix::computeSpectrum,
99 (bp::arg("self"), bp::arg("eps") = 1e-8),
100 "Computes the full spectrum associated with the input tridiagonal matrix up to "
101 "precision eps.")
102
103 .def(bp::self * PlainMatrixType())
104 .def(PlainMatrixType() * bp::self);
105 }
106
107 static void expose()
108 {
109 typedef ::boost::python::detail::not_specified HolderType;
110 bp::class_<TridiagonalSymmetricMatrix, HolderType>(
111 "TridiagonalSymmetricMatrix", "Tridiagonal symmetric matrix.", bp::no_init)
113 }
114 };
115
116 } // namespace python
117} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11