10 #ifndef EIGEN_PRODUCT_H
11 #define EIGEN_PRODUCT_H
13 #include "./InternalHeaderCheck.h"
17 template<
typename Lhs,
typename Rhs,
int Option,
typename StorageKind>
class ProductImpl;
21 template<
typename Lhs,
typename Rhs,
int Option>
22 struct traits<Product<Lhs, Rhs, Option> >
24 typedef remove_all_t<Lhs> LhsCleaned;
25 typedef remove_all_t<Rhs> RhsCleaned;
26 typedef traits<LhsCleaned> LhsTraits;
27 typedef traits<RhsCleaned> RhsTraits;
29 typedef MatrixXpr XprKind;
31 typedef typename ScalarBinaryOpTraits<typename traits<LhsCleaned>::Scalar,
typename traits<RhsCleaned>::Scalar>::ReturnType Scalar;
32 typedef typename product_promote_storage_type<
typename LhsTraits::StorageKind,
33 typename RhsTraits::StorageKind,
34 internal::product_type<Lhs,Rhs>::ret>::ret StorageKind;
35 typedef typename promote_index_type<
typename LhsTraits::StorageIndex,
36 typename RhsTraits::StorageIndex>::type StorageIndex;
39 RowsAtCompileTime = LhsTraits::RowsAtCompileTime,
40 ColsAtCompileTime = RhsTraits::ColsAtCompileTime,
41 MaxRowsAtCompileTime = LhsTraits::MaxRowsAtCompileTime,
42 MaxColsAtCompileTime = RhsTraits::MaxColsAtCompileTime,
45 InnerSize = min_size_prefer_fixed(LhsTraits::ColsAtCompileTime, RhsTraits::RowsAtCompileTime),
48 Flags = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ?
RowMajorBit
49 : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
72 template<
typename Lhs_,
typename Rhs_,
int Option>
73 class Product :
public ProductImpl<Lhs_,Rhs_,Option,
74 typename internal::product_promote_storage_type<typename internal::traits<Lhs_>::StorageKind,
75 typename internal::traits<Rhs_>::StorageKind,
76 internal::product_type<Lhs_,Rhs_>::ret>::ret>
83 typedef typename ProductImpl<
85 typename internal::product_promote_storage_type<typename internal::traits<Lhs>::StorageKind,
86 typename internal::traits<Rhs>::StorageKind,
87 internal::product_type<Lhs,Rhs>::ret>::ret>::Base Base;
88 EIGEN_GENERIC_PUBLIC_INTERFACE(
Product)
90 typedef typename internal::ref_selector<Lhs>::type LhsNested;
91 typedef typename internal::ref_selector<Rhs>::type RhsNested;
92 typedef internal::remove_all_t<LhsNested> LhsNestedCleaned;
93 typedef internal::remove_all_t<RhsNested> RhsNestedCleaned;
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
96 Product(
const Lhs& lhs,
const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs)
98 eigen_assert(lhs.cols() == rhs.rows()
99 &&
"invalid matrix product"
100 &&
"if you wanted a coeff-wise or a dot product use the respective explicit functions");
103 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
104 Index rows()
const EIGEN_NOEXCEPT {
return m_lhs.rows(); }
105 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR
106 Index cols()
const EIGEN_NOEXCEPT {
return m_rhs.cols(); }
108 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
109 const LhsNestedCleaned& lhs()
const {
return m_lhs; }
110 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
111 const RhsNestedCleaned& rhs()
const {
return m_rhs; }
121 template<typename Lhs, typename Rhs, int Option, int ProductTag = internal::product_type<Lhs,Rhs>::ret>
122 class dense_product_base
123 :
public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
127 template<
typename Lhs,
typename Rhs,
int Option>
128 class dense_product_base<Lhs, Rhs, Option, InnerProduct>
129 :
public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
131 typedef Product<Lhs,Rhs,Option> ProductXpr;
132 typedef typename internal::dense_xpr_base<ProductXpr>::type Base;
135 typedef typename Base::Scalar Scalar;
137 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
operator const Scalar()
const
139 return internal::evaluator<ProductXpr>(derived()).coeff(0,0);
146 template<
typename Lhs,
typename Rhs,
int Option,
typename StorageKind>
147 class ProductImpl :
public internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type
150 typedef typename internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type Base;
153 template<
typename Lhs,
typename Rhs,
int Option>
154 class ProductImpl<Lhs,Rhs,Option,Dense>
155 :
public internal::dense_product_base<Lhs,Rhs,Option>
157 typedef Product<Lhs, Rhs, Option> Derived;
161 typedef typename internal::dense_product_base<Lhs, Rhs, Option> Base;
162 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
165 IsOneByOne = (RowsAtCompileTime == 1 || RowsAtCompileTime ==
Dynamic) &&
166 (ColsAtCompileTime == 1 || ColsAtCompileTime ==
Dynamic),
167 EnableCoeff = IsOneByOne || Option==LazyProduct
172 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(
Index row,
Index col)
const
174 EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
175 eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
177 return internal::evaluator<Derived>(derived()).coeff(row,col);
180 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(
Index i)
const
182 EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
183 eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
185 return internal::evaluator<Derived>(derived()).coeff(i);
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:77
const unsigned int NoPreferredStorageOrderBit
Definition: Constants.h:180
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24