Eigen  3.2.91
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  using internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
50  typename NumTraits<typename internal::traits<Derived>::Scalar>::Real>::operator*;
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::RowsAtCompileTime;
59  using Base::ColsAtCompileTime;
60  using Base::SizeAtCompileTime;
61  using Base::MaxRowsAtCompileTime;
62  using Base::MaxColsAtCompileTime;
63  using Base::MaxSizeAtCompileTime;
64  using Base::IsVectorAtCompileTime;
65  using Base::Flags;
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
86  typedef typename Base::PlainObject PlainObject;
87 
89  typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,PlainObject> ConstantReturnType;
90 #endif // not EIGEN_PARSED_BY_DOXYGEN
91 
92 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
93 # include "../plugins/CommonCwiseUnaryOps.h"
94 # include "../plugins/MatrixCwiseUnaryOps.h"
95 # include "../plugins/ArrayCwiseUnaryOps.h"
96 # include "../plugins/CommonCwiseBinaryOps.h"
97 # include "../plugins/MatrixCwiseBinaryOps.h"
98 # include "../plugins/ArrayCwiseBinaryOps.h"
99 # ifdef EIGEN_ARRAYBASE_PLUGIN
100 # include EIGEN_ARRAYBASE_PLUGIN
101 # endif
102 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
103 
107  EIGEN_DEVICE_FUNC
108  Derived& operator=(const ArrayBase& other)
109  {
110  internal::call_assignment(derived(), other.derived());
111  return derived();
112  }
113 
116  EIGEN_DEVICE_FUNC
117  Derived& operator=(const Scalar &value)
118  { Base::setConstant(value); return derived(); }
119 
120  EIGEN_DEVICE_FUNC
121  Derived& operator+=(const Scalar& scalar);
122  EIGEN_DEVICE_FUNC
123  Derived& operator-=(const Scalar& scalar);
124 
125  template<typename OtherDerived>
126  EIGEN_DEVICE_FUNC
127  Derived& operator+=(const ArrayBase<OtherDerived>& other);
128  template<typename OtherDerived>
129  EIGEN_DEVICE_FUNC
130  Derived& operator-=(const ArrayBase<OtherDerived>& other);
131 
132  template<typename OtherDerived>
133  EIGEN_DEVICE_FUNC
134  Derived& operator*=(const ArrayBase<OtherDerived>& other);
135 
136  template<typename OtherDerived>
137  EIGEN_DEVICE_FUNC
138  Derived& operator/=(const ArrayBase<OtherDerived>& other);
139 
140  public:
141  EIGEN_DEVICE_FUNC
142  ArrayBase<Derived>& array() { return *this; }
143  EIGEN_DEVICE_FUNC
144  const ArrayBase<Derived>& array() const { return *this; }
145 
148  EIGEN_DEVICE_FUNC
150  EIGEN_DEVICE_FUNC
151  const MatrixWrapper<const Derived> matrix() const { return MatrixWrapper<const Derived>(derived()); }
152 
153 // template<typename Dest>
154 // inline void evalTo(Dest& dst) const { dst = matrix(); }
155 
156  protected:
157  EIGEN_DEVICE_FUNC
158  ArrayBase() : Base() {}
159 
160  private:
161  explicit ArrayBase(Index);
162  ArrayBase(Index,Index);
163  template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
164  protected:
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  // mixing arrays and matrices is not legal
169  template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& )
170  {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
171 };
177 template<typename Derived>
178 template<typename OtherDerived>
179 EIGEN_STRONG_INLINE Derived &
181 {
182  call_assignment(derived(), other.derived(), internal::sub_assign_op<Scalar>());
183  return derived();
184 }
190 template<typename Derived>
191 template<typename OtherDerived>
192 EIGEN_STRONG_INLINE Derived &
194 {
195  call_assignment(derived(), other.derived(), internal::add_assign_op<Scalar>());
196  return derived();
197 }
198 
203 template<typename Derived>
204 template<typename OtherDerived>
205 EIGEN_STRONG_INLINE Derived &
207 {
208  call_assignment(derived(), other.derived(), internal::mul_assign_op<Scalar,typename OtherDerived::Scalar>());
209  return derived();
210 }
211 
216 template<typename Derived>
217 template<typename OtherDerived>
218 EIGEN_STRONG_INLINE Derived &
220 {
221  call_assignment(derived(), other.derived(), internal::div_assign_op<Scalar>());
222  return derived();
223 }
224 
225 } // end namespace Eigen
226 
227 #endif // EIGEN_ARRAYBASE_H
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:44
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:72
Derived & operator=(const Scalar &value)
Definition: ArrayBase.h:117
Definition: LDLT.h:16
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:107
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
CoeffReturnType value() const
Definition: DenseBase.h:481
Derived & operator/=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:219
Derived & operator=(const ArrayBase &other)
Definition: ArrayBase.h:108
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
MatrixWrapper< Derived > matrix()
Definition: ArrayBase.h:149
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:212
Derived & operator*=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:206
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48