You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009 Keir Mierle <mierle@gmail.com>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include "main.h"
  10. template<DenseIndex rows, DenseIndex cols>
  11. void resizeLikeTest()
  12. {
  13. MatrixXf A(rows, cols);
  14. MatrixXf B;
  15. Matrix<double, rows, cols> C;
  16. B.resizeLike(A);
  17. C.resizeLike(B); // Shouldn't crash.
  18. VERIFY(B.rows() == rows && B.cols() == cols);
  19. VectorXf x(rows);
  20. RowVectorXf y;
  21. y.resizeLike(x);
  22. VERIFY(y.rows() == 1 && y.cols() == rows);
  23. y.resize(cols);
  24. x.resizeLike(y);
  25. VERIFY(x.rows() == cols && x.cols() == 1);
  26. }
  27. void resizeLikeTest12() { resizeLikeTest<1,2>(); }
  28. void resizeLikeTest1020() { resizeLikeTest<10,20>(); }
  29. void resizeLikeTest31() { resizeLikeTest<3,1>(); }
  30. void test_resize()
  31. {
  32. CALL_SUBTEST(resizeLikeTest12() );
  33. CALL_SUBTEST(resizeLikeTest1020() );
  34. CALL_SUBTEST(resizeLikeTest31() );
  35. }