Serialization¶
- metatensor.torch.save(path: str, data: TensorMap | TensorBlock | Labels)[source]¶
Save the given data (either
TensorMap,TensorBlock, orLabels) to the given file at the givenpath.If the file already exists, it is overwritten. When saving a
TensorMaporTensorBlock, the file extension should be.npz; and when savingLabelsit should be.npy- Parameters:
path (str) – path of the file where to save the data
data (TensorMap | TensorBlock | Labels) – data to serialize and save
- metatensor.torch.save_buffer(data: TensorMap | TensorBlock | Labels) Tensor[source]¶
Save the given data (either
TensorMap,TensorBlock, orLabels) to an in-memory buffer, represented as 1-dimensionaltorch.Tensorofuint8.- Parameters:
data (TensorMap | TensorBlock | Labels) – data to serialize and save
- Return type:
- metatensor.torch.load(path: str) TensorMap[source]¶
Load a previously saved
TensorMapfrom the given path.TensorMapare serialized using numpy’s.npzformat, i.e. a ZIP file without compression (storage method isSTORED), where each file is stored as a.npyarray. See the C API documentation for more information on the format.
- metatensor.torch.load_block(path: str) TensorBlock[source]¶
Load previously saved
TensorBlockfrom the given file.- Parameters:
path (str) – path of the file to load
- Return type:
- metatensor.torch.load_labels(path: str) Labels[source]¶
Load previously saved
Labelsfrom the given file.
- metatensor.torch.load_buffer(buffer: Tensor) TensorMap[source]¶
Load a previously saved
TensorMapfrom an in-memory buffer, stored inside a 1-dimensionaltorch.Tensorofuint8.
- metatensor.torch.load_block_buffer(buffer: Tensor) TensorBlock[source]¶
Load a previously saved
TensorBlockfrom an in-memory buffer, stored inside a 1-dimensionaltorch.Tensorofuint8.- Parameters:
buffer (Tensor) – CPU tensor of
uint8representing a in-memory buffer- Return type: