Eigen  3.2.7
 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 <[email protected]>
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>::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
86 
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 
99 
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 
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 };
172 template<typename Derived>
173 template<typename OtherDerived>
174 EIGEN_STRONG_INLINE Derived &
176 {
177  SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived());
178  tmp = other.derived();
179  return derived();
180 }
181 
186 template<typename Derived>
187 template<typename OtherDerived>
188 EIGEN_STRONG_INLINE Derived &
190 {
191  SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, Derived, OtherDerived> tmp(derived());
192  tmp = other.derived();
193  return derived();
194 }
195 
200 template<typename Derived>
201 template<typename OtherDerived>
202 EIGEN_STRONG_INLINE Derived &
204 {
205  SelfCwiseBinaryOp<internal::scalar_product_op<Scalar>, Derived, OtherDerived> tmp(derived());
206  tmp = other.derived();
207  return derived();
208 }
209 
214 template<typename Derived>
215 template<typename OtherDerived>
216 EIGEN_STRONG_INLINE Derived &
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
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:119
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:88
Definition: Constants.h:264
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
Definition: Constants.h:268
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
Derived & operator*=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:203
internal::traits< Derived >::Index Index
The type of indices.
Definition: DenseBase.h:60
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:42
Definition: Constants.h:266
const unsigned int RowMajorBit
Definition: Constants.h:53
Derived & operator/=(const ArrayBase< OtherDerived > &other)
Definition: ArrayBase.h:217
MatrixWrapper< Derived > matrix()
Definition: ArrayBase.h:146
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48