From 277b8099f72e0a4291b427a363149a224162510d Mon Sep 17 00:00:00 2001 From: Sachinn-64 Date: Tue, 29 Sep 2026 15:54:55 +0530 Subject: [PATCH 1/4] feat: add blas/ext/base/gindex-of-greater-than-equal-sorted --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../README.md | 207 +++++++++++ .../benchmark/benchmark.js | 97 +++++ .../benchmark/benchmark.ndarray.js | 97 +++++ .../docs/repl.txt | 102 ++++++ .../docs/types/index.d.ts | 111 ++++++ .../docs/types/test.ts | 129 +++++++ .../examples/index.js | 32 ++ .../lib/accessors.js | 82 +++++ .../lib/index.js | 57 +++ .../lib/main.js | 56 +++ .../lib/ndarray.js | 83 +++++ .../package.json | 69 ++++ .../test/test.js | 38 ++ .../test/test.main.js | 312 ++++++++++++++++ .../test/test.ndarray.js | 337 ++++++++++++++++++ 15 files changed, 1809 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md new file mode 100644 index 000000000000..3301da63b802 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md @@ -0,0 +1,207 @@ + + +# gindexOfGreaterThanEqualSorted + +> Return the index of the first element in a sorted strided array which is greater than or equal to a specified search element. + + + +
+ +
+ + + + + +
+ +## Usage + + + +```javascript +var gindexOfGreaterThanEqualSorted = require( '@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted' ); +``` + +#### gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX ) + +Returns the index of the first element in a sorted strided array which is greater than or equal to a specified search element. + + + +```javascript +var x = [ 1.0, 2.0, 2.0, 3.0 ]; + +var idx = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); +// returns 1 +``` + +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 greater than or equal to a specified search element, the function returns `-1`. + + + +```javascript +var x = [ 1.0, 2.0, 2.0, 3.0 ]; + +var idx = gindexOfGreaterThanEqualSorted( x.length, 4.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 = gindexOfGreaterThanEqualSorted( 3, 2.0, x, 2 ); +// returns 1 +``` + +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 = gindexOfGreaterThanEqualSorted( 3, 2.0, x1, 2 ); +// returns 1 +``` + +#### gindexOfGreaterThanEqualSorted.ndarray( N, searchElement, x, strideX, offsetX ) + +Returns the index of the first element in a sorted strided array which is greater than or equal to a specified search element using alternative indexing semantics. + + + +```javascript +var x = [ 1.0, 2.0, 2.0, 3.0 ]; + +var idx = gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, 0 ); +// returns 1 +``` + +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 = gindexOfGreaterThanEqualSorted.ndarray( 3, 2.0, x, 1, x.length-3 ); +// returns 1 +``` + +
+ + + + + +
+ +## Notes + +- The input strided array **must** be sorted in ascending order. +- If `N <= 0`, both functions return `-1`. +- When comparing elements, both functions use the less-than-or-equal-to 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 gindexOfGreaterThanEqualSorted = require( '@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +gsorthp( x.length, 1, x, 1 ); +console.log( x ); + +var idx = gindexOfGreaterThanEqualSorted( x.length, 0.0, x, 1 ); +console.log( idx ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/benchmark/benchmark.js new file mode 100644 index 000000000000..199a4872aa02 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-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 gindexOfGreaterThanEqualSorted = 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 = gindexOfGreaterThanEqualSorted( 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-greater-than-equal-sorted/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..94ec0a0001bd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-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 gindexOfGreaterThanEqualSorted = 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 = gindexOfGreaterThanEqualSorted( 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-greater-than-equal-sorted/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt new file mode 100644 index 000000000000..d0af5e76d9a9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt @@ -0,0 +1,102 @@ + +{{alias}}( N, searchElement, x, strideX ) + Returns the index of the first element in a sorted strided array which is + greater than or equal to 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 ascending order. + + If unable to find an element which is greater than or equal to 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 ) + 1 + + // 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 ) + 1 + + // 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 ) + 1 + + +{{alias}}.ndarray( N, searchElement, x, strideX, offsetX ) + Returns the index of the first element in a sorted strided array which is + greater than or equal to 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 ) + 1 + + // Advanced indexing: + > x = [ 9.0, 1.0, 9.0, 2.0, 9.0, 3.0 ]; + > idx = {{alias}}.ndarray( 3, 2.0, x, 2, 1 ) + 1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts new file mode 100644 index 000000000000..3fdf14d7ee16 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts @@ -0,0 +1,111 @@ +/* +* @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 `gindexOfGreaterThanEqualSorted`. +*/ +interface Routine { + /** + * Returns the index of the first element in a sorted strided array which is greater than or equal to a specified search element. + * + * ## Notes + * + * - The input strided array must be sorted in ascending order. + * - If the function is unable to find an element which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); + * // returns 1 + */ + ( N: number, searchElement: unknown, x: InputArray, strideX: number ): number; + + /** + * Returns the index of the first element in a sorted strided array which is greater than or equal to a specified search element using alternative indexing semantics. + * + * ## Notes + * + * - The input strided array must be sorted in ascending order. + * - If the function is unable to find an element which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, 0 ); + * // returns 1 + */ + 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 greater than or equal to a specified search element. +* +* ## Notes +* +* - The input strided array must be sorted in ascending order. +* - If the function is unable to find an element which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); +* // returns 1 +* +* @example +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, 0 ); +* // returns 1 +*/ +declare var gindexOfGreaterThanEqualSorted: Routine; + + +// EXPORTS // + +export = gindexOfGreaterThanEqualSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/test.ts new file mode 100644 index 000000000000..77b128ed5464 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-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 gindexOfGreaterThanEqualSorted = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); // $ExpectType number + gindexOfGreaterThanEqualSorted( 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 ]; + + gindexOfGreaterThanEqualSorted( '1', 2.0, x, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted( true, 2.0, x, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted( false, 2.0, x, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted( null, 2.0, x, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted( {}, 2.0, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + gindexOfGreaterThanEqualSorted( x.length, 1.0, 1, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted( x.length, 1.0, true, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted( x.length, 1.0, false, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted( x.length, 1.0, null, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted( 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 ]; + + gindexOfGreaterThanEqualSorted( x.length, 2.0, x, '1' ); // $ExpectError + gindexOfGreaterThanEqualSorted( x.length, 2.0, x, true ); // $ExpectError + gindexOfGreaterThanEqualSorted( x.length, 2.0, x, false ); // $ExpectError + gindexOfGreaterThanEqualSorted( x.length, 2.0, x, null ); // $ExpectError + gindexOfGreaterThanEqualSorted( x.length, 2.0, x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + gindexOfGreaterThanEqualSorted(); // $ExpectError + gindexOfGreaterThanEqualSorted( 3, 2.0 ); // $ExpectError + gindexOfGreaterThanEqualSorted( 3, 2.0, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + gindexOfGreaterThanEqualSorted( 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 ]; + + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, 0 ); // $ExpectType number + gindexOfGreaterThanEqualSorted.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 ]; + + gindexOfGreaterThanEqualSorted.ndarray( '1', 2.0, x, 1, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( true, 2.0, x, 1, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( false, 2.0, x, 1, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( null, 2.0, x, 1, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.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... +{ + gindexOfGreaterThanEqualSorted.ndarray( x.length, 1.0, 1, 1, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 1.0, true, 1, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 1.0, false, 1, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 1.0, null, 1, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.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 ]; + + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, '1', 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, true, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, false, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, null, 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.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 ]; + + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, '1' ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, true ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, false ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, null ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, {} ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + gindexOfGreaterThanEqualSorted.ndarray(); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( 3, 2.0 ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + gindexOfGreaterThanEqualSorted.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); // $ExpectError + gindexOfGreaterThanEqualSorted.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-greater-than-equal-sorted/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/examples/index.js new file mode 100644 index 000000000000..c68448ce7c5d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-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 gindexOfGreaterThanEqualSorted = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +gsorthp( x.length, 1, x, 1 ); +console.log( x ); + +var idx = gindexOfGreaterThanEqualSorted( x.length, 0.0, x, 1 ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js new file mode 100644 index 000000000000..f81a97a31b7d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js @@ -0,0 +1,82 @@ +/** +* @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 floor = require( '@stdlib/math/base/special/floor' ); + + +// MAIN // + +/** +* Returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 1 +*/ +function gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX, offsetX ) { + var xbuf; + var get; + var mid; + var lo; + var hi; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessors: + get = x.accessors[ 0 ]; + + lo = 0; + hi = N; + while ( lo < hi ) { + mid = lo + floor( ( hi - lo ) / 2 ); + if ( searchElement <= get( xbuf, offsetX + ( mid * strideX ) ) ) { + hi = mid; + } else { + lo = mid + 1; + } + } + if ( lo === N ) { + return -1; + } + return lo; +} + + +// EXPORTS // + +module.exports = gindexOfGreaterThanEqualSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/index.js new file mode 100644 index 000000000000..3b8e198b6d1d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-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 greater than or equal to a specified search element. +* +* @module @stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted +* +* @example +* var gindexOfGreaterThanEqualSorted = require( '@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted' ); +* +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); +* // returns 1 +* +* @example +* var gindexOfGreaterThanEqualSorted = require( '@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted' ); +* +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfGreaterThanEqualSorted.ndarray( x.length, 2.0, x, 1, 0 ); +* // returns 1 +*/ + +// 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-greater-than-equal-sorted/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js new file mode 100644 index 000000000000..c3a1124d0402 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js @@ -0,0 +1,56 @@ +/** +* @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 greater than or equal to a specified search element. +* +* ## Notes +* +* - The input strided array must be sorted in ascending order. +* - If unable to find an element which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); +* // returns 1 +*/ +function gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX ) { + return ndarray( N, searchElement, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = gindexOfGreaterThanEqualSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js new file mode 100644 index 000000000000..486dfc1a5373 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js @@ -0,0 +1,83 @@ +/** +* @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 floor = require( '@stdlib/math/base/special/floor' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// MAIN // + +/** +* Returns the index of the first element in a sorted strided array which is greater than or equal to a specified search element using alternative indexing semantics. +* +* ## Notes +* +* - The input strided array must be sorted in ascending order. +* - If unable to find an element which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1, 0 ); +* // returns 1 +*/ +function gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX, offsetX ) { + var mid; + var lo; + var hi; + var o; + + if ( N <= 0 ) { + return -1; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, searchElement, o, strideX, offsetX ); + } + lo = 0; + hi = N; + while ( lo < hi ) { + mid = lo + floor( ( hi - lo ) / 2 ); + if ( searchElement <= x[ offsetX + ( mid * strideX ) ] ) { + hi = mid; + } else { + lo = mid + 1; + } + } + if ( lo === N ) { + return -1; + } + return lo; +} + + +// EXPORTS // + +module.exports = gindexOfGreaterThanEqualSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/package.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/package.json new file mode 100644 index 000000000000..fad8e3cde56f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted", + "version": "0.0.0", + "description": "Return the index of the first element in a sorted strided array which is greater than or equal to 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", + "greater", + "equal", + "compare", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.js new file mode 100644 index 000000000000..60ae1a4b99af --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-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 gindexOfGreaterThanEqualSorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfGreaterThanEqualSorted, '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 gindexOfGreaterThanEqualSorted.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.main.js new file mode 100644 index 000000000000..87e40e6c8869 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.main.js @@ -0,0 +1,312 @@ +/** +* @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 gindexOfGreaterThanEqualSorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfGreaterThanEqualSorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( gindexOfGreaterThanEqualSorted.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is less than the search element', function test( t ) { + var actual; + var x; + + x = [ 2.0, 2.0, 2.0 ]; + + actual = gindexOfGreaterThanEqualSorted( x.length, 3.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 less than the search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 2.0, 2.0, 2.0 ] ); + + actual = gindexOfGreaterThanEqualSorted( x.length, 3.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 = gindexOfGreaterThanEqualSorted( 0, 2.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( -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 = gindexOfGreaterThanEqualSorted( 0, 2.0, toAccessorArray( x ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( -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 = gindexOfGreaterThanEqualSorted( 2, NaN, [ 0.0, 1.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( 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 = gindexOfGreaterThanEqualSorted( 2, NaN, toAccessorArray( [ 0.0, 1.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( 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 = gindexOfGreaterThanEqualSorted( 1, -0.0, [ 0.0 ], 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( 1, 0.0, [ -0.0 ], 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal (accessors)', function test( t ) { + var actual; + + actual = gindexOfGreaterThanEqualSorted( 1, -0.0, toAccessorArray( [ 0.0 ] ), 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( 1, 0.0, toAccessorArray( [ -0.0 ] ), 1 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.0, x, 2 ); + t.strictEqual( actual, 1, '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 = gindexOfGreaterThanEqualSorted( 3, 2.0, toAccessorArray( x ), 2 ); + t.strictEqual( actual, 1, '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 = gindexOfGreaterThanEqualSorted( 3, 2.0, x, -2 ); + t.strictEqual( actual, 1, '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 = gindexOfGreaterThanEqualSorted( 3, 2.0, toAccessorArray( x ), -2 ); + t.strictEqual( actual, 1, '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 = gindexOfGreaterThanEqualSorted( 3, 3.0, x, 2 ); + t.strictEqual( actual, 2, '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 = gindexOfGreaterThanEqualSorted( 3, 3.0, toAccessorArray( x ), 2 ); + t.strictEqual( actual, 2, '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 = gindexOfGreaterThanEqualSorted( 3, 2.0, x1, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.ndarray.js new file mode 100644 index 000000000000..eb92da8e49ff --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.ndarray.js @@ -0,0 +1,337 @@ +/** +* @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 gindexOfGreaterThanEqualSorted = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfGreaterThanEqualSorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gindexOfGreaterThanEqualSorted.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if every indexed element in the array is less than the search element', function test( t ) { + var actual; + var x; + + x = [ 2.0, 2.0, 2.0 ]; + + actual = gindexOfGreaterThanEqualSorted( x.length, 3.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 less than the search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 2.0, 2.0, 2.0 ] ); + + actual = gindexOfGreaterThanEqualSorted( x.length, 3.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 = gindexOfGreaterThanEqualSorted( 0, 2.0, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( -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 = gindexOfGreaterThanEqualSorted( 0, 2.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( -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 = gindexOfGreaterThanEqualSorted( 2, NaN, [ 0.0, 1.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( 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 = gindexOfGreaterThanEqualSorted( 2, NaN, toAccessorArray( [ 0.0, 1.0 ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( 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 = gindexOfGreaterThanEqualSorted( 1, -0.0, [ 0.0 ], 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( 1, 0.0, [ -0.0 ], 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats `-0` and `+0` as equal (accessors)', function test( t ) { + var actual; + + actual = gindexOfGreaterThanEqualSorted( 1, -0.0, toAccessorArray( [ 0.0 ] ), 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanEqualSorted( 1, 0.0, toAccessorArray( [ -0.0 ] ), 1, 0 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 3.0, x, 2, 0 ); + t.strictEqual( actual, 2, '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 = gindexOfGreaterThanEqualSorted( 3, 3.0, toAccessorArray( x ), 2, 0 ); + t.strictEqual( actual, 2, '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 = gindexOfGreaterThanEqualSorted( 3, 2.0, x, -2, 4 ); + t.strictEqual( actual, 1, '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 = gindexOfGreaterThanEqualSorted( 3, 2.0, toAccessorArray( x ), -2, 4 ); + t.strictEqual( actual, 1, '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 = gindexOfGreaterThanEqualSorted( 3, 3.0, x, 2, 1 ); + t.strictEqual( actual, 2, '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 = gindexOfGreaterThanEqualSorted( 3, 3.0, toAccessorArray( x ), 2, 1 ); + t.strictEqual( actual, 2, '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 = gindexOfGreaterThanEqualSorted( 3, 3.0, x, 2, 1 ); + t.strictEqual( actual, 2, '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 = gindexOfGreaterThanEqualSorted( 3, 3.0, toAccessorArray( x ), 2, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + t.end(); +}); From f788d2a582ad434e4d3846c36f90a68057363759 Mon Sep 17 00:00:00 2001 From: Sachinn-64 Date: Wed, 30 Sep 2026 14:19:32 +0530 Subject: [PATCH 2/4] refactor: add descending order support --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../README.md | 7 +- .../docs/repl.txt | 6 +- .../docs/types/index.d.ts | 6 +- .../lib/accessors.js | 13 ++ .../lib/main.js | 2 +- .../lib/ndarray.js | 15 +- .../test/test.main.js | 158 +++++++++++++++ .../test/test.ndarray.js | 182 ++++++++++++++++++ 8 files changed, 382 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md index 3301da63b802..08c148e02e2f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md @@ -53,6 +53,11 @@ var x = [ 1.0, 2.0, 2.0, 3.0 ]; var idx = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); // returns 1 + +x = [ 3.0, 2.0, 2.0, 1.0 ]; + +idx = gindexOfGreaterThanEqualSorted( x.length, 2.0, x, 1 ); +// returns 0 ``` The function has the following parameters: @@ -140,7 +145,7 @@ var idx = gindexOfGreaterThanEqualSorted.ndarray( 3, 2.0, x, 1, x.length-3 ); ## Notes -- The input strided array **must** be sorted in ascending order. +- The input strided array **must** be sorted in either ascending or descending order. - If `N <= 0`, both functions return `-1`. - When comparing elements, both functions use the less-than-or-equal-to 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]). diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt index d0af5e76d9a9..a4b7ee856f32 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt @@ -9,7 +9,8 @@ Indexing is relative to the first index. To introduce an offset, use a typed array view. - The input strided array must be sorted in ascending order. + The input strided array must be sorted in either ascending or descending + order. If unable to find an element which is greater than or equal to the search element, the function returns `-1`. @@ -41,6 +42,9 @@ > var x = [ 1.0, 2.0, 2.0, 3.0 ]; > var idx = {{alias}}( x.length, 2.0, x, 1 ) 1 + > x = [ 3.0, 2.0, 2.0, 1.0 ]; + > idx = {{alias}}( x.length, 2.0, x, 1 ) + 0 // Using `N` and stride parameters: > x = [ 1.0, 9.0, 2.0, 9.0, 3.0, 9.0 ]; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts index 3fdf14d7ee16..4a0c4d307557 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts @@ -36,7 +36,7 @@ interface Routine { * * ## Notes * - * - The input strided array must be sorted in ascending order. + * - The input strided array must be sorted in either ascending or descending order. * - If the function is unable to find an element which is greater than or equal to a search element, the function returns `-1`. * * @param N - number of indexed elements @@ -58,7 +58,7 @@ interface Routine { * * ## Notes * - * - The input strided array must be sorted in ascending order. + * - The input strided array must be sorted in either ascending or descending order. * - If the function is unable to find an element which is greater than or equal to a search element, the function returns `-1`. * * @param N - number of indexed elements @@ -82,7 +82,7 @@ interface Routine { * * ## Notes * -* - The input strided array must be sorted in ascending order. +* - The input strided array must be sorted in either ascending or descending order. * - If the function is unable to find an element which is greater than or equal to a search element, the function returns `-1`. * * @param N - number of indexed elements diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js index f81a97a31b7d..f270ac94b28d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js @@ -53,6 +53,8 @@ function gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX, offsetX ) var mid; var lo; var hi; + var v1; + var v2; // Cache reference to array data: xbuf = x.data; @@ -60,6 +62,17 @@ function gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX, offsetX ) // Cache a reference to the element accessors: get = x.accessors[ 0 ]; + v1 = get( xbuf, offsetX ); + v2 = get( xbuf, offsetX + ( ( N - 1 ) * strideX ) ); + + // Descending order: elements which are greater than or equal to the search element form a prefix, so only the first indexed element needs to be checked... + if ( v1 > v2 ) { + if ( searchElement <= v1 ) { + return 0; + } + return -1; + } + // Ascending order: perform a binary search for the first element which is greater than or equal to the search element... lo = 0; hi = N; while ( lo < hi ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js index c3a1124d0402..1b1a2355c133 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js @@ -31,7 +31,7 @@ var ndarray = require( './ndarray.js' ); * * ## Notes * -* - The input strided array must be sorted in ascending order. +* - The input strided array must be sorted in either ascending or descending order. * - If unable to find an element which is greater than or equal to the search element, the function returns `-1`. * * @param {PositiveInteger} N - number of indexed elements diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js index 486dfc1a5373..f2e0da651992 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js @@ -32,7 +32,7 @@ var accessors = require( './accessors.js' ); * * ## Notes * -* - The input strided array must be sorted in ascending order. +* - The input strided array must be sorted in either ascending or descending order. * - If unable to find an element which is greater than or equal to the search element, the function returns `-1`. * * @param {PositiveInteger} N - number of indexed elements @@ -52,6 +52,8 @@ function gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX, offsetX ) var mid; var lo; var hi; + var v1; + var v2; var o; if ( N <= 0 ) { @@ -61,6 +63,17 @@ function gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX, offsetX ) if ( o.accessorProtocol ) { return accessors( N, searchElement, o, strideX, offsetX ); } + v1 = x[ offsetX ]; + v2 = x[ offsetX + ( ( N - 1 ) * strideX ) ]; + + // Descending order: elements which are greater than or equal to the search element form a prefix, so only the first indexed element needs to be checked... + if ( v1 > v2 ) { + if ( searchElement <= v1 ) { + return 0; + } + return -1; + } + // Ascending order: perform a binary search for the first element which is greater than or equal to the search element... lo = 0; hi = N; while ( lo < hi ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.main.js index 87e40e6c8869..44b0bb595a12 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.main.js @@ -310,3 +310,161 @@ tape( 'the function supports view offsets', function test( t ) { t.end(); }); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( 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 greater than or equal to 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 = gindexOfGreaterThanEqualSorted( 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 greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.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 greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.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 less than the search element (descending order)', function test( t ) { + var actual; + var x; + + x = [ 2.0, 1.0, 0.0 ]; + + actual = gindexOfGreaterThanEqualSorted( x.length, 3.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 less than the search element (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 2.0, 1.0, 0.0 ] ); + + actual = gindexOfGreaterThanEqualSorted( x.length, 3.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 = gindexOfGreaterThanEqualSorted( 3, 2.5, x, 2 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.5, toAccessorArray( x ), 2 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.5, x, -2 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.5, toAccessorArray( x ), -2 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.5, x1, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.ndarray.js index eb92da8e49ff..174c386f2df8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/test/test.ndarray.js @@ -335,3 +335,185 @@ tape( 'the function supports complex access patterns (accessors)', function test t.end(); }); + +tape( 'the function returns the index of the first element in a sorted strided array which is greater than or equal to 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 = gindexOfGreaterThanEqualSorted( 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 greater than or equal to 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 = gindexOfGreaterThanEqualSorted( 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 greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.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 greater than or equal to 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 = gindexOfGreaterThanEqualSorted( x.length, 2.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 less than the search element (descending order)', function test( t ) { + var actual; + var x; + + x = [ 2.0, 1.0, 0.0 ]; + + actual = gindexOfGreaterThanEqualSorted( x.length, 3.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 less than the search element (descending order) (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 2.0, 1.0, 0.0 ] ); + + actual = gindexOfGreaterThanEqualSorted( x.length, 3.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 = gindexOfGreaterThanEqualSorted( 3, 2.5, x, 2, 0 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.5, toAccessorArray( x ), 2, 0 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.5, x, -2, 4 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.5, toAccessorArray( x ), -2, 4 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.5, x, 2, 1 ); + t.strictEqual( actual, 0, '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 = gindexOfGreaterThanEqualSorted( 3, 2.5, toAccessorArray( x ), 2, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); From 42974b659df10db2510523d655678df014f15a13 Mon Sep 17 00:00:00 2001 From: Sachinn-64 Date: Wed, 30 Sep 2026 15:15:00 +0530 Subject: [PATCH 3/4] chore: suggested changes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../ext/base/gindex-of-greater-than-equal-sorted/README.md | 2 +- .../base/gindex-of-greater-than-equal-sorted/docs/repl.txt | 4 ++-- .../gindex-of-greater-than-equal-sorted/docs/types/index.d.ts | 3 --- .../base/gindex-of-greater-than-equal-sorted/lib/accessors.js | 2 +- .../ext/base/gindex-of-greater-than-equal-sorted/lib/main.js | 1 - .../base/gindex-of-greater-than-equal-sorted/lib/ndarray.js | 3 +-- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md index 08c148e02e2f..6372089bd94e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md @@ -145,7 +145,7 @@ var idx = gindexOfGreaterThanEqualSorted.ndarray( 3, 2.0, x, 1, x.length-3 ); ## Notes -- The input strided array **must** be sorted in either ascending or descending order. +- 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-or-equal-to 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]). diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt index a4b7ee856f32..5aaac7cb9917 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/repl.txt @@ -9,8 +9,8 @@ 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 ascending or descending - order. + The input strided array must be sorted in either strictly ascending or + descending order. If unable to find an element which is greater than or equal to the search element, the function returns `-1`. diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts index 4a0c4d307557..2d16f2576a68 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/docs/types/index.d.ts @@ -36,7 +36,6 @@ interface Routine { * * ## Notes * - * - The input strided array must be sorted in either ascending or descending order. * - If the function is unable to find an element which is greater than or equal to a search element, the function returns `-1`. * * @param N - number of indexed elements @@ -58,7 +57,6 @@ interface Routine { * * ## Notes * - * - The input strided array must be sorted in either ascending or descending order. * - If the function is unable to find an element which is greater than or equal to a search element, the function returns `-1`. * * @param N - number of indexed elements @@ -82,7 +80,6 @@ interface Routine { * * ## Notes * -* - The input strided array must be sorted in either ascending or descending order. * - If the function is unable to find an element which is greater than or equal to a search element, the function returns `-1`. * * @param N - number of indexed elements diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js index f270ac94b28d..b57d85fa41f6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/accessors.js @@ -66,7 +66,7 @@ function gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX, offsetX ) v2 = get( xbuf, offsetX + ( ( N - 1 ) * strideX ) ); // Descending order: elements which are greater than or equal to the search element form a prefix, so only the first indexed element needs to be checked... - if ( v1 > v2 ) { + if ( v1 >= v2 ) { if ( searchElement <= v1 ) { return 0; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js index 1b1a2355c133..c5b0cc29b7c0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/main.js @@ -31,7 +31,6 @@ var ndarray = require( './ndarray.js' ); * * ## Notes * -* - The input strided array must be sorted in either ascending or descending order. * - If unable to find an element which is greater than or equal to the search element, the function returns `-1`. * * @param {PositiveInteger} N - number of indexed elements diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js index f2e0da651992..6e7f6784d3d3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/lib/ndarray.js @@ -32,7 +32,6 @@ var accessors = require( './accessors.js' ); * * ## Notes * -* - The input strided array must be sorted in either ascending or descending order. * - If unable to find an element which is greater than or equal to the search element, the function returns `-1`. * * @param {PositiveInteger} N - number of indexed elements @@ -67,7 +66,7 @@ function gindexOfGreaterThanEqualSorted( N, searchElement, x, strideX, offsetX ) v2 = x[ offsetX + ( ( N - 1 ) * strideX ) ]; // Descending order: elements which are greater than or equal to the search element form a prefix, so only the first indexed element needs to be checked... - if ( v1 > v2 ) { + if ( v1 >= v2 ) { if ( searchElement <= v1 ) { return 0; } From f5cc6e4b9e2d4d07fc074928c0867ad1999e8690 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 30 Sep 2026 20:36:00 -0700 Subject: [PATCH 4/4] style: update comments Signed-off-by: Athan --- .../ext/base/gindex-of-greater-than-equal-sorted/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md index 6372089bd94e..90b20629afda 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-equal-sorted/README.md @@ -96,13 +96,13 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -// Initial array... +// Initial array: var x0 = new Float64Array( [ 0.0, 1.0, 9.0, 2.0, 9.0, 3.0 ] ); -// Create an offset view... +// Create an offset view: var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -// Find index... +// Find index: var idx = gindexOfGreaterThanEqualSorted( 3, 2.0, x1, 2 ); // returns 1 ```