same

compression_safeguards.safeguards.pointwise.same

Same value safeguard.

Classes:

  • SameValueSafeguard

    The SameValueSafeguard guarantees that if an element has a special

SameValueSafeguard

SameValueSafeguard(
    value: int | float | str | Parameter,
    *,
    exclusive: bool = False,
)

Bases: PointwiseSafeguard

flowchart LR compression_safeguards.safeguards.pointwise.same.SameValueSafeguard[SameValueSafeguard] compression_safeguards.safeguards.pointwise.abc.PointwiseSafeguard[PointwiseSafeguard] compression_safeguards.safeguards.abc.Safeguard[Safeguard] compression_safeguards.safeguards.pointwise.abc.PointwiseSafeguard --> compression_safeguards.safeguards.pointwise.same.SameValueSafeguard compression_safeguards.safeguards.abc.Safeguard --> compression_safeguards.safeguards.pointwise.abc.PointwiseSafeguard click compression_safeguards.safeguards.pointwise.same.SameValueSafeguard href "" "compression_safeguards.safeguards.pointwise.same.SameValueSafeguard" click compression_safeguards.safeguards.pointwise.abc.PointwiseSafeguard href "" "compression_safeguards.safeguards.pointwise.abc.PointwiseSafeguard" click compression_safeguards.safeguards.abc.Safeguard href "" "compression_safeguards.safeguards.abc.Safeguard"

The SameValueSafeguard guarantees that if an element has a special value in the input, that element also has bitwise the same value in the decompressed output.

This safeguard can be used for preserving e.g. zero values, missing values, pre-computed extreme values, or any other value of importance.

By default, elements that do not have the special value in the input may still have the value in the output. Enabling the exclusive flag enforces that an element in the output only has the special value if and only if it also has the value in the input, e.g. to ensure that only missing values in the input have the missing value bitpattern in the output.

Beware that +0.0 and -0.0 are semantically equivalent in floating-point but have different bitwise patterns. To preserve both, two same value safeguards are needed, one for each bitpattern.

Parameters:
  • value (int | float | str | Parameter) –

    The value of or the late-bound parameter name for the certain value that is preserved by this safeguard. Literal values are (unsafely) cast to the data dtype before binary comparison.

  • exclusive (bool, default: False ) –

    If True, non-value elements in the data stay non-value after applying corrections. If False, non-value values may have the value after applying corrections.

Raises:

Methods:

kind class-attribute

kind: str = 'same'

late_bound property

late_bound: Set[Parameter]

The set of late-bound parameters that this safeguard has.

Late-bound parameters are only bound when checking and applying the safeguard, in contrast to the normal early-bound parameters that are configured during safeguard initialisation.

Late-bound parameters can be used for parameters that depend on the specific data that is to be safeguarded.

check_pointwise

check_pointwise(
    data: ndarray[S, dtype[T]],
    approximation: ndarray[S, dtype[T]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> ndarray[S, dtype[bool]]

Check which elements preserve the special value from the data to the approximation array.

Parameters:
  • data (ndarray[S, dtype[T]]) –

    Original data array, relative to which the approximation is checked.

  • approximation (ndarray[S, dtype[T]]) –

    Approximation of the data array.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only check at data points where the condition is True.

Returns:
  • ok( ndarray[S, dtype[bool]] ) –

    Pointwise, True if the check succeeded for this element.

Raises:
  • LateBoundParameterResolutionError

    if the value is late-bound but its late-bound parameter is not in late_bound.

  • ValueError

    if the late-bound value could not be broadcast to the data's shape.

  • TypeError

    if the value is floating-point but the data is integer.

  • ValueError

    if not all values could not be losslessly converted to the data's type.

compute_safe_intervals

compute_safe_intervals(
    data: ndarray[S, dtype[T]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> IntervalUnion[T, int, int]

Compute the intervals in which the same value guarantee is upheld with respect to the data.

Parameters:
  • data (ndarray[S, dtype[T]]) –

    Data for which the safe intervals should be computed.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only compute the safe intervals at pointwise checks where the condition is True.

Returns:
  • intervals( IntervalUnion[T, int, int] ) –

    Union of intervals in which the same value guarantee is upheld.

Raises:
  • LateBoundParameterResolutionError

    if the value is late-bound but its late-bound parameter is not in late_bound.

  • ValueError

    if the late-bound value could not be broadcast to the data's shape.

  • TypeError

    if the value is floating-point but the data is integer.

  • ValueError

    if not all values could not be losslessly converted to the data's type.

compute_footprint

compute_footprint(
    foot: ndarray[S, dtype[bool]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> ndarray[S, dtype[bool]]

Compute the footprint of the foot array, e.g. for expanding data points into the pointwise checks that they contribute to.

The footprint is equivalent to foot & where.

Parameters:
  • foot (ndarray[S, dtype[bool]]) –

    Array for which the footprint is computed.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only compute the footprint at pointwise checks where the condition is True.

Returns:

compute_inverse_footprint

compute_inverse_footprint(
    foot: ndarray[S, dtype[bool]],
    *,
    late_bound: Bindings,
    where: Literal[True] | ndarray[S, dtype[bool]] = True,
) -> ndarray[S, dtype[bool]]

Compute the inverse footprint of the foot array, e.g. for expanding pointwise check fails into the points that could have contributed to the failures.

The inverse footprint is equivalent to foot & where.

Parameters:
  • foot (ndarray[S, dtype[bool]]) –

    Array for which the inverse footprint is computed.

  • late_bound (Bindings) –

    Bindings for late-bound parameters, including for this safeguard.

  • where (Literal[True] | ndarray[S, dtype[bool]], default: True ) –

    Only compute the inverse footprint at pointwise checks where the condition is True.

Returns:

get_config

get_config() -> dict[str, JSON]

Returns the configuration of the safeguard.

Returns:
  • config( dict[str, JSON] ) –

    Configuration of the safeguard.