10 #ifndef EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H
11 #define EIGEN_SPARSESPARSEPRODUCTWITHPRUNING_H
21 template<
typename Lhs,
typename Rhs,
typename ResultType>
37 AmbiVector<ResScalar,StorageIndex> tempVector(
rows);
40 if(ResultType::IsRowMajor)
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()));
63 tempVector.init(ratioColRes);
65 for (
typename evaluator<Rhs>::InnerIterator rhsIt(rhsEval,
j); rhsIt; ++rhsIt)
69 RhsScalar
x = rhsIt.value();
70 for (
typename evaluator<Lhs>::InnerIterator lhsIt(lhsEval, rhsIt.index()); lhsIt; ++lhsIt)
72 tempVector.coeffRef(lhsIt.index()) += lhsIt.value() *
x;
76 for (
typename AmbiVector<ResScalar,StorageIndex>::Iterator it(tempVector,tolerance); it; ++it)
77 res.insertBackByOuterInner(
j,it.index()) = it.value();
82 template<
typename Lhs,
typename Rhs,
typename ResultType,
83 int LhsStorageOrder = traits<Lhs>::Flags&
RowMajorBit,
84 int RhsStorageOrder = traits<Rhs>::Flags&
RowMajorBit,
85 int ResStorageOrder = traits<ResultType>::Flags&
RowMajorBit>
86 struct sparse_sparse_product_with_pruning_selector;
88 template<
typename Lhs,
typename Rhs,
typename ResultType>
91 typedef typename ResultType::RealScalar RealScalar;
93 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType&
res,
const RealScalar& tolerance)
95 remove_all_t<ResultType> _res(
res.rows(),
res.cols());
96 internal::sparse_sparse_product_with_pruning_impl<Lhs,Rhs,ResultType>(lhs, rhs, _res, tolerance);
101 template<
typename Lhs,
typename Rhs,
typename ResultType>
104 typedef typename ResultType::RealScalar RealScalar;
105 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType&
res,
const RealScalar& tolerance)
108 typedef SparseMatrix<typename ResultType::Scalar,ColMajor,typename ResultType::StorageIndex> SparseTemporaryType;
109 SparseTemporaryType _res(
res.rows(),
res.cols());
110 internal::sparse_sparse_product_with_pruning_impl<Lhs,Rhs,SparseTemporaryType>(lhs, rhs, _res, tolerance);
115 template<
typename Lhs,
typename Rhs,
typename ResultType>
118 typedef typename ResultType::RealScalar RealScalar;
119 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType&
res,
const RealScalar& tolerance)
122 remove_all_t<ResultType> _res(
res.rows(),
res.cols());
123 internal::sparse_sparse_product_with_pruning_impl<Rhs,Lhs,ResultType>(rhs, lhs, _res, tolerance);
128 template<
typename Lhs,
typename Rhs,
typename ResultType>
131 typedef typename ResultType::RealScalar RealScalar;
132 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType&
res,
const RealScalar& tolerance)
134 typedef SparseMatrix<typename Lhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixLhs;
135 typedef SparseMatrix<typename Rhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixRhs;
136 ColMajorMatrixLhs colLhs(lhs);
137 ColMajorMatrixRhs colRhs(rhs);
138 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs,ColMajorMatrixRhs,ResultType>(colLhs, colRhs,
res, tolerance);
148 template<
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)
154 typedef SparseMatrix<typename Lhs::Scalar,RowMajor,typename Lhs::StorageIndex> RowMajorMatrixLhs;
155 RowMajorMatrixLhs rowLhs(lhs);
156 sparse_sparse_product_with_pruning_selector<RowMajorMatrixLhs,Rhs,ResultType,RowMajor,RowMajor>(rowLhs,rhs,
res,tolerance);
160 template<
typename Lhs,
typename Rhs,
typename ResultType>
163 typedef typename ResultType::RealScalar RealScalar;
164 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType&
res,
const RealScalar& tolerance)
166 typedef SparseMatrix<typename Rhs::Scalar,RowMajor,typename Lhs::StorageIndex> RowMajorMatrixRhs;
167 RowMajorMatrixRhs rowRhs(rhs);
168 sparse_sparse_product_with_pruning_selector<Lhs,RowMajorMatrixRhs,ResultType,RowMajor,RowMajor,RowMajor>(lhs,rowRhs,
res,tolerance);
172 template<
typename Lhs,
typename Rhs,
typename ResultType>
175 typedef typename ResultType::RealScalar RealScalar;
176 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType&
res,
const RealScalar& tolerance)
178 typedef SparseMatrix<typename Rhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixRhs;
179 ColMajorMatrixRhs colRhs(rhs);
180 internal::sparse_sparse_product_with_pruning_impl<Lhs,ColMajorMatrixRhs,ResultType>(lhs, colRhs,
res, tolerance);
184 template<
typename Lhs,
typename Rhs,
typename ResultType>
187 typedef typename ResultType::RealScalar RealScalar;
188 static void run(
const Lhs& lhs,
const Rhs& rhs, ResultType&
res,
const RealScalar& tolerance)
190 typedef SparseMatrix<typename Lhs::Scalar,ColMajor,typename Lhs::StorageIndex> ColMajorMatrixLhs;
191 ColMajorMatrixLhs colLhs(lhs);
192 internal::sparse_sparse_product_with_pruning_impl<ColMajorMatrixLhs,Rhs,ResultType>(colLhs, rhs,
res, tolerance);
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
const unsigned int RowMajorBit
static void sparse_sparse_product_with_pruning_impl(const Lhs &lhs, const Rhs &rhs, ResultType &res, const typename ResultType::RealScalar &tolerance)
typename remove_all< T >::type remove_all_t
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.