docstr: Tests that commutativity works, provided appropriate num_summands.
docstr_tok: ["Tests","that","commutativity","works",",","provided","appropriate","num_summands","."]
code: def test_commutes_with_sum(self):
      """Tests that commutativity works, provided appropriate num_summands."""
      encoder = (
          core_encoder.EncoderComposer(
              test_utils.PlusOneEncodingStage()
          )
          .add_parent(
              test_utils.SimpleLinearEncodingStage(2.0, 3.0), SL_VALS
          )
          .make()
      )
  
      x = tf.constant(3.0)
      encode_params, decode_params = encoder.get_params(
          encoder.initial_state()
      )
      encoded_x, _, input_shapes = encoder.encode(x, encode_params)
      decoded_x_before_sum = encoder.decode_before_sum(
          encoded_x, decode_params, input_shapes
      )
      # Trivial summing of the encoded - and partially decoded - values.
      part_decoded_and_summed_x = tf.nest.map_structure(
          lambda x: x + x + x, decoded_x_before_sum
      )
      num_summands = 3
      decoded_x_after_sum = encoder.decode_after_sum(
          part_decoded_and_summed_x,
          decode_params,
          num_summands,
          input_shapes,
      )
      data = self.evaluate(
          self.commutation_test_data(
              x, encoded_x, decoded_x_before_sum, decoded_x_after_sum
          )
      )
      self.assertEqual(3.0, data.x)
      expected_encoded_x = {
          SL_VALS: {P1_VALS: (data.x * 2.0 + 3.0) + 1.0}
      }
      self.assertAllEqual(expected_encoded_x, data.encoded_x)
      expected_decoded_x_before_sum = {SL_VALS: data.x * 2.0 + 3.0}
      self.assertAllEqual(
          expected_decoded_x_before_sum, data.decoded_x_before_sum
      )
      self.assertEqual(9.0, data.decoded_x_after_sum)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import numpy
  import tensorflow
  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.testing import test_utils
label_desc: Use image node_id 8 for calling the EncoderTest obj's underlying member method code with example usage: obj.test_commutes_with_sum() without return types