def AllocateMemoryForConvolutions(self, param, node1, node2):
    self.conv = param.conv
    self.local = param.local
    if self.conv:
      assert not self.local
    else:
      assert not self.conv
    self.conv_params = param.conv_params
    num_colors = self.conv_params.num_colors
    num_filters = self.conv_params.num_filters
    size = self.conv_params.size
    padding = self.conv_params.padding
    stride = self.conv_params.stride

    numdims, numimages = node1.state.shape
    assert numdims % num_colors == 0
    x = int(np.sqrt(numdims / num_colors))
    assert x**2 == numdims / num_colors
    n_locs = (x + 2 * padding - size) / stride + 1

    input_shape = node1.state.shape[::-1]
    output_shape = node2.state.shape[::-1]

    self.input_t = cm.empty(input_shape)
    self.input_t2 = cm.empty(input_shape)
    self.output_t = cm.empty(output_shape)
    self.output_t2 = cm.empty(output_shape)
    if param.conv_params.max_pool:
      pool_output_size = n_locs**2 * num_filters
      self.unpooled_layer = cm.empty((numimages, pool_output_size))
      pool_size = param.conv_params.pool_size
      pool_stride = param.conv_params.pool_stride
      n_pool_locs = (n_locs - pool_size) / pool_stride + 1
      assert output_shape[1] == n_pool_locs**2 * num_filters, (
        "%s expected %s outputs, got %s" % (
          self.name, n_pool_locs**2 * num_filters, output_shape[1]))
      if param.conv_params.prob:
        self.rnd = cm.empty(self.unpooled_layer.shape)
    else:
      assert output_shape[1] == n_locs**2 * num_filters, (
        "%s expected %s outputs, got %s" % (
          self.name, n_locs**2 * num_filters, output_shape[1]))
    if param.conv_params.rnorm:
      self.unrnormalized_layer = cm.empty(output_shape)
      self.denoms = cm.empty(output_shape)
      self.rnorm_temp1 = cm.empty(output_shape)
      self.rnorm_temp2 = cm.empty(output_shape)

    return n_locs
dataset/ETHPy150Open nitishsrivastava/deepnet/deepnet/edge.py/Edge.AllocateMemoryForConvolutions/original