Application Notes for Intel® oneAPI Math Kernel Library Summary Statistics

ID 772991
Date 12/04/2020
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

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()
{
    VSLSSTaskPtr task;
    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;
    /* Create a task */
    status = vsldSSNewTask(&task, &p, &n, &x_storage, (double *)x, 0, indices);
    /* Initialize the task parameters*/
    status = vsldSSEditTask(task, VSL_SS_ED_SORTED_OBSERV, y);
    status = vsliSSEditTask(task, VSL_SS_ED_SORTED_OBSERV_STORAGE, &sorted_x_storage);
    /* Sort the observation matrix using the radix method **/
    status = vsldSSCompute(task, VSL_SS_SORTED_OBSERV, VSL_SS_METHOD_RADIX);
/* Deallocate the task resources */
    status = vslSSDeleteTask(&task);
    return 0;
}