10#ifndef EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H
11#define EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H
14#include "./InternalHeaderCheck.h"
21template <
typename Lhs,
typename Rhs,
typename ResultType>
22static void sparse_sparse_product_with_pruning_impl(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
23 const typename ResultType::RealScalar& tolerance) {
26 typedef typename remove_all_t<Rhs>::Scalar RhsScalar;
27 typedef typename remove_all_t<ResultType>::Scalar ResScalar;
28 typedef typename remove_all_t<Lhs>::StorageIndex StorageIndex;
31 Index rows = lhs.innerSize();
32 Index cols = rhs.outerSize();
34 eigen_assert(lhs.outerSize() == rhs.innerSize());
37 AmbiVector<ResScalar, StorageIndex> tempVector(rows);
40 if (ResultType::IsRowMajor)
41 res.resize(cols, rows);
43 res.resize(rows, cols);
45 evaluator<Lhs> lhsEval(lhs);
46 evaluator<Rhs> rhsEval(rhs);
54 Index estimated_nnz_prod = lhsEval.nonZerosEstimate() + rhsEval.nonZerosEstimate();
56 res.reserve(estimated_nnz_prod);
57 double ratioColRes = double(estimated_nnz_prod) / (double(lhs.rows()) * double(rhs.cols()));
58 for (Index j = 0; j < cols; ++j) {
63 tempVector.init(ratioColRes);
65 for (
typename evaluator<Rhs>::InnerIterator rhsIt(rhsEval, j); rhsIt; ++rhsIt) {
68 RhsScalar x = rhsIt.value();
69 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, int LhsStorageOrder = traits<Lhs>::Flags &
RowMajorBit,
81 int RhsStorageOrder = traits<Rhs>::Flags &
RowMajorBit,
82 int ResStorageOrder = traits<ResultType>::Flags &
RowMajorBit>
83struct sparse_sparse_product_with_pruning_selector;
85template <
typename Lhs,
typename Rhs,
typename ResultType>
87 typedef typename ResultType::RealScalar RealScalar;
89 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance) {
90 remove_all_t<ResultType> res_(res.rows(), res.cols());
91 internal::sparse_sparse_product_with_pruning_impl<Lhs, Rhs, ResultType>(lhs, rhs, res_, tolerance);
96template <
typename Lhs,
typename Rhs,
typename ResultType>
98 typedef typename ResultType::RealScalar RealScalar;
99 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance) {
101 typedef SparseMatrix<typename ResultType::Scalar, ColMajor, typename ResultType::StorageIndex> SparseTemporaryType;
102 SparseTemporaryType res_(res.rows(), res.cols());
103 internal::sparse_sparse_product_with_pruning_impl<Lhs, Rhs, SparseTemporaryType>(lhs, rhs, res_, tolerance);
108template <
typename Lhs,
typename Rhs,
typename ResultType>
110 typedef typename ResultType::RealScalar RealScalar;
111 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance) {
113 remove_all_t<ResultType> res_(res.rows(), res.cols());
114 internal::sparse_sparse_product_with_pruning_impl<Rhs, Lhs, ResultType>(rhs, lhs, res_, tolerance);
119template <
typename Lhs,
typename Rhs,
typename ResultType>
121 typedef typename ResultType::RealScalar RealScalar;
122 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance) {
123 typedef SparseMatrix<typename Lhs::Scalar, ColMajor, typename Lhs::StorageIndex> ColMajorMatrixLhs;
124 typedef SparseMatrix<typename Rhs::Scalar, ColMajor, typename Lhs::StorageIndex> ColMajorMatrixRhs;
125 ColMajorMatrixLhs colLhs(lhs);
126 ColMajorMatrixRhs colRhs(rhs);
127 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs, ColMajorMatrixRhs, ResultType>(colLhs, colRhs,
138template <
typename Lhs,
typename Rhs,
typename ResultType>
140 typedef typename ResultType::RealScalar RealScalar;
141 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance) {
142 typedef SparseMatrix<typename Lhs::Scalar, RowMajor, typename Lhs::StorageIndex> RowMajorMatrixLhs;
143 RowMajorMatrixLhs rowLhs(lhs);
144 sparse_sparse_product_with_pruning_selector<RowMajorMatrixLhs, Rhs, ResultType, RowMajor, RowMajor>(rowLhs, rhs,
149template <
typename Lhs,
typename Rhs,
typename ResultType>
151 typedef typename ResultType::RealScalar RealScalar;
152 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance) {
153 typedef SparseMatrix<typename Rhs::Scalar, RowMajor, typename Lhs::StorageIndex> RowMajorMatrixRhs;
154 RowMajorMatrixRhs rowRhs(rhs);
155 sparse_sparse_product_with_pruning_selector<Lhs, RowMajorMatrixRhs, ResultType, RowMajor, RowMajor, RowMajor>(
156 lhs, rowRhs, res, tolerance);
160template <
typename Lhs,
typename Rhs,
typename ResultType>
162 typedef typename ResultType::RealScalar RealScalar;
163 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance) {
164 typedef SparseMatrix<typename Rhs::Scalar, ColMajor, typename Lhs::StorageIndex> ColMajorMatrixRhs;
165 ColMajorMatrixRhs colRhs(rhs);
166 internal::sparse_sparse_product_with_pruning_impl<Lhs, ColMajorMatrixRhs, ResultType>(lhs, colRhs, res, tolerance);
170template <
typename Lhs,
typename Rhs,
typename ResultType>
172 typedef typename ResultType::RealScalar RealScalar;
173 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
const RealScalar& tolerance) {
174 typedef SparseMatrix<typename Lhs::Scalar, ColMajor, typename Lhs::StorageIndex> ColMajorMatrixLhs;
175 ColMajorMatrixLhs colLhs(lhs);
176 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs, Rhs, ResultType>(colLhs, rhs, res, tolerance);
@ ColMajor
Definition Constants.h:318
@ RowMajor
Definition Constants.h:320
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition Core:137