Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
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 <[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_ARRAY_H
11#define EIGEN_ARRAY_H
12
13// IWYU pragma: private
14#include "./InternalHeaderCheck.h"
15
16namespace Eigen {
17
18namespace internal {
19template <typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
20struct traits<Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>>
21 : traits<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>> {
22 typedef ArrayXpr XprKind;
23 typedef ArrayBase<Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>> XprBase;
24};
25} // namespace internal
26
47template <typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
48class Array : public PlainObjectBase<Array<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>> {
49 public:
51 EIGEN_DENSE_PUBLIC_INTERFACE(Array)
52
53 enum { Options = Options_ };
54 typedef typename Base::PlainObject PlainObject;
55
56 protected:
57 template <typename Derived, typename OtherDerived, bool IsVector>
58 friend struct internal::conservative_resize_like_impl;
59
60 using Base::m_storage;
61
62 public:
63 using Base::base;
64 using Base::coeff;
65 using Base::coeffRef;
66
73 template <typename OtherDerived>
74 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived>& other) {
75 return Base::operator=(other);
76 }
77
81 /* This overload is needed because the usage of
82 * using Base::operator=;
83 * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped
84 * the usage of 'using'. This should be done only for operator=.
85 */
86 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array& operator=(const Scalar& value) {
88 return *this;
89 }
90
100 template <typename OtherDerived>
101 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array& operator=(const DenseBase<OtherDerived>& other) {
102 return Base::_set(other);
103 }
104
108 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array& operator=(const Array& other) { return Base::_set(other); }
109
120 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array() : Base() { EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
121
122#ifndef EIGEN_PARSED_BY_DOXYGEN
123 // FIXME is it still needed ??
125 EIGEN_DEVICE_FUNC Array(internal::constructor_without_unaligned_array_assert)
126 : Base(internal::constructor_without_unaligned_array_assert()){EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED}
127#endif
128
129 EIGEN_DEVICE_FUNC Array(Array && other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
130 : Base(std::move(other)) {
131 }
132 EIGEN_DEVICE_FUNC Array& operator=(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) {
133 Base::operator=(std::move(other));
134 return *this;
135 }
136
146 template <typename... ArgTypes>
147 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3,
148 const ArgTypes&... args)
149 : Base(a0, a1, a2, a3, args...) {}
150
174 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Array(
175 const std::initializer_list<std::initializer_list<Scalar>>& list)
176 : Base(list) {}
177
178#ifndef EIGEN_PARSED_BY_DOXYGEN
179 template <typename T>
180 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Array(const T& x) {
181 Base::template _init1<T>(x);
182 }
183
184 template <typename T0, typename T1>
185 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1) {
186 this->template _init2<T0, T1>(val0, val1);
187 }
188
189#else
191 EIGEN_DEVICE_FUNC explicit Array(const Scalar* data);
198 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Array(Index dim);
201 Array(const Scalar& value);
207 Array(Index rows, Index cols);
210 Array(const Scalar& val0, const Scalar& val1);
211#endif // end EIGEN_PARSED_BY_DOXYGEN
212
216 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2) {
217 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3)
218 m_storage.data()[0] = val0;
219 m_storage.data()[1] = val1;
220 m_storage.data()[2] = val2;
221 }
225 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2,
226 const Scalar& val3) {
227 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4)
228 m_storage.data()[0] = val0;
229 m_storage.data()[1] = val1;
230 m_storage.data()[2] = val2;
231 m_storage.data()[3] = val3;
232 }
233
235 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Array& other) : Base(other) {}
236
237 private:
238 struct PrivateType {};
239
240 public:
242 template <typename OtherDerived>
243 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(
244 const EigenBase<OtherDerived>& other,
245 std::enable_if_t<internal::is_convertible<typename OtherDerived::Scalar, Scalar>::value, PrivateType> =
246 PrivateType())
247 : Base(other.derived()) {}
248
249 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { return 1; }
250 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
251
252#ifdef EIGEN_ARRAY_PLUGIN
253#include EIGEN_ARRAY_PLUGIN
254#endif
255
256 private:
257 template <typename MatrixType, typename OtherDerived, bool SwapPointers>
258 friend struct internal::matrix_swap_impl;
259};
260
287#define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
288 \
289 typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix; \
290 \
291 typedef Array<Type, Size, 1> Array##SizeSuffix##TypeSuffix;
292
293#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
294 \
295 typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix; \
296 \
297 typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix;
298
299#define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
300 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \
301 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \
302 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \
303 EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
304 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
305 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
306 EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
307
308EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i)
309EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f)
310EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d)
311EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
312EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
313
314#undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES
315#undef EIGEN_MAKE_ARRAY_TYPEDEFS
316#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
317
318#define EIGEN_MAKE_ARRAY_TYPEDEFS(Size, SizeSuffix) \
319 \
320 \
321 template <typename Type> \
322 using Array##SizeSuffix##SizeSuffix = Array<Type, Size, Size>; \
323 \
324 \
325 template <typename Type> \
326 using Array##SizeSuffix = Array<Type, Size, 1>;
327
328#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Size) \
329 \
330 \
331 template <typename Type> \
332 using Array##Size##X = Array<Type, Size, Dynamic>; \
333 \
334 \
335 template <typename Type> \
336 using Array##X##Size = Array<Type, Dynamic, Size>;
337
338EIGEN_MAKE_ARRAY_TYPEDEFS(2, 2)
339EIGEN_MAKE_ARRAY_TYPEDEFS(3, 3)
340EIGEN_MAKE_ARRAY_TYPEDEFS(4, 4)
341EIGEN_MAKE_ARRAY_TYPEDEFS(Dynamic, X)
342EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(2)
343EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(3)
344EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(4)
345
346#undef EIGEN_MAKE_ARRAY_TYPEDEFS
347#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
348
349#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
350 using Eigen::Matrix##SizeSuffix##TypeSuffix; \
351 using Eigen::Vector##SizeSuffix##TypeSuffix; \
352 using Eigen::RowVector##SizeSuffix##TypeSuffix;
353
354#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \
355 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
356 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
357 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
358 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X)
359
360#define EIGEN_USING_ARRAY_TYPEDEFS \
361 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \
362 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \
363 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \
364 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \
365 EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd)
366
367} // end namespace Eigen
368
369#endif // EIGEN_ARRAY_H
General-purpose arrays with easy API for coefficient-wise operations.
Definition Array.h:48
Array(const Scalar &val0, const Scalar &val1, const Scalar &val2, const Scalar &val3)
Definition Array.h:225
Array(const Array &other)
Definition Array.h:235
Array & operator=(const Array &other)
Definition Array.h:108
Array(const EigenBase< OtherDerived > &other, std::enable_if_t< internal::is_convertible< typename OtherDerived::Scalar, Scalar >::value, PrivateType >=PrivateType())
Definition Array.h:243
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:216
Array(Index rows, Index cols)
Array()
Definition Array.h:120
Array & operator=(const Scalar &value)
Definition Array.h:86
Array(const Scalar &a0, const Scalar &a1, const Scalar &a2, const Scalar &a3, const ArgTypes &... args)
Definition Array.h:147
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:174
Array(Index dim)
Array & operator=(const DenseBase< OtherDerived > &other)
Definition Array.h:101
Array & operator=(const EigenBase< OtherDerived > &other)
Definition Array.h:74
Array(const Scalar &value)
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:44
EIGEN_CONSTEXPR Index innerSize() const
Definition DenseBase.h:220
CoeffReturnType value() const
Definition DenseBase.h:479
Derived & derived()
Definition EigenBase.h:49
EIGEN_CONSTEXPR Scalar & x()
Definition DenseCoeffsBase.h:372
Dense storage base class for matrices and arrays.
Definition PlainObjectBase.h:121
constexpr const Scalar & coeff(Index rowId, Index colId) const
Definition PlainObjectBase.h:198
constexpr Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition PlainObjectBase.h:755
Derived & setConstant(Index size, const Scalar &val)
Definition CwiseNullaryOp.h:360
constexpr Derived & operator=(const PlainObjectBase &other)
Definition PlainObjectBase.h:455
constexpr Scalar & coeffRef(Index rowId, Index colId)
Definition PlainObjectBase.h:217
Namespace containing all symbols from the Eigen library.
Definition Core:137
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:83
Definition EigenBase.h:33