16 :
public boost::python::def_visitor<PermutationMatrixVisitor<
17 SizeAtCompileTime, MaxSizeAtCompileTime, StorageIndex_>> {
18 typedef StorageIndex_ StorageIndex;
19 typedef Eigen::PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime,
22 typedef typename PermutationMatrix::DenseMatrixType DenseMatrixType;
23 typedef PermutationMatrix Self;
24 typedef Eigen::Matrix<StorageIndex, SizeAtCompileTime, 1, 0,
25 MaxSizeAtCompileTime, 1>
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 " 43 +[](
const PermutationMatrix &self) {
44 return VectorIndex(self.indices());
46 bp::arg(
"self"),
"The stored array representing the permutation.")
48 .def(
"applyTranspositionOnTheLeft",
49 &PermutationMatrix::applyTranspositionOnTheLeft,
50 bp::args(
"self",
"i",
"j"),
51 "Multiplies self by the transposition (ij) on the left.",
53 .def(
"applyTranspositionOnTheRight",
54 &PermutationMatrix::applyTranspositionOnTheRight,
55 bp::args(
"self",
"i",
"j"),
56 "Multiplies self by the transposition (ij) on the right.",
60 (
void (PermutationMatrix::*)())&PermutationMatrix::setIdentity,
62 "Sets self to be the identity permutation matrix.")
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.")
69 .def(
"toDenseMatrix", &PermutationMatrix::toDenseMatrix,
71 "Returns a numpy array object initialized from this permutation " 76 +[](
const PermutationMatrix &self) -> PermutationMatrix {
77 return self.transpose();
79 bp::arg(
"self"),
"Returns the tranpose permutation matrix.")
82 +[](
const PermutationMatrix &self) -> PermutationMatrix {
83 return self.inverse();
85 bp::arg(
"self"),
"Returns the inverse permutation matrix.")
87 .def(
"resize", &PermutationMatrix::resize, bp::args(
"self",
"size"),
88 "Resizes to given size.")
90 .def(bp::self * bp::self)
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.",