class_docstr: Tests clip_and_aggreate_gradients.
code: def _get_true_grads(
      self,
      n,
      normalize=False,
      l2_norm_clip=None,
      agg_method="mean",
      unconnected="none",
  ):
      # The per-example gradients (or jacobians) below are computed manually.
      # With the (half) quadratic loss, it is the difference between the
      # variable value and the data value.
      grad0 = np.array(
          [
              [[0.0, 0.0], [-2.0, -3.0], [0.0, 0.0], [0.0, 0.0]],
              [[0.0, 0.0], [-4.0, -5.0], [0.0, 0.0], [0.0, 0.0]],
              [[0.0, 0.0], [0.0, 0.0], [-5.0, -6.0], [0.0, 0.0]],
              [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [4.0, 3.0]],
              [[0.0, 0.0], [0.0, 0.0], [4.0, 3.0], [0.0, 0.0]],
              [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]],
          ],
          dtype=np.float32,
      )
      grad1 = np.array(
          [
              [[2.0], [0.0], [0.0], [0.0], [0.0], [0.0]],
              [[0.0], [3.0], [0.0], [0.0], [0.0], [0.0]],
              [[0.0], [0.0], [4.0], [0.0], [0.0], [0.0]],
              [[0.0], [0.0], [0.0], [5.0], [0.0], [0.0]],
              [[0.0], [0.0], [0.0], [0.0], [6.0], [0.0]],
              [[0.0], [0.0], [0.0], [0.0], [0.0], [7.0]],
          ],
          dtype=np.float32,
      )
      grad2 = np.array(
          [[[0.0]], [[0.0]], [[0.0]], [[0.0]], [[0.0]], [[0.0]]],
          dtype=np.float64,
      )
  
      grads = [
          np.sum(np.reshape(g, (n, -1, g.shape[1], g.shape[2])), axis=1)
          for g in [grad0, grad1, grad2]
      ]
  
      if normalize or l2_norm_clip is not None:
          if l2_norm_clip is None:
              l2_norm_clip = 1.0
          global_norm = np.sqrt(
              np.sum(
                  [
                      np.sum(np.square(np.reshape(g, (n, -1))), axis=1)
                      for g in grads
                  ],
                  axis=0,
              )
          )
          clip_ratio = l2_norm_clip / np.maximum(global_norm, 1e-8)
          if not normalize:
              clip_ratio = np.minimum(1.0, clip_ratio)
          r = np.reshape(clip_ratio, [n, 1, 1])
          grads = [g * r for g in grads]
  
      if agg_method == "sum":
          grads = [np.sum(g, axis=0) for g in grads]
      else:
          grads = [np.mean(g, axis=0) for g in grads]
  
      if unconnected == "none":
          grads[2] = None
      return grads
  
file_path: privacy/tensorflow_privacy/privacy/optimizers/clip_and_aggregate_gradients_test.py
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow_privacy.privacy.optimizers import clip_and_aggregate_gradients
label_desc: Use image node_id 2 for calling the ClipAndAggregateGradientsTest obj's underlying member method code with example usage: obj._get_true_grads(n, normalize, l2_norm_clip, agg_method, unconnected) and returns: grads