10 #ifndef EIGEN_SPARSE_PERMUTATION_H 11 #define EIGEN_SPARSE_PERMUTATION_H 19 template<
typename ExpressionType,
int S
ide,
bool Transposed>
20 struct permutation_matrix_product<ExpressionType, Side, Transposed, SparseShape>
22 typedef typename nested_eval<ExpressionType, 1>::type MatrixType;
23 typedef typename remove_all<MatrixType>::type MatrixTypeCleaned;
25 typedef typename MatrixTypeCleaned::Scalar Scalar;
26 typedef typename MatrixTypeCleaned::StorageIndex StorageIndex;
33 typedef typename internal::conditional<MoveOuter,
34 SparseMatrix<Scalar,SrcStorageOrder,StorageIndex>,
35 SparseMatrix<Scalar,int(SrcStorageOrder)==RowMajor?ColMajor:RowMajor,StorageIndex> >::type ReturnType;
37 template<
typename Dest,
typename PermutationType>
38 static inline void run(Dest& dst,
const PermutationType& perm,
const ExpressionType& xpr)
43 SparseMatrix<Scalar,SrcStorageOrder,StorageIndex> tmp(mat.rows(), mat.cols());
44 Matrix<StorageIndex,Dynamic,1> sizes(mat.outerSize());
45 for(
Index j=0; j<mat.outerSize(); ++j)
47 Index jp = perm.indices().coeff(j);
48 sizes[((Side==
OnTheLeft) ^ Transposed) ? jp : j] = StorageIndex(mat.innerVector(((Side==
OnTheRight) ^ Transposed) ? jp : j).nonZeros());
51 for(
Index j=0; j<mat.outerSize(); ++j)
53 Index jp = perm.indices().coeff(j);
56 for(
typename MatrixTypeCleaned::InnerIterator it(mat,jsrc); it; ++it)
57 tmp.insertByOuterInner(jdst,it.index()) = it.value();
63 SparseMatrix<Scalar,int(SrcStorageOrder)==RowMajor?ColMajor:RowMajor,StorageIndex> tmp(mat.rows(), mat.cols());
64 Matrix<StorageIndex,Dynamic,1> sizes(tmp.outerSize());
66 PermutationMatrix<Dynamic,Dynamic,StorageIndex> perm_cpy;
70 perm_cpy = perm.transpose();
72 for(
Index j=0; j<mat.outerSize(); ++j)
73 for(
typename MatrixTypeCleaned::InnerIterator it(mat,j); it; ++it)
74 sizes[perm_cpy.indices().coeff(it.index())]++;
76 for(
Index j=0; j<mat.outerSize(); ++j)
77 for(
typename MatrixTypeCleaned::InnerIterator it(mat,j); it; ++it)
78 tmp.insertByOuterInner(perm_cpy.indices().coeff(it.index()),j) = it.value();
88 template <
int ProductTag>
struct product_promote_storage_type<Sparse, PermutationStorage, ProductTag> {
typedef Sparse ret; };
89 template <
int ProductTag>
struct product_promote_storage_type<PermutationStorage, Sparse, ProductTag> {
typedef Sparse ret; };
95 template<
typename Lhs,
typename Rhs,
int ProductTag>
96 struct product_evaluator<Product<Lhs, Rhs, AliasFreeProduct>, ProductTag, PermutationShape, SparseShape>
97 :
public evaluator<typename permutation_matrix_product<Rhs,OnTheLeft,false,SparseShape>::ReturnType>
99 typedef Product<Lhs, Rhs, AliasFreeProduct> XprType;
100 typedef typename permutation_matrix_product<Rhs,OnTheLeft,false,SparseShape>::ReturnType PlainObject;
101 typedef evaluator<PlainObject> Base;
107 explicit product_evaluator(
const XprType& xpr)
108 : m_result(xpr.rows(), xpr.cols())
110 ::new (static_cast<Base*>(
this)) Base(m_result);
111 generic_product_impl<Lhs, Rhs, PermutationShape, SparseShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs());
115 PlainObject m_result;
118 template<typename Lhs, typename Rhs,
int ProductTag>
119 struct product_evaluator<Product<Lhs, Rhs, AliasFreeProduct>, ProductTag, SparseShape, PermutationShape >
120 : public evaluator<typename permutation_matrix_product<Lhs,
OnTheRight,false,SparseShape>::ReturnType>
122 typedef Product<Lhs, Rhs, AliasFreeProduct> XprType;
123 typedef typename permutation_matrix_product<Lhs,OnTheRight,false,SparseShape>::ReturnType PlainObject;
124 typedef evaluator<PlainObject> Base;
130 explicit product_evaluator(
const XprType& xpr)
131 : m_result(xpr.rows(), xpr.cols())
133 ::new (static_cast<Base*>(
this)) Base(m_result);
134 generic_product_impl<Lhs, Rhs, SparseShape, PermutationShape, ProductTag>::evalTo(m_result, xpr.lhs(), xpr.rhs());
138 PlainObject m_result;
145 template<typename SparseDerived, typename PermDerived>
146 inline const Product<SparseDerived, PermDerived, AliasFreeProduct>
152 template<
typename SparseDerived,
typename PermDerived>
160 template<
typename SparseDerived,
typename PermutationType>
164 return Product<SparseDerived, Inverse<PermutationType>, AliasFreeProduct>(matrix.
derived(), tperm.derived());
169 template<
typename SparseDerived,
typename PermutationType>
173 return Product<Inverse<PermutationType>, SparseDerived, AliasFreeProduct>(tperm.derived(), matrix.
derived());
178 #endif // EIGEN_SPARSE_SELFADJOINTVIEW_H Definition: Constants.h:320
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
Definition: Constants.h:335
Namespace containing all symbols from the Eigen library.
Definition: Core:287
Derived & derived()
Definition: EigenBase.h:45
const unsigned int RowMajorBit
Definition: Constants.h:61
Base class for permutations.
Definition: PermutationMatrix.h:46
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:281
const Product< MatrixDerived, PermutationDerived, AliasFreeProduct > operator*(const MatrixBase< MatrixDerived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:543
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: Constants.h:333
Definition: Eigen_Colamd.h:50
Definition: Constants.h:322
const unsigned int EvalBeforeNestingBit
Definition: Constants.h:65