Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Eigen_test Odometry_test AttitudeEstimation_usingTicker MPU9250_Quaternion_Binary_Serial ... more
Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > Class Template Reference
[Core module]
The matrix class, also used for vectors and row-vectors. More...
#include <Matrix.h>
Inherits PlainObjectBase< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >.
Public Types | |
typedef PlainObjectBase< Matrix > | Base |
Base class typedef. | |
Public Member Functions | |
EIGEN_STRONG_INLINE Matrix & | operator= (const Matrix &other) |
Assigns matrices to each other. | |
template<typename OtherDerived > | |
EIGEN_STRONG_INLINE Matrix & | operator= (const EigenBase< OtherDerived > &other) |
Copies the generic expression other into *this. | |
EIGEN_STRONG_INLINE | Matrix () |
Default constructor. | |
EIGEN_STRONG_INLINE | Matrix (Index dim) |
Constructs a vector or row-vector with given dimension. | |
Matrix (Index rows, Index cols) | |
Constructs an uninitialized matrix with rows rows and cols columns. | |
Matrix (const Scalar &x, const Scalar &y) | |
Constructs an initialized 2D vector with given coefficients. | |
EIGEN_STRONG_INLINE | Matrix (const Scalar &x, const Scalar &y, const Scalar &z) |
Constructs an initialized 3D vector with given coefficients. | |
EIGEN_STRONG_INLINE | Matrix (const Scalar &x, const Scalar &y, const Scalar &z, const Scalar &w) |
Constructs an initialized 4D vector with given coefficients. | |
template<typename OtherDerived > | |
EIGEN_STRONG_INLINE | Matrix (const MatrixBase< OtherDerived > &other) |
Constructor copying the value of the expression other. | |
EIGEN_STRONG_INLINE | Matrix (const Matrix &other) |
Copy constructor. | |
template<typename OtherDerived > | |
EIGEN_STRONG_INLINE | Matrix (const ReturnByValue< OtherDerived > &other) |
Copy constructor with in-place evaluation. | |
template<typename OtherDerived > | |
EIGEN_STRONG_INLINE | Matrix (const EigenBase< OtherDerived > &other) |
Copy constructor for generic expressions. | |
template<typename OtherDerived > | |
Matrix (const RotationBase< OtherDerived, ColsAtCompileTime > &r) | |
| |
template<typename OtherDerived > | |
Matrix & | operator= (const RotationBase< OtherDerived, ColsAtCompileTime > &r) |
| |
EIGEN_STRONG_INLINE const Scalar * | data () const |
EIGEN_STRONG_INLINE Scalar * | data () |
EIGEN_STRONG_INLINE void | resize (Index nbRows, Index nbCols) |
Resizes *this to a rows x cols matrix. | |
void | resize (Index size) |
Resizes *this to a vector of length size. | |
void | resize (NoChange_t, Index nbCols) |
Resizes the matrix, changing only the number of columns. | |
void | resize (Index nbRows, NoChange_t) |
Resizes the matrix, changing only the number of rows. | |
EIGEN_STRONG_INLINE void | resizeLike (const EigenBase< OtherDerived > &_other) |
Resizes *this to have the same dimensions as other. | |
EIGEN_STRONG_INLINE void | conservativeResize (Index nbRows, Index nbCols) |
Resizes the matrix to rows x cols while leaving old values untouched. | |
EIGEN_STRONG_INLINE void | conservativeResize (Index nbRows, NoChange_t) |
Resizes the matrix to rows x cols while leaving old values untouched. | |
EIGEN_STRONG_INLINE void | conservativeResize (NoChange_t, Index nbCols) |
Resizes the matrix to rows x cols while leaving old values untouched. | |
EIGEN_STRONG_INLINE void | conservativeResize (Index size) |
Resizes the vector to size while retaining old values. | |
EIGEN_STRONG_INLINE void | conservativeResizeLike (const DenseBase< OtherDerived > &other) |
Resizes the matrix to rows x cols of other , while leaving old values untouched. | |
EIGEN_STRONG_INLINE Matrix < _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & | lazyAssign (const DenseBase< OtherDerived > &other) |
Static Public Member Functions | |
Map | |
static ConstMapType | Map (const Scalar *data) |
static MapType | Map (Scalar *data) |
static ConstMapType | Map (const Scalar *data, Index size) |
static MapType | Map (Scalar *data, Index size) |
static ConstMapType | Map (const Scalar *data, Index rows, Index cols) |
static MapType | Map (Scalar *data, Index rows, Index cols) |
static StridedConstMapType < Stride< Outer, Inner > >::type | Map (const Scalar *data, const Stride< Outer, Inner > &stride) |
static StridedMapType< Stride < Outer, Inner > >::type | Map (Scalar *data, const Stride< Outer, Inner > &stride) |
static StridedConstMapType < Stride< Outer, Inner > >::type | Map (const Scalar *data, Index size, const Stride< Outer, Inner > &stride) |
static StridedMapType< Stride < Outer, Inner > >::type | Map (Scalar *data, Index size, const Stride< Outer, Inner > &stride) |
static StridedConstMapType < Stride< Outer, Inner > >::type | Map (const Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride) |
static StridedMapType< Stride < Outer, Inner > >::type | Map (Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride) |
static ConstAlignedMapType | MapAligned (const Scalar *data) |
static AlignedMapType | MapAligned (Scalar *data) |
static ConstAlignedMapType | MapAligned (const Scalar *data, Index size) |
static AlignedMapType | MapAligned (Scalar *data, Index size) |
static ConstAlignedMapType | MapAligned (const Scalar *data, Index rows, Index cols) |
static AlignedMapType | MapAligned (Scalar *data, Index rows, Index cols) |
static StridedConstAlignedMapType < Stride< Outer, Inner > >::type | MapAligned (const Scalar *data, const Stride< Outer, Inner > &stride) |
static StridedAlignedMapType < Stride< Outer, Inner > >::type | MapAligned (Scalar *data, const Stride< Outer, Inner > &stride) |
static StridedConstAlignedMapType < Stride< Outer, Inner > >::type | MapAligned (const Scalar *data, Index size, const Stride< Outer, Inner > &stride) |
static StridedAlignedMapType < Stride< Outer, Inner > >::type | MapAligned (Scalar *data, Index size, const Stride< Outer, Inner > &stride) |
static StridedConstAlignedMapType < Stride< Outer, Inner > >::type | MapAligned (const Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride) |
static StridedAlignedMapType < Stride< Outer, Inner > >::type | MapAligned (Scalar *data, Index rows, Index cols, const Stride< Outer, Inner > &stride) |
Protected Member Functions | |
EIGEN_STRONG_INLINE Matrix < _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & | _set (const DenseBase< OtherDerived > &other) |
Copies the value of the expression other into *this with automatic resizing. | |
Friends | |
class | Eigen::Map |
class | Eigen::Map< Derived, Unaligned > |
class | Eigen::Map< const Derived, Unaligned > |
class | Eigen::Map< Derived, Aligned > |
class | Eigen::Map< const Derived, Aligned > |
Detailed Description
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >
The matrix class, also used for vectors and row-vectors.
The Matrix class is the work-horse for all dense (note) matrices and vectors within Eigen. Vectors are matrices with one column, and row-vectors are matrices with one row.
The Matrix class encompasses both fixed-size and dynamic-size objects (note).
The first three template parameters are required:
- Template Parameters:
-
_Scalar Numeric type, e.g. float, double, int or std::complex<float>. User defined sclar types are supported as well (see here). _Rows Number of rows, or Dynamic _Cols Number of columns, or Dynamic
The remaining template parameters are optional -- in most cases you don't have to worry about them.
- Template Parameters:
-
_Options A combination of either RowMajor or ColMajor, and of either AutoAlign or DontAlign. The former controls storage order, and defaults to column-major. The latter controls alignment, which is required for vectorization. It defaults to aligning matrices except for fixed sizes that aren't a multiple of the packet size. _MaxRows Maximum number of rows. Defaults to _Rows (note). _MaxCols Maximum number of columns. Defaults to _Cols (note).
Eigen provides a number of typedefs covering the usual cases. Here are some examples:
Matrix2d
is a 2x2 square matrix of doubles (Matrix<double, 2, 2>
)Vector4f
is a vector of 4 floats (Matrix<float, 4, 1>
)RowVector3i
is a row-vector of 3 ints (Matrix<int, 1, 3>
)
MatrixXf
is a dynamic-size matrix of floats (Matrix<float, Dynamic, Dynamic>
)VectorXf
is a dynamic-size vector of floats (Matrix<float, Dynamic, 1>
)
Matrix2Xf
is a partially fixed-size (dynamic-size) matrix of floats (Matrix<float, 2, Dynamic>
)MatrixX3d
is a partially dynamic-size (fixed-size) matrix of double (Matrix<double, Dynamic, 3>
)
See this page for a complete list of predefined Matrix and Vector typedefs.
You can access elements of vectors and matrices using normal subscripting:
Eigen::VectorXd v(10); v[0] = 0.1; v[1] = 0.2; v(0) = 0.3; v(1) = 0.4; Eigen::MatrixXi m(10, 10); m(0, 1) = 1; m(0, 2) = 2; m(0, 3) = 3;
This class can be extended with the help of the plugin mechanism described on the page TopicCustomizingEigen by defining the preprocessor symbol EIGEN_MATRIX_PLUGIN
.
Some notes:
- Dense versus sparse:
This Matrix class handles dense, not sparse matrices and vectors. For sparse matrices and vectors, see the Sparse module.
Dense matrices and vectors are plain usual arrays of coefficients. All the coefficients are stored, in an ordinary contiguous array. This is unlike Sparse matrices and vectors where the coefficients are stored as a list of nonzero coefficients.
- Fixed-size versus dynamic-size:
Fixed-size means that the numbers of rows and columns are known are compile-time. In this case, Eigen allocates the array of coefficients as a fixed-size array, as a class member. This makes sense for very small matrices, typically up to 4x4, sometimes up to 16x16. Larger matrices should be declared as dynamic-size even if one happens to know their size at compile-time.
Dynamic-size means that the numbers of rows or columns are not necessarily known at compile-time. In this case they are runtime variables, and the array of coefficients is allocated dynamically on the heap.
Note that dense matrices, be they Fixed-size or Dynamic-size, do not expand dynamically in the sense of a std::map. If you want this behavior, see the Sparse module.
- _MaxRows and _MaxCols:
- In most cases, one just leaves these parameters to the default values. These parameters mean the maximum size of rows and columns that the matrix may have. They are useful in cases when the exact numbers of rows and columns are not known are compile-time, but it is known at compile-time that they cannot exceed a certain value. This happens when taking dynamic-size blocks inside fixed-size matrices: in this case _MaxRows and _MaxCols are the dimensions of the original matrix, while _Rows and _Cols are Dynamic.
- See also:
- MatrixBase for the majority of the API methods for matrices, TopicClassHierarchy, TopicStorageOrders
Definition at line 127 of file Matrix.h.
Member Typedef Documentation
typedef PlainObjectBase<Matrix> Base |
Base class typedef.
- See also:
- PlainObjectBase
Reimplemented from PlainObjectBase< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >.
Constructor & Destructor Documentation
EIGEN_STRONG_INLINE Matrix | ( | ) |
Default constructor.
For fixed-size matrices, does nothing.
For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix is called a null matrix. This constructor is the unique way to create null matrices: resizing a matrix to 0 is not supported.
- See also:
- resize(Index,Index)
EIGEN_STRONG_INLINE Matrix | ( | Index | dim ) | [explicit] |
Matrix | ( | Index | rows, |
Index | cols | ||
) |
Constructs an uninitialized matrix with rows rows and cols columns.
This is useful for dynamic-size matrices. For fixed-size matrices, it is redundant to pass these parameters, so one should use the default constructor Matrix() instead.
Matrix | ( | const Scalar & | x, |
const Scalar & | y | ||
) |
Constructs an initialized 2D vector with given coefficients.
EIGEN_STRONG_INLINE Matrix | ( | const Scalar & | x, |
const Scalar & | y, | ||
const Scalar & | z | ||
) |
EIGEN_STRONG_INLINE Matrix | ( | const Scalar & | x, |
const Scalar & | y, | ||
const Scalar & | z, | ||
const Scalar & | w | ||
) |
EIGEN_STRONG_INLINE Matrix | ( | const MatrixBase< OtherDerived > & | other ) |
EIGEN_STRONG_INLINE Matrix | ( | const ReturnByValue< OtherDerived > & | other ) |
Matrix | ( | const RotationBase< OtherDerived, ColsAtCompileTime > & | r ) | [explicit] |
Constructs a Dim x Dim rotation matrix from the rotation r
Definition at line 141 of file RotationBase.h.
Member Function Documentation
EIGEN_STRONG_INLINE Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & _set | ( | const DenseBase< OtherDerived > & | other ) | [protected, inherited] |
Copies the value of the expression other into *this
with automatic resizing.
*this might be resized to match the dimensions of other. If *this was a null matrix (not already initialized), it will be initialized.
Note that copying a row-vector into a vector (and conversely) is allowed. The resizing, if any, is then done in the appropriate way so that row-vectors remain row-vectors and vectors remain vectors.
- See also:
- operator=(const MatrixBase<OtherDerived>&), _set_noalias()
Definition at line 628 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE void conservativeResize | ( | Index | size ) | [inherited] |
Resizes the vector to size while retaining old values.
. This method does not work for partially dynamic matrices when the static dimension is anything other than 1. For example it will not work with Matrix<double, 2, Dynamic>.
When values are appended, they will be uninitialized.
Definition at line 381 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE void conservativeResize | ( | Index | nbRows, |
NoChange_t | |||
) | [inherited] |
Resizes the matrix to rows x cols while leaving old values untouched.
As opposed to conservativeResize(Index rows, Index cols), this version leaves the number of columns unchanged.
In case the matrix is growing, new rows will be uninitialized.
Definition at line 354 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE void conservativeResize | ( | NoChange_t | , |
Index | nbCols | ||
) | [inherited] |
Resizes the matrix to rows x cols while leaving old values untouched.
As opposed to conservativeResize(Index rows, Index cols), this version leaves the number of rows unchanged.
In case the matrix is growing, new columns will be uninitialized.
Definition at line 367 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE void conservativeResize | ( | Index | nbRows, |
Index | nbCols | ||
) | [inherited] |
Resizes the matrix to rows x cols while leaving old values untouched.
The method is intended for matrices of dynamic size. If you only want to change the number of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or conservativeResize(Index, NoChange_t).
Matrices are resized relative to the top-left element. In case values need to be appended to the matrix they will be uninitialized.
Definition at line 342 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE void conservativeResizeLike | ( | const DenseBase< OtherDerived > & | other ) | [inherited] |
Resizes the matrix to rows x cols of other
, while leaving old values untouched.
The method is intended for matrices of dynamic size. If you only want to change the number of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or conservativeResize(Index, NoChange_t).
Matrices are resized relative to the top-left element. In case values need to be appended to the matrix they will copied from other
.
Definition at line 396 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE const Scalar* data | ( | ) | const [inherited] |
- Returns:
- a const pointer to the data array of this matrix
Definition at line 212 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE Scalar* data | ( | ) | [inherited] |
- Returns:
- a pointer to the data array of this matrix
Definition at line 216 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & lazyAssign | ( | const DenseBase< OtherDerived > & | other ) | [inherited] |
- See also:
- MatrixBase::lazyAssign()
Definition at line 411 of file PlainObjectBase.h.
Matrix< _Scalar, _Rows, _Cols, _Storage, _MaxRows, _MaxCols > & operator= | ( | const RotationBase< OtherDerived, ColsAtCompileTime > & | r ) |
Set a Dim x Dim rotation matrix from the rotation r
Definition at line 155 of file RotationBase.h.
Copies the generic expression other into *this.
Reimplemented from PlainObjectBase< Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >.
void resize | ( | NoChange_t | , |
Index | nbCols | ||
) | [inherited] |
Resizes the matrix, changing only the number of columns.
For the parameter of type NoChange_t, just pass the special value NoChange
as in the example below.
Example:
Output:
- See also:
- resize(Index,Index)
Definition at line 289 of file PlainObjectBase.h.
void resize | ( | Index | nbRows, |
NoChange_t | |||
) | [inherited] |
Resizes the matrix, changing only the number of rows.
For the parameter of type NoChange_t, just pass the special value NoChange
as in the example below.
Example:
Output:
- See also:
- resize(Index,Index)
Definition at line 302 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE void resize | ( | Index | nbRows, |
Index | nbCols | ||
) | [inherited] |
Resizes *this
to a rows x cols matrix.
This method is intended for dynamic-size matrices, although it is legal to call it on any matrix as long as fixed dimensions are left unchanged. If you only want to change the number of rows and/or of columns, you can use resize(NoChange_t, Index), resize(Index, NoChange_t).
If the current number of coefficients of *this
exactly matches the product rows * cols, then no memory allocation is performed and the current values are left unchanged. In all other cases, including shrinking, the data is reallocated and all previous values are lost.
Example:
Output:
- See also:
- resize(Index) for vectors, resize(NoChange_t, Index), resize(Index, NoChange_t)
Definition at line 235 of file PlainObjectBase.h.
void resize | ( | Index | size ) | [inherited] |
Resizes *this
to a vector of length size.
. This method does not work for partially dynamic matrices when the static dimension is anything other than 1. For example it will not work with Matrix<double, 2, Dynamic>.
Example:
Output:
- See also:
- resize(Index,Index), resize(NoChange_t, Index), resize(Index, NoChange_t)
Definition at line 265 of file PlainObjectBase.h.
EIGEN_STRONG_INLINE void resizeLike | ( | const EigenBase< OtherDerived > & | _other ) | [inherited] |
Resizes *this
to have the same dimensions as other.
Takes care of doing all the checking that's needed.
Note that copying a row-vector into a vector (and conversely) is allowed. The resizing, if any, is then done in the appropriate way so that row-vectors remain row-vectors and vectors remain vectors.
Definition at line 315 of file PlainObjectBase.h.
Generated on Tue Jul 12 2022 17:47:04 by
