WPILibC++ 2023.4.3-108-ge5452e3
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
13namespace Eigen {
14
15template<typename Lhs, typename Rhs, int Option, typename StorageKind> class ProductImpl;
16
17namespace internal {
18
19template<typename Lhs, typename Rhs, int Option>
20struct traits<Product<Lhs, Rhs, Option> >
21{
26
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
56/** \class Product
57 * \ingroup Core_Module
58 *
59 * \brief Expression of the product of two arbitrary matrices or vectors
60 *
61 * \tparam _Lhs the type of the left-hand side expression
62 * \tparam _Rhs the type of the right-hand side expression
63 *
64 * This class represents an expression of the product of two arbitrary matrices.
65 *
66 * The other template parameters are:
67 * \tparam Option can be DefaultProduct, AliasFreeProduct, or LazyProduct
68 *
69 */
70template<typename _Lhs, typename _Rhs, int Option>
71class 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
94 Product(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs)
95 {
96 eigen_assert(lhs.cols() == rhs.rows()
97 && "invalid matrix product"
98 && "if you wanted a coeff-wise or a dot product use the respective explicit functions");
99 }
100
102 Index rows() const EIGEN_NOEXCEPT { return m_lhs.rows(); }
104 Index cols() const EIGEN_NOEXCEPT { return m_rhs.cols(); }
105
107 const LhsNestedCleaned& lhs() const { return m_lhs; }
109 const RhsNestedCleaned& rhs() const { return m_rhs; }
110
111 protected:
112
115};
116
117namespace internal {
118
119template<typename Lhs, typename Rhs, int Option, int ProductTag = internal::product_type<Lhs,Rhs>::ret>
121 : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
122{};
123
124/** Conversion to scalar for inner-products */
125template<typename Lhs, typename Rhs, int Option>
126class dense_product_base<Lhs, Rhs, Option, InnerProduct>
127 : public internal::dense_xpr_base<Product<Lhs,Rhs,Option> >::type
128{
130 typedef typename internal::dense_xpr_base<ProductXpr>::type Base;
131public:
132 using Base::derived;
133 typedef typename Base::Scalar Scalar;
134
136 {
137 return internal::evaluator<ProductXpr>(derived()).coeff(0,0);
138 }
139};
140
141} // namespace internal
142
143// Generic API dispatcher
144template<typename Lhs, typename Rhs, int Option, typename StorageKind>
145class ProductImpl : public internal::generic_xpr_base<Product<Lhs,Rhs,Option>, MatrixXpr, StorageKind>::type
146{
147 public:
149};
150
151template<typename Lhs, typename Rhs, int Option>
152class ProductImpl<Lhs,Rhs,Option,Dense>
153 : public internal::dense_product_base<Lhs,Rhs,Option>
154{
156
157 public:
158
161 protected:
162 enum {
163 IsOneByOne = (RowsAtCompileTime == 1 || RowsAtCompileTime == Dynamic) &&
164 (ColsAtCompileTime == 1 || ColsAtCompileTime == Dynamic),
165 EnableCoeff = IsOneByOne || Option==LazyProduct
166 };
167
168 public:
169
171 {
172 EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
173 eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
174
175 return internal::evaluator<Derived>(derived()).coeff(row,col);
176 }
177
179 {
180 EIGEN_STATIC_ASSERT(EnableCoeff, THIS_METHOD_IS_ONLY_FOR_INNER_OR_LAZY_PRODUCTS);
181 eigen_assert( (Option==LazyProduct) || (this->rows() == 1 && this->cols() == 1) );
182
183 return internal::evaluator<Derived>(derived()).coeff(i);
184 }
185
186
187};
188
189} // end namespace Eigen
190
191#endif // EIGEN_PRODUCT_H
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ColXpr col(Index i)
This is the const version of col().
Definition: BlockMethods.h:1097
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE RowXpr row(Index i)
This is the const version of row(). *‍/.
Definition: BlockMethods.h:1118
#define EIGEN_GENERIC_PUBLIC_INTERFACE(Derived)
Just a side note.
Definition: Macros.h:1274
#define EIGEN_NOEXCEPT
Definition: Macros.h:1428
#define EIGEN_CONSTEXPR
Definition: Macros.h:797
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1293
#define eigen_assert(x)
Definition: Macros.h:1047
#define EIGEN_STRONG_INLINE
Definition: Macros.h:927
#define EIGEN_SIZE_MIN_PREFER_FIXED(a, b)
Definition: Macros.h:1312
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:75
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const LhsNestedCleaned & lhs() const
Definition: Product.h:107
ProductImpl< Lhs, Rhs, Option, typenameinternal::product_promote_storage_type< typenameinternal::traits< Lhs >::StorageKind, typenameinternal::traits< Rhs >::StorageKind, internal::product_type< Lhs, Rhs >::ret >::ret >::Base Base
Definition: Product.h:85
internal::remove_all< RhsNested >::type RhsNestedCleaned
Definition: Product.h:91
internal::remove_all< LhsNested >::type LhsNestedCleaned
Definition: Product.h:90
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const RhsNestedCleaned & rhs() const
Definition: Product.h:109
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: Product.h:104
_Lhs Lhs
Definition: Product.h:78
RhsNested m_rhs
Definition: Product.h:114
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: Product.h:102
_Rhs Rhs
Definition: Product.h:79
LhsNested m_lhs
Definition: Product.h:113
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index i) const
Definition: Product.h:178
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index row, Index col) const
Definition: Product.h:170
internal::dense_product_base< Lhs, Rhs, Option > Base
Definition: Product.h:159
Definition: Product.h:146
internal::generic_xpr_base< Product< Lhs, Rhs, Option >, MatrixXpr, StorageKind >::type Base
Definition: Product.h:148
Definition: Product.h:122
type
Definition: core.h:575
const unsigned int NoPreferredStorageOrderBit
for an expression, this means that the storage order can be either row-major or column-major.
Definition: Constants.h:178
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition: Constants.h:66
Namespace containing all symbols from the Eigen library.
Definition: Core:141
@ LazyProduct
Definition: Constants.h:500
@ InnerProduct
Definition: Constants.h:500
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time,...
Definition: Constants.h:22
Definition: Eigen_Colamd.h:50
The type used to identify a dense storage.
Definition: Constants.h:507
The type used to identify a matrix expression.
Definition: Constants.h:522
Determines whether the given binary operation of two numeric types is allowed and what the scalar ret...
Definition: XprHelper.h:806
Definition: XprHelper.h:484
Definition: CoreEvaluators.h:91
Definition: XprHelper.h:501
Definition: GeneralProduct.h:52
Definition: XprHelper.h:121
T type
Definition: Meta.h:126
promote_index_type< typenameLhsTraits::StorageIndex, typenameRhsTraits::StorageIndex >::type StorageIndex
Definition: Product.h:34
traits< LhsCleaned > LhsTraits
Definition: Product.h:24
traits< RhsCleaned > RhsTraits
Definition: Product.h:25
remove_all< Lhs >::type LhsCleaned
Definition: Product.h:22
remove_all< Rhs >::type RhsCleaned
Definition: Product.h:23
ScalarBinaryOpTraits< typenametraits< LhsCleaned >::Scalar, typenametraits< RhsCleaned >::Scalar >::ReturnType Scalar
Definition: Product.h:29
product_promote_storage_type< typenameLhsTraits::StorageKind, typenameRhsTraits::StorageKind, internal::product_type< Lhs, Rhs >::ret >::ret StorageKind
Definition: Product.h:32
Definition: ForwardDeclarations.h:17
Definition: Meta.h:96