cxx11_tensor_lvalue.cpp 950 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@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. #include <Eigen/CXX11/Tensor>
  11. using Eigen::Tensor;
  12. using Eigen::RowMajor;
  13. static void test_compound_assignment()
  14. {
  15. Tensor<float, 3> mat1(2,3,7);
  16. Tensor<float, 3> mat2(2,3,7);
  17. Tensor<float, 3> mat3(2,3,7);
  18. mat1.setRandom();
  19. mat2.setRandom();
  20. mat3 = mat1;
  21. mat3 += mat2;
  22. for (int i = 0; i < 2; ++i) {
  23. for (int j = 0; j < 3; ++j) {
  24. for (int k = 0; k < 7; ++k) {
  25. VERIFY_IS_APPROX(mat3(i,j,k), mat1(i,j,k) + mat2(i,j,k));
  26. }
  27. }
  28. }
  29. }
  30. EIGEN_DECLARE_TEST(cxx11_tensor_lvalue)
  31. {
  32. CALL_SUBTEST(test_compound_assignment());
  33. }