Eigen  5.0.1-dev+60122df6
 
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
10#ifndef EIGEN_ARRAYBASE_H
11#define EIGEN_ARRAYBASE_H
12
13// IWYU pragma: private
14#include "./InternalHeaderCheck.h"
15
16namespace Eigen {
17
18template <typename ExpressionType>
19class MatrixWrapper;
23 *
24 * \brief Base class for all 1D and 2D array, and related expressions
25 *
26 * An array is similar to a dense vector or matrix. While matrices are mathematical
27 * objects with well defined linear algebra operators, an array is just a collection
28 * of scalar values arranged in a one or two dimensional fashion. As the main consequence,
29 * all operations applied to an array are performed coefficient wise. Furthermore,
30 * arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient
31 * constructors allowing to easily write generic code working for both scalar values
32 * and arrays.
33 *
34 * This class is the base that is inherited by all array expression types.
35 *
36 * \tparam Derived is the derived type, e.g., an array or an expression type.
37 *
38 * This class can be extended with the help of the plugin mechanism described on the page
39 * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN.
40 *
41 * \sa class MatrixBase, \ref TopicClassHierarchy
42 */
43template <typename Derived>
44class ArrayBase : public DenseBase<Derived> {
45 public:
46#ifndef EIGEN_PARSED_BY_DOXYGEN
47 /** The base class for a given storage type. */
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;
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();
117
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();
129
132 * \returns a reference to \c *this
133 */
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
150
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();
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 {
178 return MatrixWrapper<const Derived>(derived());
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);
190 ArrayBase(Index, 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
Base class for all 1D and 2D array, and related expressions.
Definition ArrayBase.h:44
Derived & operator/=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:165
Derived & operator=(const ArrayBase &other)
Definition ArrayBase.h:106
MatrixWrapper< Derived > matrix()
Definition ArrayBase.h:176
Derived & operator*=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:155
Derived & operator-=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:145
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:64
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
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:62
CoeffReturnType value() const
Definition DenseBase.h:486
constexpr DenseBase()=default
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
Expression of an array as a mathematical vector or matrix.
Definition ArrayWrapper.h:118
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82