docstr: Test a dataset that maps a TF function across its input elements.
docstr_tok: ["Test","a","dataset","that","maps","a","TF","function","across","its","input","elements","."]
code: def testMapAndBatch(self, num_parallel_calls, num_parallel_batches):
      """Test a dataset that maps a TF function across its input elements."""
      # The pipeline is TensorSliceDataset ->
      # RepeatDataset(count) -> MapAndBatchDataset(square_3, batch_size).
      components = (
          np.arange(7),
          np.array([[1, 2, 3]]) * np.arange(7)[:, np.newaxis],
          np.array(37.0) * np.arange(7),
      )
  
      def _map_fn(x, y, z):
          return (
              math_ops.square(x),
              math_ops.square(y),
              math_ops.square(z),
          )
  
      def dataset_fn(batch_size, count):
          dataset = (
              dataset_ops.Dataset.from_tensor_slices(components)
              .repeat(count)
              .apply(
                  batching.map_and_batch(
                      map_func=_map_fn,
                      batch_size=batch_size,
                      num_parallel_calls=num_parallel_calls,
                      num_parallel_batches=num_parallel_batches,
                  )
              )
          )
          return dataset
  
      # Batch of a finite input, where the batch_size divides the
      # total number of elements.
      dataset = dataset_fn(14, 28)
      get_next = self.getNext(dataset)
      self.assertEqual(
          [[None] + list(c.shape[1:]) for c in components],
          [
              shape.as_list()
              for shape in dataset_ops.get_legacy_output_shapes(dataset)
          ],
      )
      num_batches = (28 * 7) // 14
      for i in range(num_batches):
          result = self.evaluate(get_next())
          for component, result_component in zip(components, result):
              for j in range(14):
                  self.assertAllEqual(
                      component[(i * 14 + j) % 7] ** 2,
                      result_component[j],
                  )
      with self.assertRaises(errors.OutOfRangeError):
          self.evaluate(get_next())
  
      # Batch of a finite input, where the batch_size does not
      # divide the total number of elements.
      get_next = self.getNext(dataset_fn(8, 14))
  
      # We expect (num_batches - 1) full-sized batches.
      num_batches = int(math.ceil((14 * 7) / 8))
      for i in range(num_batches - 1):
          result = self.evaluate(get_next())
          for component, result_component in zip(components, result):
              for j in range(8):
                  self.assertAllEqual(
                      component[(i * 8 + j) % 7] ** 2,
                      result_component[j],
                  )
  
      result = self.evaluate(get_next())
      for component, result_component in zip(components, result):
          for j in range((14 * 7) % 8):
              self.assertAllEqual(
                  component[((num_batches - 1) * 8 + j) % 7] ** 2,
                  result_component[j],
              )
      with self.assertRaises(errors.OutOfRangeError):
          self.evaluate(get_next())
  
      # Batch of an empty input should fail straight away.
      self.assertDatasetProduces(dataset_fn(8, 0), expected_output=[])
  
      # Empty batch should be an initialization time error.
      with self.assertRaises(errors.InvalidArgumentError):
          self.assertDatasetProduces(
              dataset_fn(0, 14), expected_output=[]
          )
  
imports: import math
  from absl.testing import parameterized
  import numpy
  from tensorflow.python import pywrap_sanitizers
  from tensorflow.python.checkpoint import checkpoint
  from tensorflow.python.checkpoint import checkpoint_management
  from tensorflow.python.data.experimental.ops import batching
  from tensorflow.python.data.kernel_tests import checkpoint_test_base
  from tensorflow.python.data.kernel_tests import test_base
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.data.ops import options
  from tensorflow.python.eager import context
  from tensorflow.python.framework import combinations
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import cond
  from tensorflow.python.ops import control_flow_util
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import script_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling the MapAndBatchTest obj's underlying member method code with example usage: obj.testMapAndBatch(num_parallel_calls, num_parallel_batches) and returns: math_ops,  math_ops,  math_ops, dataset