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)
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) 53 processRow(lhsEval,rhs,res,alpha,
i,
c);
59 processRow(lhsEval,rhs,res,alpha,
i,
c);
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>
93 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType&
res,
const AlphaType&
alpha)
98 for(
Index j=0;
j<lhs.outerSize(); ++
j)
102 for(LhsInnerIterator it(lhsEval,
j); it ;++it)
103 res.coeffRef(it.index(),
c) += it.value() * rhs_j;
109 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
120 LhsEval lhsEval(lhs);
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) 131 processRow(lhsEval,rhs,res,alpha,
i);
137 processRow(lhsEval, rhs, res, alpha,
i);
144 for(LhsInnerIterator it(lhsEval,i); it ;++it)
145 res_i += (alpha*it.value()) * rhs.row(it.index());
149 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
159 for(
Index j=0;
j<lhs.outerSize(); ++
j)
162 for(LhsInnerIterator it(lhsEval,
j); it ;++it)
163 res.row(it.index()) += (alpha*it.value()) * rhs_j;
168 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
178 template<
typename Lhs,
typename Rhs,
int ProductType>
184 template<
typename Dest>
189 LhsNested lhsNested(lhs);
190 RhsNested rhsNested(rhs);
195 template<
typename Lhs,
typename Rhs,
int ProductType>
200 template<
typename Lhs,
typename Rhs,
int ProductType>
206 template<
typename Dst>
211 LhsNested lhsNested(lhs);
212 RhsNested rhsNested(rhs);
220 template<
typename Lhs,
typename Rhs,
int ProductType>
225 template<
typename LhsT,
typename RhsT,
bool NeedToTranspose>
237 typedef typename conditional<is_same<typename internal::traits<Lhs1>::StorageKind,
Sparse>
::value,
255 : LhsIterator(xprEval.m_lhsXprImpl, 0),
258 m_factor(
get(xprEval.m_rhsXprImpl, outer, typename
internal::
traits<ActualRhs>::StorageKind() ))
269 Scalar
get(
const RhsEval &rhs,
Index outer,
Dense = Dense())
const 271 return rhs.coeff(outer);
276 typename RhsEval::InnerIterator it(rhs, outer);
277 if (it && it.index()==0 && it.value()!=
Scalar(0))
289 : m_lhs(lhs), m_lhsXprImpl(m_lhs), m_rhsXprImpl(rhs)
296 : m_lhs(lhs), m_lhsXprImpl(m_lhs), m_rhsXprImpl(rhs)
308 template<
typename Lhs,
typename Rhs>
318 : Base(xpr.lhs(), xpr.rhs())
323 template<
typename Lhs,
typename Rhs>
333 : Base(xpr.lhs(), xpr.rhs())
342 #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
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)
EIGEN_STRONG_INLINE Index row() const
Expression of the transpose of a matrix.
const StorageIndex & row() const
Product< LhsT, RhsT, DefaultProduct > ProdXprType
internal::remove_all< DenseResType >::type Res
evaluator< Lhs >::InnerIterator LhsInnerIterator
Namespace containing all symbols from the Eigen library.
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
Eigen::SparseMatrix< double > Sparse
static void scaleAndAddTo(Dst &dst, const Lhs &lhs, const Rhs &rhs, const Scalar &alpha)
evaluator< ActualRhs > RhsEval
static void processRow(const LhsEval &lhsEval, const DenseRhsType &rhs, Res &res, const typename Res::Scalar &alpha, Index i)
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_INTERNAL_CHECK_COST_VALUE(C)
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 Scalar value() 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)
Generic expression where a coefficient-wise unary operator is applied to an expression.
conditional< is_same< typename internal::traits< Lhs1 >::StorageKind, Sparse >::value, Lhs1, SparseView< Lhs1 > >::type ActualLhs
internal::remove_all< DenseResType >::type Res
EIGEN_STRONG_INLINE Index outer() const
Product< Lhs, Rhs > XprType
internal::remove_all< SparseLhsType >::type Lhs
LhsEval::InnerIterator LhsInnerIterator
LhsEval::InnerIterator LhsInnerIterator