10 #ifndef EIGEN_SPARSE_DIAGONAL_PRODUCT_H
11 #define EIGEN_SPARSE_DIAGONAL_PRODUCT_H
29 template<
typename Lhs,
typename Rhs>
30 struct traits<SparseDiagonalProduct<Lhs, Rhs> >
32 typedef typename remove_all<Lhs>::type _Lhs;
33 typedef typename remove_all<Rhs>::type _Rhs;
34 typedef typename _Lhs::Scalar Scalar;
35 typedef typename promote_index_type<typename traits<Lhs>::Index,
36 typename traits<Rhs>::Index>::type Index;
37 typedef Sparse StorageKind;
38 typedef MatrixXpr XprKind;
40 RowsAtCompileTime = _Lhs::RowsAtCompileTime,
41 ColsAtCompileTime = _Rhs::ColsAtCompileTime,
43 MaxRowsAtCompileTime = _Lhs::MaxRowsAtCompileTime,
44 MaxColsAtCompileTime = _Rhs::MaxColsAtCompileTime,
46 SparseFlags = is_diagonal<_Lhs>::ret ? int(_Rhs::Flags) : int(_Lhs::Flags),
52 enum {SDP_IsDiagonal, SDP_IsSparseRowMajor, SDP_IsSparseColMajor};
53 template<
typename Lhs,
typename Rhs,
typename SparseDiagonalProductType,
int RhsMode,
int LhsMode>
54 class sparse_diagonal_product_inner_iterator_selector;
58 template<
typename Lhs,
typename Rhs>
59 class SparseDiagonalProduct
60 :
public SparseMatrixBase<SparseDiagonalProduct<Lhs,Rhs> >,
61 internal::no_assignment_operator
63 typedef typename Lhs::Nested LhsNested;
64 typedef typename Rhs::Nested RhsNested;
66 typedef typename internal::remove_all<LhsNested>::type _LhsNested;
67 typedef typename internal::remove_all<RhsNested>::type _RhsNested;
70 LhsMode = internal::is_diagonal<_LhsNested>::ret ? internal::SDP_IsDiagonal
71 : (_LhsNested::Flags&
RowMajorBit) ? internal::SDP_IsSparseRowMajor : internal::SDP_IsSparseColMajor,
72 RhsMode = internal::is_diagonal<_RhsNested>::ret ? internal::SDP_IsDiagonal
73 : (_RhsNested::Flags&
RowMajorBit) ? internal::SDP_IsSparseRowMajor : internal::SDP_IsSparseColMajor
78 EIGEN_SPARSE_PUBLIC_INTERFACE(SparseDiagonalProduct)
80 typedef internal::sparse_diagonal_product_inner_iterator_selector
81 <_LhsNested,_RhsNested,SparseDiagonalProduct,LhsMode,RhsMode> InnerIterator;
85 class ReverseInnerIterator;
87 EIGEN_STRONG_INLINE SparseDiagonalProduct(const Lhs& lhs, const Rhs& rhs)
88 : m_lhs(lhs), m_rhs(rhs)
90 eigen_assert(lhs.cols() == rhs.rows() &&
"invalid sparse matrix * diagonal matrix product");
93 EIGEN_STRONG_INLINE Index rows()
const {
return m_lhs.rows(); }
94 EIGEN_STRONG_INLINE Index cols()
const {
return m_rhs.cols(); }
96 EIGEN_STRONG_INLINE
const _LhsNested& lhs()
const {
return m_lhs; }
97 EIGEN_STRONG_INLINE
const _RhsNested& rhs()
const {
return m_rhs; }
106 template<
typename Lhs,
typename Rhs,
typename SparseDiagonalProductType>
107 class sparse_diagonal_product_inner_iterator_selector
108 <Lhs,Rhs,SparseDiagonalProductType,SDP_IsDiagonal,SDP_IsSparseRowMajor>
109 :
public CwiseUnaryOp<scalar_multiple_op<typename Lhs::Scalar>,const Rhs>::InnerIterator
111 typedef typename CwiseUnaryOp<scalar_multiple_op<typename Lhs::Scalar>,
const Rhs>::InnerIterator Base;
112 typedef typename Lhs::Index Index;
114 inline sparse_diagonal_product_inner_iterator_selector(
115 const SparseDiagonalProductType& expr, Index outer)
116 : Base(expr.rhs()*(expr.lhs().diagonal().coeff(outer)), outer)
120 template<
typename Lhs,
typename Rhs,
typename SparseDiagonalProductType>
121 class sparse_diagonal_product_inner_iterator_selector
122 <Lhs,Rhs,SparseDiagonalProductType,SDP_IsDiagonal,SDP_IsSparseColMajor>
123 :
public CwiseBinaryOp<
124 scalar_product_op<typename Lhs::Scalar>,
125 const typename Rhs::ConstInnerVectorReturnType,
126 const typename Lhs::DiagonalVectorType>::InnerIterator
128 typedef typename CwiseBinaryOp<
129 scalar_product_op<typename Lhs::Scalar>,
130 const typename Rhs::ConstInnerVectorReturnType,
131 const typename Lhs::DiagonalVectorType>::InnerIterator Base;
132 typedef typename Lhs::Index Index;
135 inline sparse_diagonal_product_inner_iterator_selector(
136 const SparseDiagonalProductType& expr, Index outer)
137 : Base(expr.rhs().innerVector(outer) .cwiseProduct(expr.lhs().diagonal()), 0), m_outer(outer)
140 inline Index outer()
const {
return m_outer; }
141 inline Index col()
const {
return m_outer; }
144 template<
typename Lhs,
typename Rhs,
typename SparseDiagonalProductType>
145 class sparse_diagonal_product_inner_iterator_selector
146 <Lhs,Rhs,SparseDiagonalProductType,SDP_IsSparseColMajor,SDP_IsDiagonal>
147 :
public CwiseUnaryOp<scalar_multiple_op<typename Rhs::Scalar>,const Lhs>::InnerIterator
149 typedef typename CwiseUnaryOp<scalar_multiple_op<typename Rhs::Scalar>,
const Lhs>::InnerIterator Base;
150 typedef typename Lhs::Index Index;
152 inline sparse_diagonal_product_inner_iterator_selector(
153 const SparseDiagonalProductType& expr, Index outer)
154 : Base(expr.lhs()*expr.rhs().diagonal().coeff(outer), outer)
158 template<
typename Lhs,
typename Rhs,
typename SparseDiagonalProductType>
159 class sparse_diagonal_product_inner_iterator_selector
160 <Lhs,Rhs,SparseDiagonalProductType,SDP_IsSparseRowMajor,SDP_IsDiagonal>
161 :
public CwiseBinaryOp<
162 scalar_product_op<typename Rhs::Scalar>,
163 const typename Lhs::ConstInnerVectorReturnType,
164 const Transpose<const typename Rhs::DiagonalVectorType> >::InnerIterator
166 typedef typename CwiseBinaryOp<
167 scalar_product_op<typename Rhs::Scalar>,
168 const typename Lhs::ConstInnerVectorReturnType,
169 const Transpose<const typename Rhs::DiagonalVectorType> >::InnerIterator Base;
170 typedef typename Lhs::Index Index;
173 inline sparse_diagonal_product_inner_iterator_selector(
174 const SparseDiagonalProductType& expr, Index outer)
175 : Base(expr.lhs().innerVector(outer) .cwiseProduct(expr.rhs().diagonal().transpose()), 0), m_outer(outer)
178 inline Index outer()
const {
return m_outer; }
179 inline Index row()
const {
return m_outer; }
186 template<
typename Derived>
187 template<
typename OtherDerived>
188 const SparseDiagonalProduct<Derived,OtherDerived>
191 return SparseDiagonalProduct<Derived,OtherDerived>(this->derived(), other.derived());
196 #endif // EIGEN_SPARSE_DIAGONAL_PRODUCT_H
const int Dynamic
Definition: Constants.h:21
const ScalarMultipleReturnType operator*(const Scalar &scalar) const
Definition: SparseMatrixBase.h:50
const unsigned int RowMajorBit
Definition: Constants.h:53