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<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()*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();
79template<
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>
85template<
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)
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)
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)
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)
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)
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)
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)
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)
190 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs,Rhs,ResultType>(
colLhs, rhs, res, tolerance);
Pseudo expression representing a solving operation.
Definition Solve.h:63
@ ColMajor
Storage order is column major (see TopicStorageOrders).
Definition Constants.h:320
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition Constants.h:322
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61
Definition SparseSparseProductWithPruning.h:83