TensorMap#
- 
class TensorMap#
- A TensorMap is the main user-facing class of this library, and can store any kind of data used in atomistic machine learning. - A tensor map contains a list of - TensorBlock, each one associated with a key. Users can access the blocks either one by one with the- block_by_id()function.- A tensor map provides functions to move some of these keys to the samples or properties labels of the blocks, moving from a sparse representation of the data to a dense one. - Public Functions - 
inline TensorMap(Labels keys, std::vector<TensorBlock> blocks)#
- Create a new TensorMap with the given - keysand- blocks
 - 
TensorMap(const TensorMap&) = delete#
- TensorMap can NOT be copy constructed, use TensorMap::clone instead. 
 - 
TensorMap &operator=(const TensorMap&) = delete#
- TensorMap can not be copy assigned, use TensorMap::clone instead. 
 - 
inline TensorMap clone() const#
- Make a copy of this - TensorMap, including all the data contained inside.
 - 
inline TensorMap clone_metadata_only() const#
- Get a copy of the metadata in this - TensorMap(i.e. keys, samples, components, and properties), ignoring the data itself.- The resulting blocks values will be an - EmptyDataArrayinstance, which does not contain any data.
 - 
inline std::vector<uintptr_t> blocks_matching(const Labels &selection) const#
- Get a (possibly empty) list of block indexes matching the - selection
 - 
inline TensorBlock block_by_id(uintptr_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.
 - 
inline TensorMap keys_to_properties(const Labels &keys_to_move, bool sort_samples = true) const#
- Merge blocks with the same value for selected keys dimensions along the property axis. - The dimensions (names) of - keys_to_movewill be moved from the keys to the property labels, and blocks with the same remaining keys dimensions will be merged together along the property axis.- If - keys_to_movedoes not contains any entries (i.e.- keys_to_move.count() == 0), then the new property labels will contain entries corresponding to the merged blocks only. For example, merging a block with key- a=0and properties- p=1, 2with a block with key- a=2and properties- p=1, 3will produce a block with properties- a, p = (0, 1), (0, 2), (2, 1), (2, 3).- If - keys_to_movecontains entries, then the property labels must be the same for all the merged blocks. In that case, the merged property labels will contains each of the entries of- keys_to_moveand then the current property labels. For example, using- a=2, 3in- keys_to_move, and blocks with properties- p=1, 2will result in- a, p = (2, 1), (2, 2), (3, 1), (3, 2).- The new sample labels will contains all of the merged blocks sample labels. The order of the samples is controlled by - sort_samples. If- sort_samplesis true, samples are re-ordered to keep them lexicographically sorted. Otherwise they are kept in the order in which they appear in the blocks.- Parameters:
- keys_to_move – description of the keys to move 
- sort_samples – whether to sort the merged samples or keep them in the order in which they appear in the original blocks 
 
 
 - 
inline TensorMap keys_to_properties(const std::vector<std::string> &keys_to_move, bool sort_samples = true) const#
- This function calls - keys_to_propertieswith an empty set of- Labelswith the dimensions defined in- keys_to_move
 - 
inline TensorMap keys_to_properties(const std::string &key_to_move, bool sort_samples = true) const#
- This function calls - keys_to_propertieswith an empty set of- Labelswith a single dimension:- key_to_move
 - 
inline TensorMap keys_to_samples(const Labels &keys_to_move, bool sort_samples = true) const#
- Merge blocks with the same value for selected keys dimensions along the samples axis. - The dimensions (names) of - keys_to_movewill be moved from the keys to the sample labels, and blocks with the same remaining keys dimensions will be merged together along the sample axis.- If - keys_to_movemust be an empty set of- Labels(- keys_to_move.count() == 0). The new sample labels will contain entries corresponding to the merged blocks’ keys.- The order of the samples is controlled by - sort_samples. If- sort_samplesis true, samples are re-ordered to keep them lexicographically sorted. Otherwise they are kept in the order in which they appear in the blocks.- This function is only implemented if all merged block have the same property labels. - Parameters:
- keys_to_move – description of the keys to move 
- sort_samples – whether to sort the merged samples or keep them in the order in which they appear in the original blocks 
 
 
 - 
inline TensorMap keys_to_samples(const std::vector<std::string> &keys_to_move, bool sort_samples = true) const#
- This function calls - keys_to_sampleswith an empty set of- Labelswith the dimensions defined in- keys_to_move
 - 
inline TensorMap keys_to_samples(const std::string &key_to_move, bool sort_samples = true) const#
- This function calls - keys_to_sampleswith an empty set of- Labelswith a single dimension:- key_to_move
 - 
inline TensorMap components_to_properties(const std::vector<std::string> &dimensions) const#
- Move the given - dimensionsfrom the component labels to the property labels for each block.- Parameters:
- dimensions – name of the component dimensions to move to the properties 
 
 - 
inline TensorMap components_to_properties(const std::string &dimension) const#
- Call - components_to_propertieswith a single dimension.
 - 
inline void save(const std::string &path) const#
- Save a - TensorMapto the given path.- This is identical to - metatensor::io::save(), and provided as a convenience API.
 - 
inline std::vector<uint8_t> save_buffer() const#
- Save a - TensorMapto an in-memory buffer.- This is identical to - metatensor::io::save_buffer(), and provided as a convenience API.
 - 
template<typename Buffer>
 inline Buffer save_buffer() const#
- Save a - TensorMapto an in-memory buffer.- This is identical to - metatensor::io::save_buffer(), and provided as a convenience API.
 - 
inline mts_tensormap_t *as_mts_tensormap_t() &#
- Get the - mts_tensormap_tpointer corresponding to this- TensorMap.- The tensor map pointer is still managed by the current - TensorMap
 - Public Static Functions - 
static inline TensorMap load(const std::string &path, mts_create_array_callback_t create_array = details::default_create_array)#
- Load a previously saved - TensorMapfrom the given path.- This is identical to - metatensor::io::load(), and provided as a convenience API.
 - 
static inline TensorMap load_buffer(const uint8_t *buffer, size_t buffer_count, mts_create_array_callback_t create_array = details::default_create_array)#
- Load a previously saved - TensorMapfrom a in-memory buffer.- This is identical to - metatensor::io::load_buffer(), and provided as a convenience API.
 - 
template<typename Buffer>
 static inline TensorMap load_buffer(const Buffer &buffer, mts_create_array_callback_t create_array = details::default_create_array)#
- Load a previously saved - TensorMapfrom a in-memory buffer.- This is identical to - metatensor::io::load_buffer(), and provided as a convenience API.
 
- 
inline TensorMap(Labels keys, std::vector<TensorBlock> blocks)#