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<Lhs>::type::Scalar Scalar;
25 typedef typename remove_all<Lhs>::type::StorageIndex StorageIndex;
28 Index rows = lhs.innerSize();
29 Index cols = rhs.outerSize();
31 eigen_assert(lhs.outerSize() == rhs.innerSize());
34 AmbiVector<Scalar,StorageIndex> tempVector(rows);
37 if(ResultType::IsRowMajor)
38 res.resize(cols, rows);
40 res.resize(rows, cols);
42 evaluator<Lhs> lhsEval(lhs);
43 evaluator<Rhs> rhsEval(rhs);
51 Index estimated_nnz_prod = lhsEval.nonZerosEstimate() + rhsEval.nonZerosEstimate();
53 res.reserve(estimated_nnz_prod);
54 double ratioColRes = double(estimated_nnz_prod)/(double(lhs.rows())*
double(rhs.cols()));
55 for (
Index j=0; j<cols; ++j)
60 tempVector.init(ratioColRes);
62 for (
typename evaluator<Rhs>::InnerIterator rhsIt(rhsEval, j); rhsIt; ++rhsIt)
66 Scalar x = rhsIt.value();
67 for (
typename evaluator<Lhs>::InnerIterator lhsIt(lhsEval, rhsIt.index()); lhsIt; ++lhsIt)
69 tempVector.coeffRef(lhsIt.index()) += lhsIt.value() * x;
73 for (
typename AmbiVector<Scalar,StorageIndex>::Iterator it(tempVector,tolerance); it; ++it)
74 res.insertBackByOuterInner(j,it.index()) = it.value();
79 template<
typename Lhs,
typename Rhs,
typename ResultType,
80 int LhsStorageOrder = traits<Lhs>::Flags&
RowMajorBit,
81 int RhsStorageOrder = traits<Rhs>::Flags&
RowMajorBit,
82 int ResStorageOrder = traits<ResultType>::Flags&RowMajorBit>
83 struct sparse_sparse_product_with_pruning_selector;
85 template<
typename Lhs,
typename Rhs,
typename ResultType>
88 typedef typename traits<typename remove_all<Lhs>::type>::Scalar Scalar;
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 ResultType::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixLhs;
133 typedef SparseMatrix<typename ResultType::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 ResultType::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 ResultType::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 ResultType::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 ResultType::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:320
Namespace containing all symbols from the Eigen library.
Definition: Core:287
const unsigned int RowMajorBit
Definition: Constants.h:61
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: Eigen_Colamd.h:50
Definition: Constants.h:322