Eigen  3.2.5
Array.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_ARRAY_H
11 #define EIGEN_ARRAY_H
12 
13 namespace Eigen {
14 
32 namespace internal {
33 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
34 struct traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
35 {
36  typedef ArrayXpr XprKind;
37  typedef ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > XprBase;
38 };
39 }
40 
41 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
42 class Array
43  : public PlainObjectBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
44 {
45  public:
46 
48  EIGEN_DENSE_PUBLIC_INTERFACE(Array)
49 
50  enum { Options = _Options };
51  typedef typename Base::PlainObject PlainObject;
52 
53  protected:
54  template <typename Derived, typename OtherDerived, bool IsVector>
55  friend struct internal::conservative_resize_like_impl;
56 
57  using Base::m_storage;
58 
59  public:
60 
61  using Base::base;
62  using Base::coeff;
63  using Base::coeffRef;
64 
71  template<typename OtherDerived>
72  EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other)
73  {
74  return Base::operator=(other);
75  }
76 
86  template<typename OtherDerived>
87  EIGEN_STRONG_INLINE Array& operator=(const ArrayBase<OtherDerived>& other)
88  {
89  return Base::_set(other);
90  }
91 
95  EIGEN_STRONG_INLINE Array& operator=(const Array& other)
96  {
97  return Base::_set(other);
98  }
99 
110  EIGEN_STRONG_INLINE Array() : Base()
111  {
112  Base::_check_template_params();
113  EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
114  }
115 
116 #ifndef EIGEN_PARSED_BY_DOXYGEN
117  // FIXME is it still needed ??
119  Array(internal::constructor_without_unaligned_array_assert)
120  : Base(internal::constructor_without_unaligned_array_assert())
121  {
122  Base::_check_template_params();
123  EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
124  }
125 #endif
126 
133  EIGEN_STRONG_INLINE explicit Array(Index dim)
134  : Base(dim, RowsAtCompileTime == 1 ? 1 : dim, ColsAtCompileTime == 1 ? 1 : dim)
135  {
136  Base::_check_template_params();
137  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Array)
138  eigen_assert(dim >= 0);
139  eigen_assert(SizeAtCompileTime == Dynamic || SizeAtCompileTime == dim);
140  EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
141  }
142 
143  #ifndef EIGEN_PARSED_BY_DOXYGEN
144  template<typename T0, typename T1>
145  EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1)
146  {
147  Base::_check_template_params();
148  this->template _init2<T0,T1>(val0, val1);
149  }
150  #else
151 
156  Array(Index rows, Index cols);
158  Array(const Scalar& val0, const Scalar& val1);
159  #endif
160 
162  EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2)
163  {
164  Base::_check_template_params();
165  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3)
166  m_storage.data()[0] = val0;
167  m_storage.data()[1] = val1;
168  m_storage.data()[2] = val2;
169  }
171  EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2, const Scalar& val3)
172  {
173  Base::_check_template_params();
174  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4)
175  m_storage.data()[0] = val0;
176  m_storage.data()[1] = val1;
177  m_storage.data()[2] = val2;
178  m_storage.data()[3] = val3;
179  }
180 
181  explicit Array(const Scalar *data);
182 
184  template<typename OtherDerived>
185  EIGEN_STRONG_INLINE Array(const ArrayBase<OtherDerived>& other)
186  : Base(other.rows() * other.cols(), other.rows(), other.cols())
187  {
188  Base::_check_template_params();
189  Base::_set_noalias(other);
190  }
192  EIGEN_STRONG_INLINE Array(const Array& other)
193  : Base(other.rows() * other.cols(), other.rows(), other.cols())
194  {
195  Base::_check_template_params();
196  Base::_set_noalias(other);
197  }
199  template<typename OtherDerived>
200  EIGEN_STRONG_INLINE Array(const ReturnByValue<OtherDerived>& other)
201  {
202  Base::_check_template_params();
203  Base::resize(other.rows(), other.cols());
204  other.evalTo(*this);
205  }
206 
208  template<typename OtherDerived>
209  EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived> &other)
210  : Base(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols())
211  {
212  Base::_check_template_params();
213  Base::_resize_to_match(other);
214  *this = other;
215  }
216 
220  template<typename OtherDerived>
221  void swap(ArrayBase<OtherDerived> const & other)
222  { this->_swap(other.derived()); }
223 
224  inline Index innerStride() const { return 1; }
225  inline Index outerStride() const { return this->innerSize(); }
226 
227  #ifdef EIGEN_ARRAY_PLUGIN
228  #include EIGEN_ARRAY_PLUGIN
229  #endif
230 
231  private:
232 
233  template<typename MatrixType, typename OtherDerived, bool SwapPointers>
234  friend struct internal::matrix_swap_impl;
235 };
236 
256 #define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
257  \
258 typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix; \
259  \
260 typedef Array<Type, Size, 1> Array##SizeSuffix##TypeSuffix;
261 
262 #define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
263  \
264 typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix; \
265  \
266 typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix;
267 
268 #define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
269 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \
270 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \
271 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \
272 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
273 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
274 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
275 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
276 
277 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i)
278 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f)
279 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d)
280 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
281 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
282 
283 #undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES
284 #undef EIGEN_MAKE_ARRAY_TYPEDEFS
285 
286 #undef EIGEN_MAKE_ARRAY_TYPEDEFS_LARGE
287 
288 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
289 using Eigen::Matrix##SizeSuffix##TypeSuffix; \
290 using Eigen::Vector##SizeSuffix##TypeSuffix; \
291 using Eigen::RowVector##SizeSuffix##TypeSuffix;
292 
293 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \
294 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
295 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
296 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
297 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \
298 
299 #define EIGEN_USING_ARRAY_TYPEDEFS \
300 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \
301 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \
302 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \
303 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \
304 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd)
305 
306 } // end namespace Eigen
307 
308 #endif // EIGEN_ARRAY_H
Array()
Definition: Array.h:110
Array & operator=(const Array &other)
Definition: Array.h:95
Array(const EigenBase< OtherDerived > &other)
Definition: Array.h:209
Array(const Scalar &val0, const Scalar &val1, const Scalar &val2)
Definition: Array.h:162
Array & operator=(const ArrayBase< OtherDerived > &other)
Definition: Array.h:87
void swap(ArrayBase< OtherDerived > const &other)
Definition: Array.h:221
Definition: LDLT.h:16
Definition: StdDeque.h:58
Array(const Scalar &val0, const Scalar &val1, const Scalar &val2, const Scalar &val3)
Definition: Array.h:171
Definition: EigenBase.h:26
Array(Index dim)
Definition: Array.h:133
Definition: DenseBase.h:108
Array(const ArrayBase< OtherDerived > &other)
Definition: Array.h:185
Dense storage base class for matrices and arrays.
Definition: PlainObjectBase.h:85
Array & operator=(const EigenBase< OtherDerived > &other)
Definition: Array.h:72
Base class for all 1D and 2D array, and related expressions.
Definition: ArrayBase.h:39
Index innerSize() const
Definition: DenseBase.h:207
Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition: PlainObjectBase.h:598
Array(const ReturnByValue< OtherDerived > &other)
Definition: Array.h:200
Definition: Eigen_Colamd.h:54
Derived & operator=(const PlainObjectBase &other)
Definition: PlainObjectBase.h:404
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:42
Definition: DenseBase.h:115
void resize(Index nbRows, Index nbCols)
Definition: PlainObjectBase.h:235
Array(const Array &other)
Definition: Array.h:192
Definition: DenseBase.h:102