ReshapedMethods.h File Reference

Go to the source code of this file.

Functions

template<int Order = ColMajor>
Reshaped< Derived,... > reshaped ()
 
template<int Order = ColMajor>
const Reshaped< const Derived,... > reshaped () const
 This is the const version of reshaped(). More...
 
template<int Order = ColMajor, typename NRowsType , typename NColsType >
Reshaped< Derived,... > reshaped (NRowsType nRows, NColsType nCols)
 
template<int Order = ColMajor, typename NRowsType , typename NColsType >
const Reshaped< const Derived,... > reshaped (NRowsType nRows, NColsType nCols) const
 This is the const version of reshaped(NRowsType,NColsType). More...
 

Function Documentation

◆ reshaped() [1/4]

template<int Order = ColMajor>
Reshaped<Derived,...> reshaped ( )
inline
Returns
an expression of *this with columns (or rows) stacked to a linear column vector
Template Parameters
Orderspecifies whether the coefficients should be processed in column-major-order (ColMajor), in row-major-order (RowMajor), or follows the natural order of the nested expression (AutoOrder). The default is ColMajor.

This overloads is essentially a shortcut for A.reshaped<Order>(AutoSize,fix<1>).

  • If Order==ColMajor (the default), then it returns a column-vector from the stacked columns of *this.
  • If Order==RowMajor, then it returns a column-vector from the stacked rows of *this.
  • If Order==AutoOrder, then it returns a column-vector with elements stacked following the storage order of *this. This mode is the recommended one when the particular ordering of the element is not relevant.

Example:

Matrix4i m = Matrix4i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is m.reshaped().transpose():" << endl << m.reshaped().transpose() << endl;
cout << "Here is m.reshaped<RowMajor>().transpose(): " << endl << m.reshaped<RowMajor>().transpose() << endl;
Matrix3f m
@ RowMajor
Definition: Constants.h:323
Matrix< int, 4, 4 > Matrix4i
4×4 matrix of type int.
Definition: Matrix.h:500

Output:

Here is the matrix m:
 7  9 -5 -3
-2 -6  1  0
 6 -3  0  9
 6  6  3  9
Here is m.reshaped().transpose():
 7 -2  6  6  9 -6 -3  6 -5  1  0  3 -3  0  9  9
Here is m.reshaped<RowMajor>().transpose():  
 7  9 -5 -3 -2 -6  1  0  6 -3  0  9  6  6  3  9

If you want more control, you can still fall back to reshaped(NRowsType,NColsType).

See also
reshaped(NRowsType,NColsType), class Reshaped

◆ reshaped() [2/4]

template<int Order = ColMajor>
const Reshaped<const Derived,...> reshaped ( ) const
inline

This is the const version of reshaped().

◆ reshaped() [3/4]

template<int Order = ColMajor, typename NRowsType , typename NColsType >
Reshaped<Derived,...> reshaped ( NRowsType  nRows,
NColsType  nCols 
)
inline
Returns
an expression of *this with reshaped sizes.
Parameters
nRowsthe number of rows in the reshaped expression, specified at either run-time or compile-time, or AutoSize
nColsthe number of columns in the reshaped expression, specified at either run-time or compile-time, or AutoSize
Template Parameters
Orderspecifies whether the coefficients should be processed in column-major-order (ColMajor), in row-major-order (RowMajor), or follows the natural order of the nested expression (AutoOrder). The default is ColMajor.
NRowsTypethe type of the value handling the number of rows, typically Index.
NColsTypethe type of the value handling the number of columns, typically Index.

Dynamic size example:

Matrix4i m = Matrix4i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is m.reshaped(2, 8):" << endl << m.reshaped(2, 8) << endl;

Output:

Here is the matrix m:
 7  9 -5 -3
-2 -6  1  0
 6 -3  0  9
 6  6  3  9
Here is m.reshaped(2, 8):
 7  6  9 -3 -5  0 -3  9
-2  6 -6  6  1  3  0  9

The number of rows nRows and columns nCols can also be specified at compile-time by passing Eigen::fix<N>, or Eigen::fix<N>(n) as arguments. In the later case, n plays the role of a runtime fallback value in case N equals Eigen::Dynamic. Here is an example with a fixed number of rows and columns:

Matrix4i m = Matrix4i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is m.reshaped(fix<2>,fix<8>):" << endl << m.reshaped(fix<2>,fix<8>) << endl;

Output:

Here is the matrix m:
 7  9 -5 -3
-2 -6  1  0
 6 -3  0  9
 6  6  3  9
Here is m.reshaped(fix<2>,fix<8>):
 7  6  9 -3 -5  0 -3  9
-2  6 -6  6  1  3  0  9

Finally, one of the sizes parameter can be automatically deduced from the other one by passing AutoSize as in the following example:

Matrix4i m = Matrix4i::Random();
cout << "Here is the matrix m:" << endl << m << endl;
cout << "Here is m.reshaped(2, AutoSize):" << endl << m.reshaped(2, AutoSize) << endl;
cout << "Here is m.reshaped<RowMajor>(AutoSize, fix<8>):" << endl << m.reshaped<RowMajor>(AutoSize, fix<8>) << endl;

Output:

Here is the matrix m:
 7  9 -5 -3
-2 -6  1  0
 6 -3  0  9
 6  6  3  9
Here is m.reshaped(2, AutoSize):
 7  6  9 -3 -5  0 -3  9
-2  6 -6  6  1  3  0  9
Here is m.reshaped<RowMajor>(AutoSize, fix<8>):
 7  9 -5 -3 -2 -6  1  0
 6 -3  0  9  6  6  3  9

AutoSize does preserve compile-time sizes when possible, i.e., when the sizes of the input are known at compile time and that the other size is passed at compile-time using Eigen::fix<N> as above.

See also
class Reshaped, fix, fix<N>(int)

◆ reshaped() [4/4]

template<int Order = ColMajor, typename NRowsType , typename NColsType >
const Reshaped<const Derived,...> reshaped ( NRowsType  nRows,
NColsType  nCols 
) const
inline

This is the const version of reshaped(NRowsType,NColsType).