Medial Code Documentation
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 <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
13namespace Eigen {
14
15namespace internal {
16template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
17struct traits<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > : traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
18{
19 typedef ArrayXpr XprKind;
21};
22}
23
44template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
45class Array
46 : public PlainObjectBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
47{
48 public:
49
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>
59
60 using Base::m_storage;
61
62 public:
63
64 using Base::base;
65 using Base::coeff;
66 using Base::coeffRef;
67
74 template<typename OtherDerived>
75 EIGEN_DEVICE_FUNC
76 EIGEN_STRONG_INLINE Array& operator=(const EigenBase<OtherDerived> &other)
77 {
78 return Base::operator=(other);
79 }
80
84 /* This overload is needed because the usage of
85 * using Base::operator=;
86 * fails on MSVC. Since the code below is working with GCC and MSVC, we skipped
87 * the usage of 'using'. This should be done only for operator=.
88 */
89 EIGEN_DEVICE_FUNC
90 EIGEN_STRONG_INLINE Array& operator=(const Scalar &value)
91 {
92 Base::setConstant(value);
93 return *this;
94 }
95
105 template<typename OtherDerived>
106 EIGEN_DEVICE_FUNC
107 EIGEN_STRONG_INLINE Array& operator=(const DenseBase<OtherDerived>& other)
108 {
109 return Base::_set(other);
110 }
111
115 EIGEN_DEVICE_FUNC
116 EIGEN_STRONG_INLINE Array& operator=(const Array& other)
117 {
118 return Base::_set(other);
119 }
120
131 EIGEN_DEVICE_FUNC
132 EIGEN_STRONG_INLINE Array() : Base()
133 {
134 Base::_check_template_params();
135 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
136 }
137
138#ifndef EIGEN_PARSED_BY_DOXYGEN
139 // FIXME is it still needed ??
141 EIGEN_DEVICE_FUNC
143 : Base(internal::constructor_without_unaligned_array_assert())
144 {
145 Base::_check_template_params();
146 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
147 }
148#endif
149
150#if EIGEN_HAS_RVALUE_REFERENCES
151 EIGEN_DEVICE_FUNC
152 Array(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
153 : Base(std::move(other))
154 {
155 Base::_check_template_params();
156 }
157 EIGEN_DEVICE_FUNC
158 Array& operator=(Array&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
159 {
160 Base::operator=(std::move(other));
161 return *this;
162 }
163#endif
164
165 #if EIGEN_HAS_CXX11
182 template <typename... ArgTypes>
183 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
184 Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
185 : Base(a0, a1, a2, a3, args...) {}
186
208 EIGEN_DEVICE_FUNC
209 EIGEN_STRONG_INLINE Array(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {}
210 #endif // end EIGEN_HAS_CXX11
211
212 #ifndef EIGEN_PARSED_BY_DOXYGEN
213 template<typename T>
214 EIGEN_DEVICE_FUNC
215 EIGEN_STRONG_INLINE explicit Array(const T& x)
216 {
217 Base::_check_template_params();
218 Base::template _init1<T>(x);
219 }
220
221 template<typename T0, typename T1>
222 EIGEN_DEVICE_FUNC
223 EIGEN_STRONG_INLINE Array(const T0& val0, const T1& val1)
224 {
225 Base::_check_template_params();
226 this->template _init2<T0,T1>(val0, val1);
227 }
228
229 #else
231 EIGEN_DEVICE_FUNC explicit Array(const Scalar *data);
238 EIGEN_DEVICE_FUNC
239 EIGEN_STRONG_INLINE explicit Array(Index dim);
242 Array(const Scalar& value);
248 Array(Index rows, Index cols);
251 Array(const Scalar& val0, const Scalar& val1);
252 #endif // end EIGEN_PARSED_BY_DOXYGEN
253
257 EIGEN_DEVICE_FUNC
258 EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2)
259 {
260 Base::_check_template_params();
261 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 3)
262 m_storage.data()[0] = val0;
263 m_storage.data()[1] = val1;
264 m_storage.data()[2] = val2;
265 }
269 EIGEN_DEVICE_FUNC
270 EIGEN_STRONG_INLINE Array(const Scalar& val0, const Scalar& val1, const Scalar& val2, const Scalar& val3)
271 {
272 Base::_check_template_params();
273 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Array, 4)
274 m_storage.data()[0] = val0;
275 m_storage.data()[1] = val1;
276 m_storage.data()[2] = val2;
277 m_storage.data()[3] = val3;
278 }
279
281 EIGEN_DEVICE_FUNC
282 EIGEN_STRONG_INLINE Array(const Array& other)
283 : Base(other)
284 { }
285
286 private:
287 struct PrivateType {};
288 public:
289
291 template<typename OtherDerived>
292 EIGEN_DEVICE_FUNC
293 EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived> &other,
295 PrivateType>::type = PrivateType())
296 : Base(other.derived())
297 { }
298
299 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
300 inline Index innerStride() const EIGEN_NOEXCEPT{ return 1; }
301 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
302 inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
303
304 #ifdef EIGEN_ARRAY_PLUGIN
305 #include EIGEN_ARRAY_PLUGIN
306 #endif
307
308 private:
309
310 template<typename MatrixType, typename OtherDerived, bool SwapPointers>
311 friend struct internal::matrix_swap_impl;
312};
313
339#define EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
340 \
341typedef Array<Type, Size, Size> Array##SizeSuffix##SizeSuffix##TypeSuffix; \
342 \
343typedef Array<Type, Size, 1> Array##SizeSuffix##TypeSuffix;
344
345#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
346 \
347typedef Array<Type, Size, Dynamic> Array##Size##X##TypeSuffix; \
348 \
349typedef Array<Type, Dynamic, Size> Array##X##Size##TypeSuffix;
350
351#define EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
352EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 2, 2) \
353EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 3, 3) \
354EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, 4, 4) \
355EIGEN_MAKE_ARRAY_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
356EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
357EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
358EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
359
360EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(int, i)
361EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(float, f)
362EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(double, d)
363EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
364EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
365
366#undef EIGEN_MAKE_ARRAY_TYPEDEFS_ALL_SIZES
367#undef EIGEN_MAKE_ARRAY_TYPEDEFS
368#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
369
370#if EIGEN_HAS_CXX11
371
372#define EIGEN_MAKE_ARRAY_TYPEDEFS(Size, SizeSuffix) \
373 \
374 \
375template <typename Type> \
376using Array##SizeSuffix##SizeSuffix = Array<Type, Size, Size>; \
377 \
378 \
379template <typename Type> \
380using Array##SizeSuffix = Array<Type, Size, 1>;
381
382#define EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(Size) \
383 \
384 \
385template <typename Type> \
386using Array##Size##X = Array<Type, Size, Dynamic>; \
387 \
388 \
389template <typename Type> \
390using Array##X##Size = Array<Type, Dynamic, Size>;
391
392EIGEN_MAKE_ARRAY_TYPEDEFS(2, 2)
393EIGEN_MAKE_ARRAY_TYPEDEFS(3, 3)
394EIGEN_MAKE_ARRAY_TYPEDEFS(4, 4)
395EIGEN_MAKE_ARRAY_TYPEDEFS(Dynamic, X)
396EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(2)
397EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(3)
398EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS(4)
399
400#undef EIGEN_MAKE_ARRAY_TYPEDEFS
401#undef EIGEN_MAKE_ARRAY_FIXED_TYPEDEFS
402
403#endif // EIGEN_HAS_CXX11
404
405#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, SizeSuffix) \
406using Eigen::Matrix##SizeSuffix##TypeSuffix; \
407using Eigen::Vector##SizeSuffix##TypeSuffix; \
408using Eigen::RowVector##SizeSuffix##TypeSuffix;
409
410#define EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(TypeSuffix) \
411EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 2) \
412EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 3) \
413EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, 4) \
414EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE_AND_SIZE(TypeSuffix, X) \
415
416#define EIGEN_USING_ARRAY_TYPEDEFS \
417EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(i) \
418EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(f) \
419EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(d) \
420EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cf) \
421EIGEN_USING_ARRAY_TYPEDEFS_FOR_TYPE(cd)
422
423} // end namespace Eigen
424
425#endif // EIGEN_ARRAY_H
General-purpose arrays with easy API for coefficient-wise operations.
Definition Array.h:47
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Array &other)
Copy constructor.
Definition Array.h:282
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array & operator=(const EigenBase< OtherDerived > &other)
The usage of using Base::operator=; fails on MSVC.
Definition Array.h:76
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array & operator=(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition Array.h:107
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array & operator=(const Scalar &value)
Set all the entries to value.
Definition Array.h:90
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array()
Default constructor.
Definition Array.h:132
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const EigenBase< OtherDerived > &other, typename internal::enable_if< internal::is_convertible< typename OtherDerived::Scalar, Scalar >::value, PrivateType >::type=PrivateType())
Definition Array.h:293
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Scalar &val0, const Scalar &val1, const Scalar &val2, const Scalar &val3)
constructs an initialized 4D vector with given coefficients
Definition Array.h:270
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array(const Scalar &val0, const Scalar &val1, const Scalar &val2)
constructs an initialized 3D vector with given coefficients
Definition Array.h:258
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Array & operator=(const Array &other)
This is a special case of the templated operator=.
Definition Array.h:116
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Definition PlainObjectBase.h:100
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Definition PlainObjectBase.h:247
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator=(const PlainObjectBase &other)
This is a special case of the templated operator=.
Definition PlainObjectBase.h:449
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index,...
Definition PlainObjectBase.h:152
EIGEN_DEVICE_FUNC Derived & setConstant(Index size, const Scalar &val)
Resizes to the given size, and sets all coefficients in this expression to the given value val.
Definition CwiseNullaryOp.h:361
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,...
Definition PlainObjectBase.h:175
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition PlainObjectBase.h:777
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Definition BFloat16.h:88
The type used to identify an array expression.
Definition Constants.h:525
Definition PlainObjectBase.h:1001
Definition Meta.h:262
Definition Meta.h:247
Definition ForwardDeclarations.h:17