MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / softplus

Function softplus

monai/transforms/utils_pytorch_numpy_unification.py:58–69  ·  view source on GitHub ↗

stable softplus through `np.logaddexp` with equivalent implementation for torch. Args: x: array/tensor. Returns: Softplus of the input.

(x: NdarrayOrTensor)

Source from the content-addressed store, hash-verified

56
57
58def 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
72def allclose(a: NdarrayTensor, b: NdarrayOrTensor, rtol=1e-5, atol=1e-8, equal_nan=False) -> bool:

Callers 1

soft_clipFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…