nestbyvalue.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2019 Gael Guennebaud <gael.guennebaud@inria.fr>
  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. #define TEST_ENABLE_TEMPORARY_TRACKING
  10. #include "main.h"
  11. typedef NestByValue<MatrixXd> CpyMatrixXd;
  12. typedef CwiseBinaryOp<internal::scalar_sum_op<double,double>,const CpyMatrixXd,const CpyMatrixXd> XprType;
  13. XprType get_xpr_with_temps(const MatrixXd& a)
  14. {
  15. MatrixXd t1 = a.rowwise().reverse();
  16. MatrixXd t2 = a+a;
  17. return t1.nestByValue() + t2.nestByValue();
  18. }
  19. EIGEN_DECLARE_TEST(nestbyvalue)
  20. {
  21. for(int i = 0; i < g_repeat; i++) {
  22. Index rows = internal::random<Index>(1,EIGEN_TEST_MAX_SIZE);
  23. Index cols = internal::random<Index>(1,EIGEN_TEST_MAX_SIZE);
  24. MatrixXd a = MatrixXd(rows,cols);
  25. nb_temporaries = 0;
  26. XprType x = get_xpr_with_temps(a);
  27. VERIFY_IS_EQUAL(nb_temporaries,6);
  28. MatrixXd b = x;
  29. VERIFY_IS_EQUAL(nb_temporaries,6+1);
  30. VERIFY_IS_APPROX(b, a.rowwise().reverse().eval() + (a+a).eval());
  31. }
  32. }