CADETProcess.dataStructure.parameter.RangedArray#
- class CADETProcess.dataStructure.parameter.RangedArray(*args: Any, lb: float = -inf, lb_op: Callable = <built-in function lt>, ub: float = inf, ub_op: Callable = <built-in function gt>, **kwargs: Any)[source]#
Bases:
RangedParameter descriptor for arrays with elements constrained within some bounds.
This class extends the Ranged descriptor to support array-like structures (lists, numpy arrays, etc.). Each element in the array is individually checked against the specified bounds.
See also
Notes
The class uses numpy for efficient element-wise comparison.
In case of out-of-bound values, the raised exception specifies the index/indices of such values.
Examples
Constraining elements of an array parameter between 0 and 10:
>>> class MyClass: ... values = RangedArray(lb=0, ub=10) >>> obj = MyClass() >>> obj.values = [5, 7, 2] # This is valid >>> obj.values = [5, -1, 2] # Raises an error indicating the second element is below the lower bound.
- check_range(value: ArrayLike) None[source]#
Check each element of an array-like structure against specified bounds.
- Parameters:
- valuearray-like
The array whose elements need to be checked against the range.
- Raises:
- ValueError
If any element(s) of the array are outside the specified bounds. The raised exception indicates the index/indices of out-of-bound values.