def convolution_output_size(N, M, mode):
    """Return the size of a convolution output"""
    if mode == 'full':
        return M + N - 1
    elif mode == 'valid':
        return max(M, N) - min(M, N) + 1
    elif mode == 'same':
        return max(N, M)
    else:
        raise ValueError("mode='{0}' not recognized".format(mode))