template<typename Derived>
Eigen::PlainObjectBase class

Dense storage base class for matrices and arrays.

Template parameters
Derived is the derived type, e.g., a Matrix or Array

This class can be extended with the help of the plugin mechanism described on the page Extending MatrixBase (and other classes) by defining the preprocessor symbol EIGEN_PLAINOBJECTBASE_PLUGIN.

Base classes

template<typename Derived>
struct dense_xpr_base_dispatcher

Derived classes

template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array
General-purpose arrays with easy API for coefficient-wise operations.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array
General-purpose arrays with easy API for coefficient-wise operations.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array
General-purpose arrays with easy API for coefficient-wise operations.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array
General-purpose arrays with easy API for coefficient-wise operations.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array
General-purpose arrays with easy API for coefficient-wise operations.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array
General-purpose arrays with easy API for coefficient-wise operations.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array
General-purpose arrays with easy API for coefficient-wise operations.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Array
General-purpose arrays with easy API for coefficient-wise operations.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Matrix
The matrix class, also used for vectors and row-vectors.

Constructors, destructors, conversion operators

PlainObjectBase(const PlainObjectBase& other) protected
template<typename... ArgTypes>
PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) protected
Construct a row of column vector with fixed size from an arbitrary number of coefficients. [c++11]
PlainObjectBase(const std::initializer_list<std::initializer_list<Scalar>>& list) protected explicit
Constructs a Matrix or Array and initializes it by elements given by an initializer list of initializer lists [c++11]
template<typename OtherDerived>
PlainObjectBase(const DenseBase<OtherDerived>& other) protected
template<typename OtherDerived>
PlainObjectBase(const EigenBase<OtherDerived>& other) protected
template<typename OtherDerived>
PlainObjectBase(const ReturnByValue<OtherDerived>& other) protected
Copy constructor with in-place evaluation.

Public functions

auto coeff(Index rowId, Index colId) const -> const Scalar&
auto coeff(Index index) const -> const Scalar&
auto coeffRef(Index rowId, Index colId) -> Scalar&
auto coeffRef(Index index) -> Scalar&
auto coeffRef(Index rowId, Index colId) const -> const Scalar&
auto coeffRef(Index index) const -> const Scalar&
void conservativeResize(Index rows, Index cols)
void conservativeResize(Index rows, NoChange_t)
void conservativeResize(NoChange_t, Index cols)
void conservativeResize(Index size)
template<typename OtherDerived>
void conservativeResizeLike(const DenseBase<OtherDerived>& other)
auto data() const -> const Scalar*
auto data() -> Scalar*
template<typename OtherDerived>
auto lazyAssign(const DenseBase<OtherDerived>& other) -> Derived&
auto operator=(const PlainObjectBase& other) -> Derived&
template<typename OtherDerived>
auto operator=(const EigenBase<OtherDerived>& other) -> Derived&
Copies the generic expression other into *this.
void resize(Index rows, Index cols)
void resize(Index size)
void resize(NoChange_t, Index cols)
void resize(Index rows, NoChange_t)
template<typename OtherDerived>
void resizeLike(const EigenBase<OtherDerived>& _other)
auto setConstant(Index size, const Scalar& val) -> Derived&
auto setConstant(Index rows, Index cols, const Scalar& val) -> Derived&
auto setOnes(Index size) -> Derived&
auto setOnes(Index rows, Index cols) -> Derived&
auto setRandom(Index size) -> Derived&
auto setRandom(Index rows, Index cols) -> Derived&
auto setZero(Index size) -> Derived&
auto setZero(Index rows, Index cols) -> Derived&

Protected functions

template<typename OtherDerived>
auto _set(const DenseBase<OtherDerived>& other) -> Derived&
Copies the value of the expression other into *this with automatic resizing.

Function documentation

template<typename Derived>
Eigen::PlainObjectBase<Derived>::PlainObjectBase(const PlainObjectBase& other) protected

Copy constructor

template<typename Derived> template<typename... ArgTypes>
Eigen::PlainObjectBase<Derived>::PlainObjectBase(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args) protected

Construct a row of column vector with fixed size from an arbitrary number of coefficients. [c++11]

This is only for vectors (either row-vectors or column-vectors), i.e. matrices which are known at compile-time to have either one row or one column.

This constructor is for 1D array or vectors with more than 4 coefficients. There exists c++98 anologue constructors for fixed-size array/vector having 1, 2, 3, or 4 coefficients.

template<typename Derived> template<typename OtherDerived>
Eigen::PlainObjectBase<Derived>::PlainObjectBase(const DenseBase<OtherDerived>& other) protected

template<typename Derived> template<typename OtherDerived>
Eigen::PlainObjectBase<Derived>::PlainObjectBase(const EigenBase<OtherDerived>& other) protected

template<typename Derived>
const Scalar& Eigen::PlainObjectBase<Derived>::coeff(Index rowId, Index colId) const

This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index,Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.

See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) constfor details.

template<typename Derived>
const Scalar& Eigen::PlainObjectBase<Derived>::coeff(Index index) const

This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.

See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) constfor details.

template<typename Derived>
Scalar& Eigen::PlainObjectBase<Derived>::coeffRef(Index rowId, Index colId)

This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.

See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const for details.

template<typename Derived>
Scalar& Eigen::PlainObjectBase<Derived>::coeffRef(Index index)

This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.

See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const for details.

template<typename Derived>
const Scalar& Eigen::PlainObjectBase<Derived>::coeffRef(Index rowId, Index colId) const

This is the const version of coeffRef(Index,Index) which is thus synonym of coeff(Index,Index). It is provided for convenience.

template<typename Derived>
const Scalar& Eigen::PlainObjectBase<Derived>::coeffRef(Index index) const

This is the const version of coeffRef(Index) which is thus synonym of coeff(Index). It is provided for convenience.

template<typename Derived>
void Eigen::PlainObjectBase<Derived>::conservativeResize(Index rows, Index cols)

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.

template<typename Derived>
void Eigen::PlainObjectBase<Derived>::conservativeResize(Index rows, NoChange_t)

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.

template<typename Derived>
void Eigen::PlainObjectBase<Derived>::conservativeResize(NoChange_t, Index cols)

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.

template<typename Derived>
void Eigen::PlainObjectBase<Derived>::conservativeResize(Index size)

Resizes the vector to size while retaining old values.

This is only for vectors (either row-vectors or column-vectors), i.e. matrices which are known at compile-time to have either one row or one column.. 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.

template<typename Derived> template<typename OtherDerived>
void Eigen::PlainObjectBase<Derived>::conservativeResizeLike(const DenseBase<OtherDerived>& other)

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.

template<typename Derived>
const Scalar* Eigen::PlainObjectBase<Derived>::data() const

Returns a const pointer to the data array of this matrix

template<typename Derived>
Scalar* Eigen::PlainObjectBase<Derived>::data()

Returns a pointer to the data array of this matrix

template<typename Derived> template<typename OtherDerived>
Derived& Eigen::PlainObjectBase<Derived>::lazyAssign(const DenseBase<OtherDerived>& other)

template<typename Derived>
Derived& Eigen::PlainObjectBase<Derived>::operator=(const PlainObjectBase& other)

This is a special case of the templated operator=. Its purpose is to prevent a default operator= from hiding the templated operator=.

template<typename Derived> template<typename OtherDerived>
Derived& Eigen::PlainObjectBase<Derived>::operator=(const EigenBase<OtherDerived>& other)

Copies the generic expression other into *this.

Returns a reference to *this.

The expression must provide a (templated) evalTo(Derived& dst) const function which does the actual job. In practice, this allows any user to write its own special matrix without having to modify MatrixBase

template<typename Derived>
void Eigen::PlainObjectBase<Derived>::resize(Index rows, Index cols)

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:

MatrixXd m(2,3);
m << 1,2,3,4,5,6;
cout << "here's the 2x3 matrix m:" << endl << m << endl;
cout << "let's resize m to 3x2. This is a conservative resizing because 2*3==3*2." << endl;
m.resize(3,2);
cout << "here's the 3x2 matrix m:" << endl << m << endl;
cout << "now let's resize m to size 2x2. This is NOT a conservative resizing, so it becomes uninitialized:" << endl;
m.resize(2,2);
cout << m << endl;

Output:

here's the 2x3 matrix m:
1 2 3
4 5 6
let's resize m to 3x2. This is a conservative resizing because 2*3==3*2.
here's the 3x2 matrix m:
1 5
4 3
2 6
now let's resize m to size 2x2. This is NOT a conservative resizing, so it becomes uninitialized:
0 0
0 0

template<typename Derived>
void Eigen::PlainObjectBase<Derived>::resize(Index size)

Resizes *this to a vector of length size

This is only for vectors (either row-vectors or column-vectors), i.e. matrices which are known at compile-time to have either one row or one column.. 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:

VectorXd v(10);
v.resize(3);
RowVector3d w;
w.resize(3); // this is legal, but has no effect
cout << "v: " << v.rows() << " rows, " << v.cols() << " cols" << endl;
cout << "w: " << w.rows() << " rows, " << w.cols() << " cols" << endl;

Output:

v: 3 rows, 1 cols
w: 1 rows, 3 cols

template<typename Derived>
void Eigen::PlainObjectBase<Derived>::resize(NoChange_t, Index cols)

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:

MatrixXd m(3,4);
m.resize(NoChange, 5);
cout << "m: " << m.rows() << " rows, " << m.cols() << " cols" << endl;

Output:

m: 3 rows, 5 cols

template<typename Derived>
void Eigen::PlainObjectBase<Derived>::resize(Index rows, NoChange_t)

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:

MatrixXd m(3,4);
m.resize(5, NoChange);
cout << "m: " << m.rows() << " rows, " << m.cols() << " cols" << endl;

Output:

m: 5 rows, 4 cols

template<typename Derived> template<typename OtherDerived>
void Eigen::PlainObjectBase<Derived>::resizeLike(const EigenBase<OtherDerived>& _other)

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.

template<typename Derived>
Derived& Eigen::PlainObjectBase<Derived>::setConstant(Index size, const Scalar& val)

Resizes to the given size, and sets all coefficients in this expression to the given value val.

This is only for vectors (either row-vectors or column-vectors), i.e. matrices which are known at compile-time to have either one row or one column.

Example:

VectorXf v;
v.setConstant(3, 5);
cout << v << endl;

Output:

5
5
5

template<typename Derived>
Derived& Eigen::PlainObjectBase<Derived>::setConstant(Index rows, Index cols, const Scalar& val)

Parameters
rows the new number of rows
cols the new number of columns
val the value to which all coefficients are set

Resizes to the given size, and sets all coefficients in this expression to the given value val.

Example:

MatrixXf m;
m.setConstant(3, 3, 5);
cout << m << endl;

Output:

5 5 5
5 5 5
5 5 5

template<typename Derived>
Derived& Eigen::PlainObjectBase<Derived>::setOnes(Index size)

Resizes to the given newSize, and sets all coefficients in this expression to one.

This is only for vectors (either row-vectors or column-vectors), i.e. matrices which are known at compile-time to have either one row or one column.

Example:

VectorXf v;
v.setOnes(3);
cout << v << endl;

Output:

1
1
1

template<typename Derived>
Derived& Eigen::PlainObjectBase<Derived>::setOnes(Index rows, Index cols)

Parameters
rows the new number of rows
cols the new number of columns

Resizes to the given size, and sets all coefficients in this expression to one.

Example:

MatrixXf m;
m.setOnes(3, 3);
cout << m << endl;

Output:

1 1 1
1 1 1
1 1 1

template<typename Derived>
Derived& Eigen::PlainObjectBase<Derived>::setRandom(Index size)

Resizes to the given newSize, and sets all coefficients in this expression to random values.

Numbers are uniformly spread through their whole definition range for integer types, and in the [-1:1] range for floating point scalar types.

This is only for vectors (either row-vectors or column-vectors), i.e. matrices which are known at compile-time to have either one row or one column.

Example:

VectorXf v;
v.setRandom(3);
cout << v << endl;

Output:

  0.68
-0.211
 0.566

template<typename Derived>
Derived& Eigen::PlainObjectBase<Derived>::setRandom(Index rows, Index cols)

Parameters
rows the new number of rows
cols the new number of columns

Resizes to the given size, and sets all coefficients in this expression to random values.

Numbers are uniformly spread through their whole definition range for integer types, and in the [-1:1] range for floating point scalar types.

Example:

MatrixXf m;
m.setRandom(3, 3);
cout << m << endl;

Output:

  0.68  0.597  -0.33
-0.211  0.823  0.536
 0.566 -0.605 -0.444

template<typename Derived>
Derived& Eigen::PlainObjectBase<Derived>::setZero(Index size)

Resizes to the given size, and sets all coefficients in this expression to zero.

This is only for vectors (either row-vectors or column-vectors), i.e. matrices which are known at compile-time to have either one row or one column.

Example:

VectorXf v;
v.setZero(3);
cout << v << endl;

Output:

0
0
0

template<typename Derived>
Derived& Eigen::PlainObjectBase<Derived>::setZero(Index rows, Index cols)

Parameters
rows the new number of rows
cols the new number of columns

Resizes to the given size, and sets all coefficients in this expression to zero.

Example:

MatrixXf m;
m.setZero(3, 3);
cout << m << endl;

Output:

0 0 0
0 0 0
0 0 0

template<typename Derived> template<typename OtherDerived>
Derived& Eigen::PlainObjectBase<Derived>::_set(const DenseBase<OtherDerived>& other) protected

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.