ID 772991
Date 12/04/2020
Public

## Sorting an Observation Matrix

You can use Summary Statistics routines to sort observation matrices by components of a random vector in the ascending order. The routines sort either rows or columns of the observation matrix depending on its storage, row- or column-major format. Sorting results are packed by the routines in accordance with your settings of the storage format for the output matrix. For supported storage formats see the table Storage format of matrix of observations, order statistics and matrix of sorted observations in the Summary Statistics section of [MKLMan].

You should allocate enough memory to hold the results of the calculations. The size of the array should provide storage for p x n elements, where:

• p is the dimension of the task
• n is the number of observations

Register the memory and storage format of the sorting result using the vs[d|s]EditTask editor before sorting the matrix of the observations. If you want the library to store sorting results into the input matrix, use the storage type for matrix of the sorted observations identical to the one of the input dataset. In this case you cannot choose individual components of the random vector for sorting.

The library offers the radix sort method to sort the data. The sorting follows the pattern of the example below:

#define DIM 3      /* dimension of the task */
#define N  10     /* number of observations */
int main()
{
MKL_INT p, n;
MKL_INT x_storage, sorted_x_storage;
MKL_INT indices[DIM]={1,1,0}; /* the first two vector components are processed */
double x[DIM][N];            /* matrix of observations */
double y[DIM][N];            /* sorted matrix of observations */
int status;
/* Parameters of the task and initialization */
n = N;
p = DIM;
x_storage        = VSL_SS_MATRIX_STORAGE_ROWS;
sorted_x_storage = VSL_SS_MATRIX_STORAGE_ROWS;
}