torchsig.utils.verify.verify_bounds

torchsig.utils.verify.verify_bounds(a: float, name: str, low: float | None = None, high: float | None = None, clip_low: bool = False, clip_high: bool = False, exclude_low: bool = False, exclude_high: bool = False)[source]

Verifies if the value a is within the specified bounds (low, high). If a is outside the bounds, raises a ValueError. Optionally, clips the value of a to the bounds if it is outside the specified range.

Parameters:
  • a (float | int) – The value to be checked.

  • name (str) – The name of the value to be used in error messages.

  • low (float | int, optional) – The lower bound of the value. Defaults to None.

  • high (float | int, optional) – The upper bound of the value. Defaults to None.

  • clip_low (bool, optional) – If True, the value will be clipped to low if it is below low. Defaults to False.

  • clip_high (bool, optional) – If True, the value will be clipped to high if it exceeds high. Defaults to False.

  • exclude_low (bool, optional) – If True, a must be strictly greater than low. Defaults to False.

  • exclude_high (bool, optional) – If True, a must be strictly less than high. Defaults to False.

Raises:

ValueError – If a is out of bounds and clip_low or clip_high are not enabled.

Returns:

The value a, either adjusted to the bounds or left unchanged.

Return type:

float | int