code: def testVariadicReduceKahanSum(self, is_v2):
      for dtype in set(self.numeric_types).intersection(
          set([np.float32, np.complex64])
      ):
  
          @def_function.function
          def kahan_sum_reducer(t0, t1):
              (s0, c0), (s1, c1) = t0, t1
              s0minusc = s0 - (c0 + c1)
              t = s1 + s0minusc
              c = (t - s1) - s0minusc
              s = t
              return s, c
  
          def kahan_sum_reduction(dims, output_idx):
              def fn(x):
                  arg = array_ops.zeros(
                      [], dtype
                  )  # pylint: disable=cell-var-from-loop
                  reducer = kahan_sum_reducer.get_concrete_function(  # pylint: disable=cell-var-from-loop
                      (arg, arg), (arg, arg)
                  )
  
                  if is_v2:
                      return xla.variadic_reduce(
                          (x, array_ops.zeros_like(x)),
                          init_values=(arg, arg),
                          dimensions_to_reduce=dims,
                          reducer=reducer,
                      )[output_idx]
                  else:
                      return gen_xla_ops.xla_variadic_reduce(
                          (x, array_ops.zeros_like(x)),
                          init_value=(arg, arg),
                          dimensions_to_reduce=dims,
                          reducer=reducer,
                      )[output_idx]
  
              return fn
  
          xs = np.array([1e5, np.pi, -1e5, np.exp(1.0)])
          xs = np.array([xs, xs[::-1] / 3, xs / 7], dtype)
          self._assertOpOutputMatchesExpected(
              kahan_sum_reduction(dims=[], output_idx=0),
              args=(xs,),
              expected=xs,
          )
          self._assertOpOutputMatchesExpected(
              kahan_sum_reduction(dims=[], output_idx=1),
              args=(xs,),
              expected=np.zeros_like(xs),
          )
          shuffle_indices = np.argsort(np.random.randn(xs.shape[0]))
          self._assertOpOutputMatchesExpected(
              kahan_sum_reduction(dims=[0], output_idx=0),
              args=(xs[shuffle_indices],),
              expected=np.array(
                  [
                      np.exp(1) / 3 + 1e5 * 8 / 7,
                      np.pi * 8 / 7 - 1e5 / 3,
                      -1e5 * 8 / 7 + np.pi / 3,
                      np.exp(1) * 8 / 7 + 1e5 / 3,
                  ],
                  dtype=dtype,
              ),
          )
          error_term_equality = functools.partial(
              self.assertAllClose, rtol=1e-3, atol=0.005
          )
          self._assertOpOutputMatchesExpected(
              kahan_sum_reduction(dims=[0], output_idx=1),
              args=(xs[shuffle_indices],),
              expected=np.zeros_like(xs[0]),
              equality_fn=error_term_equality,
          )
          shuffle_indices = np.argsort(np.random.randn(xs.shape[1]))
          self._assertOpOutputMatchesExpected(
              kahan_sum_reduction(dims=[1], output_idx=0),
              args=(xs[:, shuffle_indices],),
              expected=np.array(
                  [
                      np.pi + np.exp(1.0),
                      (np.pi + np.exp(1.0)) / 3,
                      (np.pi + np.exp(1.0)) / 7,
                  ],
                  dtype=dtype,
              ),
          )
          self._assertOpOutputMatchesExpected(
              kahan_sum_reduction(dims=[1], output_idx=1),
              args=(xs[:, shuffle_indices],),
              expected=np.zeros_like(xs[:, 0]),
              equality_fn=error_term_equality,
          )
          # Now, shuffle both dims.
          xs = xs[np.argsort(np.random.randn(xs.shape[0]))]
          xs = xs[:, np.argsort(np.random.randn(xs.shape[1]))]
          self._assertOpOutputMatchesExpected(
              kahan_sum_reduction(dims=[0, 1], output_idx=0),
              args=(xs,),
              expected=dtype((np.pi + np.exp(1.0)) * 31 / 21),
          )
          self._assertOpOutputMatchesExpected(
              kahan_sum_reduction(dims=[0, 1], output_idx=1),
              args=(xs,),
              expected=dtype(0),
              equality_fn=error_term_equality,
          )
  
imports: import functools
  from absl.testing import parameterized
  import numpy
  from tensorflow.compiler.tests import xla_test
  from tensorflow.compiler.tf2xla.ops import gen_xla_ops
  from tensorflow.compiler.tf2xla.python import xla
  from local_xla.xla import xla_data_pb2
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import function
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import array_ops_stack
  from tensorflow.python.ops import random_ops_util
  from tensorflow.python.platform import googletest
label_desc: Use image node_id 17 for calling the XlaOpsNumericalTest obj's underlying member method code with example usage: obj.testVariadicReduceKahanSum(is_v2) and returns: s,  c, fn, xla, gen_xla_ops