lupy.typeutils

Utility functions for type checking array dimensions and types.

These functions are intended to be used as type guards for static type checking with runtime assertions.

lupy.typeutils.is_1d_array(arr: ndarray[Any, DType_co]) TypeIs[ndarray[tuple[int], DType_co]][source]

Check if the given array is a 1-dimensional array

lupy.typeutils.is_2d_array(arr: ndarray[Any, DType_co]) TypeIs[ndarray[tuple[int, int], DType_co]][source]

Check if the given array is a 2-dimensional array

lupy.typeutils.is_3d_array(arr: ndarray[Any, DType_co]) TypeIs[ndarray[tuple[int, int, int], DType_co]][source]

Check if the given array is a 3-dimensional array

lupy.typeutils.is_nd_array(arr: ndarray[tuple[Any, ...], dtype[Any]], ndim: Literal[1]) TypeIs[ndarray[tuple[int], DType_co]][source]
lupy.typeutils.is_nd_array(arr: ndarray[tuple[Any, ...], dtype[Any]], ndim: Literal[2]) TypeIs[ndarray[tuple[int, int], DType_co]]
lupy.typeutils.is_nd_array(arr: ndarray[tuple[Any, ...], dtype[Any]], ndim: Literal[3]) TypeIs[ndarray[tuple[int, int, int], DType_co]]
lupy.typeutils.is_nd_array(arr: ndarray[tuple[Any, ...], dtype[Any]], ndim: int) TypeIs[ndarray[Any, DType_co]]

Check if the given array shape matches the specified number of dimensions

lupy.typeutils.ensure_1d_array(arr: ndarray[Any, DType_co]) ndarray[tuple[int], DType_co][source]

Ensure the given array is 1-dimensional and return it

lupy.typeutils.ensure_2d_array(arr: ndarray[Any, DType_co]) ndarray[tuple[int, int], DType_co][source]

Ensure the given array is 2-dimensional and return it

lupy.typeutils.ensure_3d_array(arr: ndarray[Any, DType_co]) ndarray[tuple[int, int, int], DType_co][source]

Ensure the given array is 3-dimensional and return it

lupy.typeutils.ensure_nd_array(arr: ndarray[Any, DType_co], ndim: Literal[1]) ndarray[tuple[int], DType_co][source]
lupy.typeutils.ensure_nd_array(arr: ndarray[Any, DType_co], ndim: Literal[2]) ndarray[tuple[int, int], DType_co]
lupy.typeutils.ensure_nd_array(arr: ndarray[Any, DType_co], ndim: Literal[3]) ndarray[tuple[int, int, int], DType_co]
lupy.typeutils.ensure_nd_array(arr: ndarray[Any, DType_co], ndim: int) ndarray[Any, DType_co]

Ensure the given array has the specified number of dimensions and return it

lupy.typeutils.is_array_of_shape(arr: ndarray[tuple[int, ...], DType_t], shape: ShapeT) TypeIs[ndarray[ShapeT, DType_t]][source]

Check if the given array’s shape matches the specified shape

lupy.typeutils.ensure_array_of_shape(arr: ndarray[tuple[int, ...], DType_t], shape: ShapeT) ndarray[ShapeT, DType_t][source]

Ensure the given array’s shape matches the specified shape and return it

lupy.typeutils.is_array_of_dtype(arr: ndarray[ShapeT, Any], dtype: DType_t) TypeIs[ndarray[ShapeT, DType_t]][source]

Check if the given array’s dtype matches the specified dtype

lupy.typeutils.is_float_array(arr: ndarray[ShapeT, Any]) TypeIs[ndarray[ShapeT, dtype[floating]]][source]

Check if the given array’s dtype is a floating-point type

lupy.typeutils.is_float32_array(arr: ndarray[ShapeT, Any]) TypeIs[ndarray[ShapeT, dtype[float32]]][source]

Check if the given array’s dtype is numpy.float32

lupy.typeutils.is_float64_array(arr: ndarray[ShapeT, Any]) TypeIs[ndarray[ShapeT, dtype[float64]]][source]

Check if the given array’s dtype is numpy.float64

lupy.typeutils.is_index_array(arr: ndarray[ShapeT, Any]) TypeIs[ndarray[ShapeT, dtype[int64]]][source]

Check if the given array’s dtype is an integer type suitable for indexing

lupy.typeutils.is_bool_array(arr: ndarray[ShapeT, Any]) TypeIs[ndarray[ShapeT, dtype[bool]]][source]

Check if the given array’s dtype is boolean

lupy.typeutils.is_complex_array(arr: ndarray[ShapeT, Any]) TypeIs[ndarray[ShapeT, dtype[complex128]]][source]

Check if the given array’s dtype is a complex floating-point type

lupy.typeutils.is_meter_array(arr: ndarray[tuple[Any, ...], dtype[Any]]) TypeIs[MeterArray][source]

Check if the given array is a MeterArray

lupy.typeutils.ensure_meter_array(arr: ndarray[tuple[Any, ...], dtype[Any]]) MeterArray[source]

Ensure the given array is a MeterArray and return it

lupy.typeutils.is_true_peak_array(arr: ndarray[tuple[Any, ...], dtype[Any]], num_channels: NumChannelsT) TypeIs[TruePeakArray[NumChannelsT]][source]

Check if the given array is a TruePeakArray for the specified number of channels

Parameters:
lupy.typeutils.ensure_true_peak_array(arr: ndarray[tuple[Any, ...], dtype[Any]], num_channels: NumChannelsT) TruePeakArray[NumChannelsT][source]

Ensure the given array is a TruePeakArray for the specified number of channels and return it

Parameters:
lupy.typeutils.build_meter_array(size: int) MeterArray[source]

Build a MeterArray of the given size

lupy.typeutils.build_true_peak_dtype(num_channels: NumChannelsT) TruePeakDtype[NumChannelsT][source]

Build a TruePeakDtype for the given number of channels

Parameters:

num_channels (NumChannelsT) – The number of audio channels

lupy.typeutils.build_true_peak_array(num_channels: NumChannelsT, size: int) TruePeakArray[NumChannelsT][source]

Build a TruePeakArray for the given number of channels and size

Parameters:
  • num_channels (NumChannelsT) – The number of audio channels

  • size (int) – The number of elements in the array