TensorMap#
- 
using metatensor_torch::TorchTensorMap = torch::intrusive_ptr<TensorMapHolder>#
- TorchScript will always manipulate - TensorMapHolderthrough a- torch::intrusive_ptr
- 
class TensorMapHolder : public CustomClassHolder#
- Wrapper around - metatensor::TensorMapfor integration with TorchScript- Python/TorchScript code will typically manipulate - torch::intrusive_ptr<TensorMapHolder>(i.e.- TorchTensorMap) instead of instances of- TensorMapHolder.- Public Functions - 
TensorMapHolder(TorchLabels keys, const std::vector<TorchTensorBlock> &blocks)#
- Create a new - TensorMapHolderfor TorchScript.- In contrast to the TensorMap constructor, this does not move from the different blocks, but instead create new ones using the same data and metadata, but with incremented reference count. 
 - 
TorchTensorMap copy() const#
- Make a copy of this - TensorMap, including all the data contained inside.
 - 
TorchLabels keys() const#
- Get the keys for this - TensorMap
 - 
std::vector<int64_t> blocks_matching(const TorchLabels &selection) const#
- Get a (possibly empty) list of block indexes matching the - selection
 - 
TorchTensorMap keys_to_properties(torch::IValue keys_to_move, bool sort_samples) const#
- Merge blocks with the same value for selected keys dimensions along the property axis. - See - metatensor::TensorMap::keys_to_propertiesfor more information on this function.- The input - torch::IValuecan be a single string, a list/tuple of strings, or a- TorchLabelsinstance.
 - 
TorchTensorMap keys_to_samples(torch::IValue keys_to_move, bool sort_samples) const#
- Merge blocks with the same value for selected keys dimensions along the sample axis. - See - metatensor::TensorMap::keys_to_samplesfor more information on this function.- The input - torch::IValuecan be a single string, a list/tuple of strings, or a- TorchLabelsinstance.
 - 
TorchTensorMap components_to_properties(torch::IValue dimensions) const#
- Move the given - dimensionsfrom the component labels to the property labels for each block.- See - metatensor::TensorMap::components_to_propertiesfor more information on this function.- The input - torch::IValuecan be a single string, or a list/tuple of strings.
 - 
std::vector<std::string> sample_names()#
- Get the names of the samples dimensions for all blocks in this - TensorMap
 - 
std::vector<std::string> component_names()#
- Get the names of the components dimensions for all blocks in this - TensorMap
 - 
std::vector<std::string> property_names()#
- Get the names of the properties dimensions for all blocks in this - TensorMap
 - 
std::string print(int64_t max_keys) const#
- Print this TensorMap to a string, including at most - max_keysin the output (-1 to include all keys).
 - 
torch::Device device() const#
- Get the device for the values stored in this - TensorMap
 - 
torch::Dtype scalar_type() const#
- Get the dtype for the values stored in this - TensorMap
 - 
TorchTensorMap to(torch::optional<torch::Dtype> dtype = torch::nullopt, torch::optional<torch::Device> device = torch::nullopt, torch::optional<std::string> arrays = torch::nullopt) const#
- Move this - TensorMapto the given- dtype,- deviceand- arraysbackend. Only- "torch"is supported for the- arraysbackend.
 - 
void save(const std::string &path) const#
- Serialize and save a TensorMap to the given path. 
 - 
torch::Tensor save_buffer() const#
- Serialize and save a TensorMap to an in-memory buffer (represented as a - torch::Tensorof bytes)
 - Public Static Functions - 
static TorchTensorBlock block_by_id(TorchTensorMap self, int64_t index)#
- Get a block inside this TensorMap by it’s index/the index of the corresponding key. - The returned - TensorBlockis a view inside memory owned by this- TensorMap, and is only valid as long as the- TensorMapis kept alive.
 - 
static TorchTensorBlock block(TorchTensorMap self, const std::map<std::string, int32_t> &selection)#
- Get the block in this - TensorMapwith the key matching the name=>values passed in- selection
 - 
static TorchTensorBlock block(TorchTensorMap self, TorchLabels selection)#
- Get the block in this - TensorMapwith the key matching the name=>values passed in- selection. The- selectionmust contain a single entry.
 - 
static TorchTensorBlock block(TorchTensorMap self, TorchLabelsEntry selection)#
- Get the block in this - TensorMapwith the key matching the name=>values passed in- selection
 - 
static TorchTensorBlock block_torch(TorchTensorMap self, torch::IValue index)#
- TorchScript implementation of - block, dispatching to one of the functions above
 - 
static std::vector<TorchTensorBlock> blocks_by_id(TorchTensorMap self, const std::vector<int64_t> &indices)#
- Similar to - block_by_id, but get all blocks with the given indices.
 - 
static std::vector<TorchTensorBlock> blocks(TorchTensorMap self)#
- Get all blocks in this TensorMap. 
 - 
static std::vector<TorchTensorBlock> blocks(TorchTensorMap self, const std::map<std::string, int32_t> &selection)#
- Similar to - block, but allow getting multiple matching blocks.
 - 
static std::vector<TorchTensorBlock> blocks(TorchTensorMap self, TorchLabels selection)#
- Similar to - block, but allow getting multiple matching blocks.
 - 
static std::vector<TorchTensorBlock> blocks(TorchTensorMap self, TorchLabelsEntry selection)#
- Similar to - block, but allow getting multiple matching blocks.
 - 
static std::vector<TorchTensorBlock> blocks_torch(TorchTensorMap self, torch::IValue index)#
- TorchScript implementation of - blocks, dispatching to one of the functions above.
 - 
static std::vector<std::tuple<TorchLabelsEntry, TorchTensorBlock>> items(TorchTensorMap self)#
- Get all (key => block) pairs in this - TensorMap
 - 
static TorchTensorMap load(const std::string &path)#
- Load a serialized TensorMap from the given path. 
 - 
static TorchTensorMap load_buffer(torch::Tensor buffer)#
- Load a serialized TensorMap from an in-memory buffer (represented as a - torch::Tensorof bytes)
 
- 
TensorMapHolder(TorchLabels keys, const std::vector<TorchTensorBlock> &blocks)#