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