25 #ifndef EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H
26 #define EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H
34 template<
typename Lhs,
typename Rhs,
typename ResultType>
35 static void sparse_sparse_product_with_pruning_impl(
const Lhs& lhs,
const Rhs& rhs, ResultType& res,
typename ResultType::RealScalar tolerance)
39 typedef typename remove_all<Lhs>::type::Scalar Scalar;
40 typedef typename remove_all<Lhs>::type::Index Index;
43 Index rows = lhs.innerSize();
44 Index cols = rhs.outerSize();
49 AmbiVector<Scalar,Index> tempVector(rows);
57 Index estimated_nnz_prod = lhs.nonZeros() + rhs.nonZeros();
60 if(ResultType::IsRowMajor)
61 res.resize(cols, rows);
63 res.resize(rows, cols);
65 res.reserve(estimated_nnz_prod);
66 double ratioColRes = double(estimated_nnz_prod)/double(lhs.rows()*rhs.cols());
67 for (Index j=0; j<cols; ++j)
72 tempVector.init(ratioColRes);
74 for (
typename Rhs::InnerIterator rhsIt(rhs, j); rhsIt; ++rhsIt)
78 Scalar x = rhsIt.value();
79 for (
typename Lhs::InnerIterator lhsIt(lhs, rhsIt.index()); lhsIt; ++lhsIt)
81 tempVector.coeffRef(lhsIt.index()) += lhsIt.value() * x;
85 for (
typename AmbiVector<Scalar,Index>::Iterator it(tempVector,tolerance); it; ++it)
86 res.insertBackByOuterInner(j,it.index()) = it.value();
91 template<
typename Lhs,
typename Rhs,
typename ResultType,
95 struct sparse_sparse_product_with_pruning_selector;
97 template<
typename Lhs,
typename Rhs,
typename ResultType>
101 typedef typename ResultType::RealScalar RealScalar;
103 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res, RealScalar tolerance)
105 typename remove_all<ResultType>::type _res(res.rows(), res.cols());
106 internal::sparse_sparse_product_with_pruning_impl<Lhs,Rhs,ResultType>(lhs, rhs, _res, tolerance);
111 template<
typename Lhs,
typename Rhs,
typename ResultType>
114 typedef typename ResultType::RealScalar RealScalar;
115 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res, RealScalar tolerance)
118 typedef SparseMatrix<typename ResultType::Scalar> SparseTemporaryType;
119 SparseTemporaryType _res(res.rows(), res.cols());
120 internal::sparse_sparse_product_with_pruning_impl<Lhs,Rhs,SparseTemporaryType>(lhs, rhs, _res, tolerance);
125 template<
typename Lhs,
typename Rhs,
typename ResultType>
128 typedef typename ResultType::RealScalar RealScalar;
129 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res, RealScalar tolerance)
132 typename remove_all<ResultType>::type _res(res.rows(), res.cols());
133 internal::sparse_sparse_product_with_pruning_impl<Rhs,Lhs,ResultType>(rhs, lhs, _res, tolerance);
138 template<
typename Lhs,
typename Rhs,
typename ResultType>
141 typedef typename ResultType::RealScalar RealScalar;
142 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType& res, RealScalar tolerance)
144 typedef SparseMatrix<typename ResultType::Scalar,ColMajor> ColMajorMatrix;
145 ColMajorMatrix colLhs(lhs);
146 ColMajorMatrix colRhs(rhs);
147 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrix,ColMajorMatrix,ResultType>(colLhs, colRhs, res, tolerance);
164 #endif // EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H