Eigen  5.0.1
 
Loading...
Searching...
No Matches
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// SPDX-License-Identifier: MPL-2.0
10
11#ifndef EIGEN_ARRAYBASE_H
12#define EIGEN_ARRAYBASE_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19template <typename ExpressionType>
20class MatrixWrapper;
21
39 * This class can be extended with the help of the plugin mechanism described on the page
40 * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN.
41 *
42 * \sa class MatrixBase, \ref TopicClassHierarchy
43 */
44template <typename Derived>
45class ArrayBase : public DenseBase<Derived> {
46 public:
47#ifndef EIGEN_PARSED_BY_DOXYGEN
49 using StorageBaseType = ArrayBase;
50
51 using Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl = ArrayBase;
52
53 using StorageKind = typename internal::traits<Derived>::StorageKind;
54 using Scalar = typename internal::traits<Derived>::Scalar;
55 using PacketScalar = typename internal::packet_traits<Scalar>::type;
56 using RealScalar = typename NumTraits<Scalar>::Real;
58 using Base = DenseBase<Derived>;
59 using Base::ColsAtCompileTime;
60 using Base::Flags;
61 using Base::IsVectorAtCompileTime;
62 using Base::MaxColsAtCompileTime;
63 using Base::MaxRowsAtCompileTime;
64 using Base::MaxSizeAtCompileTime;
65 using Base::RowsAtCompileTime;
66 using Base::SizeAtCompileTime;
67
68 using Base::coeff;
69 using Base::coeffRef;
70 using Base::cols;
71 using Base::const_cast_derived;
72 using Base::derived;
73 using Base::lazyAssign;
74 using Base::rows;
75 using Base::size;
76 using Base::operator-;
77 using Base::operator=;
78 using Base::operator+=;
79 using Base::operator-=;
80 using Base::operator*=;
81 using Base::operator/=;
83 using CoeffReturnType = typename Base::CoeffReturnType;
84
85 using PlainObject = typename Base::PlainObject;
89#endif // not EIGEN_PARSED_BY_DOXYGEN
90
91#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
92#define EIGEN_DOC_UNARY_ADDONS(X, Y)
93#include "../plugins/MatrixCwiseUnaryOps.inc"
94#include "../plugins/ArrayCwiseUnaryOps.inc"
95#include "../plugins/CommonCwiseBinaryOps.inc"
96#include "../plugins/MatrixCwiseBinaryOps.inc"
97#include "../plugins/ArrayCwiseBinaryOps.inc"
98#ifdef EIGEN_ARRAYBASE_PLUGIN
99#include EIGEN_ARRAYBASE_PLUGIN
100#endif
101#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
102#undef EIGEN_DOC_UNARY_ADDONS
107 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const ArrayBase& other) {
108 internal::call_assignment(derived(), other.derived());
109 return derived();
110 }
111
112 /** Set all the entries to \a value.
113 * \sa DenseBase::setConstant(), DenseBase::fill() */
114 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const Scalar& value) {
115 Base::setConstant(value);
116 return derived();
117 }
118
119 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(const Scalar& other) {
120 internal::call_assignment(this->derived(), PlainObject::Constant(rows(), cols(), other),
121 internal::add_assign_op<Scalar, Scalar>());
122 return derived();
124
125 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(const Scalar& other) {
126 internal::call_assignment(this->derived(), PlainObject::Constant(rows(), cols(), other),
127 internal::sub_assign_op<Scalar, Scalar>());
128 return derived();
129 }
130
134 */
135 template <typename OtherDerived>
136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(const ArrayBase<OtherDerived>& other) {
137 call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar, typename OtherDerived::Scalar>());
138 return derived();
139 }
140
145 template <typename OtherDerived>
146 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(const ArrayBase<OtherDerived>& other) {
147 call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar, typename OtherDerived::Scalar>());
148 return derived();
149 }
150
152
155 template <typename OtherDerived>
156 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*=(const ArrayBase<OtherDerived>& other) {
157 call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar, typename OtherDerived::Scalar>());
158 return derived();
159 }
163
165 template <typename OtherDerived>
166 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator/=(const ArrayBase<OtherDerived>& other) {
167 call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar, typename OtherDerived::Scalar>());
168 return derived();
169 }
170
171 public:
172 EIGEN_DEVICE_FUNC constexpr ArrayBase<Derived>& array() { return *this; }
173 EIGEN_DEVICE_FUNC constexpr const ArrayBase<Derived>& array() const { return *this; }
177 EIGEN_DEVICE_FUNC constexpr MatrixWrapper<Derived> matrix() { return MatrixWrapper<Derived>(derived()); }
178 EIGEN_DEVICE_FUNC constexpr const MatrixWrapper<const Derived> matrix() const {
179 return MatrixWrapper<const Derived>(derived());
180 }
181
182 protected:
183 EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase)
184 EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase)
185
186 private:
187 explicit ArrayBase(Index);
188 ArrayBase(Index, Index);
189 template <typename OtherDerived>
190 explicit ArrayBase(const ArrayBase<OtherDerived>&);
191
192 protected:
193 // mixing arrays and matrices is not legal
194 template <typename OtherDerived>
195 Derived& operator+=(const MatrixBase<OtherDerived>&) {
196 EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1,
197 YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);
198 return *this;
200 // mixing arrays and matrices is not legal
201 template <typename OtherDerived>
202 Derived& operator-=(const MatrixBase<OtherDerived>&) {
203 EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar)) == -1,
204 YOU_CANNOT_MIX_ARRAYS_AND_MATRICES);
205 return *this;
206 }
207};
209} // end namespace Eigen
210
211#endif // EIGEN_ARRAYBASE_H
Base class for all 1D and 2D array, and related expressions.
Definition ArrayBase.h:45
Derived & operator/=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:166
Derived & operator=(const ArrayBase &other)
Definition ArrayBase.h:107
constexpr MatrixWrapper< Derived > matrix()
Definition ArrayBase.h:177
Derived & operator*=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:156
Derived & operator+=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:136
Derived & operator-=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:146
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:65
std::conditional_t< std::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:203
CoeffReturnType value() const
Definition DenseBase.h:450
constexpr DenseBase()=default
typename internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:63
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
Expression of an array as a mathematical vector or matrix.
Definition ArrayWrapper.h:120