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 10 #include "main.h" 11 12 #include <Eigen/CXX11/Tensor> 13 14 using Eigen::Tensor; 15 using Eigen::RowMajor; 16 test_tanh()17static void test_tanh() 18 { 19 Tensor<float, 1> vec1(6); 20 vec1.setRandom(); 21 22 Tensor<float, 1> vec2 = vec1.tanh(); 23 24 for (int i = 0; i < 6; ++i) { 25 VERIFY_IS_APPROX(vec2(i), tanhf(vec1(i))); 26 } 27 } 28 test_sigmoid()29static void test_sigmoid() 30 { 31 Tensor<float, 1> vec1(6); 32 vec1.setRandom(); 33 34 Tensor<float, 1> vec2 = vec1.sigmoid(); 35 36 for (int i = 0; i < 6; ++i) { 37 VERIFY_IS_APPROX(vec2(i), 1.0f / (1.0f + std::exp(-vec1(i)))); 38 } 39 } 40 41 test_cxx11_tensor_math()42void test_cxx11_tensor_math() 43 { 44 CALL_SUBTEST(test_tanh()); 45 CALL_SUBTEST(test_sigmoid()); 46 } 47