10 #ifndef EIGEN_CONSERVATIVESPARSESPARSEPRODUCT_H 11 #define EIGEN_CONSERVATIVESPARSESPARSEPRODUCT_H 17 template<
typename Lhs,
typename Rhs,
typename ResultType>
24 Index rows = lhs.innerSize();
25 Index cols = rhs.outerSize();
28 std::vector<bool> mask(rows,
false);
38 Index estimated_nnz_prod = lhs.nonZeros() + rhs.nonZeros();
41 res.reserve(Index(estimated_nnz_prod));
43 for (Index j=0; j<cols; ++j)
48 for (
typename Rhs::InnerIterator rhsIt(rhs, j); rhsIt; ++rhsIt)
50 Scalar
y = rhsIt.value();
51 Index k = rhsIt.index();
52 for (
typename Lhs::InnerIterator lhsIt(lhs, k); lhsIt; ++lhsIt)
54 Index i = lhsIt.index();
55 Scalar x = lhsIt.value();
69 for(
int k=0; k<nnz; ++k)
72 res.insertBackByOuterInnerUnordered(j,i) = values[i];
79 int t200 = rows/(log2(200)*1.39);
80 int t = (rows*100)/139;
92 if(nnz>1) std::sort(indices.
data(),indices.
data()+nnz);
93 for(
int k=0; k<nnz; ++k)
96 res.insertBackByOuterInner(j,i) = values[i];
103 for(
int i=0; i<rows; ++i)
108 res.insertBackByOuterInner(j,i) = values[i];
123 template<
typename Lhs,
typename Rhs,
typename ResultType,
129 template<
typename Lhs,
typename Rhs,
typename ResultType>
133 typedef typename LhsCleaned::Scalar
Scalar;
135 static void run(
const Lhs& lhs,
const Rhs&
rhs, ResultType& res)
139 ColMajorMatrix resCol(lhs.rows(),rhs.cols());
140 internal::conservative_sparse_sparse_product_impl<Lhs,Rhs,ColMajorMatrix>(lhs,
rhs, resCol);
142 RowMajorMatrix resRow(resCol);
147 template<
typename Lhs,
typename Rhs,
typename ResultType>
150 static void run(
const Lhs& lhs,
const Rhs&
rhs, ResultType& res)
153 RowMajorMatrix rhsRow =
rhs;
154 RowMajorMatrix resRow(lhs.rows(), rhs.cols());
155 internal::conservative_sparse_sparse_product_impl<RowMajorMatrix,Lhs,RowMajorMatrix>(rhsRow, lhs, resRow);
160 template<
typename Lhs,
typename Rhs,
typename ResultType>
163 static void run(
const Lhs& lhs,
const Rhs&
rhs, ResultType& res)
166 RowMajorMatrix lhsRow = lhs;
167 RowMajorMatrix resRow(lhs.rows(), rhs.cols());
168 internal::conservative_sparse_sparse_product_impl<Rhs,RowMajorMatrix,RowMajorMatrix>(
rhs, lhsRow, resRow);
173 template<
typename Lhs,
typename Rhs,
typename ResultType>
176 static void run(
const Lhs& lhs,
const Rhs&
rhs, ResultType& res)
179 RowMajorMatrix resRow(lhs.rows(), rhs.cols());
180 internal::conservative_sparse_sparse_product_impl<Rhs,Lhs,RowMajorMatrix>(
rhs, lhs, resRow);
186 template<
typename Lhs,
typename Rhs,
typename ResultType>
191 static void run(
const Lhs& lhs,
const Rhs&
rhs, ResultType& res)
194 ColMajorMatrix resCol(lhs.rows(), rhs.cols());
195 internal::conservative_sparse_sparse_product_impl<Lhs,Rhs,ColMajorMatrix>(lhs,
rhs, resCol);
200 template<
typename Lhs,
typename Rhs,
typename ResultType>
203 static void run(
const Lhs& lhs,
const Rhs&
rhs, ResultType& res)
206 ColMajorMatrix lhsCol = lhs;
207 ColMajorMatrix resCol(lhs.rows(), rhs.cols());
208 internal::conservative_sparse_sparse_product_impl<ColMajorMatrix,Rhs,ColMajorMatrix>(lhsCol,
rhs, resCol);
213 template<
typename Lhs,
typename Rhs,
typename ResultType>
216 static void run(
const Lhs& lhs,
const Rhs&
rhs, ResultType& res)
219 ColMajorMatrix rhsCol =
rhs;
220 ColMajorMatrix resCol(lhs.rows(), rhs.cols());
221 internal::conservative_sparse_sparse_product_impl<Lhs,ColMajorMatrix,ColMajorMatrix>(lhs, rhsCol, resCol);
226 template<
typename Lhs,
typename Rhs,
typename ResultType>
229 static void run(
const Lhs& lhs,
const Rhs&
rhs, ResultType& res)
233 RowMajorMatrix resRow(lhs.rows(),rhs.cols());
234 internal::conservative_sparse_sparse_product_impl<Rhs,Lhs,RowMajorMatrix>(
rhs, lhs, resRow);
236 ColMajorMatrix resCol(resRow);
245 #endif // EIGEN_CONSERVATIVESPARSESPARSEPRODUCT_H
static void conservative_sparse_sparse_product_impl(const Lhs &lhs, const Rhs &rhs, ResultType &res)
static void run(const Lhs &lhs, const Rhs &rhs, ResultType &res)
LhsCleaned::Scalar Scalar
A versatible sparse matrix representation.
iterative scaling algorithm to equilibrate rows and column norms in matrices
const unsigned int RowMajorBit
static void run(const Lhs &lhs, const Rhs &rhs, ResultType &res)
traits< typename remove_all< Lhs >::type >::Scalar Scalar
static void run(const Lhs &lhs, const Rhs &rhs, ResultType &res)
static void run(const Lhs &lhs, const Rhs &rhs, ResultType &res)
void rhs(const real_t *x, real_t *f)
EIGEN_STRONG_INLINE const Scalar * data() const
remove_all< Lhs >::type LhsCleaned
static void run(const Lhs &lhs, const Rhs &rhs, ResultType &res)
static void run(const Lhs &lhs, const Rhs &rhs, ResultType &res)
static void run(const Lhs &lhs, const Rhs &rhs, ResultType &res)
static void run(const Lhs &lhs, const Rhs &rhs, ResultType &res)