10 #ifndef EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H 11 #define EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H 19 template<
typename Lhs,
typename Rhs,
typename ResultType>
20 static void sparse_sparse_product_with_pruning_impl(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const typename ResultType::RealScalar& tolerance)
24 typedef typename remove_all<Rhs>::type::Scalar RhsScalar;
25 typedef typename remove_all<ResultType>::type::Scalar ResScalar;
26 typedef typename remove_all<Lhs>::type::StorageIndex StorageIndex;
29 Index rows = lhs.innerSize();
30 Index cols = rhs.outerSize();
32 eigen_assert(lhs.outerSize() == rhs.innerSize());
35 AmbiVector<ResScalar,StorageIndex> tempVector(rows);
38 if(ResultType::IsRowMajor)
39 res.resize(cols, rows);
41 res.resize(rows, cols);
43 evaluator<Lhs> lhsEval(lhs);
44 evaluator<Rhs> rhsEval(rhs);
52 Index estimated_nnz_prod = lhsEval.nonZerosEstimate() + rhsEval.nonZerosEstimate();
54 res.reserve(estimated_nnz_prod);
55 double ratioColRes = double(estimated_nnz_prod)/(double(lhs.rows())*
double(rhs.cols()));
56 for (
Index j=0; j<cols; ++j)
61 tempVector.init(ratioColRes);
63 for (
typename evaluator<Rhs>::InnerIterator rhsIt(rhsEval, j); rhsIt; ++rhsIt)
67 RhsScalar x = rhsIt.value();
68 for (
typename evaluator<Lhs>::InnerIterator lhsIt(lhsEval, rhsIt.index()); lhsIt; ++lhsIt)
70 tempVector.coeffRef(lhsIt.index()) += lhsIt.value() * x;
74 for (
typename AmbiVector<ResScalar,StorageIndex>::Iterator it(tempVector,tolerance); it; ++it)
75 res.insertBackByOuterInner(j,it.index()) = it.value();
80 template<
typename Lhs,
typename Rhs,
typename ResultType,
81 int LhsStorageOrder = traits<Lhs>::Flags&
RowMajorBit,
82 int RhsStorageOrder = traits<Rhs>::Flags&
RowMajorBit,
83 int ResStorageOrder = traits<ResultType>::Flags&RowMajorBit>
84 struct sparse_sparse_product_with_pruning_selector;
86 template<
typename Lhs,
typename Rhs,
typename ResultType>
89 typedef typename ResultType::RealScalar RealScalar;
91 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance)
93 typename remove_all<ResultType>::type _res(res.rows(), res.cols());
94 internal::sparse_sparse_product_with_pruning_impl<Lhs,Rhs,ResultType>(lhs, rhs, _res, tolerance);
99 template<
typename Lhs,
typename Rhs,
typename ResultType>
102 typedef typename ResultType::RealScalar RealScalar;
103 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance)
106 typedef SparseMatrix<typename ResultType::Scalar,ColMajor,typename ResultType::StorageIndex> SparseTemporaryType;
107 SparseTemporaryType _res(res.rows(), res.cols());
108 internal::sparse_sparse_product_with_pruning_impl<Lhs,Rhs,SparseTemporaryType>(lhs, rhs, _res, tolerance);
113 template<
typename Lhs,
typename Rhs,
typename ResultType>
116 typedef typename ResultType::RealScalar RealScalar;
117 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance)
120 typename remove_all<ResultType>::type _res(res.rows(), res.cols());
121 internal::sparse_sparse_product_with_pruning_impl<Rhs,Lhs,ResultType>(rhs, lhs, _res, tolerance);
126 template<
typename Lhs,
typename Rhs,
typename ResultType>
129 typedef typename ResultType::RealScalar RealScalar;
130 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance)
132 typedef SparseMatrix<typename Lhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixLhs;
133 typedef SparseMatrix<typename Rhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixRhs;
134 ColMajorMatrixLhs colLhs(lhs);
135 ColMajorMatrixRhs colRhs(rhs);
136 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs,ColMajorMatrixRhs,ResultType>(colLhs, colRhs, res, tolerance);
146 template<
typename Lhs,
typename Rhs,
typename ResultType>
149 typedef typename ResultType::RealScalar RealScalar;
150 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance)
152 typedef SparseMatrix<typename Lhs::Scalar,RowMajor,typename Lhs::StorageIndex> RowMajorMatrixLhs;
153 RowMajorMatrixLhs rowLhs(lhs);
154 sparse_sparse_product_with_pruning_selector<RowMajorMatrixLhs,Rhs,ResultType,RowMajor,RowMajor>(rowLhs,rhs,res,tolerance);
158 template<
typename Lhs,
typename Rhs,
typename ResultType>
161 typedef typename ResultType::RealScalar RealScalar;
162 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance)
164 typedef SparseMatrix<typename Rhs::Scalar,RowMajor,typename Lhs::StorageIndex> RowMajorMatrixRhs;
165 RowMajorMatrixRhs rowRhs(rhs);
166 sparse_sparse_product_with_pruning_selector<Lhs,RowMajorMatrixRhs,ResultType,RowMajor,RowMajor,RowMajor>(lhs,rowRhs,res,tolerance);
170 template<
typename Lhs,
typename Rhs,
typename ResultType>
173 typedef typename ResultType::RealScalar RealScalar;
174 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance)
176 typedef SparseMatrix<typename Rhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixRhs;
177 ColMajorMatrixRhs colRhs(rhs);
178 internal::sparse_sparse_product_with_pruning_impl<Lhs,ColMajorMatrixRhs,ResultType>(lhs, colRhs, res, tolerance);
182 template<
typename Lhs,
typename Rhs,
typename ResultType>
185 typedef typename ResultType::RealScalar RealScalar;
186 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance)
188 typedef SparseMatrix<typename Lhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixLhs;
189 ColMajorMatrixLhs colLhs(lhs);
190 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs,Rhs,ResultType>(colLhs, rhs, res, tolerance);
198 #endif // EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H Definition: Constants.h:319
Namespace containing all symbols from the Eigen library.
Definition: Core:141
const unsigned int RowMajorBit
Definition: Constants.h:66
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: Eigen_Colamd.h:50
Definition: Constants.h:321