Product.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_PRODUCT_H
11 #define EIGEN_PRODUCT_H
12 
13 namespace Eigen {
14 
15 template<typename Lhs, typename Rhs, int Option, typename StorageKind> class ProductImpl;
16 
17 namespace internal {
18 
19 template<typename Lhs, typename Rhs, int Option>
20 struct traits<Product<Lhs, Rhs, Option> >
21 {
26 
27  typedef MatrixXpr XprKind;
28 
30  typedef typename product_promote_storage_type<typename LhsTraits::StorageKind,
31  typename RhsTraits::StorageKind,
33  typedef typename promote_index_type<typename LhsTraits::StorageIndex,
34  typename RhsTraits::StorageIndex>::type StorageIndex;
35 
36  enum {
37  RowsAtCompileTime = LhsTraits::RowsAtCompileTime,
38  ColsAtCompileTime = RhsTraits::ColsAtCompileTime,
39  MaxRowsAtCompileTime = LhsTraits::MaxRowsAtCompileTime,
40  MaxColsAtCompileTime = RhsTraits::MaxColsAtCompileTime,
41 
42  // FIXME: only needed by GeneralMatrixMatrixTriangular
43  InnerSize = EIGEN_SIZE_MIN_PREFER_FIXED(LhsTraits::ColsAtCompileTime, RhsTraits::RowsAtCompileTime),
44 
45  // The storage order is somewhat arbitrary here. The correct one will be determined through the evaluator.
46  Flags = (MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1) ? RowMajorBit
47  : (MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1) ? 0
48  : ( ((LhsTraits::Flags&NoPreferredStorageOrderBit) && (RhsTraits::Flags&RowMajorBit))
49  || ((RhsTraits::Flags&NoPreferredStorageOrderBit) && (LhsTraits::Flags&RowMajorBit)) ) ? RowMajorBit
51  };
52 };
53 
54 } // end namespace internal
55 
70 template<typename _Lhs, typename _Rhs, int Option>
71 class Product : public ProductImpl<_Lhs,_Rhs,Option,
72  typename internal::product_promote_storage_type<typename internal::traits<_Lhs>::StorageKind,
73  typename internal::traits<_Rhs>::StorageKind,
74  internal::product_type<_Lhs,_Rhs>::ret>::ret>
75 {
76  public:
77 
78  typedef _Lhs Lhs;
79  typedef _Rhs Rhs;
80 
81  typedef typename ProductImpl<
82  Lhs, Rhs, Option,
87 
88  typedef typename internal::ref_selector<Lhs>::type LhsNested;
89  typedef typename internal::ref_selector<Rhs>::type RhsNested;
90  typedef typename internal::remove_all<LhsNested>::type LhsNestedCleaned;
91  typedef typename internal::remove_all<RhsNested>::type RhsNestedCleaned;
92 
93  EIGEN_DEVICE_FUNC Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs)
94  {
95  eigen_assert(lhs.cols() == rhs.rows()
96  && "invalid matrix product"
97  && "if you wanted a coeff-wise or a dot product use the respective explicit functions");
98  }
99 
100  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const { return m_lhs.rows(); }
101  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const { return m_rhs.cols(); }
102 
103  EIGEN_DEVICE_FUNC const LhsNestedCleaned& lhs() const { return m_lhs; }
104  EIGEN_DEVICE_FUNC const RhsNestedCleaned& rhs() const { return m_rhs; }
105 
106  protected:
107 
110 };
111 
112 namespace internal {
113 
116  : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
117 {};
118 
120 template<typename Lhs, typename Rhs, int Option>
122  : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
123 {
126 public:
127  using Base::derived;
128  typedef typename Base::Scalar Scalar;
129 
130  EIGEN_STRONG_INLINE operator const Scalar() const
131  {
132  return internal::evaluator<ProductXpr>(derived()).coeff(0,0);
133  }
134 };
135 
136 } // namespace internal
137 
138 // Generic API dispatcher
139 template<typename Lhs, typename Rhs, int Option, typename StorageKind>
140 class ProductImpl : public internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type
141 {
142  public:
144 };
145 
146 template<typename Lhs, typename Rhs, int Option>
147 class ProductImpl<Lhs,Rhs,Option,Dense>
148  : public internal::dense_product_base<Lhs,Rhs,Option>
149 {
151 
152  public:
153 
156  protected:
157  enum {
158  IsOneByOne = (RowsAtCompileTime == 1 || RowsAtCompileTime == Dynamic) &&
159  (ColsAtCompileTime == 1 || ColsAtCompileTime == Dynamic),
160  EnableCoeff = IsOneByOne || Option==LazyProduct
161  };
162 
163  public:
164 
165  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index row, Index col) const
166  {
167  EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
168  eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
169 
170  return internal::evaluator<Derived>(derived()).coeff(row,col);
171  }
172 
173  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index i) const
174  {
175  EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
176  eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
177 
178  return internal::evaluator<Derived>(derived()).coeff(i);
179  }
180 
181 
182 };
183 
184 } // end namespace Eigen
185 
186 #endif // EIGEN_PRODUCT_H
Eigen::internal::dense_product_base< Lhs, Rhs, Option, InnerProduct >::ProductXpr
Product< Lhs, Rhs, Option > ProductXpr
Definition: Product.h:124
Eigen::Product::rows
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rows() const
Definition: Product.h:100
Eigen::MatrixXpr
Definition: Constants.h:506
Eigen::internal::traits< Product< Lhs, Rhs, Option > >::StorageIndex
promote_index_type< typename LhsTraits::StorageIndex, typename RhsTraits::StorageIndex >::type StorageIndex
Definition: Product.h:34
Eigen
Definition: common.h:73
Eigen::internal::traits< Product< Lhs, Rhs, Option > >::XprKind
MatrixXpr XprKind
Definition: Product.h:27
Eigen::internal::Rhs
@ Rhs
Definition: TensorContractionMapper.h:18
Eigen::ProductImpl< Lhs, Rhs, Option, Dense >::Base
internal::dense_product_base< Lhs, Rhs, Option > Base
Definition: Product.h:154
Eigen::Product::Base
ProductImpl< Lhs, Rhs, Option, typename internal::product_promote_storage_type< typename internal::traits< Lhs >::StorageKind, typename internal::traits< Rhs >::StorageKind, internal::product_type< Lhs, Rhs >::ret >::ret >::Base Base
Definition: Product.h:85
Eigen::ProductImpl< Lhs, Rhs, Option, Dense >::coeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index row, Index col) const
Definition: Product.h:165
Eigen::internal::dense_xpr_base
Definition: XprHelper.h:463
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:579
col
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:838
Eigen::RowMajorBit
const unsigned int RowMajorBit
Definition: Constants.h:61
Eigen::internal::remove_all::type
T type
Definition: Meta.h:78
EIGEN_DENSE_PUBLIC_INTERFACE
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:870
Eigen::ScalarBinaryOpTraits
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:766
Scalar
SCALAR Scalar
Definition: common.h:84
Eigen::internal::traits< Product< Lhs, Rhs, Option > >::StorageKind
product_promote_storage_type< typename LhsTraits::StorageKind, typename RhsTraits::StorageKind, internal::product_type< Lhs, Rhs >::ret >::ret StorageKind
Definition: Product.h:32
Eigen::internal::traits< Product< Lhs, Rhs, Option > >::RhsTraits
traits< RhsCleaned > RhsTraits
Definition: Product.h:25
ret
DenseIndex ret
Definition: level1_impl.h:59
Eigen::Product::rhs
const EIGEN_DEVICE_FUNC RhsNestedCleaned & rhs() const
Definition: Product.h:104
Eigen::ProductImpl< Lhs, Rhs, Option, Dense >::coeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index i) const
Definition: Product.h:173
Eigen::ProductImpl< Lhs, Rhs, Option, Dense >::Derived
Product< Lhs, Rhs, Option > Derived
Definition: Product.h:150
Eigen::Product::Rhs
_Rhs Rhs
Definition: Product.h:79
Eigen::ProductImpl< Lhs, Rhs, Option, internal::product_promote_storage_type< internal::traits< Lhs >::StorageKind, internal::traits< Rhs >::StorageKind, internal::product_type< Lhs, Rhs >::ret >::ret >::Base
internal::generic_xpr_base< Product< Lhs, Rhs, Option >, MatrixXpr, internal::product_promote_storage_type< internal::traits< Lhs >::StorageKind, internal::traits< Rhs >::StorageKind, internal::product_type< Lhs, Rhs >::ret >::ret >::type Base
Definition: Product.h:143
Eigen::internal::true_type
Definition: Meta.h:54
EIGEN_GENERIC_PUBLIC_INTERFACE
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:852
Eigen::internal::dense_product_base
Definition: Product.h:115
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:21
Eigen::internal::generic_xpr_base
Definition: XprHelper.h:481
row
EIGEN_DEVICE_FUNC RowXpr row(Index i)
This is the const version of row(). *‍/.
Definition: BlockMethods.h:859
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:494
Eigen::internal::traits< Product< Lhs, Rhs, Option > >::Scalar
ScalarBinaryOpTraits< typename traits< LhsCleaned >::Scalar, typename traits< RhsCleaned >::Scalar >::ReturnType Scalar
Definition: Product.h:29
Eigen::Product
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:71
Eigen::internal::product_promote_storage_type
Definition: XprHelper.h:558
Eigen::Product< Lhs, Rhs >::LhsNestedCleaned
internal::remove_all< LhsNested >::type LhsNestedCleaned
Definition: Product.h:90
Eigen::internal::evaluator
Definition: CoreEvaluators.h:90
Eigen::InnerProduct
@ InnerProduct
Definition: Constants.h:484
Eigen::Product::Lhs
_Lhs Lhs
Definition: Product.h:78
Eigen::internal::traits< Product< Lhs, Rhs, Option > >::LhsCleaned
remove_all< Lhs >::type LhsCleaned
Definition: Product.h:22
Eigen::Product::cols
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index cols() const
Definition: Product.h:101
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
EIGEN_STATIC_ASSERT
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:124
Eigen::internal::product_type
Definition: GeneralProduct.h:41
Eigen::internal::traits< Product< Lhs, Rhs, Option > >::RhsCleaned
remove_all< Rhs >::type RhsCleaned
Definition: Product.h:23
Eigen::internal::dense_product_base< Lhs, Rhs, Option, InnerProduct >::Base
internal::dense_xpr_base< ProductXpr >::type Base
Definition: Product.h:125
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::Lhs
@ Lhs
Definition: TensorContractionMapper.h:19
Eigen::Product::m_lhs
LhsNested m_lhs
Definition: Product.h:108
Eigen::Product< Lhs, Rhs >::RhsNestedCleaned
internal::remove_all< RhsNested >::type RhsNestedCleaned
Definition: Product.h:91
Eigen::NoPreferredStorageOrderBit
const unsigned int NoPreferredStorageOrderBit
Definition: Constants.h:173
Eigen::internal::promote_index_type
Definition: XprHelper.h:97
Eigen::LazyProduct
@ LazyProduct
Definition: Constants.h:484
Eigen::internal::dense_product_base< Lhs, Rhs, Option, InnerProduct >::Scalar
Base::Scalar Scalar
Definition: Product.h:128
Eigen::Product::lhs
const EIGEN_DEVICE_FUNC LhsNestedCleaned & lhs() const
Definition: Product.h:103
EIGEN_SIZE_MIN_PREFER_FIXED
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
Definition: Macros.h:889
Eigen::ProductImpl
Definition: Product.h:15
Eigen::Product::m_rhs
RhsNested m_rhs
Definition: Product.h:109
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Eigen::Dense
Definition: Constants.h:491
Eigen::internal::traits< Product< Lhs, Rhs, Option > >::LhsTraits
traits< LhsCleaned > LhsTraits
Definition: Product.h:24


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:06:04