code: def test_bias_add(self):
      for data_format in ("NCHW", "NHWC"):
          for stacked_value in (True, False):
              x_shape = [3, 4, 5, 6]
              if stacked_value:
                  x_shape = [2] + x_shape
              x = random_ops.random_uniform(x_shape)
              for stacked_bias in (True, False):
                  if not (stacked_value or stacked_bias):
                      continue
                  with backprop.GradientTape(persistent=True) as g:
                      bias_dim = -1
                      if data_format == "NCHW":
                          bias_dim = 2 if stacked_value else 1
                      bias_shape = [x_shape[bias_dim]]
                      if stacked_bias:
                          bias_shape = [2] + bias_shape
                      bias = random_ops.random_uniform(bias_shape)
                      g.watch(bias)
  
                  # pylint: disable=cell-var-from-loop
                  def loop_fn(i):
                      with g:
                          a = (
                              array_ops.gather(x, i)
                              if stacked_value
                              else x
                          )
                          b = (
                              array_ops.gather(bias, i)
                              if stacked_bias
                              else bias
                          )
                          y = nn.bias_add(a, b, data_format=data_format)
                          loss = math_ops.reduce_sum(y * y)
                      grad = g.gradient(loss, bias)
                      if stacked_bias:
                          # If we gather over bias in loop_fn, the gradient will be an
                          # instance of `IndexedSlices` with attrs `values` and `indices`.
                          return y, grad.values, grad.indices
                      else:
                          return y, grad
  
                  # pylint: enable=cell-var-from-loop
  
                  out_dtypes = [dtypes.float32, dtypes.float32]
                  if stacked_bias:
                      out_dtypes = out_dtypes + [dtypes.int32]
                  self._test_loop_fn(loop_fn, 2)
  
imports: import itertools
  from absl.testing import parameterized
  from tensorflow.python.eager import backprop
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import clip_ops
  from tensorflow.python.ops import linalg_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn
  from tensorflow.python.ops import random_ops
  from tensorflow.python.ops import special_math_ops
  from tensorflow.python.ops import tensor_array_grad
  from tensorflow.python.ops.parallel_for import control_flow_ops
  from tensorflow.python.ops.parallel_for.test_util import PForTestCase
  from tensorflow.python.platform import test
label_desc: Use image node_id 22 for calling the MathTest obj's underlying member method code with example usage: obj.test_bias_add() and returns: y,  grad,  grad, y,  grad