naginterfaces.library.sort.realvec_vec_search¶
- naginterfaces.library.sort.realvec_vec_search(valid, rv, m1, m2, item, comm=None)[source]¶
realvec_vec_search
searches a strictly ordered vector of float numbers and returns the indices of the largest numbers in the vector which are smaller than or equal to the sought-after items.For full information please refer to the NAG Library document for m01nd
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/m01/m01ndf.html
- Parameters
- validbool
If is set to argument checking will be performed. If is set to
realvec_vec_search
will be called without argument checking (which includes checking that array is sorted in strictly ascending order). See Further Comments for further details.- rvfloat, array-like, shape
, the float values to be searched.
- 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 searched.
- m2int
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 last element of to be searched.
- itemfloat, array-like, shape
, the sought-after items.
- commNone or dict, communication object, optional, modified in place
Communication structure.
If is None then searching is performed using an offset-based binary search.
Otherwise, may be supplied uninitialized.
It will then be populated and the routine will perform a direct search of .
The populated can then be supplied again to subsequent calls for repeated searching of .
- Returns
- idxint, ndarray, shape
Note: this argument represents array indices; the values returned will be base-1.
contains the index of the largest entry in which is smaller than or equal to .
- Raises
- NagValueError
- (errno )
On entry, must be sorted in strictly ascending order: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, , , .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, the values in are such that the required value of would overflow the current platform’s largest positive integer value.
- (errno )
may have become corrupted.
- Notes
realvec_vec_search
searches an array, , of strictly-increasing float numbers, , , for the elements of an unordered array of float numbers, . If a value equal to a sought-after item is not found in , the index of the immediate lower value is returned. If is less than , is returned.The function implements the direct search algorithm presented as Algorithm 8 in Cannizzo (2018). It precomputes a scalar, , and a reference vector of indices, , that it uses to speed up searches of . The length of is a function of the number of entries in and their values, and the function provides a mechanism to compute what this length should be.
If the amount of memory required for is infeasible,
realvec_vec_search
implements offset-based binary search (Algorithm 5 in Cannizzo (2018)) as an alternative that does not require to be used.See Further Comments for more information on the relative time complexities of the two search algorithms.
- References
Cannizzo, F, 2018, A fast and vectorizable alternative to binary search in O(1) with wide applicability to arrays of floating point numbers, Journal of Parallel and Distributed Computing (113), 37–54