示例#1
0
def function_load(fun, directory, filename, suffix=None):
    if suffix is not None:
        filename = filename + "." + str(suffix)
    file_exists = NumpyIO.exists_file(directory, filename)
    if file_exists:
        vec = NumpyIO.load_file(directory, filename)
        fun.vector()[:] = vec
    return file_exists
示例#2
0
def tensor_load(tensor, directory, filename):
    if NumpyIO.exists_file(directory, filename):
        loaded = NumpyIO.load_file(directory, filename)
        assert len(loaded.shape) in (1, 2)
        if len(loaded.shape) == 1:
            tensor[:] = loaded
        elif len(loaded.shape) == 2:
            tensor[:, :] = loaded
        else:
            raise ValueError("Invalid tensor shape")
    else:
        raise OSError