validate_bool_mask#

validate_bool_mask(mask, name, *, shape=None, size=None)[source]#

Validate that mask is a boolean NumPy array of the expected extent.

Parameters:
  • mask (object) – The value to validate.

  • name (str) – Name of the argument, used in error messages.

  • shape (tuple of int, optional) – If given, the exact shape mask must have.

  • size (int, optional) – If given, the exact number of elements mask must have. Useful when the rank is allowed to vary but the total extent is fixed.

Returns:

The validated mask (returned unchanged for convenient chaining).

Return type:

numpy.ndarray of bool

Raises:
  • TypeError – If mask is not a numpy.ndarray.

  • ValueError – If mask is not of boolean dtype or does not match shape/size.