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;
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)
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)
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);
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerSize() const
Definition DenseBase.h:235
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
@ ColMajor
Storage order is column major (see TopicStorageOrders).
Definition Constants.h:319
@ RowMajor
Storage order is row major (see TopicStorageOrders).
Definition Constants.h:321
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Definition SparseSparseProductWithPruning.h:84