10#ifndef EIGEN_SPARSEDENSEPRODUCT_H
11#define EIGEN_SPARSEDENSEPRODUCT_H
20template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
23 bool ColPerCol = ((DenseRhsType::Flags&
RowMajorBit)==0) || DenseRhsType::ColsAtCompileTime==1>
26template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
34 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha)
38 Index n = lhs.outerSize();
39#ifdef EIGEN_HAS_OPENMP
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>
93 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const AlphaType& alpha)
98 for(
Index j=0; j<lhs.outerSize(); ++j)
103 res.coeffRef(it.index(),
c) += it.value() * rhs_j;
109template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
117 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha)
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);
145 res_i += (alpha*it.value()) * rhs.row(it.index());
149template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
156 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha)
159 for(
Index j=0; j<lhs.outerSize(); ++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>
189 LhsNested lhsNested(lhs);
190 RhsNested rhsNested(rhs);
195template<
typename Lhs,
typename Rhs,
int ProductType>
200template<
typename Lhs,
typename Rhs,
int ProductType>
206 template<
typename Dst>
211 LhsNested lhsNested(lhs);
212 RhsNested rhsNested(rhs);
220template<
typename Lhs,
typename Rhs,
int ProductType>
225template<
typename LhsT,
typename RhsT,
bool NeedToTranspose>
243 typedef typename ProdXprType::Scalar
Scalar;
271 return rhs.coeff(
outer);
276 typename RhsEval::InnerIterator it(rhs,
outer);
277 if (it && it.index()==0 && it.value()!=
Scalar(0))
308template<
typename Lhs,
typename Rhs>
318 :
Base(xpr.lhs(), xpr.rhs())
323template<
typename Lhs,
typename Rhs>
333 :
Base(xpr.lhs(), xpr.rhs())
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:1097
const Block< const Derived, 1, internal::traits< Derived >::ColsAtCompileTime, IsRowMajor > ConstRowXpr
Definition: BlockMethods.h:18
Block< Derived, 1, internal::traits< Derived >::ColsAtCompileTime, IsRowMajor > RowXpr
Definition: BlockMethods.h:17
#define EIGEN_STRONG_INLINE
Definition: Macros.h:927
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
Definition: StaticAssert.h:218
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:75
Expression of a dense or sparse matrix with zero or too small values removed.
Definition: SparseView.h:46
Expression of the transpose of a matrix.
Definition: Transpose.h:54
Definition: SparseDenseProduct.h:252
EIGEN_STRONG_INLINE Index outer() const
Definition: SparseDenseProduct.h:261
Scalar m_factor
Definition: SparseDenseProduct.h:285
Scalar get(const RhsEval &rhs, Index outer, Sparse=Sparse())
Definition: SparseDenseProduct.h:274
EIGEN_STRONG_INLINE Scalar value() const
Definition: SparseDenseProduct.h:265
InnerIterator(const sparse_dense_outer_product_evaluator &xprEval, Index outer)
Definition: SparseDenseProduct.h:254
EIGEN_STRONG_INLINE Index col() const
Definition: SparseDenseProduct.h:263
bool m_empty
Definition: SparseDenseProduct.h:284
Scalar get(const RhsEval &rhs, Index outer, Dense=Dense()) const
Definition: SparseDenseProduct.h:269
EIGEN_STRONG_INLINE Index row() const
Definition: SparseDenseProduct.h:262
Index m_outer
Definition: SparseDenseProduct.h:283
type
Definition: core.h:575
@ 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
void sparse_time_dense_product(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const AlphaType &alpha)
Definition: SparseDenseProduct.h:169
Namespace containing all symbols from the Eigen library.
Definition: Core:141
@ DefaultProduct
Definition: Constants.h:500
@ OuterProduct
Definition: Constants.h:500
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: Eigen_Colamd.h:50
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
The type used to identify a dense storage.
Definition: Constants.h:507
Definition: Constants.h:528
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:806
The type used to identify a general sparse storage.
Definition: Constants.h:510
Definition: Constants.h:537
Definition: SparseUtil.h:137
Definition: CoreEvaluators.h:91
static void scaleAndAddTo(Dst &dst, const Lhs &lhs, const Rhs &rhs, const Scalar &alpha)
Definition: SparseDenseProduct.h:207
Product< Lhs, Rhs >::Scalar Scalar
Definition: SparseDenseProduct.h:204
Product< Lhs, Rhs >::Scalar Scalar
Definition: SparseDenseProduct.h:182
static void scaleAndAddTo(Dest &dst, const Lhs &lhs, const Rhs &rhs, const Scalar &alpha)
Definition: SparseDenseProduct.h:185
Definition: ProductEvaluators.h:344
Definition: ProductEvaluators.h:86
Definition: XprHelper.h:458
Product< Lhs, Rhs > XprType
Definition: SparseDenseProduct.h:329
XprType::PlainObject PlainObject
Definition: SparseDenseProduct.h:330
sparse_dense_outer_product_evaluator< Lhs, Rhs, Rhs::IsRowMajor > Base
Definition: SparseDenseProduct.h:327
product_evaluator(const XprType &xpr)
Definition: SparseDenseProduct.h:332
XprType::PlainObject PlainObject
Definition: SparseDenseProduct.h:315
product_evaluator(const XprType &xpr)
Definition: SparseDenseProduct.h:317
sparse_dense_outer_product_evaluator< Lhs, Rhs, Lhs::IsRowMajor > Base
Definition: SparseDenseProduct.h:312
Product< Lhs, Rhs > XprType
Definition: SparseDenseProduct.h:314
Definition: ForwardDeclarations.h:164
T type
Definition: Meta.h:126
Definition: SparseDenseProduct.h:227
evaluator< ActualLhs > m_lhsXprImpl
Definition: SparseDenseProduct.h:303
evaluator< ActualRhs > m_rhsXprImpl
Definition: SparseDenseProduct.h:304
ProdXprType::Scalar Scalar
Definition: SparseDenseProduct.h:243
conditional< is_same< typenameinternal::traits< Lhs1 >::StorageKind, Sparse >::value, Lhs1const &, SparseView< Lhs1 > >::type LhsArg
Definition: SparseDenseProduct.h:238
sparse_dense_outer_product_evaluator(const Lhs1 &lhs, const ActualRhs &rhs)
Definition: SparseDenseProduct.h:288
conditional< is_same< typenameinternal::traits< Lhs1 >::StorageKind, Sparse >::value, Lhs1, SparseView< Lhs1 > >::type ActualLhs
Definition: SparseDenseProduct.h:236
conditional< NeedToTranspose, LhsT, RhsT >::type ActualRhs
Definition: SparseDenseProduct.h:230
sparse_dense_outer_product_evaluator(const ActualRhs &rhs, const Lhs1 &lhs)
Definition: SparseDenseProduct.h:295
@ Flags
Definition: SparseDenseProduct.h:247
@ CoeffReadCost
Definition: SparseDenseProduct.h:248
conditional< NeedToTranspose, RhsT, LhsT >::type Lhs1
Definition: SparseDenseProduct.h:229
evaluator< ActualRhs > RhsEval
Definition: SparseDenseProduct.h:241
Product< LhsT, RhsT, DefaultProduct > ProdXprType
Definition: SparseDenseProduct.h:231
const LhsArg m_lhs
Definition: SparseDenseProduct.h:302
evaluator< ActualLhs >::InnerIterator LhsIterator
Definition: SparseDenseProduct.h:242
evaluator< ActualLhs > LhsEval
Definition: SparseDenseProduct.h:240
internal::remove_all< SparseLhsType >::type Lhs
Definition: SparseDenseProduct.h:112
internal::remove_all< DenseResType >::type Res
Definition: SparseDenseProduct.h:114
static void run(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const typename Res::Scalar &alpha)
Definition: SparseDenseProduct.h:117
evaluator< Lhs > LhsEval
Definition: SparseDenseProduct.h:115
static void processRow(const LhsEval &lhsEval, const DenseRhsType &rhs, Res &res, const typename Res::Scalar &alpha, Index i)
Definition: SparseDenseProduct.h:141
internal::remove_all< DenseRhsType >::type Rhs
Definition: SparseDenseProduct.h:113
LhsEval::InnerIterator LhsInnerIterator
Definition: SparseDenseProduct.h:116
internal::remove_all< SparseLhsType >::type Lhs
Definition: SparseDenseProduct.h:88
LhsEval::InnerIterator LhsInnerIterator
Definition: SparseDenseProduct.h:92
internal::remove_all< DenseResType >::type Res
Definition: SparseDenseProduct.h:90
evaluator< Lhs > LhsEval
Definition: SparseDenseProduct.h:91
static void run(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const AlphaType &alpha)
Definition: SparseDenseProduct.h:93
internal::remove_all< DenseRhsType >::type Rhs
Definition: SparseDenseProduct.h:89
static void run(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const typename Res::Scalar &alpha)
Definition: SparseDenseProduct.h:156
internal::remove_all< SparseLhsType >::type Lhs
Definition: SparseDenseProduct.h:152
internal::remove_all< DenseResType >::type Res
Definition: SparseDenseProduct.h:154
internal::remove_all< DenseRhsType >::type Rhs
Definition: SparseDenseProduct.h:153
evaluator< Lhs >::InnerIterator LhsInnerIterator
Definition: SparseDenseProduct.h:155
internal::remove_all< DenseRhsType >::type Rhs
Definition: SparseDenseProduct.h:30
evaluator< Lhs > LhsEval
Definition: SparseDenseProduct.h:33
internal::remove_all< DenseResType >::type Res
Definition: SparseDenseProduct.h:31
evaluator< Lhs >::InnerIterator LhsInnerIterator
Definition: SparseDenseProduct.h:32
static void processRow(const LhsEval &lhsEval, const DenseRhsType &rhs, DenseResType &res, const typename Res::Scalar &alpha, Index i, Index col)
Definition: SparseDenseProduct.h:64
static void run(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const typename Res::Scalar &alpha)
Definition: SparseDenseProduct.h:34
internal::remove_all< SparseLhsType >::type Lhs
Definition: SparseDenseProduct.h:29
Definition: SparseDenseProduct.h:24
Definition: ForwardDeclarations.h:17