code: def _SelfAdjointEigV2Grad(op: ops.Operation, grad_e, grad_v):
      """Gradient for SelfAdjointEigV2."""
      e = op.outputs[0]
      compute_v = op.get_attr("compute_v")
      # a = op.inputs[0], which satisfies
      # a[...,:,:] * v[...,:,i] = e[...,i] * v[...,i]
      with ops.control_dependencies([grad_e, grad_v]):
          if compute_v:
              v = op.outputs[1]
              # Construct the matrix f(i,j) = (i != j ? 1 / (e_i - e_j) : 0).
              # Notice that because of the term involving f, the gradient becomes
              # infinite (or NaN in practice) when eigenvalues are not unique.
              # Mathematically this should not be surprising, since for (k-fold)
              # degenerate eigenvalues, the corresponding eigenvectors are only defined
              # up to arbitrary rotation in a (k-dimensional) subspace.
              f = array_ops.matrix_set_diag(
                  _SafeReciprocal(
                      array_ops.expand_dims(e, -2)
                      - array_ops.expand_dims(e, -1)
                  ),
                  array_ops.zeros_like(e),
              )
              grad_a = math_ops.matmul(
                  v,
                  math_ops.matmul(
                      array_ops.matrix_diag(grad_e)
                      + f * math_ops.matmul(v, grad_v, adjoint_a=True),
                      v,
                      adjoint_b=True,
                  ),
              )
          else:
              _, v = linalg_ops.self_adjoint_eig(op.inputs[0])
              grad_a = math_ops.matmul(
                  v,
                  math_ops.matmul(
                      array_ops.matrix_diag(grad_e), v, adjoint_b=True
                  ),
              )
          # The forward op only depends on the lower triangular part of a, so here we
          # symmetrize and take the lower triangle
          grad_a = array_ops.matrix_band_part(
              grad_a + _linalg.adjoint(grad_a), -1, 0
          )
          grad_a = array_ops.matrix_set_diag(
              grad_a, 0.5 * array_ops.matrix_diag_part(grad_a)
          )
          return grad_a
  
imports: from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import array_ops_stack
  from tensorflow.python.ops import cond
  from tensorflow.python.ops import gen_linalg_ops
  from tensorflow.python.ops import linalg_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops.linalg import linalg_impl
label_desc: Use image node_id 14 for calling a global function with example usage: _SelfAdjointEigV2Grad(op, grad_e, grad_v) and returns: grad_a