pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
lanczos-decomposition.hpp
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
14namespace 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 void visit(PyClass & cl) const
31 {
32 // static const Scalar dummy_precision = Eigen::NumTraits<Scalar>::dummy_precision();
33
34 cl.def(bp::init<const context::MatrixXs &, const Eigen::DenseIndex>(
35 (bp::arg("self"), bp::arg("mat"), bp::arg("decomposition_size")),
36 "Default constructor from a given matrix and a given decomposition size."))
37
38 .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 .def(
44 "Ts", (TridiagonalMatrix & (LanczosDecomposition::*)()) & LanczosDecomposition::Ts,
45 bp::arg("self"),
46 "Returns the tridiagonal matrix associated with the Lanczos decomposition.",
47 bp::return_internal_reference<>())
48 .def(
49 "Qs", (PlainMatrix & (LanczosDecomposition::*)()) & LanczosDecomposition::Qs,
50 bp::arg("self"),
51 "Returns the orthogonal basis associated with the Lanczos decomposition.",
52 bp::return_internal_reference<>())
53
54 .def(
55 "rank", &LanczosDecomposition::rank, bp::arg("self"),
56 "Returns the rank of the decomposition.")
57
58 .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 .def(bp::self == bp::self)
67 .def(bp::self != bp::self)
68#endif
69
70 ;
71 }
72
73 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 bp::class_<LanczosDecomposition, HolderType>(
81 "LanczosDecomposition", "Lanczos decomposition.", bp::no_init)
82 .def(LanczosDecompositionPythonVisitor());
83 }
84 };
85
86 } // namespace python
87} // namespace pinocchio
88
89#endif // ifndef __pinocchio_python_math_lanczos_decomposition_hpp__
Main pinocchio namespace.
Definition treeview.dox:11