naginterfaces.library.sort.realvec_​sort

naginterfaces.library.sort.realvec_sort(rv, m1, order)[source]

realvec_sort rearranges a vector of float numbers into ascending or descending order.

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

https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/m01/m01caf.html

Parameters
rvfloat, array-like, shape

Elements to of must contain float values to be sorted.

m1int

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 sorted.

orderstr, length 1

If , the values will be sorted into ascending (i.e., nondecreasing) order.

If , into descending order.

Returns
rvfloat, ndarray, shape

These values are rearranged into sorted order.

Raises
NagValueError
(errno )

On entry, and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, has an illegal value: .

Notes

In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

realvec_sort is based on Singleton’s implementation of the ‘median-of-three’ Quicksort algorithm (see Singleton (1969)), but with two additional modifications. First, small subfiles are sorted by an insertion sort on a separate final pass (see Sedgewick (1978)). Second, if a subfile is partitioned into two very unbalanced subfiles, the larger of them is flagged for special treatment: before it is partitioned, its end points are swapped with two random points within it; this makes the worst case behaviour extremely unlikely.

References

Sedgewick, R, 1978, Implementing Quicksort programs, Comm. ACM (21), 847–857

Singleton, R C, 1969, An efficient algorithm for sorting with minimal storage: Algorithm 347, Comm. ACM (12), 185–187