From 3d4dfbac9b327e380cbd9c33decb36e458dd38ff Mon Sep 17 00:00:00 2001 From: Sachinn-64 Date: Sat, 26 Sep 2026 16:22:37 +0530 Subject: [PATCH 1/8] feat: add blas/ext/base/gindex-of-greater-than-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 --- --- .../gindex-of-greater-than-sorted/README.md | 193 ++++++++ .../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 | 74 ++++ .../lib/index.js | 57 +++ .../gindex-of-greater-than-sorted/lib/main.js | 57 +++ .../lib/ndarray.js | 80 ++++ .../package.json | 68 +++ .../test/test.js | 38 ++ .../test/test.main.js | 330 ++++++++++++++ .../test/test.ndarray.js | 418 ++++++++++++++++++ 15 files changed, 1883 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md new file mode 100644 index 000000000000..123222bd331a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md @@ -0,0 +1,193 @@ + + +# gindexOfGreaterThanSorted + +> Return the index of the first element in a sorted strided array which is greater than a specified search element. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var gindexOfGreaterThanSorted = require( '@stdlib/blas/ext/base/gindex-of-greater-than-sorted' ); +``` + +#### gindexOfGreaterThanSorted( N, searchElement, x, strideX ) + +Returns the index of the first element in a sorted strided array which is greater than a specified search element. + +```javascript +var x = [ 1.0, 2.0, 2.0, 3.0 ]; + +var idx = gindexOfGreaterThanSorted( 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 greater than a specified search element, the function returns `N`. + +```javascript +var x = [ 1.0, 2.0, 2.0, 3.0 ]; + +var idx = gindexOfGreaterThanSorted( x.length, 3.0, x, 1 ); +// returns 4 +``` + +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 = gindexOfGreaterThanSorted( 3, 1.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 = gindexOfGreaterThanSorted( 3, 1.0, x1, 2 ); +// returns 1 +``` + +#### gindexOfGreaterThanSorted.ndarray( N, searchElement, x, strideX, offsetX ) + +Returns the index of the first element in a sorted strided array which is greater than a specified search element using alternative indexing semantics. + +```javascript +var x = [ 1.0, 2.0, 2.0, 3.0 ]; + +var idx = gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); +// returns 3 +``` + +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 = gindexOfGreaterThanSorted.ndarray( 3, 1.0, x, 1, x.length-3 ); +// returns 1 +``` + +
+ + + + + +
+ +## Notes + +- The input strided array must be sorted in ascending order. +- The function performs a binary search. +- If the function is unable to find an element which is greater than a specified search element, the function returns `N`. +- If `N <= 0`, both functions return `0`. +- When comparing elements, the function uses 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 gindexOfGreaterThanSorted = require( '@stdlib/blas/ext/base/gindex-of-greater-than-sorted' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +gsorthp( x.length, 1, x, 1 ); +console.log( x ); + +var idx = gindexOfGreaterThanSorted( x.length, 0.0, x, 1 ); +console.log( idx ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.js new file mode 100644 index 000000000000..ab51888bd480 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-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/base/linspace' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gindexOfGreaterThanSorted = 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 = gindexOfGreaterThanSorted( 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-sorted/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..d653531736f5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-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/base/linspace' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gindexOfGreaterThanSorted = 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 = gindexOfGreaterThanSorted( 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-sorted/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/repl.txt new file mode 100644 index 000000000000..8b7b08cfc2ec --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-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 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 the search element, the + function returns `N`. + + If `N <= 0`, the function returns `0`. + + 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 ) + 3 + + // Using `N` and stride parameters: + > x = [ 1.0, 9.0, 2.0, 9.0, 3.0, 9.0 ]; + > idx = {{alias}}( 3, 1.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, 1.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 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 ) + 3 + + // Advanced indexing: + > x = [ 9.0, 1.0, 9.0, 2.0, 9.0, 3.0 ]; + > idx = {{alias}}.ndarray( 3, 1.0, x, 2, 1 ) + 1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/index.d.ts new file mode 100644 index 000000000000..41cd9844d85e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-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 `gindexOfGreaterThanSorted`. +*/ +interface Routine { + /** + * Returns the index of the first element in a sorted strided array which is greater than 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 a search element, the function returns `N`. + * + * @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 = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); + * // returns 3 + */ + ( 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 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 a search element, the function returns `N`. + * + * @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 = gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); + * // returns 3 + */ + 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 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 a search element, the function returns `N`. +* +* @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 = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); +* // returns 3 +* +* @example +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); +* // returns 3 +*/ +declare var gindexOfGreaterThanSorted: Routine; + + +// EXPORTS // + +export = gindexOfGreaterThanSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/test.ts new file mode 100644 index 000000000000..bb30dad79ebe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-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 gindexOfGreaterThanSorted = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); // $ExpectType number + gindexOfGreaterThanSorted( 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 ]; + + gindexOfGreaterThanSorted( '1', 2.0, x, 1 ); // $ExpectError + gindexOfGreaterThanSorted( true, 2.0, x, 1 ); // $ExpectError + gindexOfGreaterThanSorted( false, 2.0, x, 1 ); // $ExpectError + gindexOfGreaterThanSorted( null, 2.0, x, 1 ); // $ExpectError + gindexOfGreaterThanSorted( {}, 2.0, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a collection... +{ + gindexOfGreaterThanSorted( x.length, 1.0, 1, 1 ); // $ExpectError + gindexOfGreaterThanSorted( x.length, 1.0, true, 1 ); // $ExpectError + gindexOfGreaterThanSorted( x.length, 1.0, false, 1 ); // $ExpectError + gindexOfGreaterThanSorted( x.length, 1.0, null, 1 ); // $ExpectError + gindexOfGreaterThanSorted( 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 ]; + + gindexOfGreaterThanSorted( x.length, 2.0, x, '1' ); // $ExpectError + gindexOfGreaterThanSorted( x.length, 2.0, x, true ); // $ExpectError + gindexOfGreaterThanSorted( x.length, 2.0, x, false ); // $ExpectError + gindexOfGreaterThanSorted( x.length, 2.0, x, null ); // $ExpectError + gindexOfGreaterThanSorted( x.length, 2.0, x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + gindexOfGreaterThanSorted(); // $ExpectError + gindexOfGreaterThanSorted( 3, 2.0 ); // $ExpectError + gindexOfGreaterThanSorted( 3, 2.0, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + gindexOfGreaterThanSorted( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1, {} ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + var x = [ 1.0, 2.0, 3.0 ]; + + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); // $ExpectType number + gindexOfGreaterThanSorted.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 ]; + + gindexOfGreaterThanSorted.ndarray( '1', 2.0, x, 1, 1 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( true, 2.0, x, 1, 1 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( false, 2.0, x, 1, 1 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( null, 2.0, x, 1, 1 ); // $ExpectError + gindexOfGreaterThanSorted.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... +{ + gindexOfGreaterThanSorted.ndarray( x.length, 1.0, 1, 1, 1 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 1.0, true, 1, 1 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 1.0, false, 1, 1 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 1.0, null, 1, 1 ); // $ExpectError + gindexOfGreaterThanSorted.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 ]; + + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, '1', 1 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, true, 1 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, false, 1 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, null, 1 ); // $ExpectError + gindexOfGreaterThanSorted.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 ]; + + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, '1' ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, true ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, false ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, null ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, {} ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + gindexOfGreaterThanSorted.ndarray(); // $ExpectError + gindexOfGreaterThanSorted.ndarray( 3, 2.0 ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ] ); // $ExpectError + gindexOfGreaterThanSorted.ndarray( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); // $ExpectError + gindexOfGreaterThanSorted.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-sorted/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/examples/index.js new file mode 100644 index 000000000000..072a0b2aa42a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-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 gindexOfGreaterThanSorted = require( './../lib' ); + +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +gsorthp( x.length, 1, x, 1 ); +console.log( x ); + +var idx = gindexOfGreaterThanSorted( x.length, 0.0, x, 1 ); +console.log( idx ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/accessors.js new file mode 100644 index 000000000000..440e4fa01853 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/accessors.js @@ -0,0 +1,74 @@ +/** +* @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'; + +// MAIN // + +/** +* Returns the index of the first element in a sorted strided array which is greater 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 {NonNegativeInteger} 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 = gindexOfGreaterThanSorted( x.length, 2.0, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns 3 +*/ +function gindexOfGreaterThanSorted( 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 + ( ( hi - lo ) >>> 1 ); + if ( searchElement < get( xbuf, offsetX + ( mid * strideX ) ) ) { + hi = mid; + } else { + lo = mid + 1; + } + } + return lo; +} + + +// EXPORTS // + +module.exports = gindexOfGreaterThanSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/index.js new file mode 100644 index 000000000000..fbc6303e9240 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-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 greater than a specified search element. +* +* @module @stdlib/blas/ext/base/gindex-of-greater-than-sorted +* +* @example +* var gindexOfGreaterThanSorted = require( '@stdlib/blas/ext/base/gindex-of-greater-than-sorted' ); +* +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); +* // returns 3 +* +* @example +* var gindexOfGreaterThanSorted = require( '@stdlib/blas/ext/base/gindex-of-greater-than-sorted' ); +* +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfGreaterThanSorted.ndarray( x.length, 2.0, x, 1, 0 ); +* // returns 3 +*/ + +// 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-sorted/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/main.js new file mode 100644 index 000000000000..787250258a40 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/main.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'; + +// 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 a specified search element. +* +* ## Notes +* +* - The input strided array must be sorted in ascending order. +* - The function performs a binary search. +* - If unable to find an element which is greater than the search element, the function returns `N`. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {*} searchElement - search element +* @param {Collection} x - sorted input array +* @param {integer} strideX - stride length +* @returns {NonNegativeInteger} index +* +* @example +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); +* // returns 3 +*/ +function gindexOfGreaterThanSorted( N, searchElement, x, strideX ) { + return ndarray( N, searchElement, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = gindexOfGreaterThanSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/ndarray.js new file mode 100644 index 000000000000..134373826202 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/ndarray.js @@ -0,0 +1,80 @@ +/** +* @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 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 a specified search element using alternative indexing semantics. +* +* ## Notes +* +* - The input strided array must be sorted in ascending order. +* - The function performs a binary search. +* - If unable to find an element which is greater than the search element, the function returns `N`. +* +* @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 {NonNegativeInteger} index +* +* @example +* var x = [ 1.0, 2.0, 2.0, 3.0 ]; +* +* var idx = gindexOfGreaterThanSorted( x.length, 2.0, x, 1, 0 ); +* // returns 3 +*/ +function gindexOfGreaterThanSorted( N, searchElement, x, strideX, offsetX ) { + var mid; + var lo; + var hi; + var o; + + if ( N <= 0 ) { + return 0; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, searchElement, o, strideX, offsetX ); + } + lo = 0; + hi = N; + while ( lo < hi ) { + mid = lo + ( ( hi - lo ) >>> 1 ); + if ( searchElement < x[ offsetX + ( mid * strideX ) ] ) { + hi = mid; + } else { + lo = mid + 1; + } + } + return lo; +} + + +// EXPORTS // + +module.exports = gindexOfGreaterThanSorted; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/package.json b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/package.json new file mode 100644 index 000000000000..bd84b7c414b1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/blas/ext/base/gindex-of-greater-than-sorted", + "version": "0.0.0", + "description": "Return the index of the first element in a sorted strided array which is greater 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", + "greater", + "compare", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.js new file mode 100644 index 000000000000..6c7ecb065875 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-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 gindexOfGreaterThanSorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfGreaterThanSorted, '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 gindexOfGreaterThanSorted.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.main.js new file mode 100644 index 000000000000..5d8fee88a510 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.main.js @@ -0,0 +1,330 @@ +/** +* @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 gindexOfGreaterThanSorted = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfGreaterThanSorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( gindexOfGreaterThanSorted.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted array which is greater than a search element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + // Nonnegative stride... + actual = gindexOfGreaterThanSorted( x.length, 0.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.0, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + // Negative stride... + x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; + + actual = gindexOfGreaterThanSorted( x.length, 0.0, x, -1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.0, x, -1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 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 array which is greater than a search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + // Nonnegative stride... + actual = gindexOfGreaterThanSorted( x.length, 0.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.0, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + // Negative stride... + x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + + actual = gindexOfGreaterThanSorted( x.length, 0.0, x, -1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.0, x, -1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, -1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `N` if all elements are less than or equal to a search element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + // Nonnegative stride... + actual = gindexOfGreaterThanSorted( x.length, 3.0, x, 1 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 4.0, x, 1 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + // Negative stride... + x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; + + actual = gindexOfGreaterThanSorted( x.length, 3.0, x, -1 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `N` if all elements are less than or equal to a search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + // Nonnegative stride... + actual = gindexOfGreaterThanSorted( x.length, 3.0, x, 1 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 4.0, x, 1 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + // Negative stride... + x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + + actual = gindexOfGreaterThanSorted( x.length, 3.0, x, -1 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `0` if provided an `N` parameter which is less than or equal to zero', function test( t ) { + var actual; + + actual = gindexOfGreaterThanSorted( 0, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( -1, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `0` if provided an `N` parameter which is less than or equal to zero (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + + actual = gindexOfGreaterThanSorted( 0, 2.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( -1, 2.0, x, 1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `N` if comparisons involve `NaN` values', function test( t ) { + var actual; + + actual = gindexOfGreaterThanSorted( 1, NaN, [ 0.0 ], 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 1, 0.0, [ NaN ], 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `N` if comparisons involve `NaN` values (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 0.0 ] ); + + actual = gindexOfGreaterThanSorted( 1, NaN, x, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + x = toAccessorArray( [ NaN ] ); + + actual = gindexOfGreaterThanSorted( 1, 0.0, x, 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 = gindexOfGreaterThanSorted( 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; + var x; + + x = toAccessorArray( [ 0.0 ] ); + + actual = gindexOfGreaterThanSorted( 1, -0.0, x, 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 = gindexOfGreaterThanSorted( 3, 2.0, x, 2 ); + + 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 = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), 2 ); + + t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 0 + ]; + + actual = gindexOfGreaterThanSorted( 3, 2.0, x, -2 ); + + t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 0 + ]; + + actual = gindexOfGreaterThanSorted( 3, 2.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; + + // Initial array... + x0 = new Float64Array([ + 9.0, + 3.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 0 + ]); + + // Create offset view... + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + + actual = gindexOfGreaterThanSorted( 3, 2.0, x1, -2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.ndarray.js new file mode 100644 index 000000000000..f6b34e1a24fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.ndarray.js @@ -0,0 +1,418 @@ +/** +* @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 gindexOfGreaterThanSorted = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gindexOfGreaterThanSorted, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( gindexOfGreaterThanSorted.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted array which is greater than a search element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + // Nonnegative stride... + actual = gindexOfGreaterThanSorted( x.length, 0.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.0, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length-1, 1.0, x, 1, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length-2, 2.0, x, 1, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + // Negative stride... + x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; + + actual = gindexOfGreaterThanSorted( x.length, 0.0, x, -1, x.length-1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.0, x, -1, x.length-1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, -1, x.length-1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 3, 1.0, x, -2, x.length-1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the index of the first element in a sorted array which is greater than a search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + // Nonnegative stride... + actual = gindexOfGreaterThanSorted( x.length, 0.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.0, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length-1, 1.0, x, 1, 1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length-2, 2.0, x, 1, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + // Negative stride... + x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + + actual = gindexOfGreaterThanSorted( x.length, 0.0, x, -1, x.length-1 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 1.0, x, -1, x.length-1 ); + t.strictEqual( actual, 2, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, -1, x.length-1 ); + t.strictEqual( actual, 4, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 3, 1.0, x, -2, x.length-1 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `N` if all elements are less than or equal to a search element', function test( t ) { + var actual; + var x; + + x = [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ]; + + // Nonnegative stride... + actual = gindexOfGreaterThanSorted( x.length, 3.0, x, 1, 0 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 4.0, x, 1, 0 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 1, 1.0, x, 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + // Negative stride... + x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; + + actual = gindexOfGreaterThanSorted( x.length, 3.0, x, -1, x.length-1 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `N` if all elements are less than or equal to a search element (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 ] ); + + // Nonnegative stride... + actual = gindexOfGreaterThanSorted( x.length, 3.0, x, 1, 0 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( x.length, 4.0, x, 1, 0 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 1, 1.0, x, 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + // Negative stride... + x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + + actual = gindexOfGreaterThanSorted( x.length, 3.0, x, -1, x.length-1 ); + t.strictEqual( actual, x.length, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `0` if provided an `N` parameter which is less than or equal to zero', function test( t ) { + var actual; + + actual = gindexOfGreaterThanSorted( 0, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( -1, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `0` if provided an `N` parameter which is less than or equal to zero (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + + actual = gindexOfGreaterThanSorted( 0, 2.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( -1, 2.0, x, 1, 0 ); + t.strictEqual( actual, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `N` if comparisons involve `NaN` values', function test( t ) { + var actual; + + actual = gindexOfGreaterThanSorted( 1, NaN, [ 0.0 ], 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 1, 0.0, [ NaN ], 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 3, NaN, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `N` if comparisons involve `NaN` values (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 0.0 ] ); + + actual = gindexOfGreaterThanSorted( 1, NaN, x, 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + x = toAccessorArray( [ NaN ] ); + + actual = gindexOfGreaterThanSorted( 1, 0.0, x, 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + + actual = gindexOfGreaterThanSorted( 3, NaN, x, 1, 0 ); + t.strictEqual( actual, 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function treats -0 and +0 as equal', function test( t ) { + var actual; + + actual = gindexOfGreaterThanSorted( 1, -0.0, [ 0.0 ], 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 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; + var x; + + x = toAccessorArray( [ 0.0 ] ); + + actual = gindexOfGreaterThanSorted( 1, -0.0, x, 1, 0 ); + t.strictEqual( actual, 1, 'returns expected value' ); + + x = toAccessorArray( [ -0.0 ] ); + + actual = gindexOfGreaterThanSorted( 1, 0.0, x, 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 = gindexOfGreaterThanSorted( 3, 2.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 = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), 2, 0 ); + + t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 0 + ]; + + actual = gindexOfGreaterThanSorted( 3, 2.0, x, -2, 4 ); + + t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports negative strides (accessors)', function test( t ) { + var actual; + var x; + + x = [ + 3.0, // 2 + 9.0, + 2.0, // 1 + 9.0, + 1.0 // 0 + ]; + + actual = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), -2, 4 ); + + t.strictEqual( actual, 2, '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 + 2.0, // 1 + 3.0 // 2 + ]; + + actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1, 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 + 2.0, // 1 + 3.0 // 2 + ]; + + actual = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), 1, 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 = gindexOfGreaterThanSorted( 3, 2.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 = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), 2, 1 ); + + t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); +}); From a7a43e3879a048f5e8c252b35375107aa2cda76c Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 04:27:28 -0700 Subject: [PATCH 2/8] Apply batched suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../base/gindex-of-greater-than-sorted/benchmark/benchmark.js | 2 +- .../benchmark/benchmark.ndarray.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.js index ab51888bd480..96238b8f1036 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.js @@ -23,7 +23,7 @@ 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/base/linspace' ); +var linspace = require( '@stdlib/array/linspace' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var gindexOfGreaterThanSorted = require( './../lib' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.ndarray.js index d653531736f5..daa23c8134c9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/benchmark/benchmark.ndarray.js @@ -23,7 +23,7 @@ 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/base/linspace' ); +var linspace = require( '@stdlib/array/linspace' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var gindexOfGreaterThanSorted = require( './../lib/ndarray.js' ); From 94b99b41ac0485a93b97f600a9a2028a15a267bf Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 04:31:57 -0700 Subject: [PATCH 3/8] docs: update comment Signed-off-by: Athan --- .../ext/base/gindex-of-greater-than-sorted/docs/types/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/test.ts index bb30dad79ebe..8c43eb380aaf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/test.ts @@ -69,7 +69,7 @@ import gindexOfGreaterThanSorted = require( './index' ); gindexOfGreaterThanSorted( 3, 2.0, [ 1.0, 2.0, 3.0 ], 1, {} ); // $ExpectError } -// Attached to main export is an `ndarray` method which returns a number... +// The function has an `ndarray` method which returns a number... { var x = [ 1.0, 2.0, 3.0 ]; From b519390d3ee48cdf1bfefa4e5664decda1b2b337 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 04:33:56 -0700 Subject: [PATCH 4/8] Apply batched suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../blas/ext/base/gindex-of-greater-than-sorted/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/repl.txt index 8b7b08cfc2ec..9efe02b6d8ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/repl.txt @@ -12,9 +12,9 @@ The input strided array must be sorted in ascending order. If unable to find an element which is greater than the search element, the - function returns `N`. + function returns `-1`. - If `N <= 0`, the function returns `0`. + If `N <= 0`, the function returns `-1`. Parameters ---------- From 15bc040e8efe071c99102e6c78e2b0d9f76506f3 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 26 Sep 2026 04:34:30 -0700 Subject: [PATCH 5/8] Apply batched suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../gindex-of-greater-than-sorted/docs/types/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/index.d.ts index 41cd9844d85e..e36da1a78ef6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/docs/types/index.d.ts @@ -37,7 +37,7 @@ interface Routine { * ## Notes * * - The input strided array must be sorted in ascending order. - * - If the function is unable to find an element which is greater than a search element, the function returns `N`. + * - If the function is unable to find an element which is greater than a search element, the function returns `-1`. * * @param N - number of indexed elements * @param searchElement - search element @@ -59,7 +59,7 @@ interface Routine { * ## Notes * * - The input strided array must be sorted in ascending order. - * - If the function is unable to find an element which is greater than a search element, the function returns `N`. + * - If the function is unable to find an element which is greater than a search element, the function returns `-1`. * * @param N - number of indexed elements * @param searchElement - search element @@ -83,7 +83,7 @@ interface Routine { * ## Notes * * - The input strided array must be sorted in ascending order. -* - If the function is unable to find an element which is greater than a search element, the function returns `N`. +* - If the function is unable to find an element which is greater than a search element, the function returns `-1`. * * @param N - number of indexed elements * @param searchElement - search element From e65174cf32af934045b101fb88ccc0a29fcd6a92 Mon Sep 17 00:00:00 2001 From: Sachinn-64 Date: Sat, 26 Sep 2026 19:45:46 +0530 Subject: [PATCH 6/8] 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: na - 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: na - task: lint_license_headers status: passed --- --- .../gindex-of-greater-than-sorted/README.md | 9 +- .../lib/accessors.js | 12 +- .../gindex-of-greater-than-sorted/lib/main.js | 5 +- .../lib/ndarray.js | 13 +- .../test/test.main.js | 232 ++++++++---------- .../test/test.ndarray.js | 223 ++++++----------- 6 files changed, 202 insertions(+), 292 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md index 123222bd331a..434456354ce1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md @@ -58,13 +58,13 @@ The function has the following parameters: - **x**: sorted input array. - **strideX**: stride length. -If the function is unable to find an element which is greater than a specified search element, the function returns `N`. +If the function is unable to find an element which is greater than a specified search element, the function returns `-1`. ```javascript var x = [ 1.0, 2.0, 2.0, 3.0 ]; var idx = gindexOfGreaterThanSorted( x.length, 3.0, x, 1 ); -// returns 4 +// 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: @@ -127,9 +127,8 @@ var idx = gindexOfGreaterThanSorted.ndarray( 3, 1.0, x, 1, x.length-3 ); ## Notes - The input strided array must be sorted in ascending order. -- The function performs a binary search. -- If the function is unable to find an element which is greater than a specified search element, the function returns `N`. -- If `N <= 0`, both functions return `0`. +- If the function is unable to find an element which is greater than a specified search element, the function returns `-1`. +- If `N <= 0`, both functions return `-1`. - When comparing elements, the function uses 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]). diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/accessors.js index 440e4fa01853..6aac2863c759 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/accessors.js @@ -18,6 +18,11 @@ 'use strict'; +// MODULES // + +var floor = require( '@stdlib/math/base/special/floor' ); + + // MAIN // /** @@ -31,7 +36,7 @@ * @param {Array} x.accessors - array element accessors * @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index -* @returns {NonNegativeInteger} index +* @returns {integer} index * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); @@ -58,13 +63,16 @@ function gindexOfGreaterThanSorted( N, searchElement, x, strideX, offsetX ) { lo = 0; hi = N; while ( lo < hi ) { - mid = lo + ( ( hi - lo ) >>> 1 ); + 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; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/main.js index 787250258a40..5eec29a2f95f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/main.js @@ -32,14 +32,13 @@ var ndarray = require( './ndarray.js' ); * ## Notes * * - The input strided array must be sorted in ascending order. -* - The function performs a binary search. -* - If unable to find an element which is greater than the search element, the function returns `N`. +* - If unable to find an element which is greater 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 {NonNegativeInteger} index +* @returns {integer} index * * @example * var x = [ 1.0, 2.0, 2.0, 3.0 ]; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/ndarray.js index 134373826202..36fbd7c09d2b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/lib/ndarray.js @@ -20,6 +20,7 @@ // MODULES // +var floor = require( '@stdlib/math/base/special/floor' ); var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); var accessors = require( './accessors.js' ); @@ -32,15 +33,14 @@ var accessors = require( './accessors.js' ); * ## Notes * * - The input strided array must be sorted in ascending order. -* - The function performs a binary search. -* - If unable to find an element which is greater than the search element, the function returns `N`. +* - If unable to find an element which is greater 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 {NonNegativeInteger} index +* @returns {integer} index * * @example * var x = [ 1.0, 2.0, 2.0, 3.0 ]; @@ -55,7 +55,7 @@ function gindexOfGreaterThanSorted( N, searchElement, x, strideX, offsetX ) { var o; if ( N <= 0 ) { - return 0; + return -1; } o = arraylike2object( x ); if ( o.accessorProtocol ) { @@ -64,13 +64,16 @@ function gindexOfGreaterThanSorted( N, searchElement, x, strideX, offsetX ) { lo = 0; hi = N; while ( lo < hi ) { - mid = lo + ( ( hi - lo ) >>> 1 ); + 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; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.main.js index 5d8fee88a510..9f1a67a4f1ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.main.js @@ -39,197 +39,152 @@ tape( 'the function has an arity of 4', function test( t ) { t.end(); }); -tape( 'the function returns the index of the first element in a sorted array which is greater than a search element', function test( t ) { +tape( 'the function returns the index of the first element in a sorted strided array which is greater 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 ]; - // Nonnegative stride... - actual = gindexOfGreaterThanSorted( x.length, 0.0, x, 1 ); - t.strictEqual( actual, 0, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( x.length, 1.0, x, 1 ); t.strictEqual( actual, 2, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative stride... - x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; - - actual = gindexOfGreaterThanSorted( x.length, 0.0, x, -1 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 1.0, x, -1 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( 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 array which is greater than a search element (accessors)', function test( t ) { +tape( 'the function returns the index of the first element in a sorted strided array which is greater 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 ] ); - // Nonnegative stride... - actual = gindexOfGreaterThanSorted( x.length, 0.0, x, 1 ); - t.strictEqual( actual, 0, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( x.length, 1.0, x, 1 ); t.strictEqual( actual, 2, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - // Negative stride... - x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); - - actual = gindexOfGreaterThanSorted( x.length, 0.0, x, -1 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 1.0, x, -1 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 2.0, x, -1 ); - t.strictEqual( actual, 4, 'returns expected value' ); - t.end(); }); -tape( 'the function returns `N` if all elements are less than or equal to a search element', function test( t ) { +tape( 'the function returns the index of the first element in a sorted strided array which is greater 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 ]; - // Nonnegative stride... - actual = gindexOfGreaterThanSorted( x.length, 3.0, x, 1 ); - t.strictEqual( actual, x.length, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 4.0, x, 1 ); - t.strictEqual( actual, x.length, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - // Negative stride... - x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; - - actual = gindexOfGreaterThanSorted( x.length, 3.0, x, -1 ); - t.strictEqual( actual, x.length, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); t.end(); }); -tape( 'the function returns `N` if all elements are less than or equal to a search element (accessors)', function test( t ) { +tape( 'the function returns the index of the first element in a sorted strided array which is greater 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 ] ); - // Nonnegative stride... - actual = gindexOfGreaterThanSorted( x.length, 3.0, x, 1 ); - t.strictEqual( actual, x.length, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1 ); + t.strictEqual( actual, 2, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( x.length, 4.0, x, 1 ); - t.strictEqual( actual, x.length, 'returns expected value' ); + t.end(); +}); - actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1 ); - t.strictEqual( actual, 3, 'returns expected value' ); +tape( 'the function returns `-1` if every indexed element in the array is less than or equal to the search element', function test( t ) { + var actual; + var x; - // Negative stride... - x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + x = [ 2.0, 2.0, 2.0 ]; - actual = gindexOfGreaterThanSorted( x.length, 3.0, x, -1 ); - t.strictEqual( actual, x.length, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); -tape( 'the function returns `0` if provided an `N` parameter which is less than or equal to zero', function test( t ) { +tape( 'the function returns `-1` if every indexed element in the array is less than or equal to the search element (accessors)', function test( t ) { var actual; + var x; - actual = gindexOfGreaterThanSorted( 0, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); - t.strictEqual( actual, 0, 'returns expected value' ); + x = toAccessorArray( [ 2.0, 2.0, 2.0 ] ); - actual = gindexOfGreaterThanSorted( -1, 2.0, [ 1.0, 2.0, 3.0 ], 1 ); - t.strictEqual( actual, 0, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); -tape( 'the function returns `0` if provided an `N` parameter which is less than or equal to zero (accessors)', function test( t ) { +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 = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + x = [ 1.0, 2.0, 3.0 ]; actual = gindexOfGreaterThanSorted( 0, 2.0, x, 1 ); - t.strictEqual( actual, 0, 'returns expected value' ); + t.strictEqual( actual, -1, 'returns expected value' ); actual = gindexOfGreaterThanSorted( -1, 2.0, x, 1 ); - t.strictEqual( actual, 0, 'returns expected value' ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); -tape( 'the function returns `N` if comparisons involve `NaN` values', function test( t ) { +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; - actual = gindexOfGreaterThanSorted( 1, NaN, [ 0.0 ], 1 ); - t.strictEqual( actual, 1, 'returns expected value' ); + x = [ 1.0, 2.0, 3.0 ]; - actual = gindexOfGreaterThanSorted( 1, 0.0, [ NaN ], 1 ); - t.strictEqual( actual, 1, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( 0, 2.0, toAccessorArray( x ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( -1, 2.0, toAccessorArray( x ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); -tape( 'the function returns `N` if comparisons involve `NaN` values (accessors)', function test( t ) { +tape( 'the function returns `-1` if comparisons involve `NaN` values', function test( t ) { var actual; - var x; - x = toAccessorArray( [ 0.0 ] ); + actual = gindexOfGreaterThanSorted( 2, NaN, [ 0.0, 1.0 ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( 1, NaN, x, 1 ); - t.strictEqual( actual, 1, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( 2, 0.0, [ NaN, NaN ], 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); - x = toAccessorArray( [ NaN ] ); + t.end(); +}); - actual = gindexOfGreaterThanSorted( 1, 0.0, x, 1 ); - t.strictEqual( actual, 1, 'returns expected value' ); +tape( 'the function returns `-1` if comparisons involve `NaN` values (accessors)', function test( t ) { + var actual; + + actual = gindexOfGreaterThanSorted( 2, NaN, toAccessorArray( [ 0.0, 1.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 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 ) { +tape( 'the function treats `-0` and `+0` as equal', function test( t ) { var actual; actual = gindexOfGreaterThanSorted( 1, -0.0, [ 0.0 ], 1 ); - t.strictEqual( actual, 1, 'returns expected value' ); + t.strictEqual( actual, -1, 'returns expected value' ); + + actual = gindexOfGreaterThanSorted( 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 ) { +tape( 'the function treats `-0` and `+0` as equal (accessors)', function test( t ) { var actual; - var x; - x = toAccessorArray( [ 0.0 ] ); + actual = gindexOfGreaterThanSorted( 1, -0.0, toAccessorArray( [ 0.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( 1, -0.0, x, 1 ); - t.strictEqual( actual, 1, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( 1, 0.0, toAccessorArray( [ -0.0 ] ), 1 ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); @@ -246,9 +201,9 @@ tape( 'the function supports an `x` stride', function test( t ) { 3.0 // 2 ]; - actual = gindexOfGreaterThanSorted( 3, 2.0, x, 2 ); + actual = gindexOfGreaterThanSorted( 3, 1.0, x, 2 ); + t.strictEqual( actual, 1, 'returns expected value' ); - t.strictEqual( actual, 2, 'returns expected value' ); t.end(); }); @@ -264,13 +219,13 @@ tape( 'the function supports an `x` stride (accessors)', function test( t ) { 3.0 // 2 ]; - actual = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), 2 ); + actual = gindexOfGreaterThanSorted( 3, 1.0, toAccessorArray( x ), 2 ); + t.strictEqual( actual, 1, 'returns expected value' ); - t.strictEqual( actual, 2, 'returns expected value' ); t.end(); }); -tape( 'the function supports negative strides', function test( t ) { +tape( 'the function supports a negative `x` stride', function test( t ) { var actual; var x; @@ -282,13 +237,13 @@ tape( 'the function supports negative strides', function test( t ) { 1.0 // 0 ]; - actual = gindexOfGreaterThanSorted( 3, 2.0, x, -2 ); + actual = gindexOfGreaterThanSorted( 3, 1.0, x, -2 ); + t.strictEqual( actual, 1, 'returns expected value' ); - t.strictEqual( actual, 2, 'returns expected value' ); t.end(); }); -tape( 'the function supports negative strides (accessors)', function test( t ) { +tape( 'the function supports a negative `x` stride (accessors)', function test( t ) { var actual; var x; @@ -300,31 +255,58 @@ tape( 'the function supports negative strides (accessors)', function test( t ) { 1.0 // 0 ]; - actual = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), -2 ); + actual = gindexOfGreaterThanSorted( 3, 1.0, toAccessorArray( x ), -2 ); + t.strictEqual( actual, 1, 'returns expected value' ); - t.strictEqual( actual, 2, 'returns expected value' ); t.end(); }); -tape( 'the function supports view offsets', function test( t ) { +tape( 'the function supports complex access patterns', function test( t ) { var actual; - var x0; - var x1; + var x; - // Initial array... - x0 = new Float64Array([ - 9.0, - 3.0, // 2 + x = [ + 1.0, // 0 9.0, 2.0, // 1 9.0, - 1.0 // 0 - ]); + 3.0 // 2 + ]; - // Create offset view... - x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + actual = gindexOfGreaterThanSorted( 3, 2.0, x, 2 ); + t.strictEqual( actual, 2, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( 3, 2.0, x1, -2 ); + 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 = gindexOfGreaterThanSorted( 3, 2.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 = gindexOfGreaterThanSorted( 3, 1.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-sorted/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.ndarray.js index f6b34e1a24fa..9e8e634b0fe1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/test/test.ndarray.js @@ -38,237 +38,152 @@ tape( 'the function has an arity of 5', function test( t ) { t.end(); }); -tape( 'the function returns the index of the first element in a sorted array which is greater than a search element', function test( t ) { +tape( 'the function returns the index of the first element in a sorted strided array which is greater 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 ]; - // Nonnegative stride... - actual = gindexOfGreaterThanSorted( x.length, 0.0, x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( x.length, 1.0, x, 1, 0 ); t.strictEqual( actual, 2, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1, 0 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1, 0 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length-1, 1.0, x, 1, 1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length-2, 2.0, x, 1, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - // Negative stride... - x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; - - actual = gindexOfGreaterThanSorted( x.length, 0.0, x, -1, x.length-1 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 1.0, x, -1, x.length-1 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 2.0, x, -1, x.length-1 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( 3, 1.0, x, -2, x.length-1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - t.end(); }); -tape( 'the function returns the index of the first element in a sorted array which is greater than a search element (accessors)', function test( t ) { +tape( 'the function returns the index of the first element in a sorted strided array which is greater 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 ] ); - // Nonnegative stride... - actual = gindexOfGreaterThanSorted( x.length, 0.0, x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( x.length, 1.0, x, 1, 0 ); t.strictEqual( actual, 2, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1, 0 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1, 0 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length-1, 1.0, x, 1, 1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length-2, 2.0, x, 1, 2 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - // Negative stride... - x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); - - actual = gindexOfGreaterThanSorted( x.length, 0.0, x, -1, x.length-1 ); - t.strictEqual( actual, 0, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 1.0, x, -1, x.length-1 ); - t.strictEqual( actual, 2, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 2.0, x, -1, x.length-1 ); - t.strictEqual( actual, 4, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( 3, 1.0, x, -2, x.length-1 ); - t.strictEqual( actual, 1, 'returns expected value' ); - t.end(); }); -tape( 'the function returns `N` if all elements are less than or equal to a search element', function test( t ) { +tape( 'the function returns the index of the first element in a sorted strided array which is greater 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 ]; - // Nonnegative stride... - actual = gindexOfGreaterThanSorted( x.length, 3.0, x, 1, 0 ); - t.strictEqual( actual, x.length, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 4.0, x, 1, 0 ); - t.strictEqual( actual, x.length, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( 1, 1.0, x, 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1, 0 ); - t.strictEqual( actual, 3, 'returns expected value' ); - - // Negative stride... - x = [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ]; - - actual = gindexOfGreaterThanSorted( x.length, 3.0, x, -1, x.length-1 ); - t.strictEqual( actual, x.length, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); t.end(); }); -tape( 'the function returns `N` if all elements are less than or equal to a search element (accessors)', function test( t ) { +tape( 'the function returns the index of the first element in a sorted strided array which is greater 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 ] ); - // Nonnegative stride... - actual = gindexOfGreaterThanSorted( x.length, 3.0, x, 1, 0 ); - t.strictEqual( actual, x.length, 'returns expected value' ); - - actual = gindexOfGreaterThanSorted( x.length, 4.0, x, 1, 0 ); - t.strictEqual( actual, x.length, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( x.length, 1.5, x, 1, 0 ); + t.strictEqual( actual, 2, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( 1, 1.0, x, 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); + t.end(); +}); - actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1, 0 ); - t.strictEqual( actual, 3, 'returns expected value' ); +tape( 'the function returns `-1` if every indexed element in the array is less than or equal to the search element', function test( t ) { + var actual; + var x; - // Negative stride... - x = toAccessorArray( [ 3.0, 3.0, 2.0, 2.0, 1.0, 1.0 ] ); + x = [ 2.0, 2.0, 2.0 ]; - actual = gindexOfGreaterThanSorted( x.length, 3.0, x, -1, x.length-1 ); - t.strictEqual( actual, x.length, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); -tape( 'the function returns `0` if provided an `N` parameter which is less than or equal to zero', function test( t ) { +tape( 'the function returns `-1` if every indexed element in the array is less than or equal to the search element (accessors)', function test( t ) { var actual; + var x; - actual = gindexOfGreaterThanSorted( 0, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); + x = toAccessorArray( [ 2.0, 2.0, 2.0 ] ); - actual = gindexOfGreaterThanSorted( -1, 2.0, [ 1.0, 2.0, 3.0 ], 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( x.length, 2.0, x, 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); -tape( 'the function returns `0` if provided an `N` parameter which is less than or equal to zero (accessors)', function test( t ) { +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 = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + x = [ 1.0, 2.0, 3.0 ]; actual = gindexOfGreaterThanSorted( 0, 2.0, x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); + t.strictEqual( actual, -1, 'returns expected value' ); actual = gindexOfGreaterThanSorted( -1, 2.0, x, 1, 0 ); - t.strictEqual( actual, 0, 'returns expected value' ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); -tape( 'the function returns `N` if comparisons involve `NaN` values', function test( t ) { +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; - actual = gindexOfGreaterThanSorted( 1, NaN, [ 0.0 ], 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); + x = [ 1.0, 2.0, 3.0 ]; - actual = gindexOfGreaterThanSorted( 1, 0.0, [ NaN ], 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( 0, 2.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( 3, NaN, [ 1.0, 2.0, 3.0 ], 1, 0 ); - t.strictEqual( actual, 3, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( -1, 2.0, toAccessorArray( x ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); -tape( 'the function returns `N` if comparisons involve `NaN` values (accessors)', function test( t ) { +tape( 'the function returns `-1` if comparisons involve `NaN` values', function test( t ) { var actual; - var x; - x = toAccessorArray( [ 0.0 ] ); + actual = gindexOfGreaterThanSorted( 2, NaN, [ 0.0, 1.0 ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( 1, NaN, x, 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( 2, 0.0, [ NaN, NaN ], 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); - x = toAccessorArray( [ NaN ] ); + t.end(); +}); - actual = gindexOfGreaterThanSorted( 1, 0.0, x, 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); +tape( 'the function returns `-1` if comparisons involve `NaN` values (accessors)', function test( t ) { + var actual; - x = toAccessorArray( [ 1.0, 2.0, 3.0 ] ); + actual = gindexOfGreaterThanSorted( 2, NaN, toAccessorArray( [ 0.0, 1.0 ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); - actual = gindexOfGreaterThanSorted( 3, NaN, x, 1, 0 ); - t.strictEqual( actual, 3, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( 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 ) { +tape( 'the function treats `-0` and `+0` as equal', function test( t ) { var actual; actual = gindexOfGreaterThanSorted( 1, -0.0, [ 0.0 ], 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); + t.strictEqual( actual, -1, 'returns expected value' ); actual = gindexOfGreaterThanSorted( 1, 0.0, [ -0.0 ], 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); -tape( 'the function treats -0 and +0 as equal (accessors)', function test( t ) { +tape( 'the function treats `-0` and `+0` as equal (accessors)', function test( t ) { var actual; - var x; - - x = toAccessorArray( [ 0.0 ] ); - actual = gindexOfGreaterThanSorted( 1, -0.0, x, 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( 1, -0.0, toAccessorArray( [ 0.0 ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); - x = toAccessorArray( [ -0.0 ] ); - - actual = gindexOfGreaterThanSorted( 1, 0.0, x, 1, 0 ); - t.strictEqual( actual, 1, 'returns expected value' ); + actual = gindexOfGreaterThanSorted( 1, 0.0, toAccessorArray( [ -0.0 ] ), 1, 0 ); + t.strictEqual( actual, -1, 'returns expected value' ); t.end(); }); @@ -286,8 +201,8 @@ tape( 'the function supports an `x` stride', function test( t ) { ]; actual = gindexOfGreaterThanSorted( 3, 2.0, x, 2, 0 ); - t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); }); @@ -304,12 +219,12 @@ tape( 'the function supports an `x` stride (accessors)', function test( t ) { ]; actual = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), 2, 0 ); - t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); }); -tape( 'the function supports negative strides', function test( t ) { +tape( 'the function supports a negative `x` stride', function test( t ) { var actual; var x; @@ -321,13 +236,13 @@ tape( 'the function supports negative strides', function test( t ) { 1.0 // 0 ]; - actual = gindexOfGreaterThanSorted( 3, 2.0, x, -2, 4 ); + actual = gindexOfGreaterThanSorted( 3, 1.0, x, -2, 4 ); + t.strictEqual( actual, 1, 'returns expected value' ); - t.strictEqual( actual, 2, 'returns expected value' ); t.end(); }); -tape( 'the function supports negative strides (accessors)', function test( t ) { +tape( 'the function supports a negative `x` stride (accessors)', function test( t ) { var actual; var x; @@ -339,9 +254,9 @@ tape( 'the function supports negative strides (accessors)', function test( t ) { 1.0 // 0 ]; - actual = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), -2, 4 ); + actual = gindexOfGreaterThanSorted( 3, 1.0, toAccessorArray( x ), -2, 4 ); + t.strictEqual( actual, 1, 'returns expected value' ); - t.strictEqual( actual, 2, 'returns expected value' ); t.end(); }); @@ -352,13 +267,15 @@ tape( 'the function supports an `x` offset', function test( t ) { x = [ 9.0, 1.0, // 0 + 9.0, 2.0, // 1 + 9.0, 3.0 // 2 ]; - actual = gindexOfGreaterThanSorted( 3, 2.0, x, 1, 1 ); - + actual = gindexOfGreaterThanSorted( 3, 2.0, x, 2, 1 ); t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); }); @@ -369,13 +286,15 @@ tape( 'the function supports an `x` offset (accessors)', function test( t ) { x = [ 9.0, 1.0, // 0 + 9.0, 2.0, // 1 + 9.0, 3.0 // 2 ]; - actual = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), 1, 1 ); - + actual = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), 2, 1 ); t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); }); @@ -393,8 +312,8 @@ tape( 'the function supports complex access patterns', function test( t ) { ]; actual = gindexOfGreaterThanSorted( 3, 2.0, x, 2, 1 ); - t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); }); @@ -412,7 +331,7 @@ tape( 'the function supports complex access patterns (accessors)', function test ]; actual = gindexOfGreaterThanSorted( 3, 2.0, toAccessorArray( x ), 2, 1 ); - t.strictEqual( actual, 2, 'returns expected value' ); + t.end(); }); From 64ce89524ca10fbfa0c4c768e0d9d93984de9e3c Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 28 Sep 2026 03:23:32 -0700 Subject: [PATCH 7/8] Apply batched suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../blas/ext/base/gindex-of-greater-than-sorted/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md index 434456354ce1..93dc64a43945 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md @@ -127,9 +127,8 @@ var idx = gindexOfGreaterThanSorted.ndarray( 3, 1.0, x, 1, x.length-3 ); ## Notes - The input strided array must be sorted in ascending order. -- If the function is unable to find an element which is greater than a specified search element, the function returns `-1`. - If `N <= 0`, both functions return `-1`. -- When comparing elements, the function uses the less-than operator `<`. As a consequence, comparisons involving `NaN` always evaluate to `false`, and `-0` and `+0` are considered the same. +- 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]). From 0ceac8772d35ec913acfa34bebe4df20d7e4f56c Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 28 Sep 2026 03:24:08 -0700 Subject: [PATCH 8/8] style: add markup Signed-off-by: Athan --- .../blas/ext/base/gindex-of-greater-than-sorted/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md index 93dc64a43945..8b66c4b544aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gindex-of-greater-than-sorted/README.md @@ -126,7 +126,7 @@ var idx = gindexOfGreaterThanSorted.ndarray( 3, 1.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 ascending 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]).