10 #ifndef EIGEN_SPARSEDENSEPRODUCT_H 11 #define EIGEN_SPARSEDENSEPRODUCT_H 20 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
23 bool ColPerCol = ((DenseRhsType::Flags&
RowMajorBit)==0) || DenseRhsType::ColsAtCompileTime==1>
26 template<
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 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);
64 static void processRow(
const LhsEval& lhsEval,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha,
Index i,
Index col)
66 typename Res::Scalar tmp(0);
67 for(LhsInnerIterator it(lhsEval,i); it ;++it)
68 tmp += it.value() * rhs.coeff(it.index(),
col);
69 res.coeffRef(i,col) += alpha * tmp;
85 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
92 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const AlphaType& alpha)
95 for(
Index c=0; c<rhs.cols(); ++c)
97 for(
Index j=0; j<lhs.outerSize(); ++j)
101 for(LhsInnerIterator it(lhsEval,j); it ;++it)
102 res.coeffRef(it.index(),c) += it.value() * rhs_j;
108 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
115 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha)
118 for(
Index j=0; j<lhs.outerSize(); ++j)
121 for(LhsInnerIterator it(lhsEval,j); it ;++it)
122 res_j += (alpha*it.value()) * rhs.row(it.index());
127 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
134 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha)
137 for(
Index j=0; j<lhs.outerSize(); ++j)
140 for(LhsInnerIterator it(lhsEval,j); it ;++it)
141 res.row(it.index()) += (alpha*it.value()) * rhs_j;
146 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
156 template<
typename Lhs,
typename Rhs,
int ProductType>
162 template<
typename Dest>
167 LhsNested lhsNested(lhs);
168 RhsNested rhsNested(rhs);
173 template<
typename Lhs,
typename Rhs,
int ProductType>
178 template<
typename Lhs,
typename Rhs,
int ProductType>
184 template<
typename Dst>
189 LhsNested lhsNested(lhs);
190 RhsNested rhsNested(rhs);
198 template<
typename Lhs,
typename Rhs,
int ProductType>
203 template<
typename LhsT,
typename RhsT,
bool NeedToTranspose>
215 typedef typename conditional<is_same<typename internal::traits<Lhs1>::StorageKind,
Sparse>::value,
221 typedef typename ProdXprType::Scalar
Scalar;
233 : LhsIterator(xprEval.m_lhsXprImpl, 0),
236 m_factor(
get(xprEval.m_rhsXprImpl, outer, typename
internal::
traits<ActualRhs>::StorageKind() ))
247 Scalar
get(
const RhsEval &rhs,
Index outer,
Dense = Dense())
const 249 return rhs.coeff(outer);
254 typename RhsEval::InnerIterator it(rhs, outer);
255 if (it && it.index()==0 && it.value()!=Scalar(0))
267 : m_lhs(lhs), m_lhsXprImpl(m_lhs), m_rhsXprImpl(rhs)
274 : m_lhs(lhs), m_lhsXprImpl(m_lhs), m_rhsXprImpl(rhs)
286 template<
typename Lhs,
typename Rhs>
296 : Base(xpr.lhs(), xpr.rhs())
301 template<
typename Lhs,
typename Rhs>
311 : Base(xpr.lhs(), xpr.rhs())
320 #endif // EIGEN_SPARSEDENSEPRODUCT_H product_evaluator(const XprType &xpr)
Block< Derived, 1, internal::traits< Derived >::ColsAtCompileTime, IsRowMajor > RowXpr
conditional< NeedToTranspose, RhsT, LhsT >::type Lhs1
static void processRow(const LhsEval &lhsEval, const DenseRhsType &rhs, DenseResType &res, const typename Res::Scalar &alpha, Index i, Index col)
void sparse_time_dense_product(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const AlphaType &alpha)
internal::remove_all< DenseRhsType >::type Rhs
static void run(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const typename Res::Scalar &alpha)
#define EIGEN_STRONG_INLINE
internal::remove_all< SparseLhsType >::type Lhs
XprType::PlainObject PlainObject
Expression of the product of two arbitrary matrices or vectors.
evaluator< Lhs >::InnerIterator LhsInnerIterator
EIGEN_STRONG_INLINE Scalar value() const
static void run(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const typename Res::Scalar &alpha)
Product< Lhs, Rhs >::Scalar Scalar
conditional< NeedToTranspose, LhsT, RhsT >::type ActualRhs
Product< Lhs, Rhs >::Scalar Scalar
sparse_dense_outer_product_evaluator(const ActualRhs &rhs, const Lhs1 &lhs)
Expression of the transpose of a matrix.
Product< LhsT, RhsT, DefaultProduct > ProdXprType
internal::remove_all< DenseResType >::type Res
evaluator< Lhs >::InnerIterator LhsInnerIterator
static void run(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const typename Res::Scalar &alpha)
internal::remove_all< DenseResType >::type Res
const unsigned int RowMajorBit
static void scaleAndAddTo(Dst &dst, const Lhs &lhs, const Rhs &rhs, const Scalar &alpha)
evaluator< ActualRhs > RhsEval
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
evaluator< Lhs >::InnerIterator LhsInnerIterator
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
internal::remove_all< DenseRhsType >::type Rhs
internal::remove_all< DenseResType >::type Res
product_evaluator(const XprType &xpr)
static void scaleAndAddTo(Dest &dst, const Lhs &lhs, const Rhs &rhs, const Scalar &alpha)
EIGEN_STRONG_INLINE Index col() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
evaluator< ActualLhs >::InnerIterator LhsIterator
EIGEN_STRONG_INLINE Index row() const
Expression of a dense or sparse matrix with zero or too small values removed.
evaluator< ActualRhs > m_rhsXprImpl
internal::remove_all< SparseLhsType >::type Lhs
const Block< const Derived, 1, internal::traits< Derived >::ColsAtCompileTime, IsRowMajor > ConstRowXpr
sparse_dense_outer_product_evaluator< Lhs, Rhs, Rhs::IsRowMajor > Base
XprType::PlainObject PlainObject
ProdXprType::Scalar Scalar
conditional< is_same< typename internal::traits< Lhs1 >::StorageKind, Sparse >::value, Lhs1 const &, SparseView< Lhs1 > >::type LhsArg
internal::remove_all< DenseRhsType >::type Rhs
evaluator< ActualLhs > m_lhsXprImpl
sparse_dense_outer_product_evaluator< Lhs, Rhs, Lhs::IsRowMajor > Base
Product< Lhs, Rhs > XprType
internal::remove_all< DenseRhsType >::type Rhs
static void run(const SparseLhsType &lhs, const DenseRhsType &rhs, DenseResType &res, const AlphaType &alpha)
evaluator< ActualLhs > LhsEval
sparse_dense_outer_product_evaluator(const Lhs1 &lhs, const ActualRhs &rhs)
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
internal::remove_all< SparseLhsType >::type Lhs
InnerIterator(const sparse_dense_outer_product_evaluator &xprEval, Index outer)
EIGEN_STRONG_INLINE Index outer() const
conditional< is_same< typename internal::traits< Lhs1 >::StorageKind, Sparse >::value, Lhs1, SparseView< Lhs1 > >::type ActualLhs
internal::remove_all< DenseResType >::type Res
evaluator< Lhs >::InnerIterator LhsInnerIterator
Product< Lhs, Rhs > XprType
internal::remove_all< SparseLhsType >::type Lhs
void run(Expr &expr, Dev &dev)