diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/README.md new file mode 100644 index 000000000000..18cbf47bd248 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/README.md @@ -0,0 +1,196 @@ + + +# gindexOfLessThanSorted + +> Return the index of the first element in a sorted strided array which is less than a specified search element. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var gindexOfLessThanSorted = require( '@stdlib/blas/ext/base/gindex-of-less-than-sorted' ); +``` + +#### gindexOfLessThanSorted( N, searchElement, x, strideX ) + +Returns the index of the first element in a sorted strided array which is less than a specified search element. + +```javascript +var x = [ 1.0, 2.0, 2.0, 3.0 ]; + +var idx = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); +// returns 0 + +x = [ 3.0, 2.0, 2.0, 1.0 ]; + +idx = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); +// returns 3 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **searchElement**: search element. +- **x**: sorted input array. +- **strideX**: stride length. + +If the function is unable to find an element which is less than a specified search element, the function returns `-1`. + +```javascript +var x = [ 1.0, 2.0, 2.0, 3.0 ]; + +var idx = gindexOfLessThanSorted( x.length, 1.0, x, 1 ); +// returns -1 +``` + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to search every other element: + +```javascript +var x = [ 1.0, 9.0, 2.0, 9.0, 3.0, 9.0 ]; + +var idx = gindexOfLessThanSorted( 3, 2.0, x, 2 ); +// returns 0 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ 0.0, 1.0, 9.0, 2.0, 9.0, 3.0 ] ); + +// Create an offset view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Find index: +var idx = gindexOfLessThanSorted( 3, 2.0, x1, 2 ); +// returns 0 +``` + +#### gindexOfLessThanSorted.ndarray( N, searchElement, x, strideX, offsetX ) + +Returns the index of the first element in a sorted strided array which is less than a specified search element using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0, 2.0, 3.0 ]; + +var idx = gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); +// returns 0 +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of the strided array: + +```javascript +var x = [ 9.0, 9.0, 9.0, 1.0, 2.0, 3.0 ]; + +var idx = gindexOfLessThanSorted.ndarray( 3, 2.0, x, 1, x.length-3 ); +// returns 0 +``` + +
+ + + + + +
+ +## Notes + +- The input strided array must be sorted in either **strictly** ascending or descending order. +- If `N <= 0`, both functions return `-1`. +- When comparing elements, both functions use the less-than operator `<`. As a consequence, comparisons involving `NaN` always evaluate to `false`, and `-0` and `+0` are considered the same. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gsorthp = require( '@stdlib/blas/ext/base/gsorthp' ); +var gindexOfLessThanSorted = require( '@stdlib/blas/ext/base/gindex-of-less-than-sorted' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +gsorthp( x.length, 1, x, 1 ); +console.log( x ); + +var idx = gindexOfLessThanSorted( x.length, 0.0, x, 1 ); +console.log( idx ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/benchmark/benchmark.js new file mode 100644 index 000000000000..b713e9fc749e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/benchmark/benchmark.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var linspace = require( '@stdlib/array/linspace' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gindexOfLessThanSorted = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = linspace( 0.0, 1.0, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + if ( out !== out ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..50a5999043da --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/benchmark/benchmark.ndarray.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var linspace = require( '@stdlib/array/linspace' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gindexOfLessThanSorted = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = linspace( 0.0, 1.0, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); + if ( out !== out ) { + b.fail( 'should return an integer' ); + } + } + b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/docs/repl.txt new file mode 100644 index 000000000000..5c1550f79df6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/docs/repl.txt @@ -0,0 +1,105 @@ + +{{alias}}( N, searchElement, x, strideX ) + Returns the index of the first element in a sorted strided array which is + less than a specified search element. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + The input strided array must be sorted in either strictly ascending or + descending order. + + If unable to find an element which is less than the search element, the + function returns `-1`. + + If `N <= 0`, the function returns `-1`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + searchElement: any + Search element. + + x: Array|TypedArray + Sorted input array. + + strideX: integer + Stride length. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + // Standard usage: + > var x = [ 1.0, 2.0, 2.0, 3.0 ]; + > var idx = {{alias}}( x.length, 2.0, x, 1 ) + 0 + > x = [ 3.0, 2.0, 2.0, 1.0 ]; + > idx = {{alias}}( x.length, 2.0, x, 1 ) + 3 + + // Using `N` and stride parameters: + > x = [ 1.0, 9.0, 2.0, 9.0, 3.0, 9.0 ]; + > idx = {{alias}}( 3, 2.0, x, 2 ) + 0 + + // View offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > idx = {{alias}}( 3, 2.0, x1, 1 ) + 0 + + +{{alias}}.ndarray( N, searchElement, x, strideX, offsetX ) + Returns the index of the first element in a sorted strided array which is + less than a specified search element using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + searchElement: any + Search element. + + x: Array|TypedArray + Sorted input array. + + strideX: integer + Stride length. + + offsetX: integer + Starting index. + + Returns + ------- + idx: integer + Index. + + Examples + -------- + // Standard usage: + > var x = [ 1.0, 2.0, 2.0, 3.0 ]; + > var idx = {{alias}}.ndarray( x.length, 2.0, x, 1, 0 ) + 0 + + // Advanced indexing: + > x = [ 9.0, 1.0, 9.0, 2.0, 9.0, 3.0 ]; + > idx = {{alias}}.ndarray( 3, 2.0, x, 2, 1 ) + 0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/docs/types/index.d.ts new file mode 100644 index 000000000000..3c5c70291a47 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/docs/types/index.d.ts @@ -0,0 +1,108 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gindexOfLessThanSorted`. +*/ +interface Routine { + /** + * Returns the index of the first element in a sorted strided array which is less than a specified search element. + * + * ## Notes + * + * - If the function is unable to find an element which is less than a search element, the function returns `-1`. + * + * @param N - number of indexed elements + * @param searchElement - search element + * @param x - sorted input array + * @param strideX - stride length + * @returns index + * + * @example + * var x = [ 1.0, 2.0, 2.0, 3.0 ]; + * + * var idx = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + * // returns 0 + */ + ( N: number, searchElement: unknown, x: InputArray, strideX: number ): number; + + /** + * Returns the index of the first element in a sorted strided array which is less than a specified search element using alternative indexing semantics. + * + * ## Notes + * + * - If the function is unable to find an element which is less than a search element, the function returns `-1`. + * + * @param N - number of indexed elements + * @param searchElement - search element + * @param x - sorted input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns index + * + * @example + * var x = [ 1.0, 2.0, 2.0, 3.0 ]; + * + * var idx = gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); + * // returns 0 + */ + ndarray( N: number, searchElement: unknown, x: InputArray, strideX: number, offsetX: number ): number; +} + +/** +* Returns the index of the first element in a sorted strided array which is less than a specified search element. +* +* ## Notes +* +* - If the function is unable to find an element which is less than a search element, the function returns `-1`. +* +* @param N - number of indexed elements +* @param searchElement - search element +* @param x - sorted input array +* @param strideX - stride length +* @returns index +* +* @example +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); +* // returns 0 +* +* @example +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); +* // returns 0 +*/ +declare var gindexOfLessThanSorted: Routine; + + +// EXPORTS // + +export = gindexOfLessThanSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/docs/types/test.ts new file mode 100644 index 000000000000..fdc20453b6dc --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/docs/types/test.ts @@ -0,0 +1,129 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import AccessorArray = require( '@stdlib/array/base/accessor' ); +import gindexOfLessThanSorted = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfLessThanSorted( x.length, 2.0, x, 1 ); // $ExpectType number + gindexOfLessThanSorted( x.length, 2.0, new AccessorArray( x ), 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfLessThanSorted( '1', 2.0, x, 1 ); // $ExpectError + gindexOfLessThanSorted( true, 2.0, x, 1 ); // $ExpectError + gindexOfLessThanSorted( false, 2.0, x, 1 ); // $ExpectError + gindexOfLessThanSorted( null, 2.0, x, 1 ); // $ExpectError + gindexOfLessThanSorted( {}, 2.0, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + gindexOfLessThanSorted( x.length, 1.0, 1, 1 ); // $ExpectError + gindexOfLessThanSorted( x.length, 1.0, true, 1 ); // $ExpectError + gindexOfLessThanSorted( x.length, 1.0, false, 1 ); // $ExpectError + gindexOfLessThanSorted( x.length, 1.0, null, 1 ); // $ExpectError + gindexOfLessThanSorted( x.length, 1.0, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfLessThanSorted( x.length, 2.0, x, '1' ); // $ExpectError + gindexOfLessThanSorted( x.length, 2.0, x, true ); // $ExpectError + gindexOfLessThanSorted( x.length, 2.0, x, false ); // $ExpectError + gindexOfLessThanSorted( x.length, 2.0, x, null ); // $ExpectError + gindexOfLessThanSorted( x.length, 2.0, x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + gindexOfLessThanSorted(); // $ExpectError + gindexOfLessThanSorted( 3, 2.0 ); // $ExpectError + gindexOfLessThanSorted( 3, 2.0, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + gindexOfLessThanSorted( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1, {} ); // $ExpectError +} + +// The function has an `ndarray` method which returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); // $ExpectType number + gindexOfLessThanSorted.ndarray( x.length, 2.0, new AccessorArray( x ), 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfLessThanSorted.ndarray( '1', 2.0, x, 1, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( true, 2.0, x, 1, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( false, 2.0, x, 1, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( null, 2.0, x, 1, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( {}, 2.0, x, 1, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a collection... +{ + gindexOfLessThanSorted.ndarray( x.length, 1.0, 1, 1, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 1.0, true, 1, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 1.0, false, 1, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 1.0, null, 1, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 1.0, {}, 1, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, '1', 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, true, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, false, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, null, 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, '1' ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, true ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, false ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, null ); // $ExpectError + gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, {} ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + gindexOfLessThanSorted.ndarray(); // $ExpectError + gindexOfLessThanSorted.ndarray( 3, 2.0 ); // $ExpectError + gindexOfLessThanSorted.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + gindexOfLessThanSorted.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); // $ExpectError + gindexOfLessThanSorted.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/examples/index.js new file mode 100644 index 000000000000..51ae572d64a8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/examples/index.js @@ -0,0 +1,32 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gsorthp = require( '@stdlib/blas/ext/base/gsorthp' ); +var gindexOfLessThanSorted = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +gsorthp( x.length, 1, x, 1 ); +console.log( x ); + +var idx = gindexOfLessThanSorted( x.length, 0.0, x, 1 ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/accessors.js new file mode 100644 index 000000000000..7b7db96dbbe9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/accessors.js @@ -0,0 +1,112 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var gindexOfLessThan = require( '@stdlib/blas/ext/base/gindex-of-less-than' ).ndarray; + + +// MAIN // + +/** +* Returns the index of the first element in a sorted strided array which is less than a specified search element. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {*} searchElement - search element +* @param {Object} x - sorted input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {integer} index +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfLessThanSorted( x.length, 2.0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 0 +*/ +function gindexOfLessThanSorted( N, searchElement, x, strideX, offsetX ) { + var xbuf; + var get; + var idx; + var mid; + var ix; + var lo; + var hi; + var v1; + var v2; + var v; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessors: + get = x.accessors[ 0 ]; + + v1 = get( xbuf, offsetX ); + v2 = get( xbuf, offsetX + ( ( N - 1 ) * strideX ) ); + + // If either the first or last indexed element is NaN, we cannot determine the sort order, so fall back to a linear search... + if ( isnan( v1 ) || isnan( v2 ) ) { + return gindexOfLessThan( N, searchElement, xbuf, strideX, offsetX ); + } + // Ascending order: elements which are less than the search element form a prefix, so only the first indexed element needs to be checked... + if ( v1 <= v2 ) { + if ( v1 < searchElement ) { + return 0; + } + return -1; + } + // Descending order: perform a binary search for the first element which is less than the search element... + lo = 0; + hi = N; + while ( lo < hi ) { + mid = lo + floor( ( hi - lo ) / 2 ); + v = get( xbuf, offsetX + ( mid * strideX ) ); + + // If we encounter a NaN, fall back to a linear search... + if ( isnan( v ) ) { + ix = offsetX + ( lo * strideX ); + idx = gindexOfLessThan( N-lo, searchElement, xbuf, strideX, ix ); + return ( idx < 0 ) ? idx : idx + lo; + } + if ( v < searchElement ) { + hi = mid; + } else { + lo = mid + 1; + } + } + if ( lo === N ) { + return -1; + } + return lo; +} + + +// EXPORTS // + +module.exports = gindexOfLessThanSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/index.js new file mode 100644 index 000000000000..3f88c4eaa6ba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/index.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return the index of the first element in a sorted strided array which is less than a specified search element. +* +* @module @stdlib/blas/ext/base/gindex-of-less-than-sorted +* +* @example +* var gindexOfLessThanSorted = require( '@stdlib/blas/ext/base/gindex-of-less-than-sorted' ); +* +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); +* // returns 0 +* +* @example +* var gindexOfLessThanSorted = require( '@stdlib/blas/ext/base/gindex-of-less-than-sorted' ); +* +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfLessThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); +* // returns 0 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/main.js new file mode 100644 index 000000000000..234b4afbd077 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/main.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Returns the index of the first element in a sorted strided array which is less than a specified search element. +* +* ## Notes +* +* - If unable to find an element which is less than the search element, the function returns `-1`. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {*} searchElement - search element +* @param {Collection} x - sorted input array +* @param {integer} strideX - stride length +* @returns {integer} index +* +* @example +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); +* // returns 0 +*/ +function gindexOfLessThanSorted( N, searchElement, x, strideX ) { + return ndarray( N, searchElement, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = gindexOfLessThanSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/ndarray.js new file mode 100644 index 000000000000..71b56af9988a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/lib/ndarray.js @@ -0,0 +1,112 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var gindexOfLessThan = require( '@stdlib/blas/ext/base/gindex-of-less-than' ).ndarray; +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Returns the index of the first element in a sorted strided array which is less than a specified search element using alternative indexing semantics. +* +* ## Notes +* +* - If unable to find an element which is less than the search element, the function returns `-1`. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {*} searchElement - search element +* @param {Collection} x - sorted input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {integer} index +* +* @example +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); +* // returns 0 +*/ +function gindexOfLessThanSorted( N, searchElement, x, strideX, offsetX ) { + var idx; + var mid; + var ix; + var lo; + var hi; + var v1; + var v2; + var o; + var v; + + if ( N <= 0 ) { + return -1; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, searchElement, o, strideX, offsetX ); + } + v1 = x[ offsetX ]; + v2 = x[ offsetX + ( ( N - 1 ) * strideX ) ]; + + // If either the first or last indexed element is NaN, we cannot determine the sort order, so fall back to a linear search... + if ( isnan( v1 ) || isnan( v2 ) ) { + return gindexOfLessThan( N, searchElement, x, strideX, offsetX ); + } + // Ascending order: elements which are less than the search element form a prefix, so only the first indexed element needs to be checked... + if ( v1 <= v2 ) { + if ( v1 < searchElement ) { + return 0; + } + return -1; + } + // Descending order: perform a binary search for the first element which is less than the search element... + lo = 0; + hi = N; + while ( lo < hi ) { + mid = lo + floor( ( hi - lo ) / 2 ); + v = x[ offsetX + ( mid * strideX ) ]; + + // If we encounter a NaN, fall back to a linear search... + if ( isnan( v ) ) { + ix = offsetX + ( lo * strideX ); + idx = gindexOfLessThan( N-lo, searchElement, x, strideX, ix ); + return ( idx < 0 ) ? idx : idx + lo; + } + if ( v < searchElement ) { + hi = mid; + } else { + lo = mid + 1; + } + } + if ( lo === N ) { + return -1; + } + return lo; +} + + +// EXPORTS // + +module.exports = gindexOfLessThanSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/package.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/package.json new file mode 100644 index 000000000000..0a0db60cf280 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/blas/ext/base/gindex-of-less-than-sorted", + "version": "0.0.0", + "description": "Return the index of the first element in a sorted strided array which is less than a specified search element.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "sorted", + "search", + "index", + "less", + "compare", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/test/test.js new file mode 100644 index 000000000000..eca88e3ddc33 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var gindexOfLessThanSorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfLessThanSorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gindexOfLessThanSorted.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/test/test.main.js new file mode 100644 index 000000000000..eb2b3e3a63cf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/test/test.main.js @@ -0,0 +1,524 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gindexOfLessThanSorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfLessThanSorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( gindexOfLessThanSorted.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element when the search element is not present in the strided array', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + actual = gindexOfLessThanSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element when the search element is not present in the strided array (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is greater than or equal to the search element', function test( t ) { + var actual; + var x; + + x = [ 2.0, 2.0, 2.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is greater than or equal to the search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 2.0, 2.0, 2.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if a provided `N` parameter is less than or equal to zero', function test( t ) { + var actual; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + + actual = gindexOfLessThanSorted( 0, 2.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( -1, 2.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if a provided `N` parameter is less than or equal to zero (accessors)', function test( t ) { + var actual; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + + actual = gindexOfLessThanSorted( 0, 2.0, toAccessorArray( x ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( -1, 2.0, toAccessorArray( x ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if comparisons involve `NaN` values', function test( t ) { + var actual; + + actual = gindexOfLessThanSorted( 2, NaN, [ 0.0, 1.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( 2, 0.0, [ NaN, NaN ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if comparisons involve `NaN` values (accessors)', function test( t ) { + var actual; + + actual = gindexOfLessThanSorted( 2, NaN, toAccessorArray( [ 0.0, 1.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( 2, 0.0, toAccessorArray( [ NaN, NaN ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal', function test( t ) { + var actual; + + actual = gindexOfLessThanSorted( 1, -0.0, [ 0.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( 1, 0.0, [ -0.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal (accessors)', function test( t ) { + var actual; + + actual = gindexOfLessThanSorted( 1, -0.0, toAccessorArray( [ 0.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( 1, 0.0, toAccessorArray( [ -0.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, 2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), 2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 0 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, -2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 0 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), -2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, 2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), 2 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var actual; + var x0; + var x1; + + x0 = new Float64Array( [ 9.0, 1.0, 2.0, 3.0, 4.0 ] ); + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + actual = gindexOfLessThanSorted( 3, 2.0, x1, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element (descending order)', function test( t ) { + var actual; + var x; + + x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element when the search element is not present in the strided array (descending order)', function test( t ) { + var actual; + var x; + + x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element when the search element is not present in the strided array (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is greater than or equal to the search element (descending order)', function test( t ) { + var actual; + var x; + + x = [ 3.0, 2.0, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 1.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is greater than or equal to the search element (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 3.0, 2.0, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 1.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (descending order)', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride (descending order)', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 0 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, -2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 0 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), -2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets (descending order)', function test( t ) { + var actual; + var x0; + var x1; + + x0 = new Float64Array( [ 9.0, 4.0, 3.0, 2.0, 1.0 ] ); + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + actual = gindexOfLessThanSorted( 3, 3.0, x1, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input arrays containing `NaN` values', function test( t ) { + var actual; + var x; + + x = [ 4.0, 3.0, NaN, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + x = [ NaN, 3.0, 2.0, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + x = [ 3.0, 2.0, 1.0, NaN ]; + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + x = [ 1.0, NaN, 3.0, 4.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input arrays containing `NaN` values (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 4.0, 3.0, NaN, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + x = toAccessorArray( [ NaN, 3.0, 2.0, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + x = toAccessorArray( [ 3.0, 2.0, 1.0, NaN ] ); + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + x = toAccessorArray( [ 1.0, NaN, 3.0, 4.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/test/test.ndarray.js new file mode 100644 index 000000000000..f8c3b6cc56f3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-less-than-sorted/test/test.ndarray.js @@ -0,0 +1,573 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gindexOfLessThanSorted = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfLessThanSorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gindexOfLessThanSorted.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element when the search element is not present in the strided array', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + actual = gindexOfLessThanSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element when the search element is not present in the strided array (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is greater than or equal to the search element', function test( t ) { + var actual; + var x; + + x = [ 2.0, 2.0, 2.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is greater than or equal to the search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 2.0, 2.0, 2.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if a provided `N` parameter is less than or equal to zero', function test( t ) { + var actual; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + + actual = gindexOfLessThanSorted( 0, 2.0, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( -1, 2.0, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if a provided `N` parameter is less than or equal to zero (accessors)', function test( t ) { + var actual; + var x; + + x = [ 1.0, 2.0, 3.0 ]; + + actual = gindexOfLessThanSorted( 0, 2.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( -1, 2.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if comparisons involve `NaN` values', function test( t ) { + var actual; + + actual = gindexOfLessThanSorted( 2, NaN, [ 0.0, 1.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( 2, 0.0, [ NaN, NaN ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if comparisons involve `NaN` values (accessors)', function test( t ) { + var actual; + + actual = gindexOfLessThanSorted( 2, NaN, toAccessorArray( [ 0.0, 1.0 ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( 2, 0.0, toAccessorArray( [ NaN, NaN ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal', function test( t ) { + var actual; + + actual = gindexOfLessThanSorted( 1, -0.0, [ 0.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( 1, 0.0, [ -0.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal (accessors)', function test( t ) { + var actual; + + actual = gindexOfLessThanSorted( 1, -0.0, toAccessorArray( [ 0.0 ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfLessThanSorted( 1, 0.0, toAccessorArray( [ -0.0 ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, 2, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), 2, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 0 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, -2, 4 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 0 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), -2, 4 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset', function test( t ) { + var actual; + var x; + + x = [ + 9.0, + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, 2, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 9.0, + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), 2, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns', function test( t ) { + var actual; + var x; + + x = [ + 9.0, + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, 2, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports complex access patterns (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 9.0, + 1.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), 2, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element (descending order)', function test( t ) { + var actual; + var x; + + x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element when the search element is not present in the strided array (descending order)', function test( t ) { + var actual; + var x; + + x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is less than a provided search element when the search element is not present in the strided array (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is greater than or equal to the search element (descending order)', function test( t ) { + var actual; + var x; + + x = [ 3.0, 2.0, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 1.0, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is greater than or equal to the search element (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 3.0, 2.0, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 1.0, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (descending order)', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, 2, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` stride (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), 2, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride (descending order)', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 0 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, -2, 4 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative `x` stride (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 1.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 3.0 // 0 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), -2, 4 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset (descending order)', function test( t ) { + var actual; + var x; + + x = [ + 9.0, + 3.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, x, 2, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an `x` offset (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 9.0, + 3.0, // 0 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 2 + ]; + + actual = gindexOfLessThanSorted( 3, 2.0, toAccessorArray( x ), 2, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input arrays containing `NaN` values', function test( t ) { + var actual; + var x; + + x = [ 4.0, 3.0, NaN, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + x = [ NaN, 3.0, 2.0, 1.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + x = [ 3.0, 2.0, 1.0, NaN ]; + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + x = [ 1.0, NaN, 3.0, 4.0 ]; + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports input arrays containing `NaN` values (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 4.0, 3.0, NaN, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + x = toAccessorArray( [ NaN, 3.0, 2.0, 1.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + x = toAccessorArray( [ 3.0, 2.0, 1.0, NaN ] ); + + actual = gindexOfLessThanSorted( x.length, 2.5, x, 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + x = toAccessorArray( [ 1.0, NaN, 3.0, 4.0 ] ); + + actual = gindexOfLessThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +});