These subroutines sort the elements of sequence x using a stable sort; that is, where equal elements occur in the input sequence, they remain in the same relative order in the output sequence. The original positions of the elements in sequence x are returned in the indices array INDX.
x, work | Subroutine |
Integer | ISORTS |
Short-precision real | SSORTS |
Long-precision real | DSORTS |
Fortran | CALL ISORTS | SSORTS | DSORTS (x, incx, n, indx, work, lwork) |
C and C++ | isorts | ssorts | dsorts (x, incx, n, indx, work, lwork); |
PL/I | CALL ISORTS | SSORTS | DSORTS (x, incx, n, indx, work, lwork); |
Specified as: a fullword integer. It can have any value.
Returned as: a one-dimensional array of length n, containing fullword integers; 1 <= (INDX elements) <= n.
The elements of input sequence x are sorted into ascending order using a partition sort. The sorting is stable; that is, where equal elements occur in the input sequence, they remain in the same relative order in the output sequence. The elements of output sequence x can be expressed as follows:
By specifying a negative stride for x, the elements of input sequence x are assumed to be reversed in the array, (xn, xn-1, ... , x1), thus producing a sort into descending order within the array.
In addition, the INDX array contains the n indices that indicate, for the elements in the sorted output sequence, the original positions of those elements in input sequence x. (These are not the positions in the array, but rather the positions in the sequence.) For each element xj in the input sequence, becoming element xxk in the output sequence, the elements in INDX are defined as follows:
To understand INDX when you specify a negative stride, you should remember that both the input and output sequences, x, are assumed to be in reverse order in array X, but INDX is not affected by stride. The sequence elements of x are assumed to be stored in your input array as follows:
The sequence elements of x are stored in your output array by ESSL as follows:
where the elements xxk are the elements xj, sorted into descending order in X. As an example of how INDX is calculated, if xx1 = xn-1, then INDX(1) = n-1.
If n is 0, no computation is performed. See references [28] and [75].
Unable to allocate internal work area.
None
n < 0
This example shows how to sort a sequence x into ascending order by specifying a positive stride. Because this is a stable sort, the -1 elements remain in the same relative order in the output sequence, indicated by INDX(2) = 2 and INDX(3) = 4.
X INCX N INDX WORK LWORK | | | | | | CALL ISORTS( X , 2 , 5 , INDX , WORK , 5 ) X = (2, . , -1, . , 5, . , -1, . , -2)
X = (-2, . , -1, . , -1, . , 2, . , 5) INDX = (5, 2, 4, 1, 3)
This example shows how to sort a sequence x into descending order by specifying a negative stride. Therefore, both the input and output sequences are assumed to be reversed in the array X. The input sequence is assumed to be stored as follows:
The output sequence is stored by ESSL as follows:
As a result, INDX is defined as follows:
For example, because output sequence element xx4 = 2 is input sequence element x5, then INDX(4) = 5. Also, because this is a stable sort, the -1 elements remain in the same relative order in the output sequence, indicated by INDX(2) = 2 and INDX(3) = 4.
X INCX N INDX WORK LWORK | | | | | | CALL ISORTS( X , -1 , 5 , INDX , WORK , 5 ) X = (2, -1, 5, -1, -2)
X = (5, 2, -1, -1, -2) INDX = (1, 2, 4, 5, 3)