From 2698b2050d0cb3366b610b50ee043d27deb437a7 Mon Sep 17 00:00:00 2001 From: sagar7162 Date: Fri, 16 Jan 2026 22:08:55 +0530 Subject: [PATCH 1/4] feat: add `blas/ext/base/ndarray/gsort2hp` --- 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 status: passed - 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 --- --- .../blas/ext/base/ndarray/gsort2ins/README.md | 140 ++++++++++++++++++ .../ndarray/gsort2ins/benchmark/benchmark.js | 117 +++++++++++++++ .../ext/base/ndarray/gsort2ins/docs/repl.txt | 46 ++++++ .../ndarray/gsort2ins/docs/types/index.d.ts | 59 ++++++++ .../base/ndarray/gsort2ins/docs/types/test.ts | 70 +++++++++ .../base/ndarray/gsort2ins/examples/index.js | 51 +++++++ .../ext/base/ndarray/gsort2ins/lib/index.js | 54 +++++++ .../ext/base/ndarray/gsort2ins/lib/main.js | 74 +++++++++ .../ext/base/ndarray/gsort2ins/package.json | 67 +++++++++ .../ext/base/ndarray/gsort2ins/test/test.js | 87 +++++++++++ 10 files changed, 765 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/test/test.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/README.md b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/README.md new file mode 100644 index 000000000000..ed26d3fd2b2a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/README.md @@ -0,0 +1,140 @@ + + +# gsort2ins + +> Simultaneously sort two one-dimensional ndarrays based on the sort order of the first ndarray using insertion sort. + +
+ +
+ + + +
+ +## Usage + +```javascript +var gsort2ins = require( '@stdlib/blas/ext/base/ndarray/gsort2ins' ); +``` + +#### gsort2ins( arrays ) + +Simultaneously sorts two one-dimensional ndarrays based on the sort order of the first ndarray using insertion sort. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); + +var xbuf = [ 1.0, -2.0, 3.0, -4.0 ]; +var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var ybuf = [ 0.0, 1.0, 2.0, 3.0 ]; +var y = new ndarray( 'generic', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var ord = scalar2ndarray( 1.0, { + 'dtype': 'generic' +}); + +gsort2ins( [ x, y, ord ] ); +// x => [ -4.0, -2.0, 1.0, 3.0 ] +// y => [ 3.0, 1.0, 0.0, 2.0 ] +``` + +The function has the following parameters: + +- **arrays**: array-like object containing two one-dimensional input ndarrays and a zero-dimensional ndarray specifying the sort order. + +
+ + + +
+ +## Notes + +- The input ndarrays are sorted **in-place** (i.e., the input ndarrays are **mutated**). +- When the sort order is less than zero, the first input ndarray is sorted in **decreasing** order. When the sort order is greater than zero, the first input ndarray is sorted in **increasing** order. When the sort order is equal to zero, the input ndarrays are left unchanged. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var gsort2ins = require( '@stdlib/blas/ext/base/ndarray/gsort2ins' ); + +var x = uniform( [ 10 ], -100.0, 100.0 ); +var y = uniform( [ 10 ], -100.0, 100.0 ); + +console.log( ndarray2array( x ) ); +console.log( ndarray2array( y ) ); + +var order = scalar2ndarray( 1.0, { + 'dtype': 'generic' +}); +console.log( 'Order:', ndarraylike2scalar( order ) ); + +gsort2ins( [ x, y, order ] ); + +console.log( ndarray2array( x ) ); +console.log( ndarray2array( y ) ); + +order = scalar2ndarray( -1.0, { + 'dtype': 'generic' +}); +console.log( 'Order:', ndarraylike2scalar( order ) ); + +gsort2ins( [ x, y, order ] ); + +console.log( ndarray2array( x ) ); +console.log( ndarray2array( y ) ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js new file mode 100644 index 000000000000..ef5cf77277fb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js @@ -0,0 +1,117 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var pkg = require( './../package.json' ).name; +var gsort2ins = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var order; + var xbuf; + var ybuf; + var x; + var y; + + xbuf = uniform( len, 0.0, 100.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + ybuf = uniform( len, 0.0, 100.0, options ); + y = new ndarray( options.dtype, ybuf, [ len ], [ 1 ], 0, 'row-major' ); + + order = scalar2ndarray( -1.0, options ); + + 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++ ) { + // Note: We are sorting in-place, so repeated calls sort already sorted arrays... + out = gsort2ins( [ x, y, order ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( xbuf[ i % len ] !== xbuf[ i % len ] ) { + b.fail( 'should not return NaN' ); + } + 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^1 + max = 6; // 10^6 + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg + ':len=' + len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/repl.txt new file mode 100644 index 000000000000..0e14c6b09503 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/repl.txt @@ -0,0 +1,46 @@ + +{{alias}}( arrays ) + Simultaneously sorts two one-dimensional ndarrays based on the sort order + of the first ndarray using insertion sort. + + When the sort order is less than zero, the input ndarray is sorted in + decreasing order. When the sort order is greater than zero, the input + ndarray is sorted in increasing order. When the sort order is equal to zero, + the input ndarray is left unchanged. + + The input ndarrays are sorted *in-place* (i.e., the input ndarrays are + *mutated*). + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing two one-dimensional input ndarrays and a + zero-dimensional ndarray specifying the sort order. + + Returns + ------- + out: ndarray + First input ndarray. + + Examples + -------- + > var xbuf = [ 1.0, -2.0, 3.0, -4.0 ]; + > var dt = 'generic'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > var ybuf = [ 0.0, 1.0, 2.0, 3.0 ]; + > var y = new {{alias:@stdlib/ndarray/ctor}}( dt, ybuf, sh, sx, ox, ord ); + > var o = {{alias:@stdlib/ndarray/from-scalar}}( 1.0 ); + > {{alias}}( [ x, y, o ] ) + + > var data = x.data + [ -4.0, -2.0, 1.0, 3.0 ] + > data = y.data + [ 3.0, 1.0, 0.0, 2.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/index.d.ts new file mode 100644 index 000000000000..0dab8c67d01c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/index.d.ts @@ -0,0 +1,59 @@ +/* +* @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 { typedndarray } from '@stdlib/types/ndarray'; + +/** +* Simultaneously sorts two one-dimensional ndarrays based on the sort order of the first ndarray using insertion sort. +* +* ## Notes +* +* - The algorithm sorts the first input ndarray in specified order and applies the same permutation to the second input ndarray. +* - When the sort order is less than zero, the input ndarray is sorted in **decreasing** order. When the sort order is greater than zero, the input ndarray is sorted in **increasing** order. When the sort order is equal to zero, the input ndarray is left unchanged. +* +* @param arrays - array-like object containing two one-dimensional input ndarrays and a zero-dimensional ndarray specifying the sort order +* @returns first input ndarray +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, -2.0, 3.0, -4.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var ybuf = [ 0.0, 1.0, 2.0, 3.0 ]; +* var y = new ndarray( 'generic', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var ord = scalar2ndarray( 1.0, { +* 'dtype': 'generic' +* }); +* +* gsort2ins( [ x, y, ord ] ); +* // x => [ -4.0, -2.0, 1.0, 3.0 ] +* // y => [ 3.0, 1.0, 0.0, 2.0 ] +*/ +declare function gsort2ins( arrays: [typedndarray, typedndarray, typedndarray] ): typedndarray; + +// EXPORTS // + +export = gsort2ins; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/test.ts new file mode 100644 index 000000000000..1ad4d2a1195e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/test.ts @@ -0,0 +1,70 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +import gsort2ins = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const y = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const order = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + + gsort2ins( [ x, y, order ] ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + gsort2ins( '10' ); // $ExpectError + gsort2ins( 10 ); // $ExpectError + gsort2ins( true ); // $ExpectError + gsort2ins( false ); // $ExpectError + gsort2ins( null ); // $ExpectError + gsort2ins( undefined ); // $ExpectError + gsort2ins( [] ); // $ExpectError + gsort2ins( {} ); // $ExpectError + gsort2ins( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const y = zeros( [ 10 ], { + 'dtype': 'generic' + }); + const order = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + + gsort2ins(); // $ExpectError + gsort2ins( [ x, y, order ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/examples/index.js new file mode 100644 index 000000000000..2a36729a71ab --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/examples/index.js @@ -0,0 +1,51 @@ +/** +* @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 uniform = require( '@stdlib/random/uniform' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var gsort2ins = require( './../lib' ); + +var x = uniform( [ 10 ], -100.0, 100.0 ); +var y = uniform( [ 10 ], -100.0, 100.0 ); + +console.log( ndarray2array( x ) ); +console.log( ndarray2array( y ) ); + +var order = scalar2ndarray( 1.0, { + 'dtype': 'generic' +}); +console.log( 'Order:', ndarraylike2scalar( order ) ); + +gsort2ins( [ x, y, order ] ); + +console.log( ndarray2array( x ) ); +console.log( ndarray2array( y ) ); + +order = scalar2ndarray( -1.0, { + 'dtype': 'generic' +}); +console.log( 'Order:', ndarraylike2scalar( order ) ); + +gsort2ins( [ x, y, order ] ); + +console.log( ndarray2array( x ) ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/lib/index.js new file mode 100644 index 000000000000..ea94d0285ab8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/lib/index.js @@ -0,0 +1,54 @@ +/** +* @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'; + +/** +* Simultaneously sort two one-dimensional ndarrays based on the sort order of the first ndarray using insertion sort. +* +* @module @stdlib/blas/ext/base/ndarray/gsort2ins +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var gsort2ins = require( '@stdlib/blas/ext/base/ndarray/gsort2ins' ); +* +* var xbuf = [ 1.0, -2.0, 3.0, -4.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var ybuf = [ 0.0, 1.0, 2.0, 3.0 ]; +* var y = new ndarray( 'generic', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var ord = scalar2ndarray( 1.0, { +* 'dtype': 'generic' +* }); +* +* gsort2ins( [ x, y, ord ] ); +* // x => [ -4.0, -2.0, 1.0, 3.0 ] +* // y => [ 3.0, 1.0, 0.0, 2.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/lib/main.js new file mode 100644 index 000000000000..da66bbeab09f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/lib/main.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'; + +// MODULES // + +var ndarraylike2scalar = require( '@stdlib/ndarray/base/ndarraylike2scalar' ); +var numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/blas/ext/base/gsort2ins' ).ndarray; + + +// MAIN // + +/** +* Simultaneously sorts two one-dimensional ndarrays based on the sort order of the first ndarray using insertion sort. +* +* @param {ArrayLikeObject} arrays - array-like object containing two one-dimensional input ndarrays and a zero-dimensional ndarray specifying the sort order +* @returns {ndarray} first input ndarray +* +* @example +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, -2.0, 3.0, -4.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var ybuf = [ 0.0, 1.0, 2.0, 3.0 ]; +* var y = new ndarray( 'generic', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var ord = scalar2ndarray( 1.0, { +* 'dtype': 'generic' +* }); +* +* gsort2ins( [ x, y, ord ] ); +* // x = [ -4.0, -2.0, 1.0, 3.0 ] +* // y = [ 3.0, 1.0, 0.0, 2.0 ] +*/ +function gsort2ins( arrays ) { + var ord; + var x; + var y; + + x = arrays[ 0 ]; + y = arrays[ 1 ]; + ord = ndarraylike2scalar( arrays[ 2 ] ); + + strided( numelDimension( x, 0 ), ord, getData( x ), getStride( x, 0 ), getOffset( x ), getData( y ), getStride( y, 0 ), getOffset( y ) ); // eslint-disable-line max-len + return x; +} + + +// EXPORTS // + +module.exports = gsort2ins; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/package.json b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/package.json new file mode 100644 index 000000000000..38134d52bc07 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/blas/ext/base/ndarray/gsort2ins", + "version": "0.0.0", + "description": "Simultaneously sort two one-dimensional ndarrays based on the sort order of the first ndarray using insertion sort.", + "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", + "blas", + "math", + "mathematics", + "sort", + "sorting", + "insertion", + "insertion sort", + "ndarray", + "linear algebra", + "linalg", + "array", + "matrix" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/test/test.js new file mode 100644 index 000000000000..4625be37e75b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/test/test.js @@ -0,0 +1,87 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getStrides = require( '@stdlib/ndarray/strides' ); +var getOffset = require( '@stdlib/ndarray/offset' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var gsort2ins = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gsort2ins, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function sorts two one-dimensional ndarrays (increasing order)', function test( t ) { + var actual; + var order; + var x; + var y; + + x = ndarray( 'generic', [ 3.0, 1.0, 2.0, 5.0, 4.0 ], [ 5 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'generic', [ 0.0, 1.0, 2.0, 3.0, 4.0 ], [ 5 ], [ 1 ], 0, 'row-major' ); + order = scalar2ndarray( 1.0, { + 'dtype': 'generic' + }); + + actual = gsort2ins( [ x, y, order ] ); + t.strictEqual( getDType( actual ), getDType( x ), 'returns expected value' ); + t.deepEqual( [ 1.0, 2.0, 3.0, 4.0, 5.0 ], getData( x ), 'returns expected value' ); + t.deepEqual( [ 1.0, 2.0, 0.0, 4.0, 3.0 ], getData( y ), 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.deepEqual( getStrides( actual ), getStrides( x ), 'returns expected value' ); + t.strictEqual( getOffset( actual ), getOffset( x ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function sorts two one-dimensional ndarrays (decreasing order)', function test( t ) { + var actual; + var order; + var x; + var y; + + x = ndarray( 'generic', [ 3.0, 1.0, 2.0, 5.0, 4.0 ], [ 5 ], [ 1 ], 0, 'row-major' ); + y = ndarray( 'generic', [ 0.0, 1.0, 2.0, 3.0, 4.0 ], [ 5 ], [ 1 ], 0, 'row-major' ); + + order = scalar2ndarray( -1.0, { + 'dtype': 'generic' + }); + + actual = gsort2ins( [ x, y, order ] ); + t.strictEqual( getDType( actual ), getDType( x ), 'returns expected value' ); + t.deepEqual( [ 5.0, 4.0, 3.0, 2.0, 1.0 ], getData( x ), 'returns expected value' ); + t.deepEqual( [ 3.0, 4.0, 0.0, 2.0, 1.0 ], getData( y ), 'returns expected value' ); + t.deepEqual( getShape( actual ), getShape( x ), 'returns expected value' ); + t.deepEqual( getStrides( actual ), getStrides( x ), 'returns expected value' ); + t.strictEqual( getOffset( actual ), getOffset( x ), 'returns expected value' ); + + t.end(); +}); From 030f3230b389058b0d422886053adbdbcac5ad3d Mon Sep 17 00:00:00 2001 From: sagar7162 Date: Fri, 16 Jan 2026 22:30:25 +0530 Subject: [PATCH 2/4] fix: fixed benchmarks max iteration --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js index ef5cf77277fb..cf483e4cc466 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js @@ -104,8 +104,8 @@ function main() { var f; var i; - min = 1; // 10^1 - max = 6; // 10^6 + min = 1; // 10^min + max = 4; // 10^max for ( i = min; i <= max; i++ ) { len = pow( 10, i ); From 5acb9aa545b1c02dd4da0b57e1dc0f59ea9f6280 Mon Sep 17 00:00:00 2001 From: sagar7162 Date: Fri, 16 Jan 2026 22:34:03 +0530 Subject: [PATCH 3/4] fix: benchmarks string interpolation --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js index cf483e4cc466..92783ad32b38 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/benchmark/benchmark.js @@ -25,6 +25,7 @@ var uniform = require( '@stdlib/random/array/uniform' ); var pow = require( '@stdlib/math/base/special/pow' ); var ndarray = require( '@stdlib/ndarray/base/ctor' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; var gsort2ins = require( './../lib' ); @@ -110,7 +111,7 @@ function main() { for ( i = min; i <= max; i++ ) { len = pow( 10, i ); f = createBenchmark( len ); - bench( pkg + ':len=' + len, f ); + bench( format( '%s:len=%d', pkg, len ), f ); } } From 48cfd135e0d1c9166cbe597db01f4ab1f8fce822 Mon Sep 17 00:00:00 2001 From: sagar7162 Date: Sat, 17 Jan 2026 23:10:15 +0530 Subject: [PATCH 4/4] fix: add sapce before comment --- 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 status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../blas/ext/base/ndarray/gsort2ins/docs/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/index.d.ts index 0dab8c67d01c..a41ace54cf8a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ndarray/gsort2ins/docs/types/index.d.ts @@ -54,6 +54,7 @@ import { typedndarray } from '@stdlib/types/ndarray'; */ declare function gsort2ins( arrays: [typedndarray, typedndarray, typedndarray] ): typedndarray; + // EXPORTS // export = gsort2ins;