Eigen  3.2.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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,
51 
52  typedef typename internal::traits<Derived>::StorageKind StorageKind;
53  typedef typename internal::traits<Derived>::Index Index;
54  typedef typename internal::traits<Derived>::Scalar Scalar;
55  typedef typename internal::packet_traits<Scalar>::type PacketScalar;
56  typedef typename NumTraits<Scalar>::Real RealScalar;
57 
58  typedef DenseBase<Derived> Base;
59  using Base::RowsAtCompileTime;
60  using Base::ColsAtCompileTime;
61  using Base::SizeAtCompileTime;
62  using Base::MaxRowsAtCompileTime;
63  using Base::MaxColsAtCompileTime;
64  using Base::MaxSizeAtCompileTime;
65  using Base::IsVectorAtCompileTime;
66  using Base::Flags;
67  using Base::CoeffReadCost;
68 
69  using Base::derived;
70  using Base::const_cast_derived;
71  using Base::rows;
72  using Base::cols;
73  using Base::size;
74  using Base::coeff;
75  using Base::coeffRef;
76  using Base::lazyAssign;
77  using Base::operator=;
78  using Base::operator+=;
79  using Base::operator-=;
80  using Base::operator*=;
81  using Base::operator/=;
82 
83  typedef typename Base::CoeffReturnType CoeffReturnType;
84 
85 #endif // not EIGEN_PARSED_BY_DOXYGEN
86 
87 #ifndef EIGEN_PARSED_BY_DOXYGEN
88 
94  internal::traits<Derived>::RowsAtCompileTime,
95  internal::traits<Derived>::ColsAtCompileTime,
96  AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
97  internal::traits<Derived>::MaxRowsAtCompileTime,
98  internal::traits<Derived>::MaxColsAtCompileTime
99  > PlainObject;
100 
101 
103  typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
104 #endif // not EIGEN_PARSED_BY_DOXYGEN
105 
106 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
107 # include "../plugins/CommonCwiseUnaryOps.h"
108 # include "../plugins/MatrixCwiseUnaryOps.h"
109 # include "../plugins/ArrayCwiseUnaryOps.h"
110 # include "../plugins/CommonCwiseBinaryOps.h"
111 # include "../plugins/MatrixCwiseBinaryOps.h"
112 # include "../plugins/ArrayCwiseBinaryOps.h"
113 # ifdef EIGEN_ARRAYBASE_PLUGIN
114 # include EIGEN_ARRAYBASE_PLUGIN
115 # endif
116 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
121  Derived& operator=(const ArrayBase& other)
122  {
123  return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
124  }
125 
126  Derived& operator+=(const Scalar& scalar)
127  { return *this = derived() + scalar; }
128  Derived& operator-=(const Scalar& scalar)
129  { return *this = derived() - scalar; }
131  template<typename OtherDerived>
132  Derived& operator+=(const ArrayBase<OtherDerived>& other);
133  template<typename OtherDerived>
134  Derived& operator-=(const ArrayBase<OtherDerived>& other);
135 
136  template<typename OtherDerived>
137  Derived& operator*=(const ArrayBase<OtherDerived>& other);
138 
139  template<typename OtherDerived>
140  Derived& operator/=(const ArrayBase<OtherDerived>& other);
141 
142  public:
143  ArrayBase<Derived>& array() { return *this; }
144  const ArrayBase<Derived>& array() const { return *this; }
145 
148  MatrixWrapper<Derived> matrix() { return derived(); }
149  const MatrixWrapper<const Derived> matrix() const { return derived(); }
150 
151 // template<typename Dest>
152 // inline void evalTo(Dest& dst) const { dst = matrix(); }
153 
154  protected:
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 };
169 
174 template<typename Derived>
175 template<typename OtherDerived>
176 EIGEN_STRONG_INLINE Derived &
178 {
179  SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived());
180  tmp = other.derived();
181  return derived();
182 }
183 
188 template<typename Derived>
189 template<typename OtherDerived>
190 EIGEN_STRONG_INLINE Derived &
192 {
193  SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, Derived, OtherDerived> tmp(derived());
194  tmp = other.derived();
195  return derived();
196 }
197 
202 template<typename Derived>
203 template<typename OtherDerived>
204 EIGEN_STRONG_INLINE Derived &
206 {
207  SelfCwiseBinaryOp<internal::scalar_product_op<Scalar>, Derived, OtherDerived> tmp(derived());
208  tmp = other.derived();
209  return derived();
210 }
211 
216 template<typename Derived>
217 template<typename OtherDerived>
218 EIGEN_STRONG_INLINE Derived &
220 {
221  SelfCwiseBinaryOp<internal::scalar_quotient_op<Scalar>, Derived, OtherDerived> tmp(derived());
222  tmp = other.derived();
223  return derived();
224 }
225 
226 } // end namespace Eigen
227 
228 #endif // EIGEN_ARRAYBASE_H
Generic expression of a matrix where all coefficients are defined by a functor.
Definition: CwiseNullaryOp.h:49
Derived & operator=(const ArrayBase &other)
Definition: ArrayBase.h:121
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
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
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
Derived & operator*=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:205
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:61
Definition: Constants.h:268
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:42
const unsigned int RowMajorBit
Definition: Constants.h:53
Derived & operator/=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:219
MatrixWrapper< Derived > matrix()
Definition: ArrayBase.h:148
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48
Definition: Constants.h:266
Definition: Constants.h:264