Description
colour.utilities.interval() (and the dependent is_uniform()) raise an
IndexError when passed a distribution with fewer than two elements (single
element or empty array).
Code for Reproduction
import numpy as np
from colour.utilities import interval, is_uniform
interval(np.array([1.0])) # IndexError: index 0 is out of bounds for axis 0 with size 0
is_uniform(np.array([1.0])) # same error, via interval()
Exception Message
IndexError: index 0 is out of bounds for axis 0 with size 0
The crash happens at:
differences = np.abs(distribution[1:] - distribution[:-1])
if unique and np.all(differences == differences[0]): # differences is empty -> crash
Fix
I have a fix on the branch gaoflow:fix/interval-single-element-indexerror — guard with if differences.size == 0 before accessing differences[0], returning the empty array directly. Also update is_uniform() to treat a zero-interval distribution as uniform (the correct mathematical interpretation for a single point or empty set).
Environment Information
Description
colour.utilities.interval()(and the dependentis_uniform()) raise anIndexErrorwhen passed a distribution with fewer than two elements (singleelement or empty array).
Code for Reproduction
Exception Message
The crash happens at:
Fix
I have a fix on the branch
gaoflow:fix/interval-single-element-indexerror— guard withif differences.size == 0before accessingdifferences[0], returning the empty array directly. Also updateis_uniform()to treat a zero-interval distribution as uniform (the correct mathematical interpretation for a single point or empty set).Environment Information