code: def test_case_dispatcher(self):
      with torch.random.fork_rng():
          torch.random.manual_seed(0)
          values = torch.rand([32])
  
      # Test default case
      output = utils.case_dispatcher(
          out=torch.full_like(values, float("nan")),
          default=lambda mask: 0,
      )
      self.assertTrue(output.eq(0).all())
  
      # Test randomized value assignments
      levels = 0.25, 0.5, 0.75
      cases = [  # switching cases
          (lambda level=level: values < level, lambda mask, i=i: i)
          for i, level in enumerate(levels)
      ]
  
      cases.append(  # dummy case whose predicate is always False
          (
              lambda: torch.full(values.shape, False),
              lambda mask: float("nan"),
          )
      )
  
      output = utils.case_dispatcher(
          out=torch.full_like(values, float("nan")),
          cases=cases,
          default=lambda mask: len(levels),
      )
  
      self.assertTrue(output.isfinite().all())
      active = torch.full(values.shape, True)
      for i, level in enumerate(levels):
          mask = active & (values < level)
          self.assertTrue(output[mask].eq(i).all())
          active[mask] = False
      self.assertTrue(
          ~active.any() or output[active].eq(len(levels)).all()
      )
  
      # testing mask.all() branch
      edge_cases = [
          (
              lambda: torch.full(values.shape, True),
              lambda mask: float("nan"),
          )
      ]
      output = utils.case_dispatcher(
          out=torch.full_like(values, float("nan")),
          cases=edge_cases,
          default=lambda mask: len(levels),
      )
  
      # testing if not active.any() branch
      pred = torch.full(values.shape, True)
      pred[0] = False
      edge_cases = [
          (lambda: pred, lambda mask: False),
          (lambda: torch.full(values.shape, True), lambda mask: False),
      ]
      output = utils.case_dispatcher(
          out=torch.full_like(values, float("nan")),
          cases=edge_cases,
          default=lambda mask: len(levels),
      )
  
file_path: botorch/test/utils/probability/test_utils.py
imports: from __future__ import annotations
  import torch
  from botorch.utils.probability import ndtr, utils
  from botorch.utils.probability.utils import log_erfc, log_erfcx, log_ndtr, log_phi, log_prob_normal_in, phi, standard_normal_log_hazard
  from botorch.utils.testing import BotorchTestCase
  from numpy.polynomial.legendre import leggauss
label_desc: Use image node_id 1 for calling the TestProbabilityUtils obj's underlying member method code with example usage: obj.test_case_dispatcher() without return types