code: def test_op_delay_with_initial_state(
      input_size, time_step, initial_state_size, device_id, precision
  ):
      dt = PRECISION_TO_TYPE[precision]
  
      x = np.arange(np.product(input_size), dtype=dt).reshape(
          input_size
      )
      initial_state = (
          np.arange(np.product(initial_state_size), dtype=dt).reshape(
              initial_state_size
          )
          + 3
      )
  
      expected_forward = np.zeros_like(x, dtype=dt)
      for seq_idx in range(input_size[0]):
          expected_forward[seq_idx] = np.roll(
              AA(x[seq_idx], dtype=dt), time_step, axis=0
          )
          if time_step > 0:
              expected_forward[seq_idx, :time_step] = initial_state[
                  seq_idx, -1 if time_step == 1 else -time_step :, ...
              ]
          else:
              expected_forward[seq_idx, time_step:] = initial_state[
                  seq_idx, : 1 if time_step == -1 else -time_step, ...
              ]
  
      a = sequence.input_variable(
          shape=input_size[2:],
          dtype=sanitize_dtype_cntk(precision),
          needs_gradient=True,
          name="a",
      )
      from ...axis import Axis
  
      i = sequence.input_variable(
          shape=initial_state_size[2:],
          dtype=sanitize_dtype_cntk(precision),
          needs_gradient=True,
          sequence_axis=Axis("initial_state_axis"),
          name="i",
      )
  
      backward = np.ones_like(x, dtype=dt)
      initial_state_backward = np.zeros_like(initial_state, dtype=dt)
      for seq_idx in range(input_size[0]):
          for t in range(abs(time_step)):
              initial_state_bw_val = (
                  1.0 if initial_state_size[1] > 1 else abs(time_step)
              )
              if time_step > 0:
                  backward[seq_idx, -1 - t] = 0.0
                  if t < initial_state_size[1]:
                      initial_state_backward[
                          seq_idx, -1 - t
                      ] = initial_state_bw_val
              else:
                  backward[seq_idx, t] = 0.0
                  if t < initial_state_size[1]:
                      initial_state_backward[
                          seq_idx, t
                      ] = initial_state_bw_val
  
      expected_backward = {a: backward, i: initial_state_backward}
  
      input_op_input = sequence.delay(a, i, time_step)
  
      unittest_helper(
          input_op_input,
          {a: x, i: initial_state},
          expected_forward,
          expected_backward,
          device_id=device_id,
          precision=precision,
      )
  
file_path: CNTK/bindings/python/cntk/ops/tests/recurrent_test.py
imports: from __future__ import division
  import numpy
  import pytest
  from .ops_test_utils import _test_binary_op, AA, precision, PRECISION_TO_TYPE, unittest_helper, sanitize_dtype_cntk, cntk_device
  from ..None import parameter, sequence
label_desc: Use image node_id 3 for calling a global function with example usage: test_op_delay_with_initial_state(input_size, time_step, initial_state_size, device_id, precision) without return types