code: def test_TimeseriesGenerator():
      data = np.array([[i] for i in range(50)])
      targets = np.array([[i] for i in range(50)])
  
      data_gen = sequence.TimeseriesGenerator(
          data, targets, length=10, sampling_rate=2, batch_size=2
      )
      assert len(data_gen) == 20
      assert np.allclose(
          data_gen[0][0],
          np.array(
              [[[0], [2], [4], [6], [8]], [[1], [3], [5], [7], [9]]]
          ),
      )
      assert np.allclose(data_gen[0][1], np.array([[10], [11]]))
      assert np.allclose(
          data_gen[1][0],
          np.array(
              [[[2], [4], [6], [8], [10]], [[3], [5], [7], [9], [11]]]
          ),
      )
      assert np.allclose(data_gen[1][1], np.array([[12], [13]]))
  
      data_gen = sequence.TimeseriesGenerator(
          data,
          targets,
          length=10,
          sampling_rate=2,
          reverse=True,
          batch_size=2,
      )
      assert len(data_gen) == 20
      assert np.allclose(
          data_gen[0][0],
          np.array(
              [[[8], [6], [4], [2], [0]], [[9], [7], [5], [3], [1]]]
          ),
      )
      assert np.allclose(data_gen[0][1], np.array([[10], [11]]))
  
      data_gen = sequence.TimeseriesGenerator(
          data,
          targets,
          length=10,
          sampling_rate=2,
          shuffle=True,
          batch_size=1,
      )
      batch = data_gen[0]
      r = batch[1][0][0]
      assert np.allclose(
          batch[0],
          np.array([[[r - 10], [r - 8], [r - 6], [r - 4], [r - 2]]]),
      )
      assert np.allclose(
          batch[1],
          np.array(
              [
                  [r],
              ]
          ),
      )
  
      data_gen = sequence.TimeseriesGenerator(
          data,
          targets,
          length=10,
          sampling_rate=2,
          stride=2,
          batch_size=2,
      )
      assert len(data_gen) == 10
      assert np.allclose(
          data_gen[1][0],
          np.array(
              [
                  [[4], [6], [8], [10], [12]],
                  [[6], [8], [10], [12], [14]],
              ]
          ),
      )
      assert np.allclose(data_gen[1][1], np.array([[14], [16]]))
  
      data_gen = sequence.TimeseriesGenerator(
          data,
          targets,
          length=10,
          sampling_rate=2,
          start_index=10,
          end_index=30,
          batch_size=2,
      )
      assert len(data_gen) == 6
      assert np.allclose(
          data_gen[0][0],
          np.array(
              [
                  [[10], [12], [14], [16], [18]],
                  [[11], [13], [15], [17], [19]],
              ]
          ),
      )
      assert np.allclose(data_gen[0][1], np.array([[20], [21]]))
  
      data = np.array(
          [np.random.random_sample((1, 2, 3, 4)) for i in range(50)]
      )
      targets = np.array(
          [np.random.random_sample((3, 2, 1)) for i in range(50)]
      )
      data_gen = sequence.TimeseriesGenerator(
          data,
          targets,
          length=10,
          sampling_rate=2,
          start_index=10,
          end_index=30,
          batch_size=2,
      )
      assert len(data_gen) == 6
      assert np.allclose(
          data_gen[0][0],
          np.array([np.array(data[10:19:2]), np.array(data[11:20:2])]),
      )
      assert np.allclose(
          data_gen[0][1], np.array([targets[20], targets[21]])
      )
  
      with assert_raises(ValueError) as context:
          sequence.TimeseriesGenerator(data, targets, length=50)
      error = str(context.exception)
      assert (
          "`start_index+length=50 > end_index=49` is disallowed"
          in error
      )
  
file_path: keras-preprocessing/tests/sequence_test.py
imports: from math import ceil
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_equal, assert_raises
  from keras_preprocessing import sequence
label_desc: Use image node_id 8 for calling a global function with example usage: test_TimeseriesGenerator() without return types