code: def test_bootstrap(device, sampling_strategy, metric, ref_metric):
      """Test that the different bootstraps gets updated as we expected and that the compute method works."""
      if device == "cuda" and not torch.cuda.is_available():
          pytest.skip("Test with device='cuda' requires gpu")
  
      _kwargs = {
          "base_metric": metric,
          "mean": True,
          "std": True,
          "raw": True,
          "sampling_strategy": sampling_strategy,
      }
      _kwargs.update(
          {"quantile": torch.tensor([0.05, 0.95], device=device)}
      )
  
      bootstrapper = TestBootStrapper(**_kwargs)
      bootstrapper.to(device)
  
      collected_preds = [[] for _ in range(10)]
      collected_target = [[] for _ in range(10)]
      for p, t in zip(_preds, _target):
          p, t = p.to(device), t.to(device)
          bootstrapper.update(p, t)
  
          for i, o in enumerate(bootstrapper.out):
              collected_preds[i].append(o[0])
              collected_target[i].append(o[1])
  
      collected_preds = [torch.cat(cp).cpu() for cp in collected_preds]
      collected_target = [
          torch.cat(ct).cpu() for ct in collected_target
      ]
  
      sk_scores = [
          ref_metric(ct, cp)
          for ct, cp in zip(collected_target, collected_preds)
      ]
  
      output = bootstrapper.compute()
      assert np.allclose(
          output["quantile"][0].cpu(), np.quantile(sk_scores, 0.05)
      )
      assert np.allclose(
          output["quantile"][1].cpu(), np.quantile(sk_scores, 0.95)
      )
  
      assert np.allclose(output["mean"].cpu(), np.mean(sk_scores))
      assert np.allclose(output["std"].cpu(), np.std(sk_scores, ddof=1))
      assert np.allclose(output["raw"].cpu(), sk_scores)
  
file_path: torchmetrics/tests/unittests/wrappers/test_bootstrapping.py
imports: import operator
  from functools import partial
  from typing import Any
  import numpy
  import pytest
  import torch
  from lightning_utilities import apply_to_collection
  from sklearn.metrics import mean_squared_error, precision_score, recall_score
  from torch import Tensor
  from torchmetrics.classification import MulticlassF1Score, MulticlassPrecision, MulticlassRecall
  from torchmetrics.regression import MeanSquaredError
  from torchmetrics.wrappers.bootstrapping import BootStrapper, _bootstrap_sampler
  from unittests.helpers import seed_all
label_desc: Use image node_id 3 for calling a global function with example usage: test_bootstrap(device, sampling_strategy, metric, ref_metric) without return types