10 #ifndef EIGEN_SPARSEDENSEPRODUCT_H 11 #define EIGEN_SPARSEDENSEPRODUCT_H 43 template<
typename Lhs,
typename Rhs,
bool Tr>
46 typedef Sparse StorageKind;
49 typedef typename Lhs::Index Index;
50 typedef typename Lhs::Nested LhsNested;
51 typedef typename Rhs::Nested RhsNested;
72 template<
typename Lhs,
typename Rhs,
bool Tr>
84 typedef typename Traits::LhsNested LhsNested;
85 typedef typename Traits::RhsNested RhsNested;
86 typedef typename Traits::_LhsNested _LhsNested;
87 typedef typename Traits::_RhsNested _RhsNested;
94 : m_lhs(lhs), m_rhs(rhs)
96 EIGEN_STATIC_ASSERT(!Tr,YOU_MADE_A_PROGRAMMING_MISTAKE);
99 EIGEN_STRONG_INLINE SparseDenseOuterProduct(
const Rhs& rhs,
const Lhs& lhs)
100 : m_lhs(lhs), m_rhs(rhs)
102 EIGEN_STATIC_ASSERT(Tr,YOU_MADE_A_PROGRAMMING_MISTAKE);
105 EIGEN_STRONG_INLINE Index rows()
const {
return Tr ? m_rhs.rows() : m_lhs.rows(); }
106 EIGEN_STRONG_INLINE Index cols()
const {
return Tr ? m_lhs.cols() : m_rhs.cols(); }
108 EIGEN_STRONG_INLINE
const _LhsNested& lhs()
const {
return m_lhs; }
109 EIGEN_STRONG_INLINE
const _RhsNested& rhs()
const {
return m_rhs; }
116 template<
typename Lhs,
typename Rhs,
bool Transpose>
119 typedef typename _LhsNested::InnerIterator
Base;
120 typedef typename SparseDenseOuterProduct::Index Index;
126 inline Index outer()
const {
return m_outer; }
127 inline Index row()
const {
return Transpose ? m_outer : Base::index(); }
128 inline Index col()
const {
return Transpose ? Base::index() : m_outer; }
130 inline Scalar value()
const {
return Base::value() * m_factor; }
133 static Scalar
get(
const _RhsNested &rhs, Index outer,
Dense = Dense())
135 return rhs.coeff(outer);
138 static Scalar
get(
const _RhsNested &rhs, Index outer, Sparse = Sparse())
140 typename Traits::_RhsNested::InnerIterator it(rhs, outer);
141 if (it && it.index()==0)
152 template<
typename Lhs,
typename Rhs>
154 :
traits<ProductBase<SparseTimeDenseProduct<Lhs,Rhs>, Lhs, Rhs> >
160 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
162 bool ColPerCol = ((DenseRhsType::Flags&
RowMajorBit)==0) || DenseRhsType::ColsAtCompileTime==1>
165 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
171 typedef typename Lhs::Index Index;
172 typedef typename Lhs::InnerIterator LhsInnerIterator;
173 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha)
175 for(Index c=0; c<rhs.cols(); ++c)
177 Index n = lhs.outerSize();
178 for(Index j=0; j<n; ++j)
181 for(LhsInnerIterator it(lhs,j); it ;++it)
182 tmp += it.value() * rhs.coeff(it.index(),c);
183 res.coeffRef(j,c) += alpha * tmp;
189 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
195 typedef typename Lhs::InnerIterator LhsInnerIterator;
196 typedef typename Lhs::Index Index;
197 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha)
199 for(Index c=0; c<rhs.cols(); ++c)
201 for(Index j=0; j<lhs.outerSize(); ++j)
203 typename Res::Scalar rhs_j = alpha * rhs.coeff(j,c);
204 for(LhsInnerIterator it(lhs,j); it ;++it)
205 res.coeffRef(it.index(),c) += it.value() * rhs_j;
211 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
217 typedef typename Lhs::InnerIterator LhsInnerIterator;
218 typedef typename Lhs::Index Index;
219 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha)
221 for(Index j=0; j<lhs.outerSize(); ++j)
223 typename Res::RowXpr res_j(res.row(j));
224 for(LhsInnerIterator it(lhs,j); it ;++it)
225 res_j += (alpha*it.value()) * rhs.
row(it.index());
230 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType>
236 typedef typename Lhs::InnerIterator LhsInnerIterator;
237 typedef typename Lhs::Index Index;
238 static void run(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const typename Res::Scalar& alpha)
240 for(Index j=0; j<lhs.outerSize(); ++j)
242 typename Rhs::ConstRowXpr rhs_j(rhs.row(j));
243 for(LhsInnerIterator it(lhs,j); it ;++it)
244 res.
row(it.index()) += (alpha*it.value()) * rhs_j;
249 template<
typename SparseLhsType,
typename DenseRhsType,
typename DenseResType,
typename AlphaType>
250 inline void sparse_time_dense_product(
const SparseLhsType& lhs,
const DenseRhsType& rhs, DenseResType& res,
const AlphaType& alpha)
257 template<
typename Lhs,
typename Rhs>
259 :
public ProductBase<SparseTimeDenseProduct<Lhs,Rhs>, Lhs, Rhs>
267 template<
typename Dest>
void scaleAndAddTo(Dest& dest,
const Scalar& alpha)
const 269 internal::sparse_time_dense_product(m_lhs, m_rhs, dest, alpha);
279 template<
typename Lhs,
typename Rhs>
281 :
traits<ProductBase<DenseTimeSparseProduct<Lhs,Rhs>, Lhs, Rhs> >
287 template<
typename Lhs,
typename Rhs>
289 :
public ProductBase<DenseTimeSparseProduct<Lhs,Rhs>, Lhs, Rhs>
297 template<
typename Dest>
void scaleAndAddTo(Dest& dest,
const Scalar& alpha)
const 302 internal::sparse_time_dense_product(rhs_t, lhs_t, dest_t, alpha);
311 #endif // EIGEN_SPARSEDENSEPRODUCT_H Definition: gtest_unittest.cc:5031
Definition: ProductBase.h:63
Expression of the transpose of a matrix.
Definition: Transpose.h:57
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:53
The type used to identify a matrix expression.
Definition: Constants.h:431
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:239
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:264
Definition: SparseDenseProduct.h:73
Definition: XprHelper.h:371
Definition: SparseDenseProduct.h:28
Definition: SparseDenseProduct.h:258
Definition: BandTriangularSolver.h:13
Definition: SparseDenseProduct.h:288
Storage order is row major (see TopicStorageOrders).
Definition: Constants.h:266
The type used to identify a dense storage.
Definition: Constants.h:428
Definition: SparseDenseProduct.h:15
Definition: SparseDenseProduct.h:117
Definition: ForwardDeclarations.h:17
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48
Definition: SparseDenseProduct.h:163
const Index & row() const
Definition: SparseUtil.h:158