def is_rate_curve(
    rate_curve: Tensor,
    nan_allowed: bool,
    decreasing: bool,
) -> None:
    """Validate rate curve tensor.

    Args:
        rate_curve: Tensor of shape (N,) containing rate values.
        nan_allowed: Whether NaN values are allowed.
        decreasing: Whether curve should be monotonically decreasing.

    Raises:
        ValueError: If curve is not monotonic in specified direction.

    Example:
        >>> curve = torch.tensor([0.9, 0.5, 0.1])
        >>> is_rate_curve(curve, nan_allowed=False, decreasing=True)  # No error
        >>> bad_curve = torch.tensor([0.1, 0.5, 0.9])
        >>> is_rate_curve(bad_curve, nan_allowed=False, decreasing=True)
        ValueError: Expected rate curve to be monotonically decreasing
    """
    is_rates(rate_curve, nan_allowed=nan_allowed)

    diffs = torch.diff(rate_curve)
    diffs_valid = diffs[~torch.isnan(diffs)] if nan_allowed else diffs

    if decreasing and (diffs_valid > 0).any():
        msg = "Expected rate curve to be monotonically decreasing, but got non-monotonically decreasing values."
        raise ValueError(msg)

    if not decreasing and (diffs_valid < 0).any():
        msg = "Expected rate curve to be monotonically increasing, but got non-monotonically increasing values."
        raise ValueError(msg)
Validate rate curve tensor.

    Args:
        rate_curve: Tensor of shape (N,) containing rate values.
        nan_allowed: Whether NaN values are allowed.
        decreasing: Whether curve should be monotonically decreasing.

    Raises:
        ValueError: If curve is not monotonic in specified direction.

    Example:
        >>> curve = torch.tensor([0.9, 0.5, 0.1])
        >>> is_rate_curve(curve, nan_allowed=False, decreasing=True)  # No error
        >>> bad_curve = torch.tensor([0.1, 0.5, 0.9])
        >>> is_rate_curve(bad_curve, nan_allowed=False, decreasing=True)
        ValueError: Expected rate curve to be monotonically decreasing
    
src/anomalib/metrics/pimo/_validate.py