def validate_pred_score(
        pred_score: np.ndarray | float | None,
        anomaly_map: np.ndarray | None = None,
    ) -> np.ndarray | None:
        """Validate the prediction score.

        Validates and normalizes prediction scores to float32 numpy arrays.

        Args:
            pred_score (``np.ndarray`` | ``float`` | ``None``): Input prediction score.
            anomaly_map (``np.ndarray`` | ``None``): Input anomaly map.

        Returns:
            ``np.ndarray`` | ``None``: Validated score as float32 array, or None.

        Raises:
            TypeError: If ``pred_score`` cannot be converted to numpy array.
            ValueError: If ``pred_score`` is not scalar.

        Example:
            Validate prediction scores::

                >>> import numpy as np
                >>> from anomalib.data.validators import NumpyImageValidator
                >>> score = 0.8
                >>> validated_score = NumpyImageValidator.validate_pred_score(score)
                >>> validated_score
                array(0.8, dtype=float32)
                >>> score_array = np.array(0.7)
                >>> validated_score = NumpyImageValidator.validate_pred_score(score_array)
                >>> validated_score
                array(0.7, dtype=float32)

        Note:
            - If input is None and anomaly_map provided, returns max of anomaly_map
            - Output is always float32 type
            - None inputs with no anomaly_map return None
        """
        if pred_score is None:
            return np.amax(anomaly_map) if anomaly_map is not None else None

        if not isinstance(pred_score, np.ndarray):
            try:
                pred_score = np.array(pred_score)
            except Exception as e:
                msg = "Failed to convert pred_score to a numpy.ndarray."
                raise ValueError(msg) from e
        pred_score = pred_score.squeeze()
        if pred_score.ndim != 0:
            msg = f"Predicted score must be a scalar, got shape {pred_score.shape}."
            raise ValueError(msg)

        return pred_score.astype(np.float32)
Validate the prediction score.

        Validates and normalizes prediction scores to float32 numpy arrays.

        Args:
            pred_score (``np.ndarray`` | ``float`` | ``None``): Input prediction score.
            anomaly_map (``np.ndarray`` | ``None``): Input anomaly map.

        Returns:
            ``np.ndarray`` | ``None``: Validated score as float32 array, or None.

        Raises:
            TypeError: If ``pred_score`` cannot be converted to numpy array.
            ValueError: If ``pred_score`` is not scalar.

        Example:
            Validate prediction scores::

                >>> import numpy as np
                >>> from anomalib.data.validators import NumpyImageValidator
                >>> score = 0.8
                >>> validated_score = NumpyImageValidator.validate_pred_score(score)
                >>> validated_score
                array(0.8, dtype=float32)
                >>> score_array = np.array(0.7)
                >>> validated_score = NumpyImageValidator.validate_pred_score(score_array)
                >>> validated_score
                array(0.7, dtype=float32)

        Note:
            - If input is None and anomaly_map provided, returns max of anomaly_map
            - Output is always float32 type
            - None inputs with no anomaly_map return None
        
src/anomalib/data/validators/numpy/image.py