code: def scale_and_mask(tensor, scale=1.0, mask=None):
      """
      Scale and mask a tensor, broadcasting and avoiding unnecessary ops.
  
      :param tensor: an input tensor or zero
      :type tensor: torch.Tensor or the number zero
      :param scale: a positive scale
      :type scale: torch.Tensor or number
      :param mask: an optional masking tensor
      :type mask: torch.BoolTensor, bool, or None
      """
      if is_identically_zero(tensor) or (
          mask is None and is_identically_one(scale)
      ):
          return tensor
      if mask is None or mask is True:
          return tensor * scale
      if mask is False:
          return torch.zeros_like(tensor)
      return torch.where(mask, tensor * scale, tensor.new_zeros(()))
  
imports: import copy
  import ctypes
  import functools
  import numbers
  import weakref
  from contextlib import contextmanager
  import torch
  import torch.distributions
  from torch import logsumexp
  from torch.distributions.utils import broadcast_all
  from pyro.util import ignore_jit_warnings
  from ..None import settings
label_desc: Use image node_id 11 for calling a global function with example usage: scale_and_mask(tensor, scale, mask) and returns: torch, tensor, unknown, torch