10 #ifndef EIGEN_PRODUCT_H
11 #define EIGEN_PRODUCT_H
15 template<
typename Lhs,
typename Rhs,
int Option,
typename StorageKind>
class ProductImpl;
37 template<typename Lhs, typename Rhs, typename LhsShape = typename evaluator_traits<Lhs>::Shape,
38 typename RhsShape =
typename evaluator_traits<Rhs>::Shape >
39 struct product_result_scalar
41 typedef typename scalar_product_traits<typename Lhs::Scalar, typename Rhs::Scalar>::ReturnType Scalar;
44 template<
typename Lhs,
typename Rhs,
typename RhsShape>
45 struct product_result_scalar<Lhs, Rhs, PermutationShape, RhsShape>
47 typedef typename Rhs::Scalar Scalar;
50 template<
typename Lhs,
typename Rhs,
typename LhsShape>
51 struct product_result_scalar<Lhs, Rhs, LhsShape, PermutationShape>
53 typedef typename Lhs::Scalar Scalar;
56 template<
typename Lhs,
typename Rhs,
typename RhsShape>
57 struct product_result_scalar<Lhs, Rhs, TranspositionsShape, RhsShape>
59 typedef typename Rhs::Scalar Scalar;
62 template<
typename Lhs,
typename Rhs,
typename LhsShape>
63 struct product_result_scalar<Lhs, Rhs, LhsShape, TranspositionsShape>
65 typedef typename Lhs::Scalar Scalar;
68 template<
typename Lhs,
typename Rhs,
int Option>
69 struct traits<Product<Lhs, Rhs, Option> >
71 typedef typename remove_all<Lhs>::type LhsCleaned;
72 typedef typename remove_all<Rhs>::type RhsCleaned;
73 typedef traits<LhsCleaned> LhsTraits;
74 typedef traits<RhsCleaned> RhsTraits;
76 typedef MatrixXpr XprKind;
78 typedef typename product_result_scalar<LhsCleaned,RhsCleaned>::Scalar Scalar;
79 typedef typename product_promote_storage_type<
typename LhsTraits::StorageKind,
80 typename RhsTraits::StorageKind,
81 internal::product_type<Lhs,Rhs>::ret>::ret StorageKind;
82 typedef typename promote_index_type<
typename LhsTraits::StorageIndex,
83 typename RhsTraits::StorageIndex>::type StorageIndex;
86 RowsAtCompileTime = LhsTraits::RowsAtCompileTime,
87 ColsAtCompileTime = RhsTraits::ColsAtCompileTime,
88 MaxRowsAtCompileTime = LhsTraits::MaxRowsAtCompileTime,
89 MaxColsAtCompileTime = RhsTraits::MaxColsAtCompileTime,
92 InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsTraits::ColsAtCompileTime, RhsTraits::RowsAtCompileTime),
95 Flags = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ?
RowMajorBit
96 : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
99 : NoPreferredStorageOrderBit
106 template<
typename _Lhs,
typename _Rhs,
int Option>
107 class Product :
public ProductImpl<_Lhs,_Rhs,Option,
108 typename internal::product_promote_storage_type<typename internal::traits<_Lhs>::StorageKind,
109 typename internal::traits<_Rhs>::StorageKind,
110 internal::product_type<_Lhs,_Rhs>::ret>::ret>
117 typedef typename ProductImpl<
119 typename internal::product_promote_storage_type<typename internal::traits<Lhs>::StorageKind,
120 typename internal::traits<Rhs>::StorageKind,
121 internal::product_type<Lhs,Rhs>::ret>::ret>::Base Base;
122 EIGEN_GENERIC_PUBLIC_INTERFACE(
Product)
124 typedef typename internal::ref_selector<Lhs>::type LhsNested;
125 typedef typename internal::ref_selector<Rhs>::type RhsNested;
126 typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
127 typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
129 EIGEN_DEVICE_FUNC
Product(
const Lhs& lhs,
const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs)
131 eigen_assert(lhs.cols() == rhs.rows()
132 &&
"invalid matrix product"
133 &&
"if you wanted a coeff-wise or a dot product use the respective explicit functions");
136 EIGEN_DEVICE_FUNC
inline Index rows()
const {
return m_lhs.rows(); }
137 EIGEN_DEVICE_FUNC
inline Index cols()
const {
return m_rhs.cols(); }
139 EIGEN_DEVICE_FUNC
const LhsNestedCleaned& lhs()
const {
return m_lhs; }
140 EIGEN_DEVICE_FUNC
const RhsNestedCleaned& rhs()
const {
return m_rhs; }
150 template<typename Lhs, typename Rhs, int Option, int ProductTag = internal::product_type<Lhs,Rhs>::ret>
151 class dense_product_base
152 :
public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
156 template<
typename Lhs,
typename Rhs,
int Option>
157 class dense_product_base<Lhs, Rhs, Option, InnerProduct>
158 :
public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
160 typedef Product<Lhs,Rhs,Option> ProductXpr;
161 typedef typename internal::dense_xpr_base<ProductXpr>::type Base;
164 typedef typename Base::Scalar Scalar;
166 operator const Scalar()
const
168 return internal::evaluator<ProductXpr>(derived()).coeff(0,0);
175 template<
typename Lhs,
typename Rhs,
int Option,
typename StorageKind>
176 class ProductImpl :
public internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type
179 typedef typename internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type Base;
182 template<
typename Lhs,
typename Rhs,
int Option>
183 class ProductImpl<Lhs,Rhs,Option,Dense>
184 :
public internal::dense_product_base<Lhs,Rhs,Option>
186 typedef Product<Lhs, Rhs, Option> Derived;
190 typedef typename internal::dense_product_base<Lhs, Rhs, Option> Base;
191 EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
194 IsOneByOne = (RowsAtCompileTime == 1 || RowsAtCompileTime == Dynamic) &&
195 (ColsAtCompileTime == 1 || ColsAtCompileTime == Dynamic),
196 EnableCoeff = IsOneByOne || Option==LazyProduct
201 EIGEN_DEVICE_FUNC Scalar coeff(Index row, Index col)
const
203 EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
204 eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
206 return internal::evaluator<Derived>(derived()).coeff(row,col);
209 EIGEN_DEVICE_FUNC Scalar coeff(Index i)
const
211 EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
212 eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
214 return internal::evaluator<Derived>(derived()).coeff(i);
227 template<
typename Lhs,
typename Rhs>
228 const Product<Lhs,Rhs>
229 prod(
const Lhs& lhs,
const Rhs& rhs)
231 return Product<Lhs,Rhs>(lhs,rhs);
236 template<
typename Lhs,
typename Rhs>
237 const Product<Lhs,Rhs,LazyProduct>
238 lazyprod(
const Lhs& lhs,
const Rhs& rhs)
240 return Product<Lhs,Rhs,LazyProduct>(lhs,rhs);
245 #endif // EIGEN_PRODUCT_H
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:107
const unsigned int RowMajorBit
Definition: Constants.h:53
Definition: Eigen_Colamd.h:54
const unsigned int NoPreferredStorageOrderBit
Definition: Constants.h:164