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.

46 lines
1004 B

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2015 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 <StormEigen/CXX11/Tensor>
  11. using StormEigen::Tensor;
  12. using StormEigen::RowMajor;
  13. static void test_tanh()
  14. {
  15. Tensor<float, 1> vec1({6});
  16. vec1.setRandom();
  17. Tensor<float, 1> vec2 = vec1.tanh();
  18. for (int i = 0; i < 6; ++i) {
  19. VERIFY_IS_APPROX(vec2(i), tanhf(vec1(i)));
  20. }
  21. }
  22. static void test_sigmoid()
  23. {
  24. Tensor<float, 1> vec1({6});
  25. vec1.setRandom();
  26. Tensor<float, 1> vec2 = vec1.sigmoid();
  27. for (int i = 0; i < 6; ++i) {
  28. VERIFY_IS_APPROX(vec2(i), 1.0f / (1.0f + std::exp(-vec1(i))));
  29. }
  30. }
  31. void test_cxx11_tensor_math()
  32. {
  33. CALL_SUBTEST(test_tanh());
  34. CALL_SUBTEST(test_sigmoid());
  35. }