eigenpy
3.13.0
Bindings between Numpy and Eigen using Boost.Python
Toggle main menu visibility
Loading...
Searching...
No Matches
JacobiSVD.hpp
1
/*
2
* Copyright 2025 INRIA
3
*/
4
5
#ifndef __eigenpy_decompositions_jacobisvd_hpp__
6
#define __eigenpy_decompositions_jacobisvd_hpp__
7
8
#include <Eigen/SVD>
9
#include <Eigen/Core>
10
11
#include "eigenpy/eigenpy.hpp"
12
#include "eigenpy/utils/scalar-name.hpp"
13
#include "eigenpy/eigen/EigenBase.hpp"
14
#include "eigenpy/decompositions/SVDBase.hpp"
15
16
namespace
eigenpy
{
17
18
template
<
typename
JacobiSVD>
19
struct
JacobiSVDVisitor
20
:
public
boost::python::def_visitor<JacobiSVDVisitor<JacobiSVD>> {
21
typedef
JacobiSVD Solver;
22
typedef
typename
JacobiSVD::MatrixType MatrixType;
23
typedef
Eigen::MatrixBase<MatrixType> MatrixBaseType;
24
typedef
typename
MatrixType::Scalar Scalar;
25
26
template
<
class
PyClass>
27
void
visit(PyClass& cl)
const
{
28
cl.def(bp::init<>(bp::arg(
"self"
),
"Default constructor"
))
29
.def(bp::init<Eigen::DenseIndex, Eigen::DenseIndex,
30
bp::optional<unsigned int>>(
31
bp::args(
"self"
,
"rows"
,
"cols"
,
"computationOptions "
),
32
"Default Constructor with memory preallocation."
))
33
.def(bp::init<MatrixType, bp::optional<unsigned int>>(
34
bp::args(
"self"
,
"matrix"
,
"computationOptions "
),
35
"Constructor performing the decomposition of given matrix."
))
36
37
.def(
"cols"
, &JacobiSVD::cols, bp::arg(
"self"
),
38
"Returns the number of columns. "
)
39
.def(
40
"compute"
,
41
+[](Solver& self,
const
MatrixType& matrix) -> Solver& {
42
return
self.compute(matrix);
43
},
44
bp::args(
"self"
,
"matrix"
),
45
"Method performing the decomposition of given matrix. Computes "
46
"Thin/Full "
47
"unitaries U/V if specified using the Options template parameter "
48
"or the class constructor. "
,
49
bp::return_self<>())
50
.def(
51
"compute"
,
52
+[](Solver& self,
const
MatrixType& matrix,
53
unsigned
int
computationOptions) -> Solver& {
54
return
self.compute(matrix, computationOptions);
55
},
56
bp::args(
"self"
,
"matrix"
,
"computation_options"
),
57
"Method performing the decomposition of given matrix, as "
58
"specified by the computationOptions parameter. "
,
59
bp::return_self<>())
60
.def(
"rows"
, &JacobiSVD::rows, bp::arg(
"self"
),
61
"Returns the number of rows."
)
62
63
.def(
SVDBaseVisitor<JacobiSVD>
());
64
}
65
66
static
void
expose
() {
67
static
const
std::string classname =
68
"JacobiSVD_"
+ scalar_name<Scalar>::shortname();
69
expose
(classname);
70
}
71
72
static
void
expose
(
const
std::string& name) {
73
bp::class_<JacobiSVD, boost::noncopyable>(
74
name.c_str(),
75
"Two-sided Jacobi SVD decomposition of a rectangular matrix. \n\n"
76
"SVD decomposition consists in decomposing any n-by-p matrix A as a "
77
"product "
78
"A=USV∗ where U is a n-by-n unitary, V is a p-by-p unitary, and S is a "
79
"n-by-p r"
80
"eal positive matrix which is zero outside of its main diagonal; the "
81
"diagonal "
82
"entries of S are known as the singular values of A and the columns of "
83
"U and V "
84
"are known as the left and right singular vectors of A respectively. "
85
"\n\n"
86
"Singular values are always sorted in decreasing order. \n\n "
87
"This JacobiSVD decomposition computes only the singular values by "
88
"default. "
89
"If you want U or V, you need to ask for them explicitly. \n\n"
90
"You can ask for only thin U or V to be computed, meaning the "
91
"following. "
92
"In case of a rectangular n-by-p matrix, letting m be the smaller "
93
"value among "
94
"n and p, there are only m singular vectors; the remaining columns of "
95
"U and V "
96
"do not correspond to actual singular vectors. Asking for thin U or V "
97
"means asking "
98
"for only their m first columns to be formed. So U is then a n-by-m "
99
"matrix, and V "
100
"is then a p-by-m matrix. Notice that thin U and V are all you need "
101
"for (least squares) "
102
"solving."
,
103
bp::no_init)
104
.def(
JacobiSVDVisitor
())
105
.def(
IdVisitor<JacobiSVD>
());
106
}
107
};
108
109
}
// namespace eigenpy
110
111
#endif
// ifndef __eigenpy_decompositions_jacobisvd_hpp__
eigenpy
Definition
alignment.hpp:14
eigenpy::expose
void expose()
Call the expose function of a given type T.
Definition
expose.hpp:23
eigenpy::IdVisitor
Add the Python method id to retrieving a unique id for a given object exposed with Boost....
Definition
id.hpp:18
eigenpy::JacobiSVDVisitor
Definition
JacobiSVD.hpp:20
eigenpy::SVDBaseVisitor
Definition
SVDBase.hpp:19
include
eigenpy
decompositions
JacobiSVD.hpp
Generated by
1.17.0