stable softplus through `np.logaddexp` with equivalent implementation for torch. Args: x: array/tensor. Returns: Softplus of the input.
(x: NdarrayOrTensor)
| 56 | |
| 57 | |
| 58 | def softplus(x: NdarrayOrTensor) -> NdarrayOrTensor: |
| 59 | """stable softplus through `np.logaddexp` with equivalent implementation for torch. |
| 60 | |
| 61 | Args: |
| 62 | x: array/tensor. |
| 63 | |
| 64 | Returns: |
| 65 | Softplus of the input. |
| 66 | """ |
| 67 | if isinstance(x, np.ndarray): |
| 68 | return cast(np.ndarray, np.logaddexp(np.zeros_like(x), x)) |
| 69 | return torch.logaddexp(torch.zeros_like(x), x) |
| 70 | |
| 71 | |
| 72 | def allclose(a: NdarrayTensor, b: NdarrayOrTensor, rtol=1e-5, atol=1e-8, equal_nan=False) -> bool: |
no outgoing calls
no test coverage detected
searching dependent graphs…