espnet2.gan_svs.visinger2.ddsp.safe_log
Less than 1 minute
espnet2.gan_svs.visinger2.ddsp.safe_log
espnet2.gan_svs.visinger2.ddsp.safe_log(x)
Computes the safe logarithm of a tensor.
This function applies the logarithm operation to the input tensor x while ensuring numerical stability by adding a small constant (1e-7) to x. This prevents issues that may arise from taking the logarithm of zero or negative values.
- Parameters:x (torch.Tensor) – The input tensor for which the safe logarithm is to be computed.
- Returns: A tensor containing the safe logarithm of the input tensor.
- Return type: torch.Tensor
Examples
>>> import torch
>>> x = torch.tensor([0.0, 1.0, 10.0])
>>> safe_log(x)
tensor([-7.0000e-08, 0.0000e+00, 2.3026e+00])
NOTE
This function is particularly useful in scenarios where the input tensor may contain zeros, such as in probability distributions or feature transformations.