code: def test_op_as_block(
      input_shape,
      output_shape,
      expected_output_shape,
      device_id,
      precision,
  ):
      # We test using reshape as the operation that is encapsulated in a block
  
      dev = cntk_device(device_id)
      from cntk.internal import sanitize_dtype_cntk
      from .. import reshape, element_times, as_block
  
      num_tensor_elements = np.multiply.reduce(input_shape)
      input_tensor = np.arange(
          num_tensor_elements, dtype=PRECISION_TO_TYPE[precision]
      ).reshape(input_shape)
      input_reshaped = input_tensor.reshape(expected_output_shape)
  
      a_placeholder = C.placeholder()
      a_reshaped = reshape(a_placeholder, output_shape)
  
      const_input_reshaped = constant(input_reshaped, device=dev)
      block_composite = element_times(
          a_reshaped,
          const_input_reshaped,
          name="element_times_inside_block",
      )
  
      a = C.input_variable(
          shape=input_tensor.shape,
          dtype=sanitize_dtype_cntk(PRECISION_TO_TYPE[precision]),
          needs_gradient=True,
          name="a",
      )
  
      input_op = as_block(
          block_composite,
          [(a_placeholder, a)],
          "reshape_test_op",
          block_instance_name="reshape_test_op",
      )
  
      # Test some basic methods related to blocks
      assert input_op.is_composite
      block_primitive = input_op.root_function.find_by_name(
          "reshape_test_op"
      )
      assert block_primitive.name == "reshape_test_op"
      assert block_primitive.is_primitive
      assert block_primitive.is_block
      element_times_inside_block = (
          block_primitive.block_root.find_by_name(
              "element_times_inside_block"
          )
      )
      assert (
          element_times_inside_block.name
          == "element_times_inside_block"
      )
      assert element_times_inside_block.is_primitive
      block_arguments_map = block_primitive.block_arguments_mapping
      assert len(block_arguments_map) == 1
  
      expected_forward = [input_reshaped**2]
      expected_backward = {a: input_tensor}
  
      # create batch
      input_tensor.shape = (1,) + input_tensor.shape
  
      forward_input = {a: input_tensor}
  
      unittest_helper(
          input_op,
          forward_input,
          expected_forward,
          expected_backward,
          device_id=device_id,
          precision=precision,
      )
  
file_path: CNTK/bindings/python/cntk/ops/tests/block_test.py
imports: from __future__ import division
  import numpy
  import pytest
  from .ops_test_utils import unittest_helper, _test_unary_op, _test_binary_op, AA, precision, PRECISION_TO_TYPE, cntk_device
  import cntk
  from cntk.axis import Axis
  from cntk.internal import sanitize_dtype_cntk
  from ..None import constant
label_desc: Use image node_id 1 for calling a global function with example usage: test_op_as_block(input_shape, output_shape, expected_output_shape, device_id, precision) without return types