code: def _col2im_shape_check_2d(X, output_shape, kernel_shape, dilations, pads, strides):  # type: ignore
      output_height, output_width = output_shape
      kernel_height, kernel_width = kernel_shape
      dilation_height, dilation_width = dilations
      stride_height, stride_width = strides
  
      ndim = len(X.shape)
      if not (
          (ndim == 2 and X.shape[0] != 0 and X.shape[1] != 0)
          or (ndim == 3 and X.shape[1] != 0 and X.shape[2] != 0)
      ):
          raise ValueError(
              "Expected 2D or 3D (batch mode) tensor for input with possibly 0 batch size and non-zero dimensions for input."
          )
  
      batch_dim = 0 if len(X.shape) == 3 else -1
      n_input_plane = X.shape[batch_dim + 1]
  
      if n_input_plane % (kernel_width * kernel_height) != 0:
          raise ValueError(
              f"Expected size of input's dimension 1 to be divisible by the "
              f"product of kernel_size, but got input.size(1)={n_input_plane} "
              f"and kernel_size={kernel_shape}."
          )
  
      input_length = X.shape[batch_dim + 2]
      n_blocks_height = (
          output_height
          + pads[0, :].sum()
          - dilation_height * (kernel_height - 1)
          - 1
      ) // stride_height + 1
      n_blocks_width = (
          output_width
          + pads[1, :].sum()
          - dilation_width * (kernel_width - 1)
          - 1
      ) // stride_width + 1
  
      if input_length != (n_blocks_height * n_blocks_width):
          raise ValueError(
              f"Given batch_dim={batch_dim}, n_input_plane={n_input_plane}, X.shape={X.shape}, "
              f"output_shape={output_shape}, kernel_shape={kernel_shape}, "
              f"dilations={dilations}, pads={pads}, strides={strides}, "
              f"expected size of input's dimension 2 to match the calculated number of ",
              f"sliding blocks {n_blocks_height} * {n_blocks_width} = {n_blocks_height * n_blocks_width}, "
              f"but got input.size(2)={input_length}.",
          )
  
      if not (n_blocks_height >= 1 and n_blocks_width >= 1):
          raise ValueError(
              f"Given batch_dim={batch_dim}, n_input_plane={n_input_plane}, X.shape={X.shape}, "
              f"output_shape={output_shape}, kernel_shape={kernel_shape}, "
              f"dilations={dilations}, pads={pads}, strides={strides}, "
              f"calculated shape of the array of sliding blocks as ({n_blocks_height}, {n_blocks_width}), "
              f"which is too small (non-positive)."
          )
  
file_path: onnx/onnx/reference/ops/op_col2im.py
imports: import numpy
  from onnx.reference.op_run import OpRun
  from onnx.reference.ops._op_common_indices import _get_indices, _is_out
label_desc: Use image node_id 1 for calling a global function with example usage: _col2im_shape_check_2d(X, output_shape, kernel_shape, dilations, pads, strides) without return types