def test_aupimo_values(
    anomaly_maps: torch.Tensor,
    masks: torch.Tensor,
    fpr_bounds: tuple[float, float],
    expected_thresholds: torch.Tensor,
    expected_shared_fpr: torch.Tensor,
    expected_per_image_tprs: torch.Tensor,
    expected_image_classes: torch.Tensor,
    expected_aupimos: torch.Tensor,
) -> None:
    """Test if `aupimo()` returns the expected values."""

    def do_assertions(pimo_result: PIMOResult, aupimo_result: AUPIMOResult) -> None:
        # test metadata
        assert aupimo_result.fpr_bounds == fpr_bounds
        # recall: this one is not the same as the number of thresholds in the curve
        # this is the number of thresholds used to compute the integral in `aupimo()`
        # always less because of the integration bounds
        assert aupimo_result.num_thresholds < 7

        # test data
        # from pimo result
        thresholds = pimo_result.thresholds
        shared_fpr = pimo_result.shared_fpr
        per_image_tprs = pimo_result.per_image_tprs
        image_classes = pimo_result.image_classes
        # from aupimo result
        aupimos = aupimo_result.aupimos
        _do_test_aupimo_outputs(
            thresholds,
            shared_fpr,
            per_image_tprs,
            image_classes,
            aupimos,
            expected_thresholds,
            expected_shared_fpr,
            expected_per_image_tprs,
            expected_image_classes,
            expected_aupimos,
        )
        thresh_lower_bound = aupimo_result.thresh_lower_bound
        thresh_upper_bound = aupimo_result.thresh_upper_bound
        assert anomaly_maps.min() <= thresh_lower_bound < thresh_upper_bound <= anomaly_maps.max()

    # metric interface
    metric = pimo._AUPIMO(  # noqa: SLF001
        num_thresholds=7,
        fpr_bounds=fpr_bounds,
        return_average=False,
        force=True,
    )
    metric.update(anomaly_maps, masks)
    pimo_result_from_metric, aupimo_result_from_metric = metric.compute()
    do_assertions(pimo_result_from_metric, aupimo_result_from_metric)

    # metric interface
    metric = pimo._AUPIMO(  # noqa: SLF001
        num_thresholds=7,
        fpr_bounds=fpr_bounds,
        return_average=True,  # only return the average AUPIMO
        force=True,
    )
    metric.update(anomaly_maps, masks)
    metric.compute()
Test if `aupimo()` returns the expected values.
tests/unit/metrics/pimo/test_pimo.py