code: def im2col_nd_cpu(
      img, ksize, stride, pad, pval=0, cover_all=False, dilate=1
  ):
      n, c = img.shape[0:2]  # (n, c, d_1, d_2, ..., d_N)
      dims = img.shape[2:]
      ndim = len(dims)
      dilate = as_tuple(dilate, ndim)
      assert ndim == len(ksize) == len(stride) == len(pad)
      outs = tuple(
          get_conv_outsize(d, k, s, p, cover_all, di)
          for (d, k, s, p, di) in zip(dims, ksize, stride, pad, dilate)
      )
      assert all(
          out > 0 for out in outs
      ), "Output sizes should be positive."
  
      # Pad around image.
      pad_width = ((0, 0), (0, 0)) + tuple(
          (p, p + s - 1) for (s, p) in zip(stride, pad)
      )
      img = numpy.pad(
          img, pad_width, mode="constant", constant_values=(pval,)
      )
  
      # Make patch array with which we will compute correlation with filter.
      # shape: (n, c, k_1, k_2, ..., k_N, out_1, out_2, ..., out_N)
      shape = (n, c) + ksize + outs
      col = numpy.ndarray(shape, dtype=img.dtype)
  
      # Fill the patch array.
      colon = slice(None)
      for kxs in itertools.product(
          *[six.moves.range(k) for k in ksize]
      ):
          # col[:, :, kx_1, kx_2, ..., kx_N, :, :, ..., :]
          col_index = (colon, colon) + kxs + (colon,) * ndim
          # img[:, :, kx_1:kx_lim_1:s_1, ..., kx_N:kx_lim_N:s_N]
          kx_dilate = tuple(kx * di for (kx, di) in zip(kxs, dilate))
          kx_lims = tuple(
              kx_di + s * out
              for (kx_di, s, out) in zip(kx_dilate, stride, outs)
          )
          img_index = (colon, colon) + tuple(
              slice(kx_di, kx_lim, s)
              for (kx_di, kx_lim, s) in zip(kx_dilate, kx_lims, stride)
          )
          col[col_index] = img[img_index]
  
      return col
  
file_path: chainer/chainer/utils/conv_nd.py
imports: import itertools
  import numpy
  import six
  from chainer.backends import cuda
  from chainer.utils.conv import get_conv_outsize
  from chainer.utils import conv_nd_kernel
label_desc: Use image node_id 2 for calling a global function with example usage: im2col_nd_cpu(img, ksize, stride, pad, pval, cover_all, dilate) and returns: col