code: def pack(value, dim_to_symbol):
      """
      Converts an unpacked tensor to a packed tensor.
  
      :param value: a number or tensor
      :param dim_to_symbol: a map from negative integers to characters
      """
      if isinstance(value, torch.Tensor):
          assert not hasattr(
              value, "_pyro_dims"
          ), "tried to pack an already-packed tensor"
          shape = value.shape
          shift = len(shape)
          try:
              with ignore_jit_warnings():
                  dims = "".join(
                      dim_to_symbol[dim - shift]
                      for dim, size in enumerate(shape)
                      if size > 1
                  )
          except KeyError as e:
              raise ValueError(
                  "\n  ".join(
                      [
                          "Invalid tensor shape.",
                          "Allowed dims: {}".format(
                              ", ".join(map(str, sorted(dim_to_symbol)))
                          ),
                          "Actual shape: {}".format(tuple(value.shape)),
                          "Try adding shape assertions for your model's sample values and distribution parameters.",
                      ]
                  )
              ) from e
          value = value.squeeze()
          value._pyro_dims = dims
          assert value.dim() == len(value._pyro_dims)
      return value
  
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 1 for calling a global function with example usage: pack(value, dim_to_symbol) and returns: value