xref: /aosp_15_r20/external/eigen/doc/examples/class_Reshaped.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li #include <Eigen/Core>
2*bf2c3715SXin Li #include <iostream>
3*bf2c3715SXin Li using namespace std;
4*bf2c3715SXin Li using namespace Eigen;
5*bf2c3715SXin Li 
6*bf2c3715SXin Li template<typename Derived>
7*bf2c3715SXin Li const Reshaped<const Derived>
reshape_helper(const MatrixBase<Derived> & m,int rows,int cols)8*bf2c3715SXin Li reshape_helper(const MatrixBase<Derived>& m, int rows, int cols)
9*bf2c3715SXin Li {
10*bf2c3715SXin Li   return Reshaped<const Derived>(m.derived(), rows, cols);
11*bf2c3715SXin Li }
12*bf2c3715SXin Li 
main(int,char **)13*bf2c3715SXin Li int main(int, char**)
14*bf2c3715SXin Li {
15*bf2c3715SXin Li   MatrixXd m(3, 4);
16*bf2c3715SXin Li   m << 1, 4, 7, 10,
17*bf2c3715SXin Li        2, 5, 8, 11,
18*bf2c3715SXin Li        3, 6, 9, 12;
19*bf2c3715SXin Li   cout << m << endl;
20*bf2c3715SXin Li   Ref<const MatrixXd> n = reshape_helper(m, 2, 6);
21*bf2c3715SXin Li   cout << "Matrix m is:" << endl << m << endl;
22*bf2c3715SXin Li   cout << "Matrix n is:" << endl << n << endl;
23*bf2c3715SXin Li }
24