Labels¶
-
struct mts_labels_t¶
A set of labels used to carry metadata associated with a tensor map.
This is similar to a list of
countnamed tuples, but stored as a 2D array of shape(count, size), with a set of names associated with the columns of this array (often called dimensions). Each row/entry in this array is unique, and they are often (but not always) sorted in lexicographic order.mts_labels_twith a non-NULLinternal_ptr_correspond to a reference-counted Rust data structure, which allow for fast lookup inside the labels withmts_labels_positions.Public Members
-
void *internal_ptr_¶
internal: pointer to the rust
Labelsstruct if any, null otherwise
-
const char *const *names¶
Names of the dimensions composing this set of labels. There are
sizeelements in this array, each being a NULL terminated UTF-8 string.
-
const int32_t *values¶
Pointer to the first element of a 2D row-major array of 32-bit signed integer containing the values taken by the different dimensions in
names. Each row hassizeelements, and there arecountrows in total.
-
uintptr_t size¶
Number of dimensions/size of a single entry in the set of labels
-
uintptr_t count¶
Number entries in the set of labels
-
void *internal_ptr_¶
The following functions operate on mts_labels_t:
mts_labels_create(): create the Rust-side data for the labelsmts_labels_clone(): increment the reference count of the Rust-side datamts_labels_free(): decrement the reference count of the Rust-side data, and free the data when it reaches 0mts_labels_position(): get the position of an entry in the labelsmts_labels_union(): get the union of two labelsmts_labels_intersection(): get the intersection of two labelsmts_labels_select(): select entries in labels that match a selectionmts_labels_set_user_data(): store some data inside the labels for later retrievalmts_labels_user_data(): retrieve data stored earlier in the labels
-
mts_status_t mts_labels_create(struct mts_labels_t *labels)¶
Finish the creation of
mts_labels_tby associating it to Rust-owned labels.This allows using the
mts_labels_positionsandmts_labels_clonefunctions on themts_labels_t.This function allocates memory which must be released
mts_labels_freewhen you don’t need it anymore.- Parameters:
labels – new set of labels containing pointers to user-managed memory on input, and pointers to Rust-managed memory on output.
- Returns:
The status code of this operation. If the status is not
MTS_SUCCESS, you can usemts_last_error()to get the full error message.
-
mts_status_t mts_labels_clone(struct mts_labels_t labels, struct mts_labels_t *clone)¶
Make a copy of
labelsinsideclone.Since
mts_labels_tare immutable, the copy is actually just a reference count increase, and as such should not be an expensive operation.mts_labels_freemust be used withcloneto decrease the reference count and release the memory when you don’t need it anymore.- Parameters:
labels – set of labels with an associated Rust data structure
clone – empty labels, on output will contain a copy of
labels
- Returns:
The status code of this operation. If the status is not
MTS_SUCCESS, you can usemts_last_error()to get the full error message.
-
mts_status_t mts_labels_free(struct mts_labels_t *labels)¶
Decrease the reference count of
labels, and release the corresponding memory once the reference count reaches 0.- Parameters:
labels – set of labels with an associated Rust data structure
- Returns:
The status code of this operation. If the status is not
MTS_SUCCESS, you can usemts_last_error()to get the full error message.
-
mts_status_t mts_labels_position(struct mts_labels_t labels, const int32_t *values, uintptr_t values_count, int64_t *result)¶
Get the position of the entry defined by the
valuesarray in the given set oflabels. This operation is only available if the labels correspond to a set of Rust Labels (i.e.labels.internal_ptr_is not NULL).- Parameters:
labels – set of labels with an associated Rust data structure
values – array containing the label to lookup
values_count – size of the values array
result – position of the values in the labels or -1 if the values were not found
- Returns:
The status code of this operation. If the status is not
MTS_SUCCESS, you can usemts_last_error()to get the full error message.
-
mts_status_t mts_labels_union(struct mts_labels_t first, struct mts_labels_t second, struct mts_labels_t *result, int64_t *first_mapping, uintptr_t first_mapping_count, int64_t *second_mapping, uintptr_t second_mapping_count)¶
Take the union of two
mts_labels_t.If requested, this function can also give the positions in the union where each entry of the input
mts_labels_tended up.This function allocates memory for
resultwhich must be releasedmts_labels_freewhen you don’t need it anymore.- Parameters:
first – first set of labels
second – second set of labels
result – empty labels, on output will contain the union of
firstandsecondfirst_mapping – if you want the mapping from the positions of entries in
firstto the positions inresult, this should be a pointer to an array containingfirst.countelements, to be filled by this function. Otherwise it should be aNULLpointer.first_mapping_count – number of elements in the
first_mappingarraysecond_mapping – if you want the mapping from the positions of entries in
secondto the positions inresult, this should be a pointer to an array containingsecond.countelements, to be filled by this function. Otherwise it should be aNULLpointer.second_mapping_count – number of elements in the
second_mappingarray
- Returns:
The status code of this operation. If the status is not
MTS_SUCCESS, you can usemts_last_error()to get the full error message.
-
mts_status_t mts_labels_intersection(struct mts_labels_t first, struct mts_labels_t second, struct mts_labels_t *result, int64_t *first_mapping, uintptr_t first_mapping_count, int64_t *second_mapping, uintptr_t second_mapping_count)¶
Take the intersection of two
mts_labels_t.If requested, this function can also give the positions in the intersection where each entry of the input
mts_labels_tended up.This function allocates memory for
resultwhich must be releasedmts_labels_freewhen you don’t need it anymore.- Parameters:
first – first set of labels
second – second set of labels
result – empty labels, on output will contain the intersection of
firstandsecondfirst_mapping – if you want the mapping from the positions of entries in
firstto the positions inresult, this should be a pointer to an array containingfirst.countelements, to be filled by this function. Otherwise it should be aNULLpointer. If an entry infirstis not used inresult, the mapping will be set to -1.first_mapping_count – number of elements in the
first_mappingarraysecond_mapping – if you want the mapping from the positions of entries in
secondto the positions inresult, this should be a pointer to an array containingsecond.countelements, to be filled by this function. Otherwise it should be aNULLpointer. If an entry infirstis not used inresult, the mapping will be set to -1.second_mapping_count – number of elements in the
second_mappingarray
- Returns:
The status code of this operation. If the status is not
MTS_SUCCESS, you can usemts_last_error()to get the full error message.
-
mts_status_t mts_labels_select(struct mts_labels_t labels, struct mts_labels_t selection, int64_t *selected, uintptr_t *selected_count)¶
Select entries in the
labelsthat match theselection.The selection’s names must be a subset of the name of the
labelsnames.All entries in the
labelsthat match one of the entry in theselectionfor all the selection’s dimension will be picked. Any entry in theselectionbut not in thelabelswill be ignored.- Parameters:
labels – Labels on which to run the selection
selection – definition of the selection criteria. Multiple entries are interpreted as a logical
oroperation.selected – on input, a pointer to an array with space for
*selected_countentries. On output, the first*selected_countvalues will contain the index inlabelsof selected entries.selected_count – on input, size of the
selectedarray. On output, this will contain the number of selected entries.
- Returns:
The status code of this operation. If the status is not
MTS_SUCCESS, you can usemts_last_error()to get the full error message.
-
mts_status_t mts_labels_set_user_data(struct mts_labels_t labels, void *user_data, void (*user_data_delete)(void*))¶
Update the registered user data in
labelsThis function changes the registered user data in the Rust Labels to be
user_data; and store the correspondinguser_data_deletefunction to be called once the labels go out of scope.Any existing user data will be released (by calling the provided
user_data_deletefunction) before overwriting with the new data.- Parameters:
labels – set of labels where we want to add user data
user_data – pointer to the data
user_data_delete – function pointer that will be used (if not NULL) to free the memory associated with
datawhen thelabelsare freed.
- Returns:
The status code of this operation. If the status is not
MTS_SUCCESS, you can usemts_last_error()to get the full error message.
-
mts_status_t mts_labels_user_data(struct mts_labels_t labels, void **user_data)¶
Get the registered user data in
labelsin*user_data.If no data has been registered,
*user_datawill be NULL.- Parameters:
labels – set of labels containing user data
user_data – this will be set to the pointer than was registered with these
labels
- Returns:
The status code of this operation. If the status is not
MTS_SUCCESS, you can usemts_last_error()to get the full error message.