These methods allow the user to save any serializable objects on disk and reload it later in its original state. In other words, it can perform a deep copy of an object into a given File.

Serializable objects are Torch objects having a read() and write() method. Lua objects such as table, number or string are also serializable.

If the object to save contains several other objects (let say it is a tree of objects), then objects appearing several times in this tree will be saved only once. This saves disk space, speedup loading/saving and respect the dependencies between objects.

Interestingly, if the File is a MemoryFile, it allows the user to easily make a clone of any serializable object:

file = torch.MemoryFile() -- creates a file in memory
file:writeObject(object) -- writes the object into file
file:seek(1) -- comes back at the beginning of the file
objectClone = file:readObject() -- gets a clone of object

Subsections

  1. readObject()
  2. writeObject(object)
  3. [string] readString([format])
  4. [number] writeString(str)