Eigen/Eigen/src/Core/Matrix.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) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
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 
17 namespace Eigen {
18 
19 namespace internal {
20 template <typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
21 struct traits<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>> {
22  private:
23  constexpr static int size = internal::size_at_compile_time(Rows_, Cols_);
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_,
30  actual_alignment = ((Options_ & DontAlign) == 0) ? default_alignment : 0,
32  packet_access_bit = (packet_traits<Scalar_>::Vectorizable &&
33  (EIGEN_UNALIGNED_VECTORIZE || (int(actual_alignment) >= int(required_alignment))))
35  : 0
36  };
37 
38  public:
39  typedef Scalar_ Scalar;
40  typedef Dense StorageKind;
42  typedef MatrixXpr XprKind;
43  enum {
44  RowsAtCompileTime = Rows_,
45  ColsAtCompileTime = Cols_,
46  MaxRowsAtCompileTime = MaxRows_,
47  MaxColsAtCompileTime = MaxCols_,
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 
185 template <typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
186 class Matrix : public PlainObjectBase<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>> {
187  public:
192 
193  enum { Options = Options_ };
194 
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>
224  return Base::_set(other);
225  }
226 
227  /* Here, doxygen failed to copy the brief information when using \copydoc */
228 
233  template <typename OtherDerived>
235  return Base::operator=(other);
236  }
237 
238  template <typename OtherDerived>
240  return Base::operator=(func);
241  }
242 
253 #if defined(EIGEN_INITIALIZE_COEFFS)
255 #else
257 #endif
265  Base::operator=(std::move(other));
266  return *this;
267  }
268 
276  template <typename... ArgTypes>
277  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3,
278  const ArgTypes&... args)
279  : Base(a0, a1, a2, a3, args...) {}
280 
305  const std::initializer_list<std::initializer_list<Scalar>>& list)
306  : Base(list) {}
307 
308 #ifndef EIGEN_PARSED_BY_DOXYGEN
309 
310  // This constructor is for both 1x1 matrices and dynamic vectors
311  template <typename T>
313  Base::template _init1<T>(x);
314  }
315 
316  template <typename T0, typename T1>
318  Base::template _init2<T0, T1>(x, y);
319  }
320 
321 #else
323  EIGEN_DEVICE_FUNC explicit Matrix(const Scalar* data);
324 
337  EIGEN_STRONG_INLINE explicit Matrix(Index dim);
340  Matrix(const Scalar& x);
354 
357  Matrix(const Scalar& x, const Scalar& y);
358 #endif // end EIGEN_PARSED_BY_DOXYGEN
359 
365  m_storage.data()[0] = x;
366  m_storage.data()[1] = y;
367  m_storage.data()[2] = z;
368  }
374  m_storage.data()[0] = x;
375  m_storage.data()[1] = y;
376  m_storage.data()[2] = z;
377  m_storage.data()[3] = w;
378  }
379 
381  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix(const Matrix&) = default;
382 
386  template <typename OtherDerived>
388 
390  EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
391 
393 
394  template <typename OtherDerived>
396  template <typename OtherDerived>
398 
399 // allow to extend Matrix outside Eigen
400 #ifdef EIGEN_MATRIX_PLUGIN
401 #include EIGEN_MATRIX_PLUGIN
402 #endif
403 
404  protected:
405  template <typename Derived, typename OtherDerived, bool IsVector>
407 
408  using Base::m_storage;
409 };
410 
442 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
443  \
444  \
445  typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
446  \
447  \
448  typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
449  \
450  \
451  typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
452 
453 #define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
454  \
455  \
456  typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
457  \
458  \
459  typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
460 
461 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
462  EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
463  EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
464  EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
465  EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
466  EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
467  EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
468  EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
469 
473 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
474 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
475 
476 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
477 #undef EIGEN_MAKE_TYPEDEFS
478 #undef EIGEN_MAKE_FIXED_TYPEDEFS
479 
480 #define EIGEN_MAKE_TYPEDEFS(Size, SizeSuffix) \
481  \
482  \
483  template <typename Type> \
484  using Matrix##SizeSuffix = Matrix<Type, Size, Size>; \
485  \
486  \
487  template <typename Type> \
488  using Vector##SizeSuffix = Matrix<Type, Size, 1>; \
489  \
490  \
491  template <typename Type> \
492  using RowVector##SizeSuffix = Matrix<Type, 1, Size>;
493 
494 #define EIGEN_MAKE_FIXED_TYPEDEFS(Size) \
495  \
496  \
497  template <typename Type> \
498  using Matrix##Size##X = Matrix<Type, Size, Dynamic>; \
499  \
500  \
501  template <typename Type> \
502  using Matrix##X##Size = Matrix<Type, Dynamic, Size>;
503 
511 
514 template <typename Type, int Size>
515 using Vector = Matrix<Type, Size, 1>;
516 
519 template <typename Type, int Size>
520 using RowVector = Matrix<Type, 1, Size>;
521 
522 #undef EIGEN_MAKE_TYPEDEFS
523 #undef EIGEN_MAKE_FIXED_TYPEDEFS
524 
525 } // end namespace Eigen
526 
527 #endif // EIGEN_MATRIX_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_UNALIGNED_VECTORIZE
Definition: ConfigureVectorization.h:173
#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix)
Definition: Eigen/Eigen/src/Core/Matrix.h:480
#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix)
Definition: Eigen/Eigen/src/Core/Matrix.h:461
#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size)
Definition: Eigen/Eigen/src/Core/Matrix.h:494
#define EIGEN_NOEXCEPT_IF(x)
Definition: Macros.h:1268
#define EIGEN_NOEXCEPT
Definition: Macros.h:1267
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1171
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
RowVector3d w
Definition: Matrix_resize_int.cpp:3
#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
Definition: PlainObjectBase.h:24
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:50
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:44
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:217
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w)
Constructs an initialized 4D vector with given coefficients.
Definition: Eigen/Eigen/src/Core/Matrix.h:372
@ Options
Definition: Eigen/Eigen/src/Core/Matrix.h:193
Base::PlainObject PlainObject
Definition: Eigen/Eigen/src/Core/Matrix.h:197
DenseStorage< Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options > m_storage
Definition: PlainObjectBase.h:164
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Matrix & operator=(Matrix &&other) EIGEN_NOEXCEPT_IF(std
Moves the matrix into the other one.
Definition: Eigen/Eigen/src/Core/Matrix.h:263
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Matrix(Matrix &&)=default
Move constructor.
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT
Definition: Eigen/Eigen/src/Core/Matrix.h:390
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Matrix(const Matrix &)=default
Copy constructor.
EIGEN_DEVICE_FUNC const Base & base() const
Definition: PlainObjectBase.h:189
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const T0 &x, const T1 &y)
Definition: Eigen/Eigen/src/Core/Matrix.h:317
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 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: Eigen/Eigen/src/Core/Matrix.h:304
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix & operator=(const ReturnByValue< OtherDerived > &func)
Definition: Eigen/Eigen/src/Core/Matrix.h:239
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix & operator=(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition: Eigen/Eigen/src/Core/Matrix.h:223
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const EigenBase< OtherDerived > &other)
Copy constructor for generic expressions.
Definition: Eigen/Eigen/src/Core/Matrix.h:387
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix & operator=(const EigenBase< OtherDerived > &other)
Copies the generic expression other into *this.
Definition: Eigen/Eigen/src/Core/Matrix.h:234
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const T &x)
Definition: Eigen/Eigen/src/Core/Matrix.h:312
PlainObjectBase< Matrix > Base
Base class typedef.
Definition: Eigen/Eigen/src/Core/Matrix.h:191
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar &a0, const Scalar &a1, const Scalar &a2, const Scalar &a3, const ArgTypes &... args)
Definition: Eigen/Eigen/src/Core/Matrix.h:277
EIGEN_DEVICE_FUNC Matrix & operator=(const RotationBase< OtherDerived, ColsAtCompileTime > &r)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Scalar &x, const Scalar &y, const Scalar &z)
Constructs an initialized 3D vector with given coefficients.
Definition: Eigen/Eigen/src/Core/Matrix.h:363
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Matrix()=default
Default constructor.
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerStride() const EIGEN_NOEXCEPT
Definition: Eigen/Eigen/src/Core/Matrix.h:389
Definition: PlainObjectBase.h:121
DenseStorage< Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options > m_storage
Definition: PlainObjectBase.h:164
constexpr EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: PlainObjectBase.h:273
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:192
internal::traits< Matrix< Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_ > >::Scalar Scalar
Definition: PlainObjectBase.h:127
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition: PlainObjectBase.h:743
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Derived & operator=(const PlainObjectBase &other)
Definition: PlainObjectBase.h:455
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:191
Definition: ReturnByValue.h:50
Common base class for compact rotation representations.
Definition: RotationBase.h:32
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE T * data()
Definition: DenseStorage.h:122
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
@ DontAlign
Definition: Constants.h:324
@ RowMajor
Definition: Constants.h:320
const unsigned int PacketAccessBit
Definition: Constants.h:97
const unsigned int LinearAccessBit
Definition: Constants.h:133
const unsigned int DirectAccessBit
Definition: Constants.h:159
const unsigned int RowMajorBit
Definition: Constants.h:70
#define X
Definition: icosphere.cpp:20
Scalar * y
Definition: level1_cplx_impl.h:128
return int(ret)+1
constexpr unsigned compute_matrix_flags(int Options)
Definition: XprHelper.h:365
constexpr int size_at_compile_time(int rows, int cols)
Definition: XprHelper.h:373
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
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
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56
r
Definition: UniformPSDSelfTest.py:20
args
Definition: compute_granudrum_aor.py:143
Definition: Eigen_Colamd.h:49
list x
Definition: plotDoE.py:28
Type
Type of JSON value.
Definition: rapidjson.h:513
Definition: Constants.h:519
Definition: EigenBase.h:33
Definition: Constants.h:534
Definition: PlainObjectBase.h:931
find_best_packet_helper< Size, typename packet_traits< T >::type >::type type
Definition: XprHelper.h:290
Definition: GenericPacketMath.h:108
find_best_packet< Scalar_, size >::type PacketScalar
Definition: Eigen/Eigen/src/Core/Matrix.h:24
Eigen::Index StorageIndex
Definition: Eigen/Eigen/src/Core/Matrix.h:41
Definition: ForwardDeclarations.h:21
Definition: GenericPacketMath.h:134
Definition: benchGeometry.cpp:21