25 #ifndef EIGEN_SPARSEDENSEPRODUCT_H
26 #define EIGEN_SPARSEDENSEPRODUCT_H
52 template<
typename Lhs,
typename Rhs,
bool Tr>
53 struct traits<SparseDenseOuterProduct<Lhs,Rhs,Tr> >
55 typedef Sparse StorageKind;
56 typedef typename scalar_product_traits<typename traits<Lhs>::Scalar,
58 typedef typename Lhs::Index Index;
59 typedef typename Lhs::Nested LhsNested;
60 typedef typename Rhs::Nested RhsNested;
61 typedef typename remove_all<LhsNested>::type _LhsNested;
62 typedef typename remove_all<RhsNested>::type _RhsNested;
81 template<
typename Lhs,
typename Rhs,
bool Tr>
93 typedef typename Traits::LhsNested LhsNested;
94 typedef typename Traits::RhsNested RhsNested;
95 typedef typename Traits::_LhsNested _LhsNested;
96 typedef typename Traits::_RhsNested _RhsNested;
125 template<
typename Lhs,
typename Rhs,
bool Transpose>
128 typedef typename _LhsNested::InnerIterator
Base;
131 :
Base(prod.
lhs(), 0), m_outer(outer), m_factor(prod.
rhs().coeff(outer))
135 inline Index outer()
const {
return m_outer; }
139 inline Scalar value()
const {
return Base::value() * m_factor; }
147 template<
typename Lhs,
typename Rhs>
148 struct traits<SparseTimeDenseProduct<Lhs,Rhs> >
149 :
traits<ProductBase<SparseTimeDenseProduct<Lhs,Rhs>, Lhs, Rhs> >
151 typedef Dense StorageKind;
152 typedef MatrixXpr XprKind;
155 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
157 bool ColPerCol = ((DenseRhsType::Flags&
RowMajorBit)==0) || DenseRhsType::ColsAtCompileTime==1>
158 struct sparse_time_dense_product_impl;
160 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
161 struct sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType,
RowMajor, true>
163 typedef typename internal::remove_all<SparseLhsType>::type Lhs;
164 typedef typename internal::remove_all<DenseRhsType>::type Rhs;
165 typedef typename internal::remove_all<DenseResType>::type Res;
166 typedef typename Lhs::Index Index;
167 typedef typename Lhs::InnerIterator LhsInnerIterator;
168 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
typename Res::Scalar alpha)
170 for(Index c=0; c<rhs.cols(); ++c)
172 int n = lhs.outerSize();
173 for(Index j=0; j<n; ++j)
175 typename Res::Scalar tmp(0);
176 for(LhsInnerIterator it(lhs,j); it ;++it)
177 tmp += it.value() * rhs.coeff(it.index(),c);
178 res.coeffRef(j,c) = alpha * tmp;
184 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
185 struct sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType,
ColMajor, true>
187 typedef typename internal::remove_all<SparseLhsType>::type Lhs;
188 typedef typename internal::remove_all<DenseRhsType>::type Rhs;
189 typedef typename internal::remove_all<DenseResType>::type Res;
190 typedef typename Lhs::InnerIterator LhsInnerIterator;
191 typedef typename Lhs::Index Index;
192 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
typename Res::Scalar alpha)
194 for(Index c=0; c<rhs.cols(); ++c)
196 for(Index j=0; j<lhs.outerSize(); ++j)
198 typename Res::Scalar rhs_j = alpha * rhs.coeff(j,c);
199 for(LhsInnerIterator it(lhs,j); it ;++it)
200 res.coeffRef(it.index(),c) += it.value() * rhs_j;
206 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
207 struct sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType,
RowMajor, false>
209 typedef typename internal::remove_all<SparseLhsType>::type Lhs;
210 typedef typename internal::remove_all<DenseRhsType>::type Rhs;
211 typedef typename internal::remove_all<DenseResType>::type Res;
212 typedef typename Lhs::InnerIterator LhsInnerIterator;
213 typedef typename Lhs::Index Index;
214 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
typename Res::Scalar alpha)
216 for(Index j=0; j<lhs.outerSize(); ++j)
218 typename Res::RowXpr res_j(res.row(j));
219 for(LhsInnerIterator it(lhs,j); it ;++it)
220 res_j += (alpha*it.value()) * rhs.row(it.index());
225 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
226 struct sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType,
ColMajor, false>
228 typedef typename internal::remove_all<SparseLhsType>::type Lhs;
229 typedef typename internal::remove_all<DenseRhsType>::type Rhs;
230 typedef typename internal::remove_all<DenseResType>::type Res;
231 typedef typename Lhs::InnerIterator LhsInnerIterator;
232 typedef typename Lhs::Index Index;
233 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
typename Res::Scalar alpha)
235 for(Index j=0; j<lhs.outerSize(); ++j)
237 typename Rhs::ConstRowXpr rhs_j(rhs.row(j));
238 for(LhsInnerIterator it(lhs,j); it ;++it)
239 res.row(it.index()) += (alpha*it.value()) * rhs_j;
244 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
247 sparse_time_dense_product_impl<SparseLhsType,DenseRhsType,DenseResType>::run(lhs, rhs, res, alpha);
252 template<
typename Lhs,
typename Rhs>
254 :
public ProductBase<SparseTimeDenseProduct<Lhs,Rhs>, Lhs, Rhs>
274 template<
typename Lhs,
typename Rhs>
275 struct traits<DenseTimeSparseProduct<Lhs,Rhs> >
276 :
traits<ProductBase<DenseTimeSparseProduct<Lhs,Rhs>, Lhs, Rhs> >
278 typedef Dense StorageKind;
282 template<
typename Lhs,
typename Rhs>
284 :
public ProductBase<DenseTimeSparseProduct<Lhs,Rhs>, Lhs, Rhs>
305 template<
typename Derived>
306 template<
typename OtherDerived>
315 #endif // EIGEN_SPARSEDENSEPRODUCT_H