code: def test_endian_encodings(self):
      spec = {
          "a": array_spec.ArraySpec((2,), np.int16),
          "b": array_spec.ArraySpec((2,), np.int32),
          "c": array_spec.ArraySpec((2,), np.float32),
      }
  
      serializer = example_encoding.get_example_serializer(spec)
      decoder = example_encoding.get_example_decoder(spec)
  
      # Little endian encoding.
      le_sample = {
          "a": np.array([100, 25000]).astype("<i2"),
          "b": np.array([-5, 80000000]).astype("<i4"),
          "c": np.array([12.5, np.pi]).astype("<f4"),
      }
  
      example_proto = serializer(le_sample)
      recovered = self.evaluate(decoder(example_proto))
      tf.nest.map_structure(
          np.testing.assert_almost_equal, le_sample, recovered
      )
  
      # Big endian encoding.
      be_sample = {
          "a": np.array([100, 25000]).astype(">i2"),
          "b": np.array([-5, 80000000]).astype(">i4"),
          "c": np.array([12.5, np.pi]).astype(">f4"),
      }
  
      example_proto = serializer(be_sample)
      recovered = self.evaluate(decoder(example_proto))
      tf.nest.map_structure(
          np.testing.assert_almost_equal, be_sample, recovered
      )
  
file_path: agents/tf_agents/utils/example_encoding_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl.testing import parameterized
  import gin
  import numpy
  import tensorflow
  from tf_agents.specs import array_spec
  from tf_agents.utils import common
  from tf_agents.utils import example_encoding
label_desc: Use image node_id 2 for calling the NestExampleEncodeUtilsTest obj's underlying member method code with example usage: obj.test_endian_encodings() without return types