def validate_pred_score(
        pred_score: torch.Tensor | float | None,
        anomaly_map: torch.Tensor | None = None,
    ) -> torch.Tensor | None:
        """Validate prediction score.

        Validates prediction scores and optionally computes them from anomaly maps.

        Args:
            pred_score (torch.Tensor | float | None): Input prediction score or ``None``.
            anomaly_map (torch.Tensor | None): Optional anomaly map to compute score from.

        Returns:
            torch.Tensor | None: Validated float32 prediction score or ``None``.

        Raises:
            TypeError: If ``pred_score`` is not a float, tensor or ``None``.
            ValueError: If prediction score is not a scalar.

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoValidator
            >>> score = 0.8
            >>> validated = VideoValidator.validate_pred_score(score)
            >>> validated
            tensor(0.8000)
        """
        if pred_score is None:
            return torch.amax(anomaly_map, dim=(-3, -2, -1)) if anomaly_map is not None else None

        if not isinstance(pred_score, torch.Tensor):
            try:
                pred_score = torch.tensor(pred_score)
            except Exception as e:
                msg = "Failed to convert pred_score to a torch.Tensor."
                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.to(torch.float32)
Validate prediction score.

        Validates prediction scores and optionally computes them from anomaly maps.

        Args:
            pred_score (torch.Tensor | float | None): Input prediction score or ``None``.
            anomaly_map (torch.Tensor | None): Optional anomaly map to compute score from.

        Returns:
            torch.Tensor | None: Validated float32 prediction score or ``None``.

        Raises:
            TypeError: If ``pred_score`` is not a float, tensor or ``None``.
            ValueError: If prediction score is not a scalar.

        Examples:
            >>> import torch
            >>> from anomalib.data.validators import VideoValidator
            >>> score = 0.8
            >>> validated = VideoValidator.validate_pred_score(score)
            >>> validated
            tensor(0.8000)
        
src/anomalib/data/validators/torch/video.py