easy primitives

Implement Tanh

Implement the hyperbolic tangent (tanh) activation function.

$$\tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}$$

Equivalently: $\tanh(x) = 2\sigma(2x) - 1$ where $\sigma$ is the sigmoid function.

Input: A tensor x of any shape

Output: A tensor of the same shape with values in $(-1, 1)$

Hints

activation basics
Detecting runtime...