Array.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 // 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 
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>
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  */
92  EIGEN_STRONG_INLINE Array& operator=(const Scalar &value)
93  {
95  return *this;
96  }
97 
107  template<typename OtherDerived>
109  EIGEN_STRONG_INLINE Array& operator=(const DenseBase<OtherDerived>& other)
110  {
111  return Base::_set(other);
112  }
113 
118  EIGEN_STRONG_INLINE Array& operator=(const Array& other)
119  {
120  return Base::_set(other);
121  }
122 
134  EIGEN_STRONG_INLINE Array() : Base()
135  {
137  }
138 
139 #ifndef EIGEN_PARSED_BY_DOXYGEN
140  // FIXME is it still needed ??
143  Array(internal::constructor_without_unaligned_array_assert)
144  : Base(internal::constructor_without_unaligned_array_assert())
145  {
147  }
148 #endif
149 
151  Array(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
152  : Base(std::move(other))
153  {
154  }
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 EIGEN_STRONG_INLINE constexpr Array(
197  const std::initializer_list<std::initializer_list<Scalar>>& list)
198  : Base(list) {}
199 
200  #ifndef EIGEN_PARSED_BY_DOXYGEN
201  template<typename T>
203  EIGEN_STRONG_INLINE explicit Array(const T& x)
204  {
205  Base::template _init1<T>(x);
206  }
207 
208  template<typename T0, typename T1>
210  EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1)
211  {
212  this->template _init2<T0,T1>(val0, val1);
213  }
214 
215  #else
217  EIGEN_DEVICE_FUNC explicit Array(const Scalar *data);
225  EIGEN_STRONG_INLINE explicit Array(Index dim);
228  Array(const Scalar& value);
237  Array(const Scalar& val0, const Scalar& val1);
238  #endif // end EIGEN_PARSED_BY_DOXYGEN
239 
244  EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2)
245  {
247  m_storage.data()[0] = val0;
248  m_storage.data()[1] = val1;
249  m_storage.data()[2] = val2;
250  }
255  EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2, const Scalar& val3)
256  {
258  m_storage.data()[0] = val0;
259  m_storage.data()[1] = val1;
260  m_storage.data()[2] = val2;
261  m_storage.data()[3] = val3;
262  }
263 
266  EIGEN_STRONG_INLINE Array(const Array& other)
267  : Base(other)
268  { }
269 
270  private:
271  struct PrivateType {};
272  public:
273 
275  template<typename OtherDerived>
277  EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived> &other,
278  std::enable_if_t<internal::is_convertible<typename OtherDerived::Scalar,Scalar>::value,
280  : Base(other.derived())
281  { }
282 
284  inline Index innerStride() const EIGEN_NOEXCEPT{ return 1; }
286  inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
287 
288  #ifdef EIGEN_ARRAY_PLUGIN
289  #include EIGEN_ARRAY_PLUGIN
290  #endif
291 
292  private:
293 
294  template<typename MatrixType, typename OtherDerived, bool SwapPointers>
295  friend struct internal::matrix_swap_impl;
296 };
297 
323 #define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
324  \
325 typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix; \
326  \
327 typedef Array<Type, Size, 1> Array##SizeSuffix##TypeSuffix;
328 
329 #define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
330  \
331 typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix; \
332  \
333 typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix;
334 
335 #define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
336 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \
337 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \
338 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \
339 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
340 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
341 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
342 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
343 
349 
350 #undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES
351 #undef EIGEN_MAKE_ARRAY_TYPEDEFS
352 #undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
353 
354 #define EIGEN_MAKE_ARRAY_TYPEDEFS(Size, SizeSuffix) \
355  \
356  \
357 template <typename Type> \
358 using Array##SizeSuffix##SizeSuffix = Array<Type, Size, Size>; \
359  \
360  \
361 template <typename Type> \
362 using Array##SizeSuffix = Array<Type, Size, 1>;
363 
364 #define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Size) \
365  \
366  \
367 template <typename Type> \
368 using Array##Size##X = Array<Type, Size, Dynamic>; \
369  \
370  \
371 template <typename Type> \
372 using Array##X##Size = Array<Type, Dynamic, Size>;
373 
381 
382 #undef EIGEN_MAKE_ARRAY_TYPEDEFS
383 #undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
384 
385 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
386 using Eigen::Matrix##SizeSuffix##TypeSuffix; \
387 using Eigen::Vector##SizeSuffix##TypeSuffix; \
388 using Eigen::RowVector##SizeSuffix##TypeSuffix;
389 
390 #define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \
391 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
392 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
393 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
394 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \
395 
396 #define EIGEN_USING_ARRAY_TYPEDEFS \
397 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \
398 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \
399 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \
400 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \
401 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd)
402 
403 } // end namespace Eigen
404 
405 #endif // EIGEN_ARRAY_H
#define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix)
Definition: Array.h:335
#define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix)
Definition: Array.h:354
#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size)
Definition: Array.h:364
#define EIGEN_NOEXCEPT_IF(x)
Definition: Macros.h:1261
#define EIGEN_NOEXCEPT
Definition: Macros.h:1260
#define EIGEN_CONSTEXPR
Definition: Macros.h:747
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1168
#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:51
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:49
Array & operator=(Array &&other) EIGEN_NOEXCEPT_IF(std
Definition: Array.h:156
Array(const Scalar &val0, const Scalar &val1, const Scalar &val2, const Scalar &val3)
Definition: Array.h:255
@ Options
Definition: Array.h:55
Array(const Array &other)
Definition: Array.h:266
DenseStorage< Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options > m_storage
Array(const EigenBase< OtherDerived > &other, std::enable_if_t< internal::is_convertible< typename OtherDerived::Scalar, Scalar >::value, PrivateType >=PrivateType())
Definition: Array.h:277
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:244
constexpr 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:196
Array(Index rows, Index cols)
Array & operator=(const EigenBase< OtherDerived > &other)
Definition: Array.h:78
Array & operator=(const Array &other)
Definition: Array.h:118
EIGEN_CONSTEXPR Index innerStride() const EIGEN_NOEXCEPT
Definition: Array.h:284
Array(const Scalar &a0, const Scalar &a1, const Scalar &a2, const Scalar &a3, const ArgTypes &... args)
Definition: Array.h:172
Array(Index dim)
EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT
Definition: Array.h:286
Array & operator=(const Scalar &value)
Definition: Array.h:92
PlainObjectBase< Array > Base
Definition: Array.h:52
Array(const Scalar &value)
Base::PlainObject PlainObject
Definition: Array.h:56
Array(Array &&other) EIGEN_NOEXCEPT_IF(std
Definition: Array.h:151
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:524
Dense storage base class for matrices and arrays.
Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
DenseStorage< Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options > m_storage
constexpr const Scalar & coeff(Index rowId, Index colId) const
const Base & base() const
Derived & setConstant(Index size, const Scalar &val)
constexpr Scalar & coeffRef(Index rowId, Index colId)
Derived & operator=(const PlainObjectBase &other)
: InteropHeaders
Definition: Core:139
const int Dynamic
Definition: Constants.h:24
Definition: BFloat16.h:222
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41