def max_pool_forward_fast(x, pool_param):
    '\n  A fast implementation of the forward pass for a max pooling layer.\n\n  This chooses between the reshape method and the im2col method. If the pooling\n  regions are square and tile the input image, then we can use the reshape\n  method which is very fast. Otherwise we fall back on the im2col method, which\n  is not much faster than the naive method.\n  '
    (N, C, H, W) = x.shape
    (pool_height, pool_width) = (pool_param['pool_height'], pool_param['pool_width'])
    stride = pool_param['stride']
    same_size = (pool_height == pool_width == stride)
    tiles = (((H % pool_height) == 0) and ((W % pool_width) == 0))
    if (same_size and tiles):
        (out, reshape_cache) = max_pool_forward_reshape(x, pool_param)
        cache = ('reshape', reshape_cache)
    else:
        (out, im2col_cache) = max_pool_forward_im2col(x, pool_param)
        cache = ('im2col', im2col_cache)
    return (out, cache)
A fast implementation of the forward pass for a max pooling layer.

This chooses between the reshape method and the im2col method. If the pooling
regions are square and tile the input image, then we can use the reshape
method which is very fast. Otherwise we fall back on the im2col method, which
is not much faster than the naive method.
def max_pool_forward_fast(x, pool_param):
    '\n  A fast implementation of the forward pass for a max pooling layer.\n\n  This chooses between the reshape method and the im2col method. If the pooling\n  regions are square and tile the input image, then we can use the reshape\n  method which is very fast. Otherwise we fall back on the im2col method, which\n  is not much faster than the naive method.\n  '
    (N, C, H, W) = x.shape
    (pool_height, pool_width) = (pool_param['pool_height'], pool_param['pool_width'])
    stride = pool_param['stride']
    same_size = (pool_height == pool_width == stride)
    tiles = (((H % pool_height) == 0) and ((W % pool_width) == 0))
    if (same_size and tiles):
        (out, reshape_cache) = max_pool_forward_reshape(x, pool_param)
        cache = ('reshape', reshape_cache)
    else:
        (out, im2col_cache) = max_pool_forward_im2col(x, pool_param)
        cache = ('im2col', im2col_cache)
    return (out, cache)