mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-16 21:00:14 +00:00
### Description
```math
\tanh(x)=\frac{e^x-e^{-x}}{e^x+e^{-x}}=
\left\{
\begin{array}{cc}
-\frac{1-e^{-2\cdot(-x)}}{1+e^{-2\cdot(-x)}}, & x<0 \\
0, & x=0 \\
\frac{1-e^{-2x}}{1+e^{-2x}}, & x>0
\end{array}
\right.
```
### Motivation and Context
On some platforms,
$$\tanh(1000)=\frac{e^{1000}-e^{-1000}}{e^{1000}+e^{-1000}}$$ would
produce NaN instead of 0.999... or 1 (imagine $e^{1000}=\infty$ and
$\frac{\infty}{\infty}$ explodes).
26 lines
531 B
Text
26 lines
531 B
Text
[
|
|
{
|
|
"name": "tanh with no attributes",
|
|
"operator": "Tanh",
|
|
"attributes": [],
|
|
"cases": [
|
|
{
|
|
"name": "T[2,4]",
|
|
"inputs": [
|
|
{
|
|
"data": [-1000, -1, 0, 0.1, 0.2, 0.3, 0.4, 1000],
|
|
"dims": [2, 4],
|
|
"type": "float32"
|
|
}
|
|
],
|
|
"outputs": [
|
|
{
|
|
"data": [-1, -0.761594, 0, 0.099668, 0.197375, 0.291313, 0.379949, 1],
|
|
"dims": [2, 4],
|
|
"type": "float32"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|