docstr: Tests that encoder that commutes with sum works.
docstr_tok: ["Tests","that","encoder","that","commutes","with","sum","works","."]
code: def test_commutativity_with_sum(self):
      """Tests that encoder that commutes with sum works."""
      x_fn = lambda: tf.constant([1.0, 3.0])
      encoder = gather_encoder.GatherEncoder.from_encoder(
          core_encoder.EncoderComposer(
              test_utils.TimesTwoEncodingStage()
          ).make(),
          tf.TensorSpec.from_tensor(x_fn()),
      )
  
      for num_summands in [1, 3, 7]:
          iteration = _make_iteration_function(
              encoder, x_fn, num_summands
          )
          data = self.evaluate(iteration(encoder.initial_state()))
          for i in range(num_summands):
              self.assertAllClose([1.0, 3.0], data.x[i])
              self.assertAllClose(
                  [2.0, 6.0],
                  _encoded_x_field(
                      data.encoded_x[i], [TENSORS, T2_VALS]
                  ),
              )
              self.assertAllClose(
                  list(data.part_decoded_x[i].values())[0],
                  list(data.encoded_x[i].values())[0],
              )
          self.assertAllClose(
              np.array([2.0, 6.0]) * num_summands,
              list(data.summed_part_decoded_x.values())[0],
          )
          self.assertAllClose(
              np.array([1.0, 3.0]) * num_summands, data.decoded_x
          )
  
imports: import collections
  from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow.python.framework import test_util
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.core import core_encoder
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.core import encoding_stage
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.core import gather_encoder
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.testing import test_utils
label_desc: Use image node_id 6 for calling the GatherEncoderTest obj's underlying member method code with example usage: obj.test_commutativity_with_sum() without return types