NDDEM
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 namespace Eigen {
15 
16 namespace internal {
17 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
18 struct traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
19 {
20 private:
23  enum {
24  row_major_bit = _Options&RowMajor ? RowMajorBit : 0,
25  is_dynamic_size_storage = _MaxRows==Dynamic || _MaxCols==Dynamic,
26  max_size = is_dynamic_size_storage ? Dynamic : _MaxRows*_MaxCols,
28  actual_alignment = ((_Options&DontAlign)==0) ? default_alignment : 0,
30  packet_access_bit = (packet_traits<_Scalar>::Vectorizable && (EIGEN_UNALIGNED_VECTORIZE || (actual_alignment>=required_alignment))) ? PacketAccessBit : 0
31  };
32 
33 public:
34  typedef _Scalar Scalar;
35  typedef Dense StorageKind;
37  typedef MatrixXpr XprKind;
38  enum {
39  RowsAtCompileTime = _Rows,
40  ColsAtCompileTime = _Cols,
41  MaxRowsAtCompileTime = _MaxRows,
42  MaxColsAtCompileTime = _MaxCols,
44  Options = _Options,
45  InnerStrideAtCompileTime = 1,
46  OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
47 
48  // FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase
49  EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit,
50  Alignment = actual_alignment
51  };
52 };
53 }
54 
177 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
178 class Matrix
179  : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
180 {
181  public:
182 
187 
188  enum { Options = _Options };
189 
191 
192  typedef typename Base::PlainObject PlainObject;
193 
194  using Base::base;
195  using Base::coeffRef;
196 
207  {
208  return Base::_set(other);
209  }
210 
221  template<typename OtherDerived>
224  {
225  return Base::_set(other);
226  }
227 
228  /* Here, doxygen failed to copy the brief information when using \copydoc */
229 
234  template<typename OtherDerived>
237  {
238  return Base::operator=(other);
239  }
240 
241  template<typename OtherDerived>
244  {
245  return Base::operator=(func);
246  }
247 
259  Matrix() : Base()
260  {
263  }
264 
265  // FIXME is it still needed
268  : Base(internal::constructor_without_unaligned_array_assert())
270 
271 #if EIGEN_HAS_RVALUE_REFERENCES
274  : Base(std::move(other))
275  {
277  }
280  {
281  Base::operator=(std::move(other));
282  return *this;
283  }
284 #endif
285 
286 #if EIGEN_HAS_CXX11
294  template <typename... ArgTypes>
296  Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
297  : Base(a0, a1, a2, a3, args...) {}
298 
321  explicit EIGEN_STRONG_INLINE Matrix(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {}
322 #endif // end EIGEN_HAS_CXX11
323 
324 #ifndef EIGEN_PARSED_BY_DOXYGEN
325 
326  // This constructor is for both 1x1 matrices and dynamic vectors
327  template<typename T>
329  explicit Matrix(const T& x)
330  {
332  Base::template _init1<T>(x);
333  }
334 
335  template<typename T0, typename T1>
337  Matrix(const T0& x, const T1& y)
338  {
340  Base::template _init2<T0,T1>(x, y);
341  }
342 
343 
344 #else
347  explicit Matrix(const Scalar *data);
348 
361  EIGEN_STRONG_INLINE explicit Matrix(Index dim);
364  Matrix(const Scalar& x);
379 
382  Matrix(const Scalar& x, const Scalar& y);
383  #endif // end EIGEN_PARSED_BY_DOXYGEN
384 
389  EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
390  {
393  m_storage.data()[0] = x;
394  m_storage.data()[1] = y;
395  m_storage.data()[2] = z;
396  }
401  EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
402  {
405  m_storage.data()[0] = x;
406  m_storage.data()[1] = y;
407  m_storage.data()[2] = z;
408  m_storage.data()[3] = w;
409  }
410 
411 
414  EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other)
415  { }
416 
420  template<typename OtherDerived>
423  : Base(other.derived())
424  { }
425 
427  inline Index innerStride() const EIGEN_NOEXCEPT { return 1; }
429  inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
430 
432 
433  template<typename OtherDerived>
436  template<typename OtherDerived>
439 
440  // allow to extend Matrix outside Eigen
441  #ifdef EIGEN_MATRIX_PLUGIN
442  #include EIGEN_MATRIX_PLUGIN
443  #endif
444 
445  protected:
446  template <typename Derived, typename OtherDerived, bool IsVector>
448 
449  using Base::m_storage;
450 };
451 
481 #define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
482  \
483 typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
484  \
485 typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
486  \
487 typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
488 
489 #define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
490  \
491 typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
492  \
493 typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
494 
495 #define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
496 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
497 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
498 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
499 EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
500 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
501 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
502 EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
503 
507 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
508 EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
509 
510 #undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
511 #undef EIGEN_MAKE_TYPEDEFS
512 #undef EIGEN_MAKE_FIXED_TYPEDEFS
513 
514 #if EIGEN_HAS_CXX11
515 
516 #define EIGEN_MAKE_TYPEDEFS(Size, SizeSuffix) \
517  \
518  \
519 template <typename Type> \
520 using Matrix##SizeSuffix = Matrix<Type, Size, Size>; \
521  \
522  \
523 template <typename Type> \
524 using Vector##SizeSuffix = Matrix<Type, Size, 1>; \
525  \
526  \
527 template <typename Type> \
528 using RowVector##SizeSuffix = Matrix<Type, 1, Size>;
529 
530 #define EIGEN_MAKE_FIXED_TYPEDEFS(Size) \
531  \
532  \
533 template <typename Type> \
534 using Matrix##Size##X = Matrix<Type, Size, Dynamic>; \
535  \
536  \
537 template <typename Type> \
538 using Matrix##X##Size = Matrix<Type, Dynamic, Size>;
539 
547 
550 template <typename Type, int Size>
551 using Vector = Matrix<Type, Size, 1>;
552 
555 template <typename Type, int Size>
556 using RowVector = Matrix<Type, 1, Size>;
557 
558 #undef EIGEN_MAKE_TYPEDEFS
559 #undef EIGEN_MAKE_FIXED_TYPEDEFS
560 
561 #endif // EIGEN_HAS_CXX11
562 
563 } // end namespace Eigen
564 
565 #endif // EIGEN_MATRIX_H
#define EIGEN_UNALIGNED_VECTORIZE
Definition: ConfigureVectorization.h:186
#define EIGEN_NOEXCEPT_IF(x)
Definition: Macros.h:1419
#define EIGEN_NOEXCEPT
Definition: Macros.h:1418
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1283
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix)
Definition: Matrix.h:481
#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix)
Definition: Matrix.h:495
#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size)
Definition: Matrix.h:489
#define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
Definition: PlainObjectBase.h:22
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:157
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:47
EIGEN_DEVICE_FUNC const T * data() const
Definition: DenseStorage.h:266
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:180
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const T &x)
Definition: Matrix.h:329
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: Matrix.h:389
Base::PlainObject PlainObject
Definition: Matrix.h:192
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(internal::constructor_without_unaligned_array_assert)
Definition: Matrix.h:267
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix()
Default constructor.
Definition: Matrix.h:259
DenseStorage< Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options > m_storage
Definition: PlainObjectBase.h:131
EIGEN_DEVICE_FUNC Matrix & operator=(const RotationBase< OtherDerived, ColsAtCompileTime > &r)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:175
EIGEN_DEVICE_FUNC Base & base()
Definition: PlainObjectBase.h:138
@ Options
Definition: Matrix.h:188
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT
Definition: Matrix.h:429
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const T0 &x, const T1 &y)
Definition: Matrix.h:337
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerStride() const EIGEN_NOEXCEPT
Definition: Matrix.h:427
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix & operator=(const ReturnByValue< OtherDerived > &func)
Definition: Matrix.h:243
PlainObjectBase< Matrix > Base
Base class typedef.
Definition: Matrix.h:186
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition: Matrix.h:206
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix & operator=(const DenseBase< OtherDerived > &other)
Definition: Matrix.h:223
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix & operator=(const EigenBase< OtherDerived > &other)
Copies the generic expression other into *this.
Definition: Matrix.h:236
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const EigenBase< OtherDerived > &other)
Copy constructor for generic expressions.
Definition: Matrix.h:422
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(const Matrix &other)
Copy constructor.
Definition: Matrix.h:414
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: Matrix.h:401
Definition: PlainObjectBase.h:100
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void _check_template_params()
Definition: PlainObjectBase.h:968
DenseStorage< Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options > m_storage
Definition: PlainObjectBase.h:131
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:145
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived & operator=(const PlainObjectBase &other)
Definition: PlainObjectBase.h:449
internal::traits< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >::Scalar Scalar
Definition: PlainObjectBase.h:106
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
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Definition: PlainObjectBase.h:247
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:143
Definition: ReturnByValue.h:52
Common base class for compact rotation representations.
Definition: RotationBase.h:30
Definition: XprHelper.h:272
uint d
@ DontAlign
Definition: Constants.h:325
@ RowMajor
Definition: Constants.h:321
const unsigned int PacketAccessBit
Definition: Constants.h:94
const unsigned int LinearAccessBit
Definition: Constants.h:130
const unsigned int DirectAccessBit
Definition: Constants.h:155
const unsigned int RowMajorBit
Definition: Constants.h:66
const Scalar & y
Definition: MathFunctions.h:821
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
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
const int Dynamic
Definition: Constants.h:22
Flags
Special flags for archives.
Definition: cereal.hpp:185
Definition: document.h:416
Definition: json.hpp:5678
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282
Type
Type of JSON value.
Definition: rapidjson.h:644
Definition: Constants.h:507
Definition: EigenBase.h:30
Definition: Constants.h:522
Definition: PlainObjectBase.h:1001
find_best_packet_helper< Size, typename packet_traits< T >::type >::type type
Definition: XprHelper.h:208
Definition: GenericPacketMath.h:107
Definition: XprHelper.h:282
find_best_packet< _Scalar, size >::type PacketScalar
Definition: Matrix.h:22
Definition: ForwardDeclarations.h:17
Definition: GenericPacketMath.h:133
#define const
Definition: zconf.h:233