Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
Matrix.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2006-2010 Benoit Jacob <[email protected]>
5// Copyright (C) 2008-2009 Gael Guennebaud <[email protected]>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_MATRIX_H
12#define EIGEN_MATRIX_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20template <typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
21struct traits<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>> {
22 private:
23 constexpr static int size = internal::size_at_compile_time(Rows_, Cols_);
24 typedef typename find_best_packet<Scalar_, size>::type PacketScalar;
25 enum {
26 row_major_bit = Options_ & RowMajor ? RowMajorBit : 0,
27 is_dynamic_size_storage = MaxRows_ == Dynamic || MaxCols_ == Dynamic,
28 max_size = is_dynamic_size_storage ? Dynamic : MaxRows_ * MaxCols_,
29 default_alignment = compute_default_alignment<Scalar_, max_size>::value,
30 actual_alignment = ((Options_ & DontAlign) == 0) ? default_alignment : 0,
31 required_alignment = unpacket_traits<PacketScalar>::alignment,
32 packet_access_bit = (packet_traits<Scalar_>::Vectorizable &&
33 (EIGEN_UNALIGNED_VECTORIZE || (int(actual_alignment) >= int(required_alignment))))
34 ? PacketAccessBit
35 : 0
36 };
37
38 public:
39 typedef Scalar_ Scalar;
40 typedef Dense StorageKind;
41 typedef Eigen::Index StorageIndex;
42 typedef MatrixXpr XprKind;
43 enum {
44 RowsAtCompileTime = Rows_,
45 ColsAtCompileTime = Cols_,
46 MaxRowsAtCompileTime = MaxRows_,
47 MaxColsAtCompileTime = MaxCols_,
48 Flags = compute_matrix_flags(Options_),
49 Options = Options_,
50 InnerStrideAtCompileTime = 1,
51 OuterStrideAtCompileTime = (int(Options) & int(RowMajor)) ? ColsAtCompileTime : RowsAtCompileTime,
52
53 // FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase
54 EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit,
55 Alignment = actual_alignment
56 };
57};
58} // namespace internal
59
185template <typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
186class Matrix : public PlainObjectBase<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>> {
187 public:
192
193 enum { Options = Options_ };
194
195 EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
196
197 typedef typename Base::PlainObject PlainObject;
198
199 using Base::base;
200 using Base::coeffRef;
201
210 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix& operator=(const Matrix& other) { return Base::_set(other); }
211
222 template <typename OtherDerived>
223 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(const DenseBase<OtherDerived>& other) {
224 return Base::_set(other);
225 }
226
227 /* Here, doxygen failed to copy the brief information when using \copydoc */
228
233 template <typename OtherDerived>
234 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived>& other) {
235 return Base::operator=(other);
236 }
237
238 template <typename OtherDerived>
239 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func) {
240 return Base::operator=(func);
241 }
242
253 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix()
254 : Base(){EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED}
255
256 // FIXME is it still needed
257 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr explicit Matrix(
258 internal::constructor_without_unaligned_array_assert)
259 : Base(internal::constructor_without_unaligned_array_assert()){EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED}
260
261 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix(Matrix && other)
262 EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
263 : Base(std::move(other)) {}
264 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix& operator=(Matrix&& other)
265 EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) {
266 Base::operator=(std::move(other));
267 return *this;
268 }
269
277 template <typename... ArgTypes>
278 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3,
279 const ArgTypes&... args)
280 : Base(a0, a1, a2, a3, args...) {}
281
305 EIGEN_DEVICE_FUNC explicit constexpr EIGEN_STRONG_INLINE Matrix(
306 const std::initializer_list<std::initializer_list<Scalar>>& list)
307 : Base(list) {}
308
309#ifndef EIGEN_PARSED_BY_DOXYGEN
310
311 // This constructor is for both 1x1 matrices and dynamic vectors
312 template <typename T>
313 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Matrix(const T& x) {
314 Base::template _init1<T>(x);
315 }
316
317 template <typename T0, typename T1>
318 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const T0& x, const T1& y) {
319 Base::template _init2<T0, T1>(x, y);
320 }
321
322#else
324 EIGEN_DEVICE_FUNC explicit Matrix(const Scalar* data);
325
338 EIGEN_STRONG_INLINE explicit Matrix(Index dim);
341 Matrix(const Scalar& x);
354 EIGEN_DEVICE_FUNC Matrix(Index rows, Index cols);
355
358 Matrix(const Scalar& x, const Scalar& y);
359#endif // end EIGEN_PARSED_BY_DOXYGEN
360
364 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z) {
365 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
366 m_storage.data()[0] = x;
367 m_storage.data()[1] = y;
368 m_storage.data()[2] = z;
369 }
373 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w) {
374 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
375 m_storage.data()[0] = x;
376 m_storage.data()[1] = y;
377 m_storage.data()[2] = z;
378 m_storage.data()[3] = w;
379 }
380
382 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other) {}
383
387 template <typename OtherDerived>
388 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived>& other) : Base(other.derived()) {}
389
390 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index innerStride() const EIGEN_NOEXCEPT { return 1; }
391 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
392
394
395 template <typename OtherDerived>
396 EIGEN_DEVICE_FUNC explicit Matrix(const RotationBase<OtherDerived, ColsAtCompileTime>& r);
397 template <typename OtherDerived>
398 EIGEN_DEVICE_FUNC Matrix& operator=(const RotationBase<OtherDerived, ColsAtCompileTime>& r);
399
400// allow to extend Matrix outside Eigen
401#ifdef EIGEN_MATRIX_PLUGIN
402#include EIGEN_MATRIX_PLUGIN
403#endif
404
405 protected:
406 template <typename Derived, typename OtherDerived, bool IsVector>
407 friend struct internal::conservative_resize_like_impl;
408
409 using Base::m_storage;
410};
411
443#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
444 \
445 \
446 typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
447 \
448 \
449 typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
450 \
451 \
452 typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
453
454#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
455 \
456 \
457 typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
458 \
459 \
460 typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
461
462#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
463 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
464 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
465 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
466 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
467 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
468 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
469 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
470
471EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
472EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
473EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
474EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
475EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
476
477#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
478#undef EIGEN_MAKE_TYPEDEFS
479#undef EIGEN_MAKE_FIXED_TYPEDEFS
480
481#define EIGEN_MAKE_TYPEDEFS(Size, SizeSuffix) \
482 \
483 \
484 template <typename Type> \
485 using Matrix##SizeSuffix = Matrix<Type, Size, Size>; \
486 \
487 \
488 template <typename Type> \
489 using Vector##SizeSuffix = Matrix<Type, Size, 1>; \
490 \
491 \
492 template <typename Type> \
493 using RowVector##SizeSuffix = Matrix<Type, 1, Size>;
494
495#define EIGEN_MAKE_FIXED_TYPEDEFS(Size) \
496 \
497 \
498 template <typename Type> \
499 using Matrix##Size##X = Matrix<Type, Size, Dynamic>; \
500 \
501 \
502 template <typename Type> \
503 using Matrix##X##Size = Matrix<Type, Dynamic, Size>;
504
505EIGEN_MAKE_TYPEDEFS(2, 2)
506EIGEN_MAKE_TYPEDEFS(3, 3)
507EIGEN_MAKE_TYPEDEFS(4, 4)
508EIGEN_MAKE_TYPEDEFS(Dynamic, X)
509EIGEN_MAKE_FIXED_TYPEDEFS(2)
510EIGEN_MAKE_FIXED_TYPEDEFS(3)
511EIGEN_MAKE_FIXED_TYPEDEFS(4)
512
515template <typename Type, int Size>
516using Vector = Matrix<Type, Size, 1>;
517
520template <typename Type, int Size>
521using RowVector = Matrix<Type, 1, Size>;
522
523#undef EIGEN_MAKE_TYPEDEFS
524#undef EIGEN_MAKE_FIXED_TYPEDEFS
525
526} // end namespace Eigen
527
528#endif // EIGEN_MATRIX_H
Base class for all dense matrices, vectors, and arrays.
Definition DenseBase.h:44
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:62
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:186
constexpr Matrix(const std::initializer_list< std::initializer_list< Scalar > > &list)
Constructs a Matrix and initializes it from the coefficients given as initializer-lists grouped by ro...
Definition Matrix.h:305
Matrix(const Scalar &x, const Scalar &y, const Scalar &z)
Constructs an initialized 3D vector with given coefficients.
Definition Matrix.h:364
Matrix(Index dim)
Constructs a vector or row-vector with given dimension. This is only for vectors (either row-vectors ...
Matrix(const EigenBase< OtherDerived > &other)
Copy constructor for generic expressions.
Definition Matrix.h:388
Matrix(Index rows, Index cols)
Constructs an uninitialized matrix with rows rows and cols columns.
Matrix(const Scalar &a0, const Scalar &a1, const Scalar &a2, const Scalar &a3, const ArgTypes &... args)
Definition Matrix.h:278
Matrix(const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w)
Constructs an initialized 4D vector with given coefficients.
Definition Matrix.h:373
Matrix(const Matrix &other)
Copy constructor.
Definition Matrix.h:382
Matrix(const Scalar &x)
Constructs an initialized 1x1 matrix with the given coefficient.
Matrix(const Scalar *data)
Constructs a fixed-sized matrix initialized with coefficients starting at data.
constexpr Matrix()
Default constructor.
Definition Matrix.h:253
PlainObjectBase< Matrix > Base
Base class typedef.
Definition Matrix.h:191
constexpr Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition Matrix.h:210
Matrix(const Scalar &x, const Scalar &y)
Constructs an initialized 2D vector with given coefficients.
Matrix & operator=(const EigenBase< OtherDerived > &other)
Copies the generic expression other into *this.
Definition Matrix.h:234
Dense storage base class for matrices and arrays.
Definition PlainObjectBase.h:121
@ DontAlign
Definition Constants.h:324
@ RowMajor
Definition Constants.h:320
const unsigned int LinearAccessBit
Definition Constants.h:133
const unsigned int DirectAccessBit
Definition Constants.h:159
const unsigned int RowMajorBit
Definition Constants.h:70
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
const int Dynamic
Definition Constants.h:25
Definition EigenBase.h:33