code: def scale_and_mask(tensor, scale=1.0, mask=None):
      """
      Scale and mask a packed tensor, broadcasting and avoiding unnecessary ops.
  
      :param torch.Tensor tensor: a packed tensor
      :param scale: a positive scale
      :type scale: torch.Tensor or number
      :param mask: an optional packed tensor mask
      :type mask: torch.BoolTensor, bool, or None
      """
      if isinstance(scale, torch.Tensor) and scale.dim():
          raise NotImplementedError("non-scalar scale is not supported")
      if mask is None or mask is True:
          if is_identically_one(scale):
              return tensor
          result = tensor * scale
          result._pyro_dims = tensor._pyro_dims
          return result
      if mask is False:
          result = torch.zeros_like(tensor)
          result._pyro_dims = tensor._pyro_dims
          return result
      tensor, mask = broadcast_all(tensor, mask)
      result = torch.where(mask, tensor, tensor.new_zeros(()))
      result._pyro_dims = tensor._pyro_dims
      return result
  
file_path: pyro/pyro/ops/packed.py
imports: import math
  import torch
  from pyro.distributions.util import is_identically_one
  from pyro.util import ignore_jit_warnings
label_desc: Use image node_id 6 for calling a global function with example usage: scale_and_mask(tensor, scale, mask) and returns: result, result, result, tensor