Eigen  3.4.90 (git rev a4098ac676528a83cfb73d4d26ce1b42ec05f47c)
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 <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#include "./InternalHeaderCheck.h"
15
16namespace Eigen {
17
18namespace internal {
19template<typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
20struct traits<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_> >
21{
22private:
23 enum { size = internal::size_at_compile_time<Rows_,Cols_>::ret };
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 && (EIGEN_UNALIGNED_VECTORIZE || (actual_alignment>=required_alignment))) ? PacketAccessBit : 0
33 };
34
35public:
36 typedef Scalar_ Scalar;
37 typedef Dense StorageKind;
38 typedef Eigen::Index StorageIndex;
39 typedef MatrixXpr XprKind;
40 enum {
41 RowsAtCompileTime = Rows_,
42 ColsAtCompileTime = Cols_,
43 MaxRowsAtCompileTime = MaxRows_,
44 MaxColsAtCompileTime = MaxCols_,
45 Flags = compute_matrix_flags<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_>::ret,
46 Options = Options_,
47 InnerStrideAtCompileTime = 1,
48 OuterStrideAtCompileTime = (Options&RowMajor) ? ColsAtCompileTime : RowsAtCompileTime,
49
50 // FIXME, the following flag in only used to define NeedsToAlign in PlainObjectBase
51 EvaluatorFlags = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit,
52 Alignment = actual_alignment
53 };
54};
55}
56
179template<typename Scalar_, int Rows_, int Cols_, int Options_, int MaxRows_, int MaxCols_>
181 : public PlainObjectBase<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_> >
182{
183 public:
184
189
190 enum { Options = Options_ };
191
192 EIGEN_DENSE_PUBLIC_INTERFACE(Matrix)
193
194 typedef typename Base::PlainObject PlainObject;
195
196 using Base::base;
197 using Base::coeffRef;
198
207 EIGEN_DEVICE_FUNC
208 EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other)
209 {
210 return Base::_set(other);
211 }
212
223 template<typename OtherDerived>
224 EIGEN_DEVICE_FUNC
225 EIGEN_STRONG_INLINE Matrix& operator=(const DenseBase<OtherDerived>& other)
226 {
227 return Base::_set(other);
228 }
229
230 /* Here, doxygen failed to copy the brief information when using \copydoc */
231
236 template<typename OtherDerived>
237 EIGEN_DEVICE_FUNC
238 EIGEN_STRONG_INLINE Matrix& operator=(const EigenBase<OtherDerived> &other)
239 {
240 return Base::operator=(other);
241 }
242
243 template<typename OtherDerived>
244 EIGEN_DEVICE_FUNC
245 EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
246 {
247 return Base::operator=(func);
248 }
249
260 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
261 Matrix() : Base()
262 {
263 EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
264 }
265
266 // FIXME is it still needed
267 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
268 explicit Matrix(internal::constructor_without_unaligned_array_assert)
269 : Base(internal::constructor_without_unaligned_array_assert())
270 { EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED }
271
272 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
273 Matrix(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
274 : Base(std::move(other)) {}
275 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
276 Matrix& operator=(Matrix&& other) EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value)
277 {
278 Base::operator=(std::move(other));
279 return *this;
280 }
281
289 template <typename... ArgTypes>
290 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
291 Matrix(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)
292 : Base(a0, a1, a2, a3, args...) {}
293
315 EIGEN_DEVICE_FUNC
316 explicit EIGEN_STRONG_INLINE Matrix(const std::initializer_list<std::initializer_list<Scalar>>& list) : Base(list) {}
317
318#ifndef EIGEN_PARSED_BY_DOXYGEN
319
320 // This constructor is for both 1x1 matrices and dynamic vectors
321 template<typename T>
322 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
323 explicit Matrix(const T& x)
324 {
325 Base::template _init1<T>(x);
326 }
327
328 template<typename T0, typename T1>
329 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
330 Matrix(const T0& x, const T1& y)
331 {
332 Base::template _init2<T0,T1>(x, y);
333 }
334
335
336#else
338 EIGEN_DEVICE_FUNC
339 explicit Matrix(const Scalar *data);
340
353 EIGEN_STRONG_INLINE explicit Matrix(Index dim);
356 Matrix(const Scalar& x);
369 EIGEN_DEVICE_FUNC
370 Matrix(Index rows, Index cols);
371
374 Matrix(const Scalar& x, const Scalar& y);
375 #endif // end EIGEN_PARSED_BY_DOXYGEN
376
380 EIGEN_DEVICE_FUNC
381 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z)
382 {
383 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 3)
384 m_storage.data()[0] = x;
385 m_storage.data()[1] = y;
386 m_storage.data()[2] = z;
387 }
391 EIGEN_DEVICE_FUNC
392 EIGEN_STRONG_INLINE Matrix(const Scalar& x, const Scalar& y, const Scalar& z, const Scalar& w)
393 {
394 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix, 4)
395 m_storage.data()[0] = x;
396 m_storage.data()[1] = y;
397 m_storage.data()[2] = z;
398 m_storage.data()[3] = w;
399 }
400
401
403 EIGEN_DEVICE_FUNC
404 EIGEN_STRONG_INLINE Matrix(const Matrix& other) : Base(other)
405 { }
406
410 template<typename OtherDerived>
411 EIGEN_DEVICE_FUNC
412 EIGEN_STRONG_INLINE Matrix(const EigenBase<OtherDerived> &other)
413 : Base(other.derived())
414 { }
415
416 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
417 inline Index innerStride() const EIGEN_NOEXCEPT { return 1; }
418 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
419 inline Index outerStride() const EIGEN_NOEXCEPT { return this->innerSize(); }
420
422
423 template<typename OtherDerived>
424 EIGEN_DEVICE_FUNC
425 explicit Matrix(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
426 template<typename OtherDerived>
427 EIGEN_DEVICE_FUNC
428 Matrix& operator=(const RotationBase<OtherDerived,ColsAtCompileTime>& r);
429
430 // allow to extend Matrix outside Eigen
431 #ifdef EIGEN_MATRIX_PLUGIN
432 #include EIGEN_MATRIX_PLUGIN
433 #endif
434
435 protected:
436 template <typename Derived, typename OtherDerived, bool IsVector>
437 friend struct internal::conservative_resize_like_impl;
438
439 using Base::m_storage;
440};
441
471#define EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Size, SizeSuffix) \
472 \
473typedef Matrix<Type, Size, Size> Matrix##SizeSuffix##TypeSuffix; \
474 \
475typedef Matrix<Type, Size, 1> Vector##SizeSuffix##TypeSuffix; \
476 \
477typedef Matrix<Type, 1, Size> RowVector##SizeSuffix##TypeSuffix;
478
479#define EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, Size) \
480 \
481typedef Matrix<Type, Size, Dynamic> Matrix##Size##X##TypeSuffix; \
482 \
483typedef Matrix<Type, Dynamic, Size> Matrix##X##Size##TypeSuffix;
484
485#define EIGEN_MAKE_TYPEDEFS_ALL_SIZES(Type, TypeSuffix) \
486EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 2, 2) \
487EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 3, 3) \
488EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, 4, 4) \
489EIGEN_MAKE_TYPEDEFS(Type, TypeSuffix, Dynamic, X) \
490EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 2) \
491EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 3) \
492EIGEN_MAKE_FIXED_TYPEDEFS(Type, TypeSuffix, 4)
493
494EIGEN_MAKE_TYPEDEFS_ALL_SIZES(int, i)
495EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)
496EIGEN_MAKE_TYPEDEFS_ALL_SIZES(double, d)
497EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<float>, cf)
498EIGEN_MAKE_TYPEDEFS_ALL_SIZES(std::complex<double>, cd)
499
500#undef EIGEN_MAKE_TYPEDEFS_ALL_SIZES
501#undef EIGEN_MAKE_TYPEDEFS
502#undef EIGEN_MAKE_FIXED_TYPEDEFS
503
504#define EIGEN_MAKE_TYPEDEFS(Size, SizeSuffix) \
505 \
506 \
507template <typename Type> \
508using Matrix##SizeSuffix = Matrix<Type, Size, Size>; \
509 \
510 \
511template <typename Type> \
512using Vector##SizeSuffix = Matrix<Type, Size, 1>; \
513 \
514 \
515template <typename Type> \
516using RowVector##SizeSuffix = Matrix<Type, 1, Size>;
517
518#define EIGEN_MAKE_FIXED_TYPEDEFS(Size) \
519 \
520 \
521template <typename Type> \
522using Matrix##Size##X = Matrix<Type, Size, Dynamic>; \
523 \
524 \
525template <typename Type> \
526using Matrix##X##Size = Matrix<Type, Dynamic, Size>;
527
528EIGEN_MAKE_TYPEDEFS(2, 2)
529EIGEN_MAKE_TYPEDEFS(3, 3)
530EIGEN_MAKE_TYPEDEFS(4, 4)
531EIGEN_MAKE_TYPEDEFS(Dynamic, X)
532EIGEN_MAKE_FIXED_TYPEDEFS(2)
533EIGEN_MAKE_FIXED_TYPEDEFS(3)
534EIGEN_MAKE_FIXED_TYPEDEFS(4)
535
538template <typename Type, int Size>
539using Vector = Matrix<Type, Size, 1>;
540
543template <typename Type, int Size>
544using RowVector = Matrix<Type, 1, Size>;
545
546#undef EIGEN_MAKE_TYPEDEFS
547#undef EIGEN_MAKE_FIXED_TYPEDEFS
548
549} // end namespace Eigen
550
551#endif // EIGEN_MATRIX_H
Base class for all dense matrices, vectors, and arrays.
Definition: DenseBase.h:42
EIGEN_CONSTEXPR Index innerSize() const
Definition: DenseBase.h:225
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:61
Derived & derived()
Definition: EigenBase.h:48
Scalar & z()
Definition: DenseCoeffsBase.h:453
Scalar & w()
Definition: DenseCoeffsBase.h:463
Scalar & y()
Definition: DenseCoeffsBase.h:443
Scalar & x()
Definition: DenseCoeffsBase.h:437
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
Matrix(const Scalar &x, const Scalar &y, const Scalar &z)
Constructs an initialized 3D vector with given coefficients.
Definition: Matrix.h:381
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:412
Matrix()
Default constructor.
Definition: Matrix.h:261
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:291
Matrix(const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w)
Constructs an initialized 4D vector with given coefficients.
Definition: Matrix.h:392
Matrix(const Matrix &other)
Copy constructor.
Definition: Matrix.h:404
Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition: Matrix.h:208
Matrix(const Scalar &x)
Constructs an initialized 1x1 matrix with the given coefficient.
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:316
Matrix(const Scalar *data)
Constructs a fixed-sized matrix initialized with coefficients starting at data.
PlainObjectBase< Matrix > Base
Base class typedef.
Definition: Matrix.h:188
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:238
Dense storage base class for matrices and arrays.
Definition: PlainObjectBase.h:102
Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:187
Derived & _set(const DenseBase< OtherDerived > &other)
Copies the value of the expression other into *this with automatic resizing.
Definition: PlainObjectBase.h:776
Derived & operator=(const PlainObjectBase &other)
Definition: PlainObjectBase.h:461
@ DontAlign
Definition: Constants.h:327
@ RowMajor
Definition: Constants.h:323
const unsigned int PacketAccessBit
Definition: Constants.h:96
const unsigned int LinearAccessBit
Definition: Constants.h:132
const unsigned int DirectAccessBit
Definition: Constants.h:157
const unsigned int RowMajorBit
Definition: Constants.h:68
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:59
const int Dynamic
Definition: Constants.h:24
Definition: EigenBase.h:32
Eigen::Index Index
The interface type of indices.
Definition: EigenBase.h:41