torch.distributions.integer_interval
function integer_interval(lower_bound: number, upper_bound: number): _IntegerIntervalCreates a constraint for integer values in a closed interval [lower_bound, upper_bound].
Returns a constraint that validates whether tensor values are integers in the range [lower_bound, upper_bound] (inclusive on both sides). Useful for:
- Count/discrete parameters (number of categories, trials)
- Categorical and multinomial distributions
- Discrete random variables
- Integer-valued parameters
- Closed interval: Both bounds are inclusive [lower, upper]
- Integer check: Validates values are whole numbers (no decimals)
- Both conditions: Must be integer AND in range
- Discrete constraint: Used for discrete distributions
Parameters
lower_boundnumber- The minimum integer value (inclusive)
upper_boundnumber- The maximum integer value (inclusive)
Returns
_IntegerInterval– A constraint object that validates integer values in [lower_bound, upper_bound]Examples
const valid_categories = torch.distributions.constraints.integer_interval(0, 10);
const categories = torch.tensor([0, 5, 10]);
valid_categories.check(categories); // Validates all are integers in [0, 10]
// Both bounds are inclusive for integers
const boundary = torch.tensor([0, 10]);
valid_categories.check(boundary); // true - boundary values included
// Non-integers are rejected
const non_int = torch.tensor([5.5]);
valid_categories.check(non_int); // false - not an integerSee Also
- PyTorch torch.distributions.constraints.integer_interval()
- half_open_interval - For continuous half-open intervals
- interval - For continuous open intervals
- nonnegative_integer - For non-negative integers only
- constraints - Other available constraints