ArrayBase.h
Go to the documentation of this file.
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 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_ARRAYBASE_H
26 #define EIGEN_ARRAYBASE_H
27 
28 namespace Eigen {
29 
30 template<typename ExpressionType> class MatrixWrapper;
31 
54 template<typename Derived> class ArrayBase
55  : public DenseBase<Derived>
56 {
57  public:
58 #ifndef EIGEN_PARSED_BY_DOXYGEN
59 
60  typedef ArrayBase StorageBaseType;
61 
62  typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl;
63 
64  using internal::special_scalar_op_base<Derived,typename internal::traits<Derived>::Scalar,
66 
67  typedef typename internal::traits<Derived>::StorageKind StorageKind;
68  typedef typename internal::traits<Derived>::Index Index;
69  typedef typename internal::traits<Derived>::Scalar Scalar;
70  typedef typename internal::packet_traits<Scalar>::type PacketScalar;
71  typedef typename NumTraits<Scalar>::Real RealScalar;
72 
73  typedef DenseBase<Derived> Base;
81  using Base::Flags;
82  using Base::CoeffReadCost;
83 
84  using Base::derived;
85  using Base::const_cast_derived;
86  using Base::rows;
87  using Base::cols;
88  using Base::size;
89  using Base::coeff;
90  using Base::coeffRef;
91  using Base::lazyAssign;
92  using Base::operator=;
93  using Base::operator+=;
94  using Base::operator-=;
95  using Base::operator*=;
96  using Base::operator/=;
97 
98  typedef typename Base::CoeffReturnType CoeffReturnType;
99 
100 #endif // not EIGEN_PARSED_BY_DOXYGEN
101 
102 #ifndef EIGEN_PARSED_BY_DOXYGEN
103 
109  internal::traits<Derived>::RowsAtCompileTime,
110  internal::traits<Derived>::ColsAtCompileTime,
111  AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor),
112  internal::traits<Derived>::MaxRowsAtCompileTime,
113  internal::traits<Derived>::MaxColsAtCompileTime
114  > PlainObject;
115 
116 
118  typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType;
119 #endif // not EIGEN_PARSED_BY_DOXYGEN
120 
121 #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase
122 # include "../plugins/CommonCwiseUnaryOps.h"
123 # include "../plugins/MatrixCwiseUnaryOps.h"
124 # include "../plugins/ArrayCwiseUnaryOps.h"
125 # include "../plugins/CommonCwiseBinaryOps.h"
126 # include "../plugins/MatrixCwiseBinaryOps.h"
127 # include "../plugins/ArrayCwiseBinaryOps.h"
128 # ifdef EIGEN_ARRAYBASE_PLUGIN
129 # include EIGEN_ARRAYBASE_PLUGIN
130 # endif
131 #undef EIGEN_CURRENT_STORAGE_BASE_CLASS
136  Derived& operator=(const ArrayBase& other)
137  {
138  return internal::assign_selector<Derived,Derived>::run(derived(), other.derived());
139  }
140 
141  Derived& operator+=(const Scalar& scalar)
142  { return *this = derived() + scalar; }
143  Derived& operator-=(const Scalar& scalar)
144  { return *this = derived() - scalar; }
145 
146  template<typename OtherDerived>
147  Derived& operator+=(const ArrayBase<OtherDerived>& other);
148  template<typename OtherDerived>
149  Derived& operator-=(const ArrayBase<OtherDerived>& other);
150 
151  template<typename OtherDerived>
152  Derived& operator*=(const ArrayBase<OtherDerived>& other);
153 
154  template<typename OtherDerived>
155  Derived& operator/=(const ArrayBase<OtherDerived>& other);
156 
157  public:
158  ArrayBase<Derived>& array() { return *this; }
159  const ArrayBase<Derived>& array() const { return *this; }
160 
163  MatrixWrapper<Derived> matrix() { return derived(); }
164  const MatrixWrapper<const Derived> matrix() const { return derived(); }
165 
166 // template<typename Dest>
167 // inline void evalTo(Dest& dst) const { dst = matrix(); }
168 
169  protected:
170  ArrayBase() : Base() {}
171 
172  private:
173  explicit ArrayBase(Index);
175  template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&);
176  protected:
177  // mixing arrays and matrices is not legal
178  template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& )
179  {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
180  // mixing arrays and matrices is not legal
181  template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& )
182  {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;}
183 };
184 
189 template<typename Derived>
190 template<typename OtherDerived>
191 EIGEN_STRONG_INLINE Derived &
193 {
194  SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived());
195  tmp = other.derived();
196  return derived();
197 }
198 
203 template<typename Derived>
204 template<typename OtherDerived>
205 EIGEN_STRONG_INLINE Derived &
207 {
208  SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, Derived, OtherDerived> tmp(derived());
209  tmp = other.derived();
210  return derived();
211 }
212 
217 template<typename Derived>
218 template<typename OtherDerived>
219 EIGEN_STRONG_INLINE Derived &
221 {
222  SelfCwiseBinaryOp<internal::scalar_product_op<Scalar>, Derived, OtherDerived> tmp(derived());
223  tmp = other.derived();
224  return derived();
225 }
226 
231 template<typename Derived>
232 template<typename OtherDerived>
233 EIGEN_STRONG_INLINE Derived &
235 {
236  SelfCwiseBinaryOp<internal::scalar_quotient_op<Scalar>, Derived, OtherDerived> tmp(derived());
237  tmp = other.derived();
238  return derived();
239 }
240 
241 } // end namespace Eigen
242 
243 #endif // EIGEN_ARRAYBASE_H