eigenpy 3.12.0
Bindings between Numpy and Eigen using Boost.Python
Loading...
Searching...
No Matches
PermutationMatrix.hpp
1/*
2 * Copyright 2024 INRIA
3 */
4
5#ifndef __eigenpy_decompositions_permutation_matrix_hpp__
6#define __eigenpy_decompositions_permutation_matrix_hpp__
7
8#include "eigenpy/eigenpy.hpp"
9#include "eigenpy/eigen/EigenBase.hpp"
10
11namespace eigenpy {
12
13template <int SizeAtCompileTime, int MaxSizeAtCompileTime = SizeAtCompileTime,
14 typename StorageIndex_ = int>
16 : public boost::python::def_visitor<PermutationMatrixVisitor<
17 SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>> {
18 typedef StorageIndex_ StorageIndex;
19 typedef Eigen::PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime,
20 StorageIndex>
21 PermutationMatrix;
22 typedef typename PermutationMatrix::DenseMatrixType DenseMatrixType;
23 typedef PermutationMatrix Self;
24 typedef Eigen::Matrix<StorageIndex, SizeAtCompileTime, 1, 0,
25 MaxSizeAtCompileTime, 1>
26 VectorIndex;
27
28 template <class PyClass>
29 void visit(PyClass &cl) const {
30 cl.def(bp::init<const Eigen::DenseIndex>(bp::args("self", "size"),
31 "Default constructor"))
32 .def(bp::init<VectorIndex>(
33 bp::args("self", "indices"),
34 "The indices array has the meaning that the permutations sends "
35 "each integer i to indices[i].\n"
36 "It is your responsibility to check that the indices array that "
37 "you passes actually describes a permutation, i.e., each value "
38 "between 0 and n-1 occurs exactly once, where n is the array's "
39 "size."))
40
41 .def(
42 "indices",
43 +[](const PermutationMatrix &self) {
44 return VectorIndex(self.indices());
45 },
46 bp::arg("self"), "The stored array representing the permutation.")
47
48 .def("applyTranspositionOnTheLeft",
49 &PermutationMatrix::applyTranspositionOnTheLeft,
50 bp::args("self", "i", "j"),
51 "Multiplies self by the transposition (ij) on the left.",
52 bp::return_self<>())
53 .def("applyTranspositionOnTheRight",
54 &PermutationMatrix::applyTranspositionOnTheRight,
55 bp::args("self", "i", "j"),
56 "Multiplies self by the transposition (ij) on the right.",
57 bp::return_self<>())
58
59 .def("setIdentity",
60 (void (PermutationMatrix::*)())&PermutationMatrix::setIdentity,
61 bp::arg("self"),
62 "Sets self to be the identity permutation matrix.")
63 .def("setIdentity",
64 (void (PermutationMatrix::*)(
65 Eigen::DenseIndex))&PermutationMatrix::setIdentity,
66 bp::args("self", "size"),
67 "Sets self to be the identity permutation matrix of given size.")
68
69 .def("toDenseMatrix", &PermutationMatrix::toDenseMatrix,
70 bp::arg("self"),
71 "Returns a numpy array object initialized from this permutation "
72 "matrix.")
73
74 .def(
75 "transpose",
76 +[](const PermutationMatrix &self) -> PermutationMatrix {
77 return self.transpose();
78 },
79 bp::arg("self"), "Returns the tranpose permutation matrix.")
80 .def(
81 "inverse",
82 +[](const PermutationMatrix &self) -> PermutationMatrix {
83 return self.inverse();
84 },
85 bp::arg("self"), "Returns the inverse permutation matrix.")
86
87 .def("resize", &PermutationMatrix::resize, bp::args("self", "size"),
88 "Resizes to given size.")
89
90 .def(bp::self * bp::self)
92 }
93
94 static void expose(const std::string &name) {
95 bp::class_<PermutationMatrix>(name.c_str(),
96 "Permutation matrix.\n"
97 "This class represents a permutation matrix, "
98 "internally stored as a vector of integers.",
99 bp::no_init)
102 }
103};
104
105} // namespace eigenpy
106
107#endif // ifndef __eigenpy_decompositions_permutation_matrix_hpp__
void expose()
Call the expose function of a given type T.
Definition expose.hpp:23
Add the Python method id to retrieving a unique id for a given object exposed with Boost....
Definition id.hpp:18