Eigen  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)
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 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 namespace internal {
18 template<typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
19 struct traits<Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_> > : traits<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_> >
20 {
21  typedef ArrayXpr XprKind;
22  typedef ArrayBase<Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_> > XprBase;
23 };
24 }
25 
46 template<typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
47 class Array
48  : public PlainObjectBase<Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_> >
49 {
50  public:
51 
53  EIGEN_DENSE_PUBLIC_INTERFACE(Array)
54 
55  enum { Options = Options_ };
56  typedef typename Base::PlainObject PlainObject;
57 
58  protected:
59  template <typename Derived, typename OtherDerived, bool IsVector>
60  friend struct internal::conservative_resize_like_impl;
61 
62  using Base::m_storage;
63 
64  public:
65 
66  using Base::base;
67  using Base::coeff;
68  using Base::coeffRef;
69 
76  template<typename OtherDerived>
77  EIGEN_DEVICE_FUNC
78  EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other)
79  {
80  return Base::operator=(other);
81  }
82 
86  /* This overload is needed because the usage of
87  * using Base::operator=;
88  * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped
89  * the usage of 'using'. This should be done only for operator=.
90  */
91  EIGEN_DEVICE_FUNC
92  EIGEN_STRONG_INLINE Array& operator=(const Scalar &value)
93  {
95  return *this;
96  }
97 
107  template<typename OtherDerived>
108  EIGEN_DEVICE_FUNC
109  EIGEN_STRONG_INLINE Array& operator=(const DenseBase<OtherDerived>& other)
110  {
111  return Base::_set(other);
112  }
113 
117  EIGEN_DEVICE_FUNC
118  EIGEN_STRONG_INLINE Array& operator=(const Array& other)
119  {
120  return Base::_set(other);
121  }
122 
133  EIGEN_DEVICE_FUNC
134  EIGEN_STRONG_INLINE Array() : Base()
135  {
136  EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
137  }
138 
139 #ifndef EIGEN_PARSED_BY_DOXYGEN
140  // FIXME is it still needed ??
142  EIGEN_DEVICE_FUNC
143  Array(internal::constructor_without_unaligned_array_assert)
144  : Base(internal::constructor_without_unaligned_array_assert())
145  {
146  EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
147  }
148 #endif
149 
150  EIGEN_DEVICE_FUNC
151  Array(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
152  : Base(std::move(other))
153  {
154  }
155  EIGEN_DEVICE_FUNC
156  Array& operator=(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
157  {
158  Base::operator=(std::move(other));
159  return *this;
160  }
161 
170  template <typename... ArgTypes>
171  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
172  Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
173  : Base(a0, a1, a2, a3, args...) {}
174 
196  EIGEN_DEVICE_FUNC
197  EIGEN_STRONG_INLINE Array(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {}
198 
199  #ifndef EIGEN_PARSED_BY_DOXYGEN
200  template<typename T>
201  EIGEN_DEVICE_FUNC
202  EIGEN_STRONG_INLINE explicit Array(const T& x)
203  {
204  Base::template _init1<T>(x);
205  }
206 
207  template<typename T0, typename T1>
208  EIGEN_DEVICE_FUNC
209  EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1)
210  {
211  this->template _init2<T0,T1>(val0, val1);
212  }
213 
214  #else
216  EIGEN_DEVICE_FUNC explicit Array(const Scalar *data);
223  EIGEN_DEVICE_FUNC
224  EIGEN_STRONG_INLINE explicit Array(Index dim);
227  Array(const Scalar& value);
233  Array(Index rows, Index cols);
236  Array(const Scalar& val0, const Scalar& val1);
237  #endif // end EIGEN_PARSED_BY_DOXYGEN
238 
242  EIGEN_DEVICE_FUNC
243  EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2)
244  {
245  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3)
246  m_storage.data()[0] = val0;
247  m_storage.data()[1] = val1;
248  m_storage.data()[2] = val2;
249  }
253  EIGEN_DEVICE_FUNC
254  EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2, const Scalar& val3)
255  {
256  EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4)
257  m_storage.data()[0] = val0;
258  m_storage.data()[1] = val1;
259  m_storage.data()[2] = val2;
260  m_storage.data()[3] = val3;
261  }
262 
264  EIGEN_DEVICE_FUNC
265  EIGEN_STRONG_INLINE Array(const Array& other)
266  : Base(other)
267  { }
268 
269  private:
270  struct PrivateType {};
271  public:
272 
274  template<typename OtherDerived>
275  EIGEN_DEVICE_FUNC
276  EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived> &other,
277  std::enable_if_t<internal::is_convertible<typename OtherDerived::Scalar,Scalar>::value,
278  PrivateType> = PrivateType())
279  : Base(other.derived())
280  { }
281 
282  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
283  inline Index innerStride() const EIGEN_NOEXCEPT{ return 1; }
284  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
285  inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
286 
287  #ifdef EIGEN_ARRAY_PLUGIN
288  #include EIGEN_ARRAY_PLUGIN
289  #endif
290 
291  private:
292 
293  template<typename MatrixType, typename OtherDerived, bool SwapPointers>
294  friend struct internal::matrix_swap_impl;
295 };
296 
322 #define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
323  \
324 typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix; \
325  \
326 typedef Array<Type, Size, 1> Array##SizeSuffix##TypeSuffix;
327 
328 #define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
329  \
330 typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix; \
331  \
332 typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix;
333 
334 #define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
335 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \
336 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \
337 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \
338 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
339 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
340 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
341 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
342 
343 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i)
344 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f)
345 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d)
346 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
347 EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
348 
349 #undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES
350 #undef EIGEN_MAKE_ARRAY_TYPEDEFS
351 #undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
352 
353 #define EIGEN_MAKE_ARRAY_TYPEDEFS(Size, SizeSuffix) \
354  \
355  \
356 template <typename Type> \
357 using Array##SizeSuffix##SizeSuffix = Array<Type, Size, Size>; \
358  \
359  \
360 template <typename Type> \
361 using Array##SizeSuffix = Array<Type, Size, 1>;
362 
363 #define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Size) \
364  \
365  \
366 template <typename Type> \
367 using Array##Size##X = Array<Type, Size, Dynamic>; \
368  \
369  \
370 template <typename Type> \
371 using Array##X##Size = Array<Type, Dynamic, Size>;
372 
373 EIGEN_MAKE_ARRAY_TYPEDEFS(2, 2)
374 EIGEN_MAKE_ARRAY_TYPEDEFS(3, 3)
375 EIGEN_MAKE_ARRAY_TYPEDEFS(4, 4)
376 EIGEN_MAKE_ARRAY_TYPEDEFS(Dynamic, X)
377 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(2)
378 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(3)
379 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(4)
380 
381 #undef EIGEN_MAKE_ARRAY_TYPEDEFS
382 #undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
383 
384 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
385 using Eigen::Matrix##SizeSuffix##TypeSuffix; \
386 using Eigen::Vector##SizeSuffix##TypeSuffix; \
387 using Eigen::RowVector##SizeSuffix##TypeSuffix;
388 
389 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \
390 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
391 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
392 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
393 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \
394 
395 #define EIGEN_USING_ARRAY_TYPEDEFS \
396 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \
397 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \
398 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \
399 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \
400 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd)
401 
402 } // end namespace Eigen
403 
404 #endif // EIGEN_ARRAY_H
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:49
Array(const Scalar &val0, const Scalar &val1, const Scalar &val2, const Scalar &val3)
Definition: Array.h:254
Array(const Array &other)
Definition: Array.h:265
Array(const EigenBase< OtherDerived > &other, std::enable_if_t< internal::is_convertible< typename OtherDerived::Scalar, Scalar >::value, PrivateType >=PrivateType())
Definition: Array.h:276
Array(const Scalar &val0, const Scalar &val1)
Array(const Scalar *data)
Constructs a fixed-sized array initialized with coefficients starting at data.
Array(const Scalar &val0, const Scalar &val1, const Scalar &val2)
Definition: Array.h:243
Array(Index rows, Index cols)
Array & operator=(const EigenBase< OtherDerived > &other)
Definition: Array.h:78
Array & operator=(const Array &other)
Definition: Array.h:118
Array()
Definition: Array.h:134
Array(const std::initializer_list< std::initializer_list< Scalar >> &list)
Constructs an array and initializes it from the coefficients given as initializer-lists grouped by ro...
Definition: Array.h:197
Array(const Scalar &a0, const Scalar &a1, const Scalar &a2, const Scalar &a3, const ArgTypes &... args)
Definition: Array.h:172
Array(Index dim)
Array & operator=(const Scalar &value)
Definition: Array.h:92
Array(const Scalar &value)
Array & operator=(const DenseBase< OtherDerived > &other)
Definition: Array.h:109
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:42
EIGEN_CONSTEXPR Index innerSize() const
Definition: DenseBase.h:224
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:61
CoeffReturnType value() const
Definition: DenseBase.h:515
Derived & derived()
Definition: EigenBase.h:48
Scalar & x()
Definition: DenseCoeffsBase.h:437
Dense storage base class for matrices and arrays.
Definition: PlainObjectBase.h:102
Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition: PlainObjectBase.h:775
const Scalar & coeff(Index rowId, Index colId) const
Definition: PlainObjectBase.h:164
Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:187
Derived & setConstant(Index size, const Scalar &val)
Definition: CwiseNullaryOp.h:363
Derived & operator=(const PlainObjectBase &other)
Definition: PlainObjectBase.h:461
Namespace containing all symbols from the Eigen library.
Definition: Core:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24
Definition: EigenBase.h:32
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41