code: def _trim_boundaries(tensor, from_dim, shifts=None):
      """Trims tensor boundaries starting from given dimension."""
      # For example, if tensor has shape (a, b, c, d) and from_dim=1, then the
      # output tensor has shape (a, b-2, c-2, d-2).
      # For example _trim_boundaries(t, 1) with a rank-4
      # tensor t yields t[:, 1:-1, 1:-1, 1:-1].
      #
      # If shifts is specified, the slices applied are shifted. shifts is an array
      # of length rank(tensor) - from_dim, with values -1, 0, or 1, meaning slices
      # [:-2], [-1, 1], and [2:], respectively.
      # For example _trim_boundaries(t, 1, (1, 0, -1)) with a rank-4
      #  tensor t yields t[:, 2:, 1:-1, :-2].
      rank = tensor.shape.rank
      slices = rank * [slice(None)]
      for i in range(from_dim, rank):
          slice_begin = 1
          slice_end = -1
          # Apply shifts
          if shifts is not None:
              shift = shifts[i - from_dim]
              slice_begin += shift
              slice_end += shift
          # If slice_end is `0` integer, do not trim that upper dimension
          if isinstance(slice_end, int) and slice_end == 0:
              slice_end = None
          slices[i] = slice(slice_begin, slice_end)
      res = tensor[slices]
      return res
  
file_path: tf-quant-finance/tf_quant_finance/math/pde/steppers/douglas_adi.py
imports: import numpy
  import tensorflow.compat.v2
  from tf_quant_finance.math.pde.steppers.multidim_parabolic_equation_stepper import multidim_parabolic_equation_step
label_desc: Use image node_id 7 for calling a global function with example usage: _trim_boundaries(tensor, from_dim, shifts) and returns: res