code: def _apply_tridiag_matrix_explicitly(
      values, superdiag, diag, subdiag, dim, n_dims
  ):
      """Applies tridiagonal matrix explicitly."""
      perm = _get_permutation(values, n_dims, dim)
  
      # Make the given dimension the last one in the tensors, treat all the
      # other spatial dimensions as batch dimensions.
      if perm is not None:
          values = tf.transpose(values, perm)
          superdiag, diag, subdiag = (
              tf.transpose(c, perm) for c in (superdiag, diag, subdiag)
          )
  
      values = tf.squeeze(
          tf.linalg.tridiagonal_matmul(
              (superdiag, diag, subdiag),
              tf.expand_dims(values, -1),
              diagonals_format="sequence",
          ),
          -1,
      )
  
      # Transpose back to how it was.
      if perm is not None:
          values = tf.transpose(values, perm)
      return values
  
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 4 for calling a global function with example usage: _apply_tridiag_matrix_explicitly(values, superdiag, diag, subdiag, dim, n_dims) and returns: values