Skip to content

Commit 5e39de9

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

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tmva/sofie/inc/TMVA/ROperator_Tanh.hxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ public:
5757
std::stringstream out;
5858
size_t length = ConvertShapeToLength(fShape);
5959
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";
60+
out << SP << "for (size_t id = 0; id < " << length << " ; id++){\n";
61+
out << SP << SP << "auto x = tensor_" << fNX << "[id];\n";
62+
out << SP << SP << "auto exp2x = std::exp(2.0f * x);\n";
63+
out << SP << SP << "tensor_" << fNY << "[id] = (exp2x - 1.0f) / (exp2x + 1.0f);\n";
6264
out << SP << "}\n";
6365
return out.str();
6466
}

0 commit comments

Comments
 (0)