def pad_dims(input, leftdims, rightdims):
 assert (input.ndim >= rightdims)
 if (input.ndim == (leftdims + rightdims)):
  return input
 img_shape = input.shape[(- rightdims):]
 non_pool_ndim = (input.ndim - rightdims)
 if (non_pool_ndim < leftdims):
  dummy_dims = tensor.as_tensor(([1] * (leftdims - non_pool_ndim)))
  new_shape = tensor.join(0, dummy_dims, input.shape[:non_pool_ndim], img_shape)
 else:
  batched_ndim = ((non_pool_ndim - leftdims) + 1)
  batch_size = tensor.prod(input.shape[:batched_ndim])
  batch_size = tensor.shape_padright(batch_size, 1)
  new_shape = tensor.join(0, batch_size, input.shape[batched_ndim:non_pool_ndim], img_shape)
 new_shape = tensor.cast(new_shape, 'int64')
 input_ND = GpuReshape((leftdims + rightdims))(input, new_shape)
 return input_ND

def pad_dims ( input , leftdims , rightdims ) : assert ( input . ndim >= rightdims ) if ( input . ndim == ( leftdims + rightdims ) ) : return input img_shape = input . shape [ ( - rightdims ) : ] non_pool_ndim = ( input . ndim - rightdims ) if ( non_pool_ndim < leftdims ) : dummy_dims = tensor . as_tensor ( ( [ 1 ] * ( leftdims - non_pool_ndim ) ) ) new_shape = tensor . join ( 0 , dummy_dims , input . shape [ : non_pool_ndim ] , img_shape ) else : batched_ndim = ( ( non_pool_ndim - leftdims ) + 1 ) batch_size = tensor . prod ( input . shape [ : batched_ndim ] ) batch_size = tensor . shape_padright ( batch_size , 1 ) new_shape = tensor . join ( 0 , batch_size , input . shape [ batched_ndim : non_pool_ndim ] , img_shape ) new_shape = tensor . cast ( new_shape , 'int64' ) input_ND = GpuReshape ( ( leftdims + rightdims ) ) ( input , new_shape ) return input_ND
reshapes the input to a tensor this helper function is used to convert pooling inputs with arbitrary non-pooling dimensions to the correct number of dimensions for the gpu pooling ops .