10 #ifndef EIGEN_SPARSE_PERMUTATION_H
11 #define EIGEN_SPARSE_PERMUTATION_H
19 template<
typename MatrixType,
int S
ide,
bool Transposed>
20 struct permutation_matrix_product<MatrixType, Side, Transposed, SparseShape>
22 typedef typename remove_all<typename MatrixType::Nested>::type MatrixTypeNestedCleaned;
23 typedef typename MatrixTypeNestedCleaned::Scalar Scalar;
24 typedef typename MatrixTypeNestedCleaned::StorageIndex StorageIndex;
31 typedef typename internal::conditional<MoveOuter,
32 SparseMatrix<Scalar,SrcStorageOrder,StorageIndex>,
33 SparseMatrix<Scalar,int(SrcStorageOrder)==RowMajor?ColMajor:RowMajor,StorageIndex> >::type ReturnType;
35 template<
typename Dest,
typename PermutationType>
36 static inline void run(Dest& dst,
const PermutationType& perm,
const MatrixType& mat)
40 SparseMatrix<Scalar,SrcStorageOrder,StorageIndex> tmp(mat.rows(), mat.cols());
41 Matrix<StorageIndex,Dynamic,1> sizes(mat.outerSize());
42 for(Index j=0; j<mat.outerSize(); ++j)
44 Index jp = perm.indices().coeff(j);
45 sizes[((Side==
OnTheLeft) ^ Transposed) ? jp : j] = StorageIndex(mat.innerVector(((Side==
OnTheRight) ^ Transposed) ? jp : j).nonZeros());
48 for(Index j=0; j<mat.outerSize(); ++j)
50 Index jp = perm.indices().coeff(j);
51 Index jsrc = ((Side==
OnTheRight) ^ Transposed) ? jp : j;
52 Index jdst = ((Side==
OnTheLeft) ^ Transposed) ? jp : j;
53 for(
typename MatrixTypeNestedCleaned::InnerIterator it(mat,jsrc); it; ++it)
54 tmp.insertByOuterInner(jdst,it.index()) = it.value();
60 SparseMatrix<Scalar,int(SrcStorageOrder)==RowMajor?ColMajor:RowMajor,StorageIndex> tmp(mat.rows(), mat.cols());
61 Matrix<StorageIndex,Dynamic,1> sizes(tmp.outerSize());
63 PermutationMatrix<Dynamic,Dynamic,StorageIndex> perm_cpy;
67 perm_cpy = perm.transpose();
69 for(Index j=0; j<mat.outerSize(); ++j)
70 for(
typename MatrixTypeNestedCleaned::InnerIterator it(mat,j); it; ++it)
71 sizes[perm_cpy.indices().coeff(it.index())]++;
73 for(Index j=0; j<mat.outerSize(); ++j)
74 for(
typename MatrixTypeNestedCleaned::InnerIterator it(mat,j); it; ++it)
75 tmp.insertByOuterInner(perm_cpy.indices().coeff(it.index()),j) = it.value();
85 template <
int ProductTag>
struct product_promote_storage_type<Sparse, PermutationStorage, ProductTag> {
typedef Sparse ret; };
86 template <
int ProductTag>
struct product_promote_storage_type<PermutationStorage, Sparse, ProductTag> {
typedef Sparse ret; };
92 template<
typename Lhs,
typename Rhs,
int ProductTag>
93 struct product_evaluator<Product<Lhs, Rhs, AliasFreeProduct>, ProductTag, PermutationShape, SparseShape, typename traits<Lhs>::Scalar, typename traits<Rhs>::Scalar>
94 :
public evaluator<typename permutation_matrix_product<Rhs,OnTheRight,false,SparseShape>::ReturnType>
96 typedef Product<Lhs, Rhs, AliasFreeProduct> XprType;
97 typedef typename permutation_matrix_product<Rhs,OnTheRight,false,SparseShape>::ReturnType PlainObject;
98 typedef evaluator<PlainObject> Base;
100 explicit product_evaluator(
const XprType& xpr)
101 : m_result(xpr.rows(), xpr.cols())
103 ::new (static_cast<Base*>(
this)) Base(m_result);
104 generic_product_impl<Lhs, Rhs, PermutationShape, SparseShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs());
108 PlainObject m_result;
111 template<typename Lhs, typename Rhs,
int ProductTag>
112 struct product_evaluator<Product<Lhs, Rhs, AliasFreeProduct>, ProductTag, SparseShape, PermutationShape, typename traits<Lhs>::Scalar, typename traits<Rhs>::Scalar>
113 : public evaluator<typename permutation_matrix_product<Lhs,
OnTheRight,false,SparseShape>::ReturnType>
115 typedef Product<Lhs, Rhs, AliasFreeProduct> XprType;
116 typedef typename permutation_matrix_product<Lhs,OnTheRight,false,SparseShape>::ReturnType PlainObject;
117 typedef evaluator<PlainObject> Base;
119 explicit product_evaluator(
const XprType& xpr)
120 : m_result(xpr.rows(), xpr.cols())
122 ::new (static_cast<Base*>(
this)) Base(m_result);
123 generic_product_impl<Lhs, Rhs, SparseShape, PermutationShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs());
127 PlainObject m_result;
134 template<typename SparseDerived, typename PermDerived>
135 inline const Product<SparseDerived, PermDerived>
136 operator*(const SparseMatrixBase<SparseDerived>& matrix, const PermutationBase<PermDerived>& perm)
137 {
return Product<SparseDerived, PermDerived>(matrix.derived(), perm.derived()); }
141 template<
typename SparseDerived,
typename PermDerived>
142 inline const Product<PermDerived, SparseDerived>
143 operator*(
const PermutationBase<PermDerived>& perm,
const SparseMatrixBase<SparseDerived>& matrix)
144 {
return Product<PermDerived, SparseDerived>(perm.derived(), matrix.derived()); }
150 template<
typename SparseDerived,
typename PermDerived>
151 inline const Product<SparseDerived, Transpose<PermutationBase<PermDerived> > >
152 operator*(
const SparseMatrixBase<SparseDerived>& matrix,
const Transpose<PermutationBase<PermDerived> >& tperm)
154 return Product<SparseDerived, Transpose<PermutationBase<PermDerived> > >(matrix.derived(), tperm);
159 template<
typename SparseDerived,
typename PermDerived>
160 inline const Product<Transpose<PermutationBase<PermDerived> >, SparseDerived>
161 operator*(
const Transpose<PermutationBase<PermDerived> >& tperm,
const SparseMatrixBase<SparseDerived>& matrix)
163 return Product<Transpose<PermutationBase<PermDerived> >, SparseDerived>(tperm, matrix.derived());
168 #endif // EIGEN_SPARSE_SELFADJOINTVIEW_H
Definition: Constants.h:314
Definition: Constants.h:327
const unsigned int RowMajorBit
Definition: Constants.h:53
Definition: Eigen_Colamd.h:54
Definition: Constants.h:312
Definition: Constants.h:325