TensorBlock#
- 
typedef struct mts_block_t mts_block_t#
- Basic building block for tensor map. A single block contains a n-dimensional - mts_array_t, and n sets of- mts_labels_t(one for each dimension).- A block can also contain gradients of the values with respect to a variety of parameters. In this case, each gradient has a separate set of sample and component labels but share the property labels with the values. 
The following functions operate on mts_block_t:
- mts_block(): create new blocks
- mts_block_copy(): copy existing blocks
- mts_block_free(): free allocated blocks
- mts_block_labels(): get one of the- mts_labels_tassociated with this block
- mts_block_data(): get one of the- mts_array_tassociated with this block
- mts_block_add_gradient(): add gradient data to this block
- mts_block_gradients_list(): get the list of gradients in this block
- 
struct mts_block_t *mts_block(struct mts_array_t data, struct mts_labels_t samples, const struct mts_labels_t *components, uintptr_t components_count, struct mts_labels_t properties)#
- Create a new - mts_block_twith the given- dataand- samples,- componentsand- propertieslabels.- The memory allocated by this function and the blocks should be released using - mts_block_free, or moved into a tensor map using- mts_tensormap.- Parameters:
- data – array handle containing the data for this block. The block takes ownership of the array, and will release it with - array.destroy(array.ptr)when it no longer needs it.
- samples – sample labels corresponding to the first dimension of the data 
- components – array of component labels corresponding to intermediary dimensions of the data 
- components_count – number of entries in the - componentsarray
- properties – property labels corresponding to the last dimension of the data 
 
- Returns:
- A pointer to the newly allocated block, or a - NULLpointer in case of error. In case of error, you can use- mts_last_error()to get the error message.
 
- 
struct mts_block_t *mts_block_copy(const struct mts_block_t *block)#
- Make a copy of an - mts_block_t.- The memory allocated by this function and the blocks should be released using - mts_block_free, or moved into a tensor map using- mts_tensormap.- Parameters:
- block – existing block to copy 
 
- Returns:
- A pointer to the newly allocated block, or a - NULLpointer in case of error. In case of error, you can use- mts_last_error()to get the error message.
 
- 
mts_status_t mts_block_free(struct mts_block_t *block)#
- Free the memory associated with a - blockpreviously created with- mts_block.- If - blockis- NULL, this function does nothing.- Parameters:
- block – pointer to an existing block, or - NULL
 
- Returns:
- The status code of this operation. If the status is not - MTS_SUCCESS, you can use- mts_last_error()to get the full error message.
 
- 
mts_status_t mts_block_labels(const struct mts_block_t *block, uintptr_t axis, struct mts_labels_t *labels)#
- Get the set of labels from this - block.- This function allocates memory for - labelswhich must be released- mts_labels_freewhen you don’t need it anymore.- Parameters:
- block – pointer to an existing block 
- axis – axis/dimension of the data array for which you need the labels 
- labels – pointer to an empty - mts_labels_tthat will be set to the- block’s labels
 
- Returns:
- The status code of this operation. If the status is not - MTS_SUCCESS, you can use- mts_last_error()to get the full error message.
 
- 
mts_status_t mts_block_data(struct mts_block_t *block, struct mts_array_t *data)#
- Get the array handle for the values in this - block.- Parameters:
- block – pointer to an existing block 
- data – pointer to an empty - mts_array_tthat will be set to the requested array
 
- Returns:
- The status code of this operation. If the status is not - MTS_SUCCESS, you can use- mts_last_error()to get the full error message.
 
- 
mts_status_t mts_block_add_gradient(struct mts_block_t *block, const char *parameter, struct mts_block_t *gradient)#
- Add a new gradient to this - blockwith the given- name.- The block takes ownership of the gradient, which should not be released separately. - Parameters:
- block – pointer to an existing block 
- parameter – name of the gradient as a NULL-terminated UTF-8 string. This is usually the parameter used when taking derivatives (e.g. - "positions",- "cell", etc.)
- gradient – a block whose values contain the gradients with respect to the - parameter. The labels of the- gradientshould be organized as follows: its- samplesmust contain- "sample"as the first label, which establishes a correspondence with the- samplesof the original- block; its components must contain at least the same components as the original- TensorBlock, with any additional component coming before those; its properties must match those of the original- block.
 
- Returns:
- The status code of this operation. If the status is not - MTS_SUCCESS, you can use- mts_last_error()to get the full error message.
 
- 
mts_status_t mts_block_gradients_list(const struct mts_block_t *block, const char *const **parameters, uintptr_t *parameters_count)#
- Get a list of all gradients defined in this - blockin the- parametersarray.- Parameters:
- block – pointer to an existing block 
- parameters – will be set to the first element of an array of NULL-terminated UTF-8 strings containing all the parameters for which a gradient exists in the block 
- parameters_count – will be set to the number of elements in - parameters
 
- Returns:
- The status code of this operation. If the status is not - MTS_SUCCESS, you can use- mts_last_error()to get the full error message.