code: def test_sum_reduction():
      (
          batch_size,
          sequence_length,
          _,
          logits,
          targets,
          weights,
          expected_loss,
      ) = get_test_data()
      seq_loss = loss.SequenceLoss(
          average_across_timesteps=False,
          average_across_batch=False,
          sum_over_timesteps=True,
          sum_over_batch=True,
      )
      average_loss_per_example = seq_loss(targets, logits, weights)
      res = average_loss_per_example.numpy()
      np.testing.assert_allclose(
          expected_loss, res, atol=1e-6, rtol=1e-6
      )
  
      seq_loss = loss.SequenceLoss(
          average_across_timesteps=False,
          average_across_batch=False,
          sum_over_timesteps=False,
          sum_over_batch=True,
      )
      average_loss_per_sequence = seq_loss(targets, logits, weights)
      res = average_loss_per_sequence.numpy()
      compare_per_sequence = np.full((sequence_length), expected_loss)
      np.testing.assert_allclose(
          compare_per_sequence, res, atol=1e-6, rtol=1e-6
      )
  
      seq_loss = loss.SequenceLoss(
          average_across_timesteps=False,
          average_across_batch=False,
          sum_over_timesteps=True,
          sum_over_batch=False,
      )
      average_loss_per_batch = seq_loss(targets, logits, weights)
      res = average_loss_per_batch.numpy()
      compare_per_batch = np.full((batch_size), expected_loss)
      np.testing.assert_allclose(
          compare_per_batch, res, atol=1e-6, rtol=1e-6
      )
  
      seq_loss = loss.SequenceLoss(
          average_across_timesteps=False,
          average_across_batch=False,
          sum_over_timesteps=False,
          sum_over_batch=False,
      )
      total_loss = seq_loss(targets, logits, weights)
      res = total_loss.numpy()
      compare_total = np.full(
          (batch_size, sequence_length), expected_loss
      )
      np.testing.assert_allclose(
          compare_total, res, atol=1e-6, rtol=1e-6
      )
  
file_path: addons/tensorflow_addons/seq2seq/tests/loss_test.py
imports: import pytest
  import numpy
  import tensorflow
  from tensorflow_addons.seq2seq import loss
label_desc: Use image node_id 4 for calling a global function with example usage: test_sum_reduction() without return types