Skip to content

Commit d22aab5

Browse files
author
Olia
committed
improved std::tanh with formula with exponential function (e^x)
1 parent fd48a6d commit d22aab5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tmva/sofie/inc/TMVA/ROperator_Tanh.hxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "TMVA/RModel.hxx"
77

88
#include <sstream>
9+
#include <vector>
10+
#include <string>
911

1012
namespace TMVA{
1113
namespace Experimental{
@@ -57,8 +59,10 @@ public:
5759
std::stringstream out;
5860
size_t length = ConvertShapeToLength(fShape);
5961
out << "\n//------ TANH\n";
60-
out << SP << "for (int id = 0; id < " << length << " ; id++){\n";
61-
out << SP << SP << "tensor_" << fNY << "[id] = std::tanh(tensor_" << fNX << "[id]);\n";
62+
out << SP << "for (size_t id = 0; id < " << length << " ; id++){\n";
63+
out << SP << SP << "auto x = tensor_" << fNX << "[id];\n";
64+
out << SP << SP << "auto exp2x = std::exp(2.0f * x);\n";
65+
out << SP << SP << "tensor_" << fNY << "[id] = (exp2x - 1.0f) / (exp2x + 1.0f);\n";
6266
out << SP << "}\n";
6367
return out.str();
6468
}

0 commit comments

Comments
 (0)