cxx11_tensor_math.cpp
Go to the documentation of this file.
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 
17 static 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 
29 static 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 
43 {
44  CALL_SUBTEST(test_tanh());
45  CALL_SUBTEST(test_sigmoid());
46 }
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition: TensorBase.h:848
static void test_tanh()
void test_cxx11_tensor_math()
static void test_sigmoid()
The tensor class.
Definition: Tensor.h:63


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:09