PermutationMatrix.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
  5. // Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
  6. //
  7. // This Source Code Form is subject to the terms of the Mozilla
  8. // Public License v. 2.0. If a copy of the MPL was not distributed
  9. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  10. #ifndef EIGEN_PERMUTATIONMATRIX_H
  11. #define EIGEN_PERMUTATIONMATRIX_H
  12. namespace Eigen {
  13. namespace internal {
  14. enum PermPermProduct_t {PermPermProduct};
  15. } // end namespace internal
  16. /** \class PermutationBase
  17. * \ingroup Core_Module
  18. *
  19. * \brief Base class for permutations
  20. *
  21. * \tparam Derived the derived class
  22. *
  23. * This class is the base class for all expressions representing a permutation matrix,
  24. * internally stored as a vector of integers.
  25. * The convention followed here is that if \f$ \sigma \f$ is a permutation, the corresponding permutation matrix
  26. * \f$ P_\sigma \f$ is such that if \f$ (e_1,\ldots,e_p) \f$ is the canonical basis, we have:
  27. * \f[ P_\sigma(e_i) = e_{\sigma(i)}. \f]
  28. * This convention ensures that for any two permutations \f$ \sigma, \tau \f$, we have:
  29. * \f[ P_{\sigma\circ\tau} = P_\sigma P_\tau. \f]
  30. *
  31. * Permutation matrices are square and invertible.
  32. *
  33. * Notice that in addition to the member functions and operators listed here, there also are non-member
  34. * operator* to multiply any kind of permutation object with any kind of matrix expression (MatrixBase)
  35. * on either side.
  36. *
  37. * \sa class PermutationMatrix, class PermutationWrapper
  38. */
  39. template<typename Derived>
  40. class PermutationBase : public EigenBase<Derived>
  41. {
  42. typedef internal::traits<Derived> Traits;
  43. typedef EigenBase<Derived> Base;
  44. public:
  45. #ifndef EIGEN_PARSED_BY_DOXYGEN
  46. typedef typename Traits::IndicesType IndicesType;
  47. enum {
  48. Flags = Traits::Flags,
  49. RowsAtCompileTime = Traits::RowsAtCompileTime,
  50. ColsAtCompileTime = Traits::ColsAtCompileTime,
  51. MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
  52. MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
  53. };
  54. typedef typename Traits::StorageIndex StorageIndex;
  55. typedef Matrix<StorageIndex,RowsAtCompileTime,ColsAtCompileTime,0,MaxRowsAtCompileTime,MaxColsAtCompileTime>
  56. DenseMatrixType;
  57. typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,StorageIndex>
  58. PlainPermutationType;
  59. typedef PlainPermutationType PlainObject;
  60. using Base::derived;
  61. typedef Inverse<Derived> InverseReturnType;
  62. typedef void Scalar;
  63. #endif
  64. /** Copies the other permutation into *this */
  65. template<typename OtherDerived>
  66. Derived& operator=(const PermutationBase<OtherDerived>& other)
  67. {
  68. indices() = other.indices();
  69. return derived();
  70. }
  71. /** Assignment from the Transpositions \a tr */
  72. template<typename OtherDerived>
  73. Derived& operator=(const TranspositionsBase<OtherDerived>& tr)
  74. {
  75. setIdentity(tr.size());
  76. for(Index k=size()-1; k>=0; --k)
  77. applyTranspositionOnTheRight(k,tr.coeff(k));
  78. return derived();
  79. }
  80. /** \returns the number of rows */
  81. inline Index rows() const { return Index(indices().size()); }
  82. /** \returns the number of columns */
  83. inline Index cols() const { return Index(indices().size()); }
  84. /** \returns the size of a side of the respective square matrix, i.e., the number of indices */
  85. inline Index size() const { return Index(indices().size()); }
  86. #ifndef EIGEN_PARSED_BY_DOXYGEN
  87. template<typename DenseDerived>
  88. void evalTo(MatrixBase<DenseDerived>& other) const
  89. {
  90. other.setZero();
  91. for (Index i=0; i<rows(); ++i)
  92. other.coeffRef(indices().coeff(i),i) = typename DenseDerived::Scalar(1);
  93. }
  94. #endif
  95. /** \returns a Matrix object initialized from this permutation matrix. Notice that it
  96. * is inefficient to return this Matrix object by value. For efficiency, favor using
  97. * the Matrix constructor taking EigenBase objects.
  98. */
  99. DenseMatrixType toDenseMatrix() const
  100. {
  101. return derived();
  102. }
  103. /** const version of indices(). */
  104. const IndicesType& indices() const { return derived().indices(); }
  105. /** \returns a reference to the stored array representing the permutation. */
  106. IndicesType& indices() { return derived().indices(); }
  107. /** Resizes to given size.
  108. */
  109. inline void resize(Index newSize)
  110. {
  111. indices().resize(newSize);
  112. }
  113. /** Sets *this to be the identity permutation matrix */
  114. void setIdentity()
  115. {
  116. StorageIndex n = StorageIndex(size());
  117. for(StorageIndex i = 0; i < n; ++i)
  118. indices().coeffRef(i) = i;
  119. }
  120. /** Sets *this to be the identity permutation matrix of given size.
  121. */
  122. void setIdentity(Index newSize)
  123. {
  124. resize(newSize);
  125. setIdentity();
  126. }
  127. /** Multiplies *this by the transposition \f$(ij)\f$ on the left.
  128. *
  129. * \returns a reference to *this.
  130. *
  131. * \warning This is much slower than applyTranspositionOnTheRight(Index,Index):
  132. * this has linear complexity and requires a lot of branching.
  133. *
  134. * \sa applyTranspositionOnTheRight(Index,Index)
  135. */
  136. Derived& applyTranspositionOnTheLeft(Index i, Index j)
  137. {
  138. eigen_assert(i>=0 && j>=0 && i<size() && j<size());
  139. for(Index k = 0; k < size(); ++k)
  140. {
  141. if(indices().coeff(k) == i) indices().coeffRef(k) = StorageIndex(j);
  142. else if(indices().coeff(k) == j) indices().coeffRef(k) = StorageIndex(i);
  143. }
  144. return derived();
  145. }
  146. /** Multiplies *this by the transposition \f$(ij)\f$ on the right.
  147. *
  148. * \returns a reference to *this.
  149. *
  150. * This is a fast operation, it only consists in swapping two indices.
  151. *
  152. * \sa applyTranspositionOnTheLeft(Index,Index)
  153. */
  154. Derived& applyTranspositionOnTheRight(Index i, Index j)
  155. {
  156. eigen_assert(i>=0 && j>=0 && i<size() && j<size());
  157. std::swap(indices().coeffRef(i), indices().coeffRef(j));
  158. return derived();
  159. }
  160. /** \returns the inverse permutation matrix.
  161. *
  162. * \note \blank \note_try_to_help_rvo
  163. */
  164. inline InverseReturnType inverse() const
  165. { return InverseReturnType(derived()); }
  166. /** \returns the tranpose permutation matrix.
  167. *
  168. * \note \blank \note_try_to_help_rvo
  169. */
  170. inline InverseReturnType transpose() const
  171. { return InverseReturnType(derived()); }
  172. /**** multiplication helpers to hopefully get RVO ****/
  173. #ifndef EIGEN_PARSED_BY_DOXYGEN
  174. protected:
  175. template<typename OtherDerived>
  176. void assignTranspose(const PermutationBase<OtherDerived>& other)
  177. {
  178. for (Index i=0; i<rows();++i) indices().coeffRef(other.indices().coeff(i)) = i;
  179. }
  180. template<typename Lhs,typename Rhs>
  181. void assignProduct(const Lhs& lhs, const Rhs& rhs)
  182. {
  183. eigen_assert(lhs.cols() == rhs.rows());
  184. for (Index i=0; i<rows();++i) indices().coeffRef(i) = lhs.indices().coeff(rhs.indices().coeff(i));
  185. }
  186. #endif
  187. public:
  188. /** \returns the product permutation matrix.
  189. *
  190. * \note \blank \note_try_to_help_rvo
  191. */
  192. template<typename Other>
  193. inline PlainPermutationType operator*(const PermutationBase<Other>& other) const
  194. { return PlainPermutationType(internal::PermPermProduct, derived(), other.derived()); }
  195. /** \returns the product of a permutation with another inverse permutation.
  196. *
  197. * \note \blank \note_try_to_help_rvo
  198. */
  199. template<typename Other>
  200. inline PlainPermutationType operator*(const InverseImpl<Other,PermutationStorage>& other) const
  201. { return PlainPermutationType(internal::PermPermProduct, *this, other.eval()); }
  202. /** \returns the product of an inverse permutation with another permutation.
  203. *
  204. * \note \blank \note_try_to_help_rvo
  205. */
  206. template<typename Other> friend
  207. inline PlainPermutationType operator*(const InverseImpl<Other, PermutationStorage>& other, const PermutationBase& perm)
  208. { return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); }
  209. /** \returns the determinant of the permutation matrix, which is either 1 or -1 depending on the parity of the permutation.
  210. *
  211. * This function is O(\c n) procedure allocating a buffer of \c n booleans.
  212. */
  213. Index determinant() const
  214. {
  215. Index res = 1;
  216. Index n = size();
  217. Matrix<bool,RowsAtCompileTime,1,0,MaxRowsAtCompileTime> mask(n);
  218. mask.fill(false);
  219. Index r = 0;
  220. while(r < n)
  221. {
  222. // search for the next seed
  223. while(r<n && mask[r]) r++;
  224. if(r>=n)
  225. break;
  226. // we got one, let's follow it until we are back to the seed
  227. Index k0 = r++;
  228. mask.coeffRef(k0) = true;
  229. for(Index k=indices().coeff(k0); k!=k0; k=indices().coeff(k))
  230. {
  231. mask.coeffRef(k) = true;
  232. res = -res;
  233. }
  234. }
  235. return res;
  236. }
  237. protected:
  238. };
  239. namespace internal {
  240. template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
  241. struct traits<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> >
  242. : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
  243. {
  244. typedef PermutationStorage StorageKind;
  245. typedef Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1> IndicesType;
  246. typedef _StorageIndex StorageIndex;
  247. typedef void Scalar;
  248. };
  249. }
  250. /** \class PermutationMatrix
  251. * \ingroup Core_Module
  252. *
  253. * \brief Permutation matrix
  254. *
  255. * \tparam SizeAtCompileTime the number of rows/cols, or Dynamic
  256. * \tparam MaxSizeAtCompileTime the maximum number of rows/cols, or Dynamic. This optional parameter defaults to SizeAtCompileTime. Most of the time, you should not have to specify it.
  257. * \tparam _StorageIndex the integer type of the indices
  258. *
  259. * This class represents a permutation matrix, internally stored as a vector of integers.
  260. *
  261. * \sa class PermutationBase, class PermutationWrapper, class DiagonalMatrix
  262. */
  263. template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex>
  264. class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex> >
  265. {
  266. typedef PermutationBase<PermutationMatrix> Base;
  267. typedef internal::traits<PermutationMatrix> Traits;
  268. public:
  269. typedef const PermutationMatrix& Nested;
  270. #ifndef EIGEN_PARSED_BY_DOXYGEN
  271. typedef typename Traits::IndicesType IndicesType;
  272. typedef typename Traits::StorageIndex StorageIndex;
  273. #endif
  274. inline PermutationMatrix()
  275. {}
  276. /** Constructs an uninitialized permutation matrix of given size.
  277. */
  278. explicit inline PermutationMatrix(Index size) : m_indices(size)
  279. {
  280. eigen_internal_assert(size <= NumTraits<StorageIndex>::highest());
  281. }
  282. /** Copy constructor. */
  283. template<typename OtherDerived>
  284. inline PermutationMatrix(const PermutationBase<OtherDerived>& other)
  285. : m_indices(other.indices()) {}
  286. /** Generic constructor from expression of the indices. The indices
  287. * array has the meaning that the permutations sends each integer i to indices[i].
  288. *
  289. * \warning It is your responsibility to check that the indices array that you passes actually
  290. * describes a permutation, i.e., each value between 0 and n-1 occurs exactly once, where n is the
  291. * array's size.
  292. */
  293. template<typename Other>
  294. explicit inline PermutationMatrix(const MatrixBase<Other>& indices) : m_indices(indices)
  295. {}
  296. /** Convert the Transpositions \a tr to a permutation matrix */
  297. template<typename Other>
  298. explicit PermutationMatrix(const TranspositionsBase<Other>& tr)
  299. : m_indices(tr.size())
  300. {
  301. *this = tr;
  302. }
  303. /** Copies the other permutation into *this */
  304. template<typename Other>
  305. PermutationMatrix& operator=(const PermutationBase<Other>& other)
  306. {
  307. m_indices = other.indices();
  308. return *this;
  309. }
  310. /** Assignment from the Transpositions \a tr */
  311. template<typename Other>
  312. PermutationMatrix& operator=(const TranspositionsBase<Other>& tr)
  313. {
  314. return Base::operator=(tr.derived());
  315. }
  316. /** const version of indices(). */
  317. const IndicesType& indices() const { return m_indices; }
  318. /** \returns a reference to the stored array representing the permutation. */
  319. IndicesType& indices() { return m_indices; }
  320. /**** multiplication helpers to hopefully get RVO ****/
  321. #ifndef EIGEN_PARSED_BY_DOXYGEN
  322. template<typename Other>
  323. PermutationMatrix(const InverseImpl<Other,PermutationStorage>& other)
  324. : m_indices(other.derived().nestedExpression().size())
  325. {
  326. eigen_internal_assert(m_indices.size() <= NumTraits<StorageIndex>::highest());
  327. StorageIndex end = StorageIndex(m_indices.size());
  328. for (StorageIndex i=0; i<end;++i)
  329. m_indices.coeffRef(other.derived().nestedExpression().indices().coeff(i)) = i;
  330. }
  331. template<typename Lhs,typename Rhs>
  332. PermutationMatrix(internal::PermPermProduct_t, const Lhs& lhs, const Rhs& rhs)
  333. : m_indices(lhs.indices().size())
  334. {
  335. Base::assignProduct(lhs,rhs);
  336. }
  337. #endif
  338. protected:
  339. IndicesType m_indices;
  340. };
  341. namespace internal {
  342. template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
  343. struct traits<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
  344. : traits<Matrix<_StorageIndex,SizeAtCompileTime,SizeAtCompileTime,0,MaxSizeAtCompileTime,MaxSizeAtCompileTime> >
  345. {
  346. typedef PermutationStorage StorageKind;
  347. typedef Map<const Matrix<_StorageIndex, SizeAtCompileTime, 1, 0, MaxSizeAtCompileTime, 1>, _PacketAccess> IndicesType;
  348. typedef _StorageIndex StorageIndex;
  349. typedef void Scalar;
  350. };
  351. }
  352. template<int SizeAtCompileTime, int MaxSizeAtCompileTime, typename _StorageIndex, int _PacketAccess>
  353. class Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess>
  354. : public PermutationBase<Map<PermutationMatrix<SizeAtCompileTime, MaxSizeAtCompileTime, _StorageIndex>,_PacketAccess> >
  355. {
  356. typedef PermutationBase<Map> Base;
  357. typedef internal::traits<Map> Traits;
  358. public:
  359. #ifndef EIGEN_PARSED_BY_DOXYGEN
  360. typedef typename Traits::IndicesType IndicesType;
  361. typedef typename IndicesType::Scalar StorageIndex;
  362. #endif
  363. inline Map(const StorageIndex* indicesPtr)
  364. : m_indices(indicesPtr)
  365. {}
  366. inline Map(const StorageIndex* indicesPtr, Index size)
  367. : m_indices(indicesPtr,size)
  368. {}
  369. /** Copies the other permutation into *this */
  370. template<typename Other>
  371. Map& operator=(const PermutationBase<Other>& other)
  372. { return Base::operator=(other.derived()); }
  373. /** Assignment from the Transpositions \a tr */
  374. template<typename Other>
  375. Map& operator=(const TranspositionsBase<Other>& tr)
  376. { return Base::operator=(tr.derived()); }
  377. #ifndef EIGEN_PARSED_BY_DOXYGEN
  378. /** This is a special case of the templated operator=. Its purpose is to
  379. * prevent a default operator= from hiding the templated operator=.
  380. */
  381. Map& operator=(const Map& other)
  382. {
  383. m_indices = other.m_indices;
  384. return *this;
  385. }
  386. #endif
  387. /** const version of indices(). */
  388. const IndicesType& indices() const { return m_indices; }
  389. /** \returns a reference to the stored array representing the permutation. */
  390. IndicesType& indices() { return m_indices; }
  391. protected:
  392. IndicesType m_indices;
  393. };
  394. template<typename _IndicesType> class TranspositionsWrapper;
  395. namespace internal {
  396. template<typename _IndicesType>
  397. struct traits<PermutationWrapper<_IndicesType> >
  398. {
  399. typedef PermutationStorage StorageKind;
  400. typedef void Scalar;
  401. typedef typename _IndicesType::Scalar StorageIndex;
  402. typedef _IndicesType IndicesType;
  403. enum {
  404. RowsAtCompileTime = _IndicesType::SizeAtCompileTime,
  405. ColsAtCompileTime = _IndicesType::SizeAtCompileTime,
  406. MaxRowsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
  407. MaxColsAtCompileTime = IndicesType::MaxSizeAtCompileTime,
  408. Flags = 0
  409. };
  410. };
  411. }
  412. /** \class PermutationWrapper
  413. * \ingroup Core_Module
  414. *
  415. * \brief Class to view a vector of integers as a permutation matrix
  416. *
  417. * \tparam _IndicesType the type of the vector of integer (can be any compatible expression)
  418. *
  419. * This class allows to view any vector expression of integers as a permutation matrix.
  420. *
  421. * \sa class PermutationBase, class PermutationMatrix
  422. */
  423. template<typename _IndicesType>
  424. class PermutationWrapper : public PermutationBase<PermutationWrapper<_IndicesType> >
  425. {
  426. typedef PermutationBase<PermutationWrapper> Base;
  427. typedef internal::traits<PermutationWrapper> Traits;
  428. public:
  429. #ifndef EIGEN_PARSED_BY_DOXYGEN
  430. typedef typename Traits::IndicesType IndicesType;
  431. #endif
  432. inline PermutationWrapper(const IndicesType& indices)
  433. : m_indices(indices)
  434. {}
  435. /** const version of indices(). */
  436. const typename internal::remove_all<typename IndicesType::Nested>::type&
  437. indices() const { return m_indices; }
  438. protected:
  439. typename IndicesType::Nested m_indices;
  440. };
  441. /** \returns the matrix with the permutation applied to the columns.
  442. */
  443. template<typename MatrixDerived, typename PermutationDerived>
  444. EIGEN_DEVICE_FUNC
  445. const Product<MatrixDerived, PermutationDerived, AliasFreeProduct>
  446. operator*(const MatrixBase<MatrixDerived> &matrix,
  447. const PermutationBase<PermutationDerived>& permutation)
  448. {
  449. return Product<MatrixDerived, PermutationDerived, AliasFreeProduct>
  450. (matrix.derived(), permutation.derived());
  451. }
  452. /** \returns the matrix with the permutation applied to the rows.
  453. */
  454. template<typename PermutationDerived, typename MatrixDerived>
  455. EIGEN_DEVICE_FUNC
  456. const Product<PermutationDerived, MatrixDerived, AliasFreeProduct>
  457. operator*(const PermutationBase<PermutationDerived> &permutation,
  458. const MatrixBase<MatrixDerived>& matrix)
  459. {
  460. return Product<PermutationDerived, MatrixDerived, AliasFreeProduct>
  461. (permutation.derived(), matrix.derived());
  462. }
  463. template<typename PermutationType>
  464. class InverseImpl<PermutationType, PermutationStorage>
  465. : public EigenBase<Inverse<PermutationType> >
  466. {
  467. typedef typename PermutationType::PlainPermutationType PlainPermutationType;
  468. typedef internal::traits<PermutationType> PermTraits;
  469. protected:
  470. InverseImpl() {}
  471. public:
  472. typedef Inverse<PermutationType> InverseType;
  473. using EigenBase<Inverse<PermutationType> >::derived;
  474. #ifndef EIGEN_PARSED_BY_DOXYGEN
  475. typedef typename PermutationType::DenseMatrixType DenseMatrixType;
  476. enum {
  477. RowsAtCompileTime = PermTraits::RowsAtCompileTime,
  478. ColsAtCompileTime = PermTraits::ColsAtCompileTime,
  479. MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime,
  480. MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime
  481. };
  482. #endif
  483. #ifndef EIGEN_PARSED_BY_DOXYGEN
  484. template<typename DenseDerived>
  485. void evalTo(MatrixBase<DenseDerived>& other) const
  486. {
  487. other.setZero();
  488. for (Index i=0; i<derived().rows();++i)
  489. other.coeffRef(i, derived().nestedExpression().indices().coeff(i)) = typename DenseDerived::Scalar(1);
  490. }
  491. #endif
  492. /** \return the equivalent permutation matrix */
  493. PlainPermutationType eval() const { return derived(); }
  494. DenseMatrixType toDenseMatrix() const { return derived(); }
  495. /** \returns the matrix with the inverse permutation applied to the columns.
  496. */
  497. template<typename OtherDerived> friend
  498. const Product<OtherDerived, InverseType, AliasFreeProduct>
  499. operator*(const MatrixBase<OtherDerived>& matrix, const InverseType& trPerm)
  500. {
  501. return Product<OtherDerived, InverseType, AliasFreeProduct>(matrix.derived(), trPerm.derived());
  502. }
  503. /** \returns the matrix with the inverse permutation applied to the rows.
  504. */
  505. template<typename OtherDerived>
  506. const Product<InverseType, OtherDerived, AliasFreeProduct>
  507. operator*(const MatrixBase<OtherDerived>& matrix) const
  508. {
  509. return Product<InverseType, OtherDerived, AliasFreeProduct>(derived(), matrix.derived());
  510. }
  511. };
  512. template<typename Derived>
  513. const PermutationWrapper<const Derived> MatrixBase<Derived>::asPermutation() const
  514. {
  515. return derived();
  516. }
  517. namespace internal {
  518. template<> struct AssignmentKind<DenseShape,PermutationShape> { typedef EigenBase2EigenBase Kind; };
  519. } // end namespace internal
  520. } // end namespace Eigen
  521. #endif // EIGEN_PERMUTATIONMATRIX_H