bindings
compression_safeguards.utils.bindings
Types and helpers for late-bound safeguard parameters.
Classes:
Parameter
Parameter(param: str)
Bases: str
Parameter name / identifier type.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Value
module-attribute
Parameter value type that includes scalar numbers and arrays thereof.
Bindings
Bindings(**kwargs: Value)
Bindings from parameter names to values.
| Parameters: |
|
|---|
Methods:
-
update–Create new bindings that contain the old and the new parameters, where
-
parameters–Access the set of parameter names for which bindings exist.
-
resolve_ndarray_with_lossless_cast–Resolve the
parameter to a numpy array with the givenshapeand -
resolve_ndarray_with_saturating_finite_float_cast–Resolve the
parameter to a numpy array with the givenshapeand -
expect_broadcastable_to–Check that all late-bound array parameters can be broadcast to the
-
apply_slice_index–Apply the slice
indexto the late-bound array values and return the sliced bindings. -
apply_roll–Apply the roll
shiftto the late-bound array values and return the rolled bindings. -
get_config–Returns the configuration of the bindings in a JSON compatible format.
-
from_config–Instantiate the bindings from a configuration
dict.
update
parameters
resolve_ndarray_with_lossless_cast
resolve_ndarray_with_lossless_cast(
param: Parameter, shape: Si, dtype: dtype[T]
) -> ndarray[Si, dtype[T]]
Resolve the parameter to a numpy array with the given shape and
dtype.
The parameter must be contained in the bindings and refer to a value
that can be broadcast to the shape and losslessly converted to the
dtype.
| Parameters: |
|---|
| Returns: |
|---|
| Raises: |
|
|---|
resolve_ndarray_with_saturating_finite_float_cast
resolve_ndarray_with_saturating_finite_float_cast(
param: Parameter, shape: Si, dtype: dtype[F]
) -> ndarray[Si, dtype[F]]
Resolve the parameter to a numpy array with the given shape and
floating-point dtype.
The parameter must be contained in the bindings and refer to a finite
value that can be broadcast to the shape. It will be converted to the
floating-point dtype, with under- and overflows being clamped to
finite values.
| Parameters: |
|---|
| Returns: |
|---|
| Raises: |
|
|---|
expect_broadcastable_to
Check that all late-bound array parameters can be broadcast to the
given shape.
| Parameters: |
|---|
| Raises: |
|
|---|
apply_slice_index
Apply the slice index to the late-bound array values and return the sliced bindings.
The index is only applied to an array value if
- the value is not scalar (no effect)
- the value has the same number of dimensions as the index (bail out)
Furthermore, the index is only applied along dimensions with a size greater than 1, since smaller dimensions can be broadcast.
| Parameters: |
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
apply_roll
Apply the roll shift to the late-bound array values and return the rolled bindings.
The shift is only applied to an array value if
- the value is not scalar (no effect)
- the value has the same number of dimensions as the shift (bail out)
Furthermore, the shift is only applied along dimensions with a size greater than 1, since smaller dimensions can be broadcast.
| Parameters: |
|---|
| Returns: |
|
|---|