naginterfaces.library.sort.realvec_search¶
- naginterfaces.library.sort.realvec_search(valid, rv, item, m1=1)[source]¶
realvec_search
searches an ordered vector of float numbers and returns the index of the first value equal to the sought-after item.For full information please refer to the NAG Library document for m01na
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/m01/m01naf.html
- Parameters
- validbool
If is set to argument checking will be performed. If is set to
realvec_search
will be called without argument checking (which includes checking that array is sorted in ascending order) and the function will return with no exception or warning is raised. See Further Comments for further details.- rvfloat, array-like, shape
Elements to contain float values to be searched.
- itemfloat
The sought-after item.
- m1int, optional
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.
- Returns
- irvint
Note: this argument represents an array index; the value returned will be base-1.
The index of the first value equal to the sought-after item.
- Raises
- NagValueError
- (errno )
On entry, must be sorted in ascending order: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, , .
Constraint: .
- Notes
realvec_search
is based on Professor Niklaus Wirth’s implementation of the Binary Search algorithm (see Wirth (2004)), but with two modifications. First, if the sought-after item is less than the value of the first element of the array to be searched, is returned. Second, if a value equal to the sought-after item is not found, the index of the immediate lower value is returned.
- References
Wirth, N, 2004, Algorithms and Data Structures, 35–36, Prentice Hall