25 #ifndef EIGEN_PRODUCTBASE_H
26 #define EIGEN_PRODUCTBASE_H
36 template<
typename Derived,
typename _Lhs,
typename _Rhs>
37 struct traits<ProductBase<Derived,_Lhs,_Rhs> >
39 typedef MatrixXpr XprKind;
40 typedef typename remove_all<_Lhs>::type Lhs;
41 typedef typename remove_all<_Rhs>::type Rhs;
42 typedef typename scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar;
43 typedef typename promote_storage_type<typename traits<Lhs>::StorageKind,
45 typedef typename promote_index_type<typename traits<Lhs>::Index,
61 #define EIGEN_PRODUCT_PUBLIC_INTERFACE(Derived) \
62 typedef ProductBase<Derived, Lhs, Rhs > Base; \
63 EIGEN_DENSE_PUBLIC_INTERFACE(Derived) \
64 typedef typename Base::LhsNested LhsNested; \
65 typedef typename Base::_LhsNested _LhsNested; \
66 typedef typename Base::LhsBlasTraits LhsBlasTraits; \
67 typedef typename Base::ActualLhsType ActualLhsType; \
68 typedef typename Base::_ActualLhsType _ActualLhsType; \
69 typedef typename Base::RhsNested RhsNested; \
70 typedef typename Base::_RhsNested _RhsNested; \
71 typedef typename Base::RhsBlasTraits RhsBlasTraits; \
72 typedef typename Base::ActualRhsType ActualRhsType; \
73 typedef typename Base::_ActualRhsType _ActualRhsType; \
77 template<
typename Derived,
typename Lhs,
typename Rhs>
85 typedef typename internal::remove_all<LhsNested>::type
_LhsNested;
92 typedef typename internal::remove_all<RhsNested>::type
_RhsNested;
106 : m_lhs(lhs), m_rhs(rhs)
109 &&
"invalid matrix product"
110 &&
"if you wanted a coeff-wise or a dot product use the respective explicit functions");
116 template<
typename Dest>
117 inline void evalTo(Dest& dst)
const { dst.setZero(); scaleAndAddTo(dst,
Scalar(1)); }
119 template<
typename Dest>
120 inline void addTo(Dest& dst)
const { scaleAndAddTo(dst,
Scalar(1)); }
122 template<
typename Dest>
123 inline void subTo(Dest& dst)
const { scaleAndAddTo(dst,
Scalar(-1)); }
125 template<
typename Dest>
134 m_result.
resize(m_lhs.rows(), m_rhs.cols());
135 derived().evalTo(m_result);
152 #ifdef EIGEN2_SUPPORT
153 return lhs().row(row).cwiseProduct(rhs().
col(col).transpose()).sum();
158 return result.
coeff(row,col);
162 typename Base::CoeffReturnType coeff(
Index i)
const
167 return result.
coeff(i);
174 return derived().coeffRef(row,col);
181 return derived().coeffRef(i);
195 template<
typename Lhs,
typename Rhs,
int Mode,
int N,
typename PlainObject>
196 struct nested<GeneralProduct<Lhs,Rhs,Mode>, N, PlainObject>
198 typedef PlainObject
const& type;
202 template<
typename NestedProduct>
211 template<
typename Derived,
typename Lhs,
typename Rhs>
212 const ScaledProduct<Derived>
216 template<
typename Derived,
typename Lhs,
typename Rhs>
217 typename internal::enable_if<!internal::is_same<typename Derived::Scalar,typename Derived::RealScalar>::value,
218 const ScaledProduct<Derived> >::type
223 template<
typename Derived,
typename Lhs,
typename Rhs>
224 const ScaledProduct<Derived>
228 template<
typename Derived,
typename Lhs,
typename Rhs>
229 typename internal::enable_if<!internal::is_same<typename Derived::Scalar,typename Derived::RealScalar>::value,
230 const ScaledProduct<Derived> >::type
235 template<
typename NestedProduct>
236 struct traits<ScaledProduct<NestedProduct> >
237 :
traits<ProductBase<ScaledProduct<NestedProduct>,
238 typename NestedProduct::_LhsNested,
239 typename NestedProduct::_RhsNested> >
245 template<
typename NestedProduct>
248 typename NestedProduct::_LhsNested,
249 typename NestedProduct::_RhsNested>
253 typename NestedProduct::_LhsNested,
254 typename NestedProduct::_RhsNested>
Base;
260 :
Base(prod.lhs(),prod.rhs()), m_prod(prod), m_alpha(x) {}
262 template<
typename Dest>
263 inline void evalTo(Dest& dst)
const { dst.setZero(); scaleAndAddTo(dst,
Scalar(1)); }
265 template<
typename Dest>
266 inline void addTo(Dest& dst)
const { scaleAndAddTo(dst,
Scalar(1)); }
268 template<
typename Dest>
269 inline void subTo(Dest& dst)
const { scaleAndAddTo(dst,
Scalar(-1)); }
271 template<
typename Dest>
272 inline void scaleAndAddTo(Dest& dst,
Scalar alpha)
const { m_prod.derived().scaleAndAddTo(dst,alpha * m_alpha); }
283 template<
typename Derived>
284 template<
typename ProductDerived,
typename Lhs,
typename Rhs>
287 other.derived().
evalTo(derived());
293 #endif // EIGEN_PRODUCTBASE_H