def is_rates(rates: Tensor, nan_allowed: bool) -> None:
    """Validate rates tensor.

    Args:
        rates: Tensor of shape (N,) containing rate values in [0,1].
        nan_allowed: Whether NaN values are allowed.

    Raises:
        ValueError: If tensor is not 1D, contains values outside [0,1], or has
            NaN when not allowed.
        TypeError: If tensor is not floating point.

    Example:
        >>> rates = torch.tensor([0.1, 0.5, 0.9])
        >>> is_rates(rates, nan_allowed=False)  # No error
        >>> bad_rates = torch.tensor([0.1, float('nan'), 0.9])
        >>> is_rates(bad_rates, nan_allowed=False)  # Raises ValueError
    """
    if rates.ndim != 1:
        msg = f"Expected rates to be 1D, but got {rates.ndim}D."
        raise ValueError(msg)

    if not rates.dtype.is_floating_point:
        msg = f"Expected rates to have dtype of float type, but got {rates.dtype}."
        raise TypeError(msg)

    isnan_mask = torch.isnan(rates)
    if nan_allowed:
        # if they are all nan, then there is nothing to validate
        if isnan_mask.all():
            return
        valid_values = rates[~isnan_mask]
    elif isnan_mask.any():
        msg = "Expected rates to not contain NaN values, but got NaN values."
        raise ValueError(msg)
    else:
        valid_values = rates

    if (valid_values < 0).any():
        msg = "Expected rates to have values in the interval [0, 1], but got values < 0."
        raise ValueError(msg)

    if (valid_values > 1).any():
        msg = "Expected rates to have values in the interval [0, 1], but got values > 1."
        raise ValueError(msg)
Validate rates tensor.

    Args:
        rates: Tensor of shape (N,) containing rate values in [0,1].
        nan_allowed: Whether NaN values are allowed.

    Raises:
        ValueError: If tensor is not 1D, contains values outside [0,1], or has
            NaN when not allowed.
        TypeError: If tensor is not floating point.

    Example:
        >>> rates = torch.tensor([0.1, 0.5, 0.9])
        >>> is_rates(rates, nan_allowed=False)  # No error
        >>> bad_rates = torch.tensor([0.1, float('nan'), 0.9])
        >>> is_rates(bad_rates, nan_allowed=False)  # Raises ValueError
    
src/anomalib/metrics/pimo/_validate.py