Skip to content

voiage.core.utils.check_input_array

check_input_array([positional or keyword] arr: np.ndarray = None, [positional or keyword] expected_ndim: int | Sequence[int] = None, [positional or keyword] name: str = 'Input array', [positional or keyword] expected_dtype: np.dtype | type | str | None = None, [positional or keyword] allow_empty: bool = False, [positional or keyword] expected_shape: Sequence[int | None] | None = None) -> None

Validate a NumPy array against expected dimensions, dtype, and shape.

Args: arr (np.ndarray): The array to validate. expected_ndim (Union[int, Sequence[int]]): The expected number of dimensions, or a sequence of allowed numbers of dimensions. name (str): Name of the array for error messages. Defaults to “Input array”. expected_dtype (Optional[np.dtype]): Expected data type. If None, uses DEFAULT_DTYPE. If “any”, skips dtype check. allow_empty (bool): If False, raises error if the array is empty (size 0). expected_shape (Optional[Sequence[Optional[int]]]): Expected shape. Use None for dimensions that can have any size (e.g., (None, 3) for N-by-3).

InputError: If arr is not a NumPy array or fails validation. DimensionMismatchError: If dimensions or shape are incorrect.

Parameters:

  • arr np.ndarray
  • expected_ndim int | Sequence[int]
  • name str (default: 'Input array')
  • expected_dtype np.dtype | type | str | None (default: None)
  • allow_empty bool (default: False)
  • expected_shape Sequence[int | None] | None (default: None)

Returns: None