$darkmode
Eigen  5.0.1-dev
ArrayBase.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2009 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_ARRAYBASE_H
11 #define EIGEN_ARRAYBASE_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 template <typename ExpressionType>
20 
43 template <typename Derived>
44 class ArrayBase : public DenseBase<Derived> {
45  public:
46 #ifndef EIGEN_PARSED_BY_DOXYGEN
47 
48  typedef ArrayBase StorageBaseType;
49 
50  typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl;
51 
52  typedef typename internal::traits<Derived>::StorageKind StorageKind;
53  typedef typename internal::traits<Derived>::Scalar Scalar;
54  typedef typename internal::packet_traits<Scalar>::type PacketScalar;
55  typedef typename NumTraits<Scalar>::Real RealScalar;
56 
57  typedef DenseBase<Derived> Base;
58  using Base::ColsAtCompileTime;
59  using Base::Flags;
60  using Base::IsVectorAtCompileTime;
61  using Base::MaxColsAtCompileTime;
62  using Base::MaxRowsAtCompileTime;
63  using Base::MaxSizeAtCompileTime;
64  using Base::RowsAtCompileTime;
65  using Base::SizeAtCompileTime;
66 
67  using Base::coeff;
68  using Base::coeffRef;
69  using Base::cols;
70  using Base::const_cast_derived;
71  using Base::derived;
72  using Base::lazyAssign;
73  using Base::rows;
74  using Base::size;
75  using Base::operator-;
76  using Base::operator=;
77  using Base::operator+=;
78  using Base::operator-=;
79  using Base::operator*=;
80  using Base::operator/=;
81 
82  typedef typename Base::CoeffReturnType CoeffReturnType;
83 
84  typedef typename Base::PlainObject PlainObject;
85 
88 #endif // not EIGEN_PARSED_BY_DOXYGEN
89 
90 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
91 #define EIGEN_DOC_UNARY_ADDONS(X, Y)
92 #include "../plugins/MatrixCwiseUnaryOps.inc"
93 #include "../plugins/ArrayCwiseUnaryOps.inc"
94 #include "../plugins/CommonCwiseBinaryOps.inc"
95 #include "../plugins/MatrixCwiseBinaryOps.inc"
96 #include "../plugins/ArrayCwiseBinaryOps.inc"
97 #ifdef EIGEN_ARRAYBASE_PLUGIN
98 #include EIGEN_ARRAYBASE_PLUGIN
99 #endif
100 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
101 #undef EIGEN_DOC_UNARY_ADDONS
102 
106  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const ArrayBase& other) {
107  internal::call_assignment(derived(), other.derived());
108  return derived();
109  }
110 
113  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Scalar& value) {
114  Base::setConstant(value);
115  return derived();
116  }
118  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(const Scalar& other) {
119  internal::call_assignment(this->derived(), PlainObject::Constant(rows(), cols(), other),
120  internal::add_assign_op<Scalar, Scalar>());
121  return derived();
122  }
123 
124  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(const Scalar& other) {
125  internal::call_assignment(this->derived(), PlainObject::Constant(rows(), cols(), other),
126  internal::sub_assign_op<Scalar, Scalar>());
127  return derived();
128  }
129 
134  template <typename OtherDerived>
135  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(const ArrayBase<OtherDerived>& other) {
136  call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar, typename OtherDerived::Scalar>());
137  return derived();
138  }
139 
144  template <typename OtherDerived>
145  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(const ArrayBase<OtherDerived>& other) {
146  call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar, typename OtherDerived::Scalar>());
147  return derived();
148  }
149 
154  template <typename OtherDerived>
155  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*=(const ArrayBase<OtherDerived>& other) {
156  call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar, typename OtherDerived::Scalar>());
157  return derived();
158  }
159 
164  template <typename OtherDerived>
165  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator/=(const ArrayBase<OtherDerived>& other) {
166  call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar, typename OtherDerived::Scalar>());
167  return derived();
168  }
169 
170  public:
171  EIGEN_DEVICE_FUNC ArrayBase<Derived>& array() { return *this; }
172  EIGEN_DEVICE_FUNC const ArrayBase<Derived>& array() const { return *this; }
173 
176  EIGEN_DEVICE_FUNC MatrixWrapper<Derived> matrix() { return MatrixWrapper<Derived>(derived()); }
177  EIGEN_DEVICE_FUNC const MatrixWrapper<const Derived> matrix() const {
179  }
180 
181  // template<typename Dest>
182  // inline void evalTo(Dest& dst) const { dst = matrix(); }
183 
184  protected:
185  EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase)
186  EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase)
187 
188  private:
189  explicit ArrayBase(Index);
191  template <typename OtherDerived>
192  explicit ArrayBase(const ArrayBase<OtherDerived>&);
193 
194  protected:
195  // mixing arrays and matrices is not legal
196  template <typename OtherDerived>
197  Derived& operator+=(const MatrixBase<OtherDerived>&) {
198  EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1,
199  YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);
200  return *this;
201  }
202  // mixing arrays and matrices is not legal
203  template <typename OtherDerived>
204  Derived& operator-=(const MatrixBase<OtherDerived>&) {
205  EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1,
206  YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);
207  return *this;
208  }
209 };
210 
211 } // end namespace Eigen
213 #endif // EIGEN_ARRAYBASE_H
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:63
constexpr Derived & derived()
Definition: EigenBase.h:49
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:62
Derived & operator=(const Scalar &value)
Definition: ArrayBase.h:113
std::conditional_t< internal::is_same< typename internal::traits< Derived >::XprKind, MatrixXpr >::value, PlainMatrix, PlainArray > PlainObject
The plain matrix or array type corresponding to this expression.
Definition: DenseBase.h:204
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Derived & operator-=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:145
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:43
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:38
constexpr Index rows() const noexcept
Definition: EigenBase.h:59
Derived & operator/=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:165
Expression of an array as a mathematical vector or matrix.
Definition: ArrayBase.h:19
constexpr Index cols() const noexcept
Definition: EigenBase.h:61
Derived & operator*=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:155
Derived & operator=(const ArrayBase &other)
Definition: ArrayBase.h:106
Derived & operator+=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:135
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:44
constexpr Derived & derived()
Definition: EigenBase.h:49
MatrixWrapper< Derived > matrix()
Definition: ArrayBase.h:176
CoeffReturnType value() const
Definition: DenseBase.h:486
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52