10#ifndef EIGEN_SPARSEDENSEPRODUCT_H
11#define EIGEN_SPARSEDENSEPRODUCT_H
26template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
29 typedef typename internal::remove_all<SparseLhsType>::type Lhs;
30 typedef typename internal::remove_all<DenseRhsType>::type Rhs;
31 typedef typename internal::remove_all<DenseResType>::type Res;
39#ifdef EIGEN_HAS_OPENMP
44 for(
Index c=0; c<rhs.cols(); ++c)
46#ifdef EIGEN_HAS_OPENMP
49 if(threads>1 &&
lhsEval.nonZerosEstimate() > 20000)
51 #pragma omp parallel for schedule(dynamic,(n+threads*4-1)/(threads*4)) num_threads(threads)
52 for(
Index i=0; i<n; ++i)
53 processRow(
lhsEval,rhs,res,alpha,i,c);
58 for(
Index i=0; i<n; ++i)
59 processRow(
lhsEval,rhs,res,alpha,i,c);
66 typename Res::Scalar tmp(0);
68 tmp += it.value() * rhs.coeff(it.index(),col);
69 res.coeffRef(i,col) += alpha * tmp;
85template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
88 typedef typename internal::remove_all<SparseLhsType>::type Lhs;
89 typedef typename internal::remove_all<DenseRhsType>::type Rhs;
90 typedef typename internal::remove_all<DenseResType>::type Res;
92 typedef typename LhsEval::InnerIterator LhsInnerIterator;
96 for(
Index c=0; c<rhs.cols(); ++c)
102 for(LhsInnerIterator it(
lhsEval,j); it ;++it)
103 res.coeffRef(it.index(),c) += it.value() *
rhs_j;
109template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
112 typedef typename internal::remove_all<SparseLhsType>::type Lhs;
113 typedef typename internal::remove_all<DenseRhsType>::type Rhs;
114 typedef typename internal::remove_all<DenseResType>::type Res;
116 typedef typename LhsEval::InnerIterator LhsInnerIterator;
119 Index n = lhs.rows();
122#ifdef EIGEN_HAS_OPENMP
127 if(threads>1 &&
lhsEval.nonZerosEstimate()*rhs.cols() > 20000)
129 #pragma omp parallel for schedule(dynamic,(n+threads*4-1)/(threads*4)) num_threads(threads)
130 for(
Index i=0; i<n; ++i)
131 processRow(
lhsEval,rhs,res,alpha,i);
136 for(
Index i=0; i<n; ++i)
137 processRow(
lhsEval, rhs, res, alpha, i);
143 typename Res::RowXpr
res_i(res.row(i));
144 for(LhsInnerIterator it(
lhsEval,i); it ;++it)
145 res_i += (alpha*it.value()) * rhs.row(it.index());
149template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
152 typedef typename internal::remove_all<SparseLhsType>::type Lhs;
153 typedef typename internal::remove_all<DenseRhsType>::type Rhs;
154 typedef typename internal::remove_all<DenseResType>::type Res;
161 typename Rhs::ConstRowXpr
rhs_j(rhs.row(j));
163 res.row(it.index()) += (alpha*it.value()) *
rhs_j;
168template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
178template<
typename Lhs,
typename Rhs,
int ProductType>
184 template<
typename Dest>
185 static void scaleAndAddTo(
Dest&
dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
187 typedef typename nested_eval<Lhs,((Rhs::Flags&
RowMajorBit)==0) ? 1 : Rhs::ColsAtCompileTime>::type LhsNested;
195template<
typename Lhs,
typename Rhs,
int ProductType>
200template<
typename Lhs,
typename Rhs,
int ProductType>
206 template<
typename Dst>
207 static void scaleAndAddTo(Dst&
dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
220template<
typename Lhs,
typename Rhs,
int ProductType>
225template<
typename LhsT,
typename RhsT,
bool NeedToTranspose>
243 typedef typename ProdXprType::Scalar Scalar;
255 : LhsIterator(
xprEval.m_lhsXprImpl, 0),
261 EIGEN_STRONG_INLINE
Index outer()
const {
return m_outer; }
262 EIGEN_STRONG_INLINE
Index row()
const {
return NeedToTranspose ? m_outer : LhsIterator::index(); }
263 EIGEN_STRONG_INLINE
Index col()
const {
return NeedToTranspose ? LhsIterator::index() : m_outer; }
265 EIGEN_STRONG_INLINE Scalar value()
const {
return LhsIterator::value() * m_factor; }
266 EIGEN_STRONG_INLINE
operator bool()
const {
return LhsIterator::operator bool() && (!m_empty); }
271 return rhs.coeff(outer);
277 if (it && it.index()==0 && it.
value()!=Scalar(0))
289 : m_lhs(lhs), m_lhsXprImpl(m_lhs), m_rhsXprImpl(rhs)
291 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
296 : m_lhs(lhs), m_lhsXprImpl(m_lhs), m_rhsXprImpl(rhs)
298 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
308template<
typename Lhs,
typename Rhs>
315 typedef typename XprType::PlainObject PlainObject;
323template<
typename Lhs,
typename Rhs>
330 typedef typename XprType::PlainObject PlainObject;
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerSize() const
Definition DenseBase.h:223
EIGEN_DEVICE_FUNC CoeffReturnType value() const
Definition DenseBase.h:526
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Definition Transpose.h:182
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Expression of the product of two arbitrary matrices or vectors.
Definition Product.h:75
Definition SparseDenseProduct.h:252
@ 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
const int HugeCost
This value means that the cost to evaluate an expression coefficient is either very expensive or cann...
Definition Constants.h:44
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
void initParallel()
Must be call first when calling Eigen from multiple threads.
Definition Parallelizer.h:53
int nbThreads()
Definition Parallelizer.h:63
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time,...
Definition Constants.h:22
Definition Constants.h:528
The type used to identify a dense storage.
Definition Constants.h:507
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition XprHelper.h:806
Definition Constants.h:537
The type used to identify a general sparse storage.
Definition Constants.h:510
Definition SparseUtil.h:137
Definition CoreEvaluators.h:91
Definition ProductEvaluators.h:344
Definition ProductEvaluators.h:86
Definition XprHelper.h:458
Definition ForwardDeclarations.h:164
Definition SparseDenseProduct.h:227
Definition SparseDenseProduct.h:24
Definition ForwardDeclarations.h:17