Data arrays#
- 
struct mts_array_t#
- mts_array_tmanages n-dimensional arrays used as data in a block or tensor map. The array itself if opaque to this library and can come from multiple sources: Rust program, a C/C++ program, a Fortran program, Python with numpy or torch. The data does not have to live on CPU, or even on the same machine where this code is executed.- This struct contains a C-compatible manual implementation of a virtual table (vtable, i.e. trait in Rust, pure virtual class in C++); allowing manipulation of the array in an opaque way. - WARNING: all function implementations MUST be thread-safe, and can be called from multiple threads at the same time. The - mts_array_titself might be moved from one thread to another.- Public Members - 
void *ptr#
- User-provided data should be stored here, it will be passed as the first parameter to all function pointers below. 
 - 
mts_status_t (*origin)(const void *array, mts_data_origin_t *origin)#
- This function needs to store the “data origin” for this array in - origin. Users of- mts_array_tshould register a single data origin with- mts_register_data_origin, and use it for all compatible arrays.
 - 
mts_status_t (*data)(void *array, double **data)#
- Get a pointer to the underlying data storage. - This function is allowed to fail if the data is not accessible in RAM, not stored as 64-bit floating point values, or not stored as a C-contiguous array. 
 - 
mts_status_t (*shape)(const void *array, const uintptr_t **shape, uintptr_t *shape_count)#
- Get the shape of the array managed by this - mts_array_tin the- *shapepointer, and the number of dimension (size of the- *shapearray) in- *shape_count.
 - 
mts_status_t (*reshape)(void *array, const uintptr_t *shape, uintptr_t shape_count)#
- Change the shape of the array managed by this - mts_array_tto the given- shape.- shape_countmust contain the number of elements in the- shapearray
 - 
mts_status_t (*swap_axes)(void *array, uintptr_t axis_1, uintptr_t axis_2)#
- Swap the axes - axis_1and- axis_2in this- array.
 - 
mts_status_t (*create)(const void *array, const uintptr_t *shape, uintptr_t shape_count, struct mts_array_t *new_array)#
- Create a new array with the same options as the current one (data type, data location, etc.) and the requested - shape; and store it in- new_array. The number of elements in the- shapearray should be given in- shape_count.- The new array should be filled with zeros. 
 - 
mts_status_t (*copy)(const void *array, struct mts_array_t *new_array)#
- Make a copy of this - arrayand return the new array in- new_array.- The new array is expected to have the same data origin and parameters (data type, data location, etc.) 
 - 
void (*destroy)(void *array)#
- Remove this array and free the associated memory. This function can be set to - NULLis there is no memory management to do.
 - 
mts_status_t (*move_samples_from)(void *output, const void *input, const struct mts_sample_mapping_t *samples, uintptr_t samples_count, uintptr_t property_start, uintptr_t property_end)#
- Set entries in the - outputarray (the current array) taking data from the- inputarray. The- outputarray is guaranteed to be created by calling- mts_array_t::createwith one of the arrays in the same block or tensor map as the- input.- The - samplesarray of size- samples_countindicate where the data should be moved from- inputto- output.- This function should copy data from - input[samples[i].input, ..., :]to- array[samples[i].output, ..., property_start:property_end]for- iup to- samples_count. All indexes are 0-based.
 
- 
void *ptr#
- 
mts_status_t mts_register_data_origin(const char *name, mts_data_origin_t *origin)#
- Register a new data origin with the given - name. Calling this function multiple times with the same name will give the same- mts_data_origin_t.- Parameters:
- name – name of the data origin as an UTF-8 encoded NULL-terminated string 
- origin – pointer to an - mts_data_origin_twhere the origin will be stored
 
- 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_get_data_origin(mts_data_origin_t origin, char *buffer, uintptr_t buffer_size)#
- Get the name used to register a given data - originin the given- buffer- Parameters:
- origin – pre-registered data origin 
- buffer – buffer to be filled with the data origin name. The origin name will be written as an UTF-8 encoded, NULL-terminated string 
- buffer_size – size of the buffer 
 
- 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.