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
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
def tensor_save(tensor, directory, filename): NumpyIO.save_file(tensor, directory, filename)
def function_save(fun, directory, filename, suffix=None): if suffix is not None: filename = filename + "." + str(suffix) NumpyIO.save_file(fun.vector(), directory, filename)