class_Reshaped.cpp 545 B

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