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)
120 typename Res::RowXpr res_j(res.row(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)
139 typename Rhs::ConstRowXpr rhs_j(rhs.row(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>
147 inline void sparse_time_dense_product(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const AlphaType& alpha)
156 template<
typename Lhs,
typename Rhs,
int ProductType>
162 template<
typename Dest>
163 static void scaleAndAddTo(Dest& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
167 LhsNested lhsNested(lhs);
168 RhsNested rhsNested(rhs);
169 internal::sparse_time_dense_product(lhsNested, rhsNested, dst, alpha);
173 template<
typename Lhs,
typename Rhs,
int ProductType>
178 template<
typename Lhs,
typename Rhs,
int ProductType>
184 template<
typename Dst>
185 static void scaleAndAddTo(Dst& dst,
const Lhs& lhs,
const Rhs& rhs,
const Scalar& alpha)
189 LhsNested lhsNested(lhs);
190 RhsNested rhsNested(rhs);
194 internal::sparse_time_dense_product(rhsNested.transpose(), lhsNested.transpose(), dstT, alpha);
198 template<
typename Lhs,
typename Rhs,
int ProductType>
203 template<
typename LhsT,
typename RhsT,
bool NeedToTranspose>
207 typedef typename conditional<NeedToTranspose,RhsT,LhsT>::type
Lhs1;
208 typedef typename conditional<NeedToTranspose,LhsT,RhsT>::type ActualRhs;
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),
239 EIGEN_STRONG_INLINE
Index outer()
const {
return m_outer; }
240 EIGEN_STRONG_INLINE
Index row()
const {
return NeedToTranspose ? m_outer : LhsIterator::index(); }
241 EIGEN_STRONG_INLINE
Index col()
const {
return NeedToTranspose ? LhsIterator::index() : m_outer; }
243 EIGEN_STRONG_INLINE Scalar value()
const {
return LhsIterator::value() * m_factor; }
244 EIGEN_STRONG_INLINE
operator bool()
const {
return LhsIterator::operator bool() && (!m_empty); }
247 Scalar
get(
const RhsEval &rhs,
Index outer,
Dense = Dense())
const 249 return rhs.coeff(outer);
252 Scalar
get(
const RhsEval &rhs,
Index outer,
Sparse = Sparse())
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)
269 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
274 : m_lhs(lhs), m_lhsXprImpl(m_lhs), m_rhsXprImpl(rhs)
276 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
286 template<
typename Lhs,
typename Rhs>
293 typedef typename XprType::PlainObject PlainObject;
296 : Base(xpr.lhs(), xpr.rhs())
301 template<
typename Lhs,
typename Rhs>
308 typedef typename XprType::PlainObject PlainObject;
311 : Base(xpr.lhs(), xpr.rhs())
320 #endif // EIGEN_SPARSEDENSEPRODUCT_H void initParallel()
Must be call first when calling Eigen from multiple threads.
Definition: Parallelizer.h:48
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:320
const int HugeCost
This value means that the cost to evaluate an expression coefficient is either very expensive or cann...
Definition: Constants.h:39
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
Definition: ForwardDeclarations.h:162
Expression of the transpose of a matrix.
Definition: Transpose.h:52
Definition: SparseDenseProduct.h:204
Definition: CoreEvaluators.h:90
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Definition: Constants.h:521
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:61
Definition: Constants.h:512
Definition: ProductEvaluators.h:343
int nbThreads()
Definition: Parallelizer.h:58
Definition: ProductEvaluators.h:86
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Definition: ForwardDeclarations.h:126
The type used to identify a general sparse storage.
Definition: Constants.h:494
Definition: SparseUtil.h:137
Definition: BandTriangularSolver.h:13
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:322
The type used to identify a dense storage.
Definition: Constants.h:491
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:757
Definition: SparseDenseProduct.h:229
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
Definition: ForwardDeclarations.h:17
Definition: SparseDenseProduct.h:24