Eigen::Reshaped< XprType, Rows, Cols, Order > Class Template Reference

Expression of a fixed-size or dynamic-size reshape. More...

+ Inheritance diagram for Eigen::Reshaped< XprType, Rows, Cols, Order >:

Public Types

typedef Impl Base
 

Public Member Functions

 Reshaped (XprType &xpr)
 
 Reshaped (XprType &xpr, Index reshapeRows, Index reshapeCols)
 

Private Types

typedef ReshapedImpl< XprType, Rows, Cols, Order, typename internal::traits< XprType >::StorageKind > Impl
 

Detailed Description

template<typename XprType, int Rows, int Cols, int Order>
class Eigen::Reshaped< XprType, Rows, Cols, Order >

Expression of a fixed-size or dynamic-size reshape.

Template Parameters
XprTypethe type of the expression in which we are taking a reshape
Rowsthe number of rows of the reshape we are taking at compile time (optional)
Colsthe number of columns of the reshape we are taking at compile time (optional)
Ordercan be ColMajor or RowMajor, default is ColMajor.

This class represents an expression of either a fixed-size or dynamic-size reshape. It is the return type of DenseBase::reshaped(NRowsType,NColsType) and most of the time this is the only way it is used.

If you want to directly manipulate reshaped expressions, for instance if you want to write a function returning such an expression, it is advised to use the auto keyword for such use cases.

Here is an example illustrating the dynamic case:

#include <Eigen/Core>
#include <iostream>
template<typename Derived>
{
}
int main(int, char**)
{
m << 1, 4, 7, 10,
2, 5, 8, 11,
3, 6, 9, 12;
std::cout << m << std::endl;
std::cout << "Matrix m is:" << std::endl << m << std::endl;
std::cout << "Matrix n is:" << std::endl << n << std::endl;
}
Matrix3f m
int n
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:285
Expression of a fixed-size or dynamic-size reshape.
Definition: Reshaped.h:99
int main(int, char **)
Definition: class_Block.cpp:18
Eigen::Reshaped< Derived, 4, 2 > reshape_helper(Eigen::MatrixBase< Derived > &m)

Output:

 1  4  7 10
 2  5  8 11
 3  6  9 12
Matrix m is:
 1  4  7 10
 2  5  8 11
 3  6  9 12
Matrix n is:
 1  3  5  7  9 11
 2  4  6  8 10 12

Here is an example illustrating the fixed-size case:

#include <Eigen/Core>
#include <iostream>
template<typename Derived>
{
return Eigen::Reshaped<Derived, 4, 2>(m.derived());
}
int main(int, char**)
{
m << 1, 2, 3, 4,
5, 6, 7, 8;
std::cout << "matrix m is:" << std::endl << m << std::endl;
std::cout << "matrix n is:" << std::endl << n << std::endl;
return 0;
}

Output:

matrix m is:
1 2 3 4
5 6 7 8
matrix n is:
1 3
5 7
2 4
6 8
See also
DenseBase::reshaped(NRowsType,NColsType)

Definition at line 97 of file Reshaped.h.

Member Typedef Documentation

◆ Base

template<typename XprType , int Rows, int Cols, int Order>
typedef Impl Eigen::Reshaped< XprType, Rows, Cols, Order >::Base

Definition at line 103 of file Reshaped.h.

◆ Impl

template<typename XprType , int Rows, int Cols, int Order>
typedef ReshapedImpl<XprType, Rows, Cols, Order, typename internal::traits<XprType>::StorageKind> Eigen::Reshaped< XprType, Rows, Cols, Order >::Impl
private

Definition at line 100 of file Reshaped.h.

Constructor & Destructor Documentation

◆ Reshaped() [1/2]

template<typename XprType , int Rows, int Cols, int Order>
Eigen::Reshaped< XprType, Rows, Cols, Order >::Reshaped ( XprType &  xpr)
inline

Fixed-size constructor

Definition at line 110 of file Reshaped.h.

111  : Impl(xpr)
112  {
113  EIGEN_STATIC_ASSERT(RowsAtCompileTime!=Dynamic && ColsAtCompileTime!=Dynamic,THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE)
114  eigen_assert(Rows * Cols == xpr.rows() * xpr.cols());
115  }
#define eigen_assert(x)
Definition: Macros.h:902
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
ReshapedImpl< XprType, Rows, Cols, Order, typename internal::traits< XprType >::StorageKind > Impl
Definition: Reshaped.h:100
const int Dynamic
Definition: Constants.h:24

◆ Reshaped() [2/2]

template<typename XprType , int Rows, int Cols, int Order>
Eigen::Reshaped< XprType, Rows, Cols, Order >::Reshaped ( XprType &  xpr,
Index  reshapeRows,
Index  reshapeCols 
)
inline

Dynamic-size constructor

Definition at line 120 of file Reshaped.h.

122  : Impl(xpr, reshapeRows, reshapeCols)
123  {
124  eigen_assert((RowsAtCompileTime==Dynamic || RowsAtCompileTime==reshapeRows)
125  && (ColsAtCompileTime==Dynamic || ColsAtCompileTime==reshapeCols));
126  eigen_assert(reshapeRows * reshapeCols == xpr.rows() * xpr.cols());
127  }

The documentation for this class was generated from the following file: