Eigen  3.2.10
 
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
13namespace Eigen {
14
15template<typename ExpressionType> class MatrixWrapper;
16
19 *
20 * \brief Base class for all 1D and 2D array, and related expressions
21 *
22 * An array is similar to a dense vector or matrix. While matrices are mathematical
23 * objects with well defined linear algebra operators, an array is just a collection
24 * of scalar values arranged in a one or two dimensionnal fashion. As the main consequence,
25 * all operations applied to an array are performed coefficient wise. Furthermore,
26 * arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient
27 * constructors allowing to easily write generic code working for both scalar values
28 * and arrays.
29 *
30 * This class is the base that is inherited by all array expression types.
31 *
32 * \tparam Derived is the derived type, e.g., an array or an expression type.
33 *
34 * This class can be extended with the help of the plugin mechanism described on the page
35 * \ref TopicCustomizingEigen by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN.
36 *
37 * \sa class MatrixBase, \ref TopicClassHierarchy
38 */
39template<typename Derived> class ArrayBase
40 : public DenseBase<Derived>
41{
42 public:
43#ifndef EIGEN_PARSED_BY_DOXYGEN
45 typedef ArrayBase StorageBaseType;
46
47 typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl;
48
49 typedef typename internal::traits<Derived>::StorageKind StorageKind;
50 typedef typename internal::traits<Derived>::Index Index;
51 typedef typename internal::traits<Derived>::Scalar Scalar;
52 typedef typename internal::packet_traits<Scalar>::type PacketScalar;
53 typedef typename NumTraits<Scalar>::Real RealScalar;
54
55 typedef DenseBase<Derived> Base;
56 using Base::operator*;
57 using Base::RowsAtCompileTime;
58 using Base::ColsAtCompileTime;
59 using Base::SizeAtCompileTime;
60 using Base::MaxRowsAtCompileTime;
61 using Base::MaxColsAtCompileTime;
62 using Base::MaxSizeAtCompileTime;
63 using Base::IsVectorAtCompileTime;
64 using Base::Flags;
65 using Base::CoeffReadCost;
66
67 using Base::derived;
68 using Base::const_cast_derived;
69 using Base::rows;
70 using Base::cols;
71 using Base::size;
72 using Base::coeff;
73 using Base::coeffRef;
74 using Base::lazyAssign;
75 using Base::operator=;
76 using Base::operator+=;
77 using Base::operator-=;
78 using Base::operator*=;
79 using Base::operator/=;
80
81 typedef typename Base::CoeffReturnType CoeffReturnType;
82
83#endif // not EIGEN_PARSED_BY_DOXYGEN
84
85#ifndef EIGEN_PARSED_BY_DOXYGEN
89
92 internal::traits<Derived>::RowsAtCompileTime,
93 internal::traits<Derived>::ColsAtCompileTime,
94 AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
95 internal::traits<Derived>::MaxRowsAtCompileTime,
96 internal::traits<Derived>::MaxColsAtCompileTime
97 > PlainObject;
98
101 typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
102#endif // not EIGEN_PARSED_BY_DOXYGEN
103
104#define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
105# include "../plugins/CommonCwiseUnaryOps.h"
106# include "../plugins/MatrixCwiseUnaryOps.h"
107# include "../plugins/ArrayCwiseUnaryOps.h"
108# include "../plugins/CommonCwiseBinaryOps.h"
109# include "../plugins/MatrixCwiseBinaryOps.h"
110# include "../plugins/ArrayCwiseBinaryOps.h"
111# ifdef EIGEN_ARRAYBASE_PLUGIN
112# include EIGEN_ARRAYBASE_PLUGIN
113# endif
114#undef EIGEN_CURRENT_STORAGE_BASE_CLASS
115
117 * from generating a default operator= (issue hit with g++ 4.1)
118 */
119 Derived& operator=(const ArrayBase& other)
120 {
121 return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
122 }
123
124 Derived& operator+=(const Scalar& scalar)
125 { return *this = derived() + scalar; }
126 Derived& operator-=(const Scalar& scalar)
127 { return *this = derived() - scalar; }
128
129 template<typename OtherDerived>
130 Derived& operator+=(const ArrayBase<OtherDerived>& other);
131 template<typename OtherDerived>
132 Derived& operator-=(const ArrayBase<OtherDerived>& other);
133
134 template<typename OtherDerived>
135 Derived& operator*=(const ArrayBase<OtherDerived>& other);
136
137 template<typename OtherDerived>
138 Derived& operator/=(const ArrayBase<OtherDerived>& other);
139
140 public:
141 ArrayBase<Derived>& array() { return *this; }
142 const ArrayBase<Derived>& array() const { return *this; }
143
146 MatrixWrapper<Derived> matrix() { return derived(); }
147 const MatrixWrapper<const Derived> matrix() const { return derived(); }
148
149// template<typename Dest>
150// inline void evalTo(Dest& dst) const { dst = matrix(); }
151
152 protected:
153 ArrayBase() : Base() {}
154
155 private:
156 explicit ArrayBase(Index);
157 ArrayBase(Index,Index);
158 template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
159 protected:
160 // mixing arrays and matrices is not legal
161 template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& )
162 {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
163 // mixing arrays and matrices is not legal
164 template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& )
165 {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
166};
172template<typename Derived>
173template<typename OtherDerived>
174EIGEN_STRONG_INLINE Derived &
175ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other)
176{
177 SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived());
178 tmp = other.derived();
179 return derived();
180}
181
185 */
186template<typename Derived>
187template<typename OtherDerived>
188EIGEN_STRONG_INLINE Derived &
189ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other)
190{
191 SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, Derived, OtherDerived> tmp(derived());
192 tmp = other.derived();
193 return derived();
194}
195
200template<typename Derived>
201template<typename OtherDerived>
202EIGEN_STRONG_INLINE Derived &
203ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other)
204{
205 SelfCwiseBinaryOp<internal::scalar_product_op<Scalar>, Derived, OtherDerived> tmp(derived());
206 tmp = other.derived();
207 return derived();
208}
209
211
214template<typename Derived>
215template<typename OtherDerived>
216EIGEN_STRONG_INLINE Derived &
217ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other)
218{
219 SelfCwiseBinaryOp<internal::scalar_quotient_op<Scalar>, Derived, OtherDerived> tmp(derived());
220 tmp = other.derived();
221 return derived();
222}
223
224} // end namespace Eigen
225
226#endif // EIGEN_ARRAYBASE_H
Base class for all 1D and 2D array, and related expressions.
Definition ArrayBase.h:41
Derived & operator*=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:203
Derived & operator-=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:175
Derived & operator=(const ArrayBase &other)
Definition ArrayBase.h:119
MatrixWrapper< Derived > matrix()
Definition ArrayBase.h:146
Derived & operator+=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:189
Derived & operator/=(const ArrayBase< OtherDerived > &other)
Definition ArrayBase.h:217
General-purpose arrays with easy API for coefficient-wise operations.
Definition Array.h:44
Generic expression of a matrix where all coefficients are defined by a functor.
Definition CwiseNullaryOp.h:51
DenseBase()
Definition DenseBase.h:501
internal::traits< Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Index Index
Definition DenseBase.h:60
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Expression of an array as a mathematical vector or matrix.
Definition ArrayWrapper.h:167
@ AutoAlign
Definition Constants.h:268
@ RowMajor
Definition Constants.h:266
@ ColMajor
Definition Constants.h:264
const unsigned int RowMajorBit
Definition Constants.h:53