aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/PermutationMatrix.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2015-10-08 18:36:39 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2015-10-08 18:36:39 +0200
commitd866279364414235b531ab9c03eda6a14d9da1c5 (patch)
tree89a659e059bb2fd4aaea88afaa2c0fab5565950d /Eigen/src/Core/PermutationMatrix.h
parent8d00a953af6d84413abd0c8941db6666f4e0bf4e (diff)
Clean a bit the implementation of inverse permutations
Diffstat (limited to 'Eigen/src/Core/PermutationMatrix.h')
-rw-r--r--Eigen/src/Core/PermutationMatrix.h93
1 files changed, 34 insertions, 59 deletions
diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h
index b5f7e4a54..90e1df233 100644
--- a/Eigen/src/Core/PermutationMatrix.h
+++ b/Eigen/src/Core/PermutationMatrix.h
@@ -2,7 +2,7 @@
// for linear algebra.
//
// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
-// Copyright (C) 2009-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
+// Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
@@ -13,9 +13,6 @@
namespace Eigen {
-// TODO: this does not seems to be needed at all:
-// template<int RowCol,typename IndicesType,typename MatrixType, typename StorageKind> class PermutedImpl;
-
/** \class PermutationBase
* \ingroup Core_Module
*
@@ -67,8 +64,9 @@ class PermutationBase : public EigenBase<Derived>
DenseMatrixType;
typedef PermutationMatrix<IndicesType::SizeAtCompileTime,IndicesType::MaxSizeAtCompileTime,StorageIndex>
PlainPermutationType;
+ typedef PlainPermutationType PlainObject;
using Base::derived;
- typedef Transpose<PermutationBase> TransposeReturnType;
+ typedef Inverse<Derived> InverseReturnType;
typedef void Scalar;
#endif
@@ -196,14 +194,14 @@ class PermutationBase : public EigenBase<Derived>
*
* \note \note_try_to_help_rvo
*/
- inline TransposeReturnType inverse() const
- { return TransposeReturnType(derived()); }
+ inline InverseReturnType inverse() const
+ { return InverseReturnType(derived()); }
/** \returns the tranpose permutation matrix.
*
* \note \note_try_to_help_rvo
*/
- inline TransposeReturnType transpose() const
- { return TransposeReturnType(derived()); }
+ inline InverseReturnType transpose() const
+ { return InverseReturnType(derived()); }
/**** multiplication helpers to hopefully get RVO ****/
@@ -238,7 +236,7 @@ class PermutationBase : public EigenBase<Derived>
* \note \note_try_to_help_rvo
*/
template<typename Other>
- inline PlainPermutationType operator*(const Transpose<PermutationBase<Other> >& other) const
+ inline PlainPermutationType operator*(const InverseImpl<Other,PermutationStorage>& other) const
{ return PlainPermutationType(internal::PermPermProduct, *this, other.eval()); }
/** \returns the product of an inverse permutation with another permutation.
@@ -246,7 +244,7 @@ class PermutationBase : public EigenBase<Derived>
* \note \note_try_to_help_rvo
*/
template<typename Other> friend
- inline PlainPermutationType operator*(const Transpose<PermutationBase<Other> >& other, const PermutationBase& perm)
+ inline PlainPermutationType operator*(const InverseImpl<Other, PermutationStorage>& other, const PermutationBase& perm)
{ return PlainPermutationType(internal::PermPermProduct, other.eval(), perm); }
/** \returns the determinant of the permutation matrix, which is either 1 or -1 depending on the parity of the permutation.
@@ -398,13 +396,13 @@ class PermutationMatrix : public PermutationBase<PermutationMatrix<SizeAtCompile
#ifndef EIGEN_PARSED_BY_DOXYGEN
template<typename Other>
- PermutationMatrix(const Transpose<PermutationBase<Other> >& other)
- : m_indices(other.nestedExpression().size())
+ PermutationMatrix(const InverseImpl<Other,PermutationStorage>& other)
+ : m_indices(other.derived().nestedExpression().size())
{
eigen_internal_assert(m_indices.size() <= NumTraits<StorageIndex>::highest());
StorageIndex end = StorageIndex(m_indices.size());
for (StorageIndex i=0; i<end;++i)
- m_indices.coeffRef(other.nestedExpression().indices().coeff(i)) = i;
+ m_indices.coeffRef(other.derived().nestedExpression().indices().coeff(i)) = i;
}
template<typename Lhs,typename Rhs>
PermutationMatrix(internal::PermPermProduct_t, const Lhs& lhs, const Rhs& rhs)
@@ -564,84 +562,61 @@ operator*(const PermutationBase<PermutationDerived> &permutation,
(permutation.derived(), matrix.derived());
}
-namespace internal {
-
-/* Template partial specialization for transposed/inverse permutations */
-
-template<typename Derived>
-struct traits<Transpose<PermutationBase<Derived> > >
- : traits<Derived>
-{};
-
-} // end namespace internal
-// TODO: the specificties should be handled by the evaluator,
-// at the very least we should only specialize TransposeImpl
-template<typename Derived>
-class Transpose<PermutationBase<Derived> >
- : public EigenBase<Transpose<PermutationBase<Derived> > >
+template<typename PermutationType>
+class InverseImpl<PermutationType, PermutationStorage>
+ : public EigenBase<Inverse<PermutationType> >
{
- typedef Derived PermutationType;
- typedef typename PermutationType::IndicesType IndicesType;
typedef typename PermutationType::PlainPermutationType PlainPermutationType;
+ typedef internal::traits<PermutationType> PermTraits;
+ protected:
+ InverseImpl() {}
public:
+ typedef Inverse<PermutationType> InverseType;
+ using EigenBase<Inverse<PermutationType> >::derived;
#ifndef EIGEN_PARSED_BY_DOXYGEN
- typedef internal::traits<PermutationType> Traits;
- typedef typename Derived::DenseMatrixType DenseMatrixType;
+ typedef typename PermutationType::DenseMatrixType DenseMatrixType;
enum {
- Flags = Traits::Flags,
- RowsAtCompileTime = Traits::RowsAtCompileTime,
- ColsAtCompileTime = Traits::ColsAtCompileTime,
- MaxRowsAtCompileTime = Traits::MaxRowsAtCompileTime,
- MaxColsAtCompileTime = Traits::MaxColsAtCompileTime
+ RowsAtCompileTime = PermTraits::RowsAtCompileTime,
+ ColsAtCompileTime = PermTraits::ColsAtCompileTime,
+ MaxRowsAtCompileTime = PermTraits::MaxRowsAtCompileTime,
+ MaxColsAtCompileTime = PermTraits::MaxColsAtCompileTime
};
- typedef typename Traits::Scalar Scalar;
- typedef typename Traits::StorageIndex StorageIndex;
#endif
- Transpose(const PermutationType& p) : m_permutation(p) {}
-
- inline Index rows() const { return m_permutation.rows(); }
- inline Index cols() const { return m_permutation.cols(); }
-
#ifndef EIGEN_PARSED_BY_DOXYGEN
template<typename DenseDerived>
void evalTo(MatrixBase<DenseDerived>& other) const
{
other.setZero();
- for (Index i=0; i<rows();++i)
- other.coeffRef(i, m_permutation.indices().coeff(i)) = typename DenseDerived::Scalar(1);
+ for (Index i=0; i<derived().rows();++i)
+ other.coeffRef(i, derived().nestedExpression().indices().coeff(i)) = typename DenseDerived::Scalar(1);
}
#endif
/** \return the equivalent permutation matrix */
- PlainPermutationType eval() const { return *this; }
+ PlainPermutationType eval() const { return derived(); }
- DenseMatrixType toDenseMatrix() const { return *this; }
+ DenseMatrixType toDenseMatrix() const { return derived(); }
/** \returns the matrix with the inverse permutation applied to the columns.
*/
template<typename OtherDerived> friend
- const Product<OtherDerived, Transpose, AliasFreeProduct>
- operator*(const MatrixBase<OtherDerived>& matrix, const Transpose& trPerm)
+ const Product<OtherDerived, InverseType, AliasFreeProduct>
+ operator*(const MatrixBase<OtherDerived>& matrix, const InverseType& trPerm)
{
- return Product<OtherDerived, Transpose, AliasFreeProduct>(matrix.derived(), trPerm.derived());
+ return Product<OtherDerived, InverseType, AliasFreeProduct>(matrix.derived(), trPerm.derived());
}
/** \returns the matrix with the inverse permutation applied to the rows.
*/
template<typename OtherDerived>
- const Product<Transpose, OtherDerived, AliasFreeProduct>
+ const Product<InverseType, OtherDerived, AliasFreeProduct>
operator*(const MatrixBase<OtherDerived>& matrix) const
{
- return Product<Transpose, OtherDerived, AliasFreeProduct>(*this, matrix.derived());
+ return Product<InverseType, OtherDerived, AliasFreeProduct>(derived(), matrix.derived());
}
-
- const PermutationType& nestedExpression() const { return m_permutation; }
-
- protected:
- const PermutationType& m_permutation;
};
template<typename Derived>