code: def clamp(tensor, *, min=None, max=None):
      """
      Like :func:`torch.clamp` but dispatches to :func:`torch.min` and/or
      :func:`torch.max` if ``min`` and/or ``max`` is a :class:`~torch.Tensor`.
      """
      if isinstance(min, torch.Tensor):
          tensor = torch.max(tensor, min)
          min = None
      if isinstance(max, torch.Tensor):
          tensor = torch.min(tensor, max)
          max = None
      if min is None and max is None:
          return tensor
      return tensor.clamp(min=min, max=max)
  
file_path: pyro/pyro/contrib/epidemiology/util.py
imports: import numpy
  import torch
  import pyro
  import pyro.distributions
  import pyro.poutine
  from pyro.distributions.util import broadcast_shape
  from pyro.ops.special import safe_log
label_desc: Use image node_id 1 for calling a global function with example usage: clamp(tensor) and returns: tensor, tensor