def match_with_batchsize(lim, batchsize):
    """
    Function used by modify_datasets below to match return the integer closest to lim
    which is multiple of batchsize, i.e., lim%batchsize=0.

    """

    if lim % batchsize == 0:
        return lim
    else:
        return lim - lim % batchsize