def validate_gt_mask(mask: np.ndarray | None) -> np.ndarray | None:
        """Validate the ground truth mask.

        Args:
            mask (``np.ndarray`` | ``None``): Input mask to validate.

        Returns:
            ``np.ndarray`` | ``None``: Validated mask as boolean numpy array, or None if
                input is None.

        Raises:
            TypeError: If ``mask`` is not a numpy array.
            ValueError: If ``mask`` dimensions or channel count are invalid.

        Example:
            >>> import numpy as np
            >>> validator = NumpyVideoValidator()
            >>> mask = np.random.randint(0, 2, size=(5, 224, 224))  # [T, H, W]
            >>> validated_mask = validator.validate_gt_mask(mask)
            >>> print(validated_mask.shape, validated_mask.dtype)
            (5, 224, 224) bool
        """
        if mask is None:
            return None
        if not isinstance(mask, np.ndarray):
            msg = f"Mask must be a numpy.ndarray, got {type(mask)}."
            raise TypeError(msg)
        if mask.ndim not in {3, 4}:
            msg = f"Mask must have shape [T, H, W] or [T, H, W, 1] got shape {mask.shape}."
            raise ValueError(msg)
        if mask.ndim == 4 and mask.shape[3] != 1:
            msg = f"Mask must have 1 channel, got {mask.shape[3]}."
            raise ValueError(msg)
        return mask.astype(bool)
Validate the ground truth mask.

        Args:
            mask (``np.ndarray`` | ``None``): Input mask to validate.

        Returns:
            ``np.ndarray`` | ``None``: Validated mask as boolean numpy array, or None if
                input is None.

        Raises:
            TypeError: If ``mask`` is not a numpy array.
            ValueError: If ``mask`` dimensions or channel count are invalid.

        Example:
            >>> import numpy as np
            >>> validator = NumpyVideoValidator()
            >>> mask = np.random.randint(0, 2, size=(5, 224, 224))  # [T, H, W]
            >>> validated_mask = validator.validate_gt_mask(mask)
            >>> print(validated_mask.shape, validated_mask.dtype)
            (5, 224, 224) bool
        
src/anomalib/data/validators/numpy/video.py