naginterfaces.library.sort.intvec_rank(iv, m1, order)[source]

intvec_rank ranks a vector of integer numbers in ascending or descending order.

For full information please refer to the NAG Library document for m01db

ivint, array-like, shape

Elements to of must contain integer values to be ranked.


Note: this argument represents an array index; the value you supply must be base-1 for compatibility with the NAG Engine.

The index of the first element of to be ranked.

orderstr, length 1

If , the values will be ranked in ascending (i.e., nondecreasing) order.

If , into descending order.

irankint, ndarray, shape

Elements to of contain the ranks of the corresponding elements of . Note that the ranks are in the range to : thus, if is the first element in the rank order, is set to .

(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, has an illegal value: .


No equivalent traditional C interface for this routine exists in the NAG Library.

intvec_rank uses a variant of list-merging, as described on pages 165–166 in Knuth (1973). The function takes advantage of natural ordering in the data, and uses a simple list insertion in a preparatory pass to generate ordered lists of length at least . The ranking is stable: equal elements preserve their ordering in the input data.


Knuth, D E, 1973, The Art of Computer Programming (Volume 3), (2nd Edition), Addison–Wesley