10#ifndef EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H
11#define EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H
19template<
typename Lhs,
typename Rhs,
typename ResultType>
20static 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();
80template<
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>
86template<
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);
99template<
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)
107 SparseTemporaryType _res(res.rows(), res.cols());
108 internal::sparse_sparse_product_with_pruning_impl<Lhs,Rhs,SparseTemporaryType>(lhs, rhs, _res, tolerance);
113template<
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);
126template<
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)
134 ColMajorMatrixLhs colLhs(lhs);
135 ColMajorMatrixRhs colRhs(rhs);
136 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs,ColMajorMatrixRhs,ResultType>(colLhs, colRhs, res, tolerance);
146template<
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)
153 RowMajorMatrixLhs rowLhs(lhs);
158template<
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)
165 RowMajorMatrixRhs rowRhs(rhs);
170template<
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)
177 ColMajorMatrixRhs colRhs(rhs);
178 internal::sparse_sparse_product_with_pruning_impl<Lhs,ColMajorMatrixRhs,ResultType>(lhs, colRhs, res, tolerance);
182template<
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)
189 ColMajorMatrixLhs colLhs(lhs);
190 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs,Rhs,ResultType>(colLhs, rhs, res, tolerance);
A versatible sparse matrix representation.
Definition SparseMatrix.h:98
@ ColMajor
Definition Constants.h:319
@ RowMajor
Definition Constants.h:321
const unsigned int RowMajorBit
Definition Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition common.h:81
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Definition SparseSparseProductWithPruning.h:84