10 #ifndef EIGEN_SPARSE_PERMUTATION_H
11 #define EIGEN_SPARSE_PERMUTATION_H
19 template<
typename PermutationType,
typename MatrixType,
int S
ide,
bool Transposed>
20 struct traits<permut_sparsematrix_product_retval<PermutationType, MatrixType, Side, Transposed> >
22 typedef typename remove_all<typename MatrixType::Nested>::type MatrixTypeNestedCleaned;
23 typedef typename MatrixTypeNestedCleaned::Scalar Scalar;
24 typedef typename MatrixTypeNestedCleaned::Index Index;
30 typedef typename internal::conditional<MoveOuter,
31 SparseMatrix<Scalar,SrcStorageOrder,Index>,
32 SparseMatrix<Scalar,int(SrcStorageOrder)==RowMajor?ColMajor:RowMajor,Index> >::type ReturnType;
35 template<
typename PermutationType,
typename MatrixType,
int S
ide,
bool Transposed>
36 struct permut_sparsematrix_product_retval
37 :
public ReturnByValue<permut_sparsematrix_product_retval<PermutationType, MatrixType, Side, Transposed> >
39 typedef typename remove_all<typename MatrixType::Nested>::type MatrixTypeNestedCleaned;
40 typedef typename MatrixTypeNestedCleaned::Scalar Scalar;
41 typedef typename MatrixTypeNestedCleaned::Index Index;
48 permut_sparsematrix_product_retval(
const PermutationType& perm,
const MatrixType& matrix)
49 : m_permutation(perm), m_matrix(matrix)
52 inline int rows()
const {
return m_matrix.rows(); }
53 inline int cols()
const {
return m_matrix.cols(); }
55 template<
typename Dest>
inline void evalTo(Dest& dst)
const
59 SparseMatrix<Scalar,SrcStorageOrder,Index> tmp(m_matrix.rows(), m_matrix.cols());
60 Matrix<Index,Dynamic,1> sizes(m_matrix.outerSize());
61 for(Index j=0; j<m_matrix.outerSize(); ++j)
63 Index jp = m_permutation.indices().coeff(j);
64 sizes[((Side==
OnTheLeft) ^ Transposed) ? jp : j] = m_matrix.innerVector(((Side==
OnTheRight) ^ Transposed) ? jp : j).nonZeros();
67 for(Index j=0; j<m_matrix.outerSize(); ++j)
69 Index jp = m_permutation.indices().coeff(j);
70 Index jsrc = ((Side==
OnTheRight) ^ Transposed) ? jp : j;
71 Index jdst = ((Side==
OnTheLeft) ^ Transposed) ? jp : j;
72 for(
typename MatrixTypeNestedCleaned::InnerIterator it(m_matrix,jsrc); it; ++it)
73 tmp.insertByOuterInner(jdst,it.index()) = it.value();
79 SparseMatrix<Scalar,int(SrcStorageOrder)==RowMajor?ColMajor:RowMajor,Index> tmp(m_matrix.rows(), m_matrix.cols());
80 Matrix<Index,Dynamic,1> sizes(tmp.outerSize());
82 PermutationMatrix<Dynamic,Dynamic,Index> perm;
86 perm = m_permutation.transpose();
88 for(Index j=0; j<m_matrix.outerSize(); ++j)
89 for(
typename MatrixTypeNestedCleaned::InnerIterator it(m_matrix,j); it; ++it)
90 sizes[perm.indices().coeff(it.index())]++;
92 for(Index j=0; j<m_matrix.outerSize(); ++j)
93 for(
typename MatrixTypeNestedCleaned::InnerIterator it(m_matrix,j); it; ++it)
94 tmp.insertByOuterInner(perm.indices().coeff(it.index()),j) = it.value();
100 const PermutationType& m_permutation;
101 typename MatrixType::Nested m_matrix;
110 template<
typename SparseDerived,
typename PermDerived>
111 inline const internal::permut_sparsematrix_product_retval<PermutationBase<PermDerived>, SparseDerived,
OnTheRight,
false>
114 return internal::permut_sparsematrix_product_retval<PermutationBase<PermDerived>, SparseDerived,
OnTheRight,
false>(perm, matrix.
derived());
119 template<
typename SparseDerived,
typename PermDerived>
120 inline const internal::permut_sparsematrix_product_retval<PermutationBase<PermDerived>, SparseDerived,
OnTheLeft,
false>
123 return internal::permut_sparsematrix_product_retval<PermutationBase<PermDerived>, SparseDerived,
OnTheLeft,
false>(perm, matrix.
derived());
130 template<
typename SparseDerived,
typename PermDerived>
131 inline const internal::permut_sparsematrix_product_retval<PermutationBase<PermDerived>, SparseDerived,
OnTheRight,
true>
134 return internal::permut_sparsematrix_product_retval<PermutationBase<PermDerived>, SparseDerived,
OnTheRight,
true>(tperm.nestedPermutation(), matrix.
derived());
139 template<
typename SparseDerived,
typename PermDerived>
140 inline const internal::permut_sparsematrix_product_retval<PermutationBase<PermDerived>, SparseDerived,
OnTheLeft,
true>
143 return internal::permut_sparsematrix_product_retval<PermutationBase<PermDerived>, SparseDerived,
OnTheLeft,
true>(tperm.nestedPermutation(), matrix.
derived());
148 #endif // EIGEN_SPARSE_SELFADJOINTVIEW_H
Expression of the transpose of a matrix.
Definition: Transpose.h:57
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:539
Definition: Constants.h:264
Base class for permutations.
Definition: PermutationMatrix.h:53
Definition: Constants.h:279
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:239
Derived & derived()
Definition: EigenBase.h:34
Definition: Constants.h:266
const unsigned int RowMajorBit
Definition: Constants.h:53
Definition: Constants.h:277