Eigen  3.2.93
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 namespace Eigen {
14 
15 template<typename ExpressionType> class MatrixWrapper;
16 
39 template<typename Derived> class ArrayBase
40  : public DenseBase<Derived>
41 {
42  public:
43 #ifndef EIGEN_PARSED_BY_DOXYGEN
44 
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>::Scalar Scalar;
51  typedef typename internal::packet_traits<Scalar>::type PacketScalar;
52  typedef typename NumTraits<Scalar>::Real RealScalar;
53 
54  typedef DenseBase<Derived> Base;
55  using Base::RowsAtCompileTime;
56  using Base::ColsAtCompileTime;
57  using Base::SizeAtCompileTime;
58  using Base::MaxRowsAtCompileTime;
59  using Base::MaxColsAtCompileTime;
60  using Base::MaxSizeAtCompileTime;
61  using Base::IsVectorAtCompileTime;
62  using Base::Flags;
63 
64  using Base::derived;
65  using Base::const_cast_derived;
66  using Base::rows;
67  using Base::cols;
68  using Base::size;
69  using Base::coeff;
70  using Base::coeffRef;
71  using Base::lazyAssign;
72  using Base::operator=;
73  using Base::operator+=;
74  using Base::operator-=;
75  using Base::operator*=;
76  using Base::operator/=;
77 
78  typedef typename Base::CoeffReturnType CoeffReturnType;
79 
80 #endif // not EIGEN_PARSED_BY_DOXYGEN
81 
82 #ifndef EIGEN_PARSED_BY_DOXYGEN
83  typedef typename Base::PlainObject PlainObject;
84 
86  typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
87 #endif // not EIGEN_PARSED_BY_DOXYGEN
88 
89 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
90 # include "../plugins/CommonCwiseUnaryOps.h"
91 # include "../plugins/MatrixCwiseUnaryOps.h"
92 # include "../plugins/ArrayCwiseUnaryOps.h"
93 # include "../plugins/CommonCwiseBinaryOps.h"
94 # include "../plugins/MatrixCwiseBinaryOps.h"
95 # include "../plugins/ArrayCwiseBinaryOps.h"
96 # ifdef EIGEN_ARRAYBASE_PLUGIN
97 # include EIGEN_ARRAYBASE_PLUGIN
98 # endif
99 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
100 
104  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
105  Derived& operator=(const ArrayBase& other)
106  {
107  internal::call_assignment(derived(), other.derived());
108  return derived();
109  }
110 
113  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
114  Derived& operator=(const Scalar &value)
115  { Base::setConstant(value); return derived(); }
116 
117  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
118  Derived& operator+=(const Scalar& scalar);
119  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
120  Derived& operator-=(const Scalar& scalar);
121 
122  template<typename OtherDerived>
123  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
124  Derived& operator+=(const ArrayBase<OtherDerived>& other);
125  template<typename OtherDerived>
126  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
127  Derived& operator-=(const ArrayBase<OtherDerived>& other);
128 
129  template<typename OtherDerived>
130  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
131  Derived& operator*=(const ArrayBase<OtherDerived>& other);
132 
133  template<typename OtherDerived>
134  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
135  Derived& operator/=(const ArrayBase<OtherDerived>& other);
137  public:
138  EIGEN_DEVICE_FUNC
139  ArrayBase<Derived>& array() { return *this; }
140  EIGEN_DEVICE_FUNC
141  const ArrayBase<Derived>& array() const { return *this; }
142 
145  EIGEN_DEVICE_FUNC
147  EIGEN_DEVICE_FUNC
149 
150 // template<typename Dest>
151 // inline void evalTo(Dest& dst) const { dst = matrix(); }
152 
153  protected:
154  EIGEN_DEVICE_FUNC
155  ArrayBase() : Base() {}
156 
157  private:
158  explicit ArrayBase(Index);
160  template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
161  protected:
162  // mixing arrays and matrices is not legal
163  template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& )
164  {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
165  // mixing arrays and matrices is not legal
166  template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& )
167  {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
168 };
174 template<typename Derived>
175 template<typename OtherDerived>
176 EIGEN_STRONG_INLINE Derived &
178 {
179  call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar,typename OtherDerived::Scalar>());
180  return derived();
181 }
182 
187 template<typename Derived>
188 template<typename OtherDerived>
189 EIGEN_STRONG_INLINE Derived &
191 {
192  call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar,typename OtherDerived::Scalar>());
193  return derived();
194 }
195 
200 template<typename Derived>
201 template<typename OtherDerived>
202 EIGEN_STRONG_INLINE Derived &
204 {
205  call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar,typename OtherDerived::Scalar>());
206  return derived();
207 }
208 
213 template<typename Derived>
214 template<typename OtherDerived>
215 EIGEN_STRONG_INLINE Derived &
217 {
218  call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar,typename OtherDerived::Scalar>());
219  return derived();
220 }
222 } // end namespace Eigen
223 
224 #endif // EIGEN_ARRAYBASE_H
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:43
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:66
Derived & operator=(const Scalar &value)
Definition: ArrayBase.h:114
Namespace containing all symbols from the Eigen library.
Definition: Core:271
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:167
Derived & derived()
Definition: EigenBase.h:44
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:37
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:41
Expression of an array as a mathematical vector or matrix.
Definition: ArrayBase.h:15
Derived & operator/=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:216
Derived & operator=(const ArrayBase &other)
Definition: ArrayBase.h:105
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
MatrixWrapper< Derived > matrix()
Definition: ArrayBase.h:146
internal::conditional< internal::is_same< typename internal::traits< Derived >::XprKind, MatrixXpr >::value, PlainMatrix, PlainArray >::type PlainObject
The plain matrix or array type corresponding to this expression.
Definition: DenseBase.h:205
CoeffReturnType value() const
Definition: DenseBase.h:470
Derived & operator*=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:203
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48