diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/README.md
new file mode 100644
index 000000000000..f076d790b2ae
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/README.md
@@ -0,0 +1,181 @@
+
+
+# dsortmg
+
+> Sort a double-precision floating-point strided array using merge sort.
+
+
+
+## Usage
+
+```javascript
+var dsortmg = require( '@stdlib/blas/ext/base/dsortmg' );
+```
+
+#### dsortmg( N, order, x, strideX, workspace, strideW )
+
+Sorts a double-precision floating-point strided array using merge sort.
+
+```javascript
+var Float64Array = require( '@stdlib/array/float64' );
+
+var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+var workspace = new Float64Array( x.length );
+
+dsortmg( x.length, 1.0, x, 1, workspace, 1 );
+// x => [ -4.0, -2.0, 1.0, 3.0 ]
+```
+
+The function has the following parameters:
+
+- **N**: number of indexed elements.
+- **order**: sort order. If `order < 0.0`, the input strided array is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged.
+- **x**: input [`Float64Array`][@stdlib/array/float64].
+- **strideX**: stride length for `x`.
+- **workspace**: workspace [`Float64Array`][@stdlib/array/float64]. Must have at least `N` indexed elements.
+- **strideW**: stride length for `workspace`.
+
+The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to sort every other element:
+
+```javascript
+var Float64Array = require( '@stdlib/array/float64' );
+
+var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+var workspace = new Float64Array( 2 );
+
+dsortmg( 2, -1.0, x, 2, workspace, 1 );
+// x => [ 3.0, -2.0, 1.0, -4.0 ]
+```
+
+Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
+
+```javascript
+var Float64Array = require( '@stdlib/array/float64' );
+
+// Initial array...
+var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
+
+// Create an offset view...
+var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
+
+// Create a workspace array...
+var workspace = new Float64Array( 2 );
+
+// Sort every other element...
+dsortmg( 2, -1.0, x1, 2, workspace, 1 );
+// x0 => [ 1.0, 4.0, 3.0, 2.0 ]
+```
+
+#### dsortmg.ndarray( N, order, x, strideX, offsetX, workspace, strideW, offsetW )
+
+Sorts a double-precision floating-point strided array using merge sort and alternative indexing semantics.
+
+```javascript
+var Float64Array = require( '@stdlib/array/float64' );
+
+var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+var workspace = new Float64Array( x.length );
+
+dsortmg.ndarray( x.length, 1.0, x, 1, 0, workspace, 1, 0 );
+// x => [ -4.0, -2.0, 1.0, 3.0 ]
+```
+
+The function has the following additional parameters:
+
+- **offsetX**: starting index for `x`.
+- **offsetW**: starting index for `workspace`.
+
+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:
+
+```javascript
+var Float64Array = require( '@stdlib/array/float64' );
+
+var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
+var workspace = new Float64Array( 3 );
+
+dsortmg.ndarray( 3, 1.0, x, 1, x.length-3, workspace, 1, 0 );
+// x => [ 1.0, -2.0, 3.0, -6.0, -4.0, 5.0 ]
+```
+
+
+
+
+
+
+
+## Notes
+
+- If `N <= 0` or `order == 0.0`, both functions return `x` unchanged.
+- The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`.
+- The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first.
+- The algorithm has space complexity `O(N)` and time complexity `O(N log2 N)`.
+- The algorithm is **stable**, meaning that the algorithm does **not** change the order of strided array elements which are equal or equivalent (e.g., `NaN` values).
+- The input strided array is sorted **in-place** (i.e., the input strided array is **mutated**).
+
+
+
+
+
+
+
+## Examples
+
+
+
+```javascript
+var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dsortmg = require( '@stdlib/blas/ext/base/dsortmg' );
+
+var x = discreteUniform( 10, -100, 100, {
+ 'dtype': 'float64'
+});
+console.log( x );
+
+var workspace = new Float64Array( x.length );
+
+dsortmg( x.length, -1.0, x, -1, workspace, 1 );
+console.log( x );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64
+
+[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
+
+
+
+
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_few_uniques.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_few_uniques.js
new file mode 100644
index 000000000000..150cbd48790b
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_few_uniques.js
@@ -0,0 +1,135 @@
+/**
+* @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/base/uniform' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var sa;
+ var sb;
+ var a;
+ var b;
+ var x;
+ var i;
+ var j;
+
+ a = 1.0;
+ b = 10.0;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ sa = (b-a) * (j/len);
+ sb = sa / 2.0;
+ tmp[ j ] = floor( uniform( a+sa, b+sb ) );
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::mostly_sorted,few_uniques:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_few_uniques.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_few_uniques.ndarray.js
new file mode 100644
index 000000000000..1a7d1e4a713f
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_few_uniques.ndarray.js
@@ -0,0 +1,135 @@
+/**
+* @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/base/uniform' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var sa;
+ var sb;
+ var a;
+ var b;
+ var x;
+ var i;
+ var j;
+
+ a = 1.0;
+ b = 10.0;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ sa = (b-a) * (j/len);
+ sb = sa / 2.0;
+ tmp[ j ] = floor( uniform( a+sa, b+sb ) );
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::mostly_sorted,few_uniques:ndarray:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_random.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_random.js
new file mode 100644
index 000000000000..794e18720c5b
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_random.js
@@ -0,0 +1,126 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = randu() * j;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::mostly_sorted,random:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_random.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_random.ndarray.js
new file mode 100644
index 000000000000..4a816738db96
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.mostly_sorted_random.ndarray.js
@@ -0,0 +1,126 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = randu() * j;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::mostly_sorted,random:ndarray:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_few_uniques.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_few_uniques.js
new file mode 100644
index 000000000000..bd1d1c3fdbb5
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_few_uniques.js
@@ -0,0 +1,135 @@
+/**
+* @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/base/uniform' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var sa;
+ var sb;
+ var a;
+ var b;
+ var x;
+ var i;
+ var j;
+
+ a = -10.0;
+ b = -1.0;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ sb = (b-a) * (j/len);
+ sa = sb / 2.0;
+ tmp[ j ] = floor( uniform( a-sa, b-sb ) );
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::reverse_mostly_sorted,few_uniques:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_few_uniques.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_few_uniques.ndarray.js
new file mode 100644
index 000000000000..2755c7e93e50
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_few_uniques.ndarray.js
@@ -0,0 +1,135 @@
+/**
+* @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/base/uniform' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var sa;
+ var sb;
+ var a;
+ var b;
+ var x;
+ var i;
+ var j;
+
+ a = -10.0;
+ b = -1.0;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ sb = (b-a) * (j/len);
+ sa = sb / 2.0;
+ tmp[ j ] = floor( uniform( a-sa, b-sb ) );
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::reverse_mostly_sorted,few_uniques:ndarray:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_random.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_random.js
new file mode 100644
index 000000000000..3d44c1880bc4
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_random.js
@@ -0,0 +1,126 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = -1.0 * randu() * j;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::reverse_mostly_sorted,random:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_random.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_random.ndarray.js
new file mode 100644
index 000000000000..00774fd2ac48
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_mostly_sorted_random.ndarray.js
@@ -0,0 +1,126 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = -1.0 * randu() * j;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::reverse_mostly_sorted,random:ndarray:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_few_uniques.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_few_uniques.js
new file mode 100644
index 000000000000..eb135e003d83
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_few_uniques.js
@@ -0,0 +1,136 @@
+/**
+* @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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var randi;
+ var tmp;
+ var M;
+ var x;
+ var v;
+ var i;
+ var j;
+
+ randi = discreteUniform( 1, 10 );
+ M = floor( len*0.333 );
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ v = randi();
+ for ( j = 0; j < len; j++ ) {
+ if ( i % M === 0 ) {
+ v -= randi();
+ }
+ tmp[ j ] = v;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::reverse_sorted,few_uniques:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_few_uniques.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_few_uniques.ndarray.js
new file mode 100644
index 000000000000..e689525f3abe
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_few_uniques.ndarray.js
@@ -0,0 +1,136 @@
+/**
+* @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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var randi;
+ var tmp;
+ var M;
+ var x;
+ var v;
+ var i;
+ var j;
+
+ randi = discreteUniform( 1, 10 );
+ M = floor( len*0.333 );
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ v = randi();
+ for ( j = 0; j < len; j++ ) {
+ if ( i % M === 0 ) {
+ v -= randi();
+ }
+ tmp[ j ] = v;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::reverse_sorted,few_uniques:ndarray:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_random.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_random.js
new file mode 100644
index 000000000000..355181819b24
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_random.js
@@ -0,0 +1,126 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = iter - j - randu();
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::reverse_sorted,random:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_random.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_random.ndarray.js
new file mode 100644
index 000000000000..d78e2801c1dc
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.rev_sorted_random.ndarray.js
@@ -0,0 +1,126 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = iter - j - randu();
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::reverse_sorted,random:ndarray:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_few_uniques.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_few_uniques.js
new file mode 100644
index 000000000000..acc1e3e0e25d
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_few_uniques.js
@@ -0,0 +1,133 @@
+/**
+* @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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var randi;
+ var tmp;
+ var M;
+ var x;
+ var v;
+ var i;
+ var j;
+
+ randi = discreteUniform( 1, 10 );
+ M = floor( len*0.333 );
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ v = randi();
+ for ( j = 0; j < len; j++ ) {
+ if ( j % M === 0 ) {
+ v += randi();
+ }
+ tmp[ j ] = v;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ min = 1; // 10^min
+ max = 5; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ opts = {
+ 'iterations': 1e7 / len
+ };
+ f = createBenchmark( opts.iterations, len );
+ bench( format( '%s::sorted,few_uniques:len=%d', pkg, len ), opts, f );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_few_uniques.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_few_uniques.ndarray.js
new file mode 100644
index 000000000000..b67dfcbd1c7f
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_few_uniques.ndarray.js
@@ -0,0 +1,133 @@
+/**
+* @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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var randi;
+ var tmp;
+ var M;
+ var x;
+ var v;
+ var i;
+ var j;
+
+ randi = discreteUniform( 1, 10 );
+ M = floor( len*0.333 );
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ v = randi();
+ for ( j = 0; j < len; j++ ) {
+ if ( j % M === 0 ) {
+ v += randi();
+ }
+ tmp[ j ] = v;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ min = 1; // 10^min
+ max = 5; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ opts = {
+ 'iterations': 1e7 / len
+ };
+ f = createBenchmark( opts.iterations, len );
+ bench( format( '%s::sorted,few_uniques:ndarray:len=%d', pkg, len ), opts, f );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_random.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_random.js
new file mode 100644
index 000000000000..079fb1aa37ba
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_random.js
@@ -0,0 +1,122 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = randu() + j;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ min = 1; // 10^min
+ max = 5; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ opts = {
+ 'iterations': 1e7 / len
+ };
+ f = createBenchmark( opts.iterations, len );
+ bench( format( '%s::sorted,random:len=%d', pkg, len ), opts, f );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_random.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_random.ndarray.js
new file mode 100644
index 000000000000..8d773c882fce
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.sorted_random.ndarray.js
@@ -0,0 +1,122 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = randu() + j;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ min = 1; // 10^min
+ max = 5; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ opts = {
+ 'iterations': 1e7 / len
+ };
+ f = createBenchmark( opts.iterations, len );
+ bench( format( '%s::sorted,random:ndarray:len=%d', pkg, len ), opts, f );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_few_uniques.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_few_uniques.js
new file mode 100644
index 000000000000..1e6444b5d3d9
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_few_uniques.js
@@ -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.
+*/
+
+'use strict';
+
+// MODULES //
+
+var bench = require( '@stdlib/bench' );
+var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var randi;
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ randi = discreteUniform( 1, 10 );
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = randi();
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::unsorted,few_uniques:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_few_uniques.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_few_uniques.ndarray.js
new file mode 100644
index 000000000000..ff4cb898517f
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_few_uniques.ndarray.js
@@ -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.
+*/
+
+'use strict';
+
+// MODULES //
+
+var bench = require( '@stdlib/bench' );
+var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var randi;
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ randi = discreteUniform( 1, 10 );
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = randi();
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::unsorted,few_uniques:ndarray:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_random.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_random.js
new file mode 100644
index 000000000000..4e82cb1b96d0
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_random.js
@@ -0,0 +1,126 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/main.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = (randu()*20.0) - 10.0;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, w, 1 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::unsorted,random:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_random.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_random.ndarray.js
new file mode 100644
index 000000000000..d01d306a87d9
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/benchmark/benchmark.unsorted_random.ndarray.js
@@ -0,0 +1,126 @@
+/**
+* @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 randu = require( '@stdlib/random/base/randu' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var pow = require( '@stdlib/math/base/special/pow' );
+var floor = require( '@stdlib/math/base/special/floor' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var format = require( '@stdlib/string/format' );
+var pkg = require( './../package.json' ).name;
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// FUNCTIONS //
+
+/**
+* Create a benchmark function.
+*
+* @private
+* @param {PositiveInteger} iter - number of iterations
+* @param {PositiveInteger} len - array length
+* @returns {Function} benchmark function
+*/
+function createBenchmark( iter, len ) {
+ var tmp;
+ var x;
+ var i;
+ var j;
+
+ x = [];
+ for ( i = 0; i < iter; i++ ) {
+ tmp = new Float64Array( len );
+ for ( j = 0; j < len; j++ ) {
+ tmp[ j ] = (randu()*20.0) - 10.0;
+ }
+ x.push( tmp );
+ }
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var xc;
+ var w;
+ var y;
+ var i;
+
+ xc = x.slice();
+ for ( i = 0; i < iter; i++ ) {
+ xc[ i ] = dcopy( len, x[ i ], 1, new Float64Array( len ), 1 );
+ }
+ w = new Float64Array( len );
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ y = dsortmg( len, 1, xc[ i ], 1, 0, w, 1, 0 );
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ }
+ b.toc();
+ if ( isnan( y[ i%len ] ) ) {
+ b.fail( 'should not return NaN' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var opts;
+ var iter;
+ var len;
+ var min;
+ var max;
+ var f;
+ var i;
+
+ iter = 1e6;
+ min = 1; // 10^min
+ max = 4; // 10^max
+
+ for ( i = min; i <= max; i++ ) {
+ len = pow( 10, i );
+ f = createBenchmark( iter, len );
+ opts = {
+ 'iterations': iter
+ };
+ bench( format( '%s::unsorted,random:ndarray:len=%d', pkg, len ), opts, f );
+ iter = floor( pow( iter, 3.0/4.0 ) );
+ }
+}
+
+main();
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/docs/repl.txt
new file mode 100644
index 000000000000..e2402cb1f952
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/docs/repl.txt
@@ -0,0 +1,136 @@
+
+{{alias}}( N, order, x, strideX, workspace, strideW )
+ Sorts a double-precision floating-point strided array using merge sort.
+
+ 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 typed
+ array views.
+
+ If `N <= 0` or `order == 0`, the function returns `x` unchanged.
+
+ The algorithm distinguishes between `-0` and `+0`. When sorted in increasing
+ order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is
+ sorted after `+0`.
+
+ The algorithm sorts `NaN` values to the end. When sorted in increasing
+ order, `NaN` values are sorted last. When sorted in decreasing order, `NaN`
+ values are sorted first.
+
+ The algorithm has space complexity O(N) and time complexity O(N log2 N).
+
+ The algorithm is *stable*, meaning that the algorithm does *not* change the
+ order of strided array elements which are equal or equivalent (e.g., `NaN`
+ values).
+
+ The input strided array is sorted *in-place* (i.e., the input strided array
+ is *mutated*).
+
+ Parameters
+ ----------
+ N: integer
+ Number of indexed elements.
+
+ order: number
+ Sort order. If `order < 0`, the function sorts `x` in decreasing order.
+ If `order > 0`, the function sorts `x` in increasing order.
+
+ x: Float64Array
+ Input array.
+
+ strideX: integer
+ Stride length for `x`.
+
+ workspace: Float64Array
+ Workspace array. Must have at least `N` indexed elements.
+
+ strideW: integer
+ Stride length for `workspace`.
+
+ Returns
+ -------
+ x: Float64Array
+ Input array `x`.
+
+ Examples
+ --------
+ // Standard Usage:
+ > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
+ > var w = new {{alias:@stdlib/array/float64}}( x.length );
+ > {{alias}}( x.length, 1, x, 1, w, 1 )
+ [ -4.0, -2.0, 1.0, 3.0 ]
+
+ // Using `N` and `stride` parameters:
+ > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
+ > w = new {{alias:@stdlib/array/float64}}( 2 );
+ > {{alias}}( 2, -1, x, 2, w, 1 )
+ [ 3.0, -2.0, 1.0, -4.0 ]
+
+ // Using view offsets:
+ > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
+ > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
+ > w = new {{alias:@stdlib/array/float64}}( 2 );
+ > {{alias}}( 2, 1, x1, 2, w, 1 )
+ [ -4.0, 3.0, -2.0 ]
+ > x0
+ [ 1.0, -4.0, 3.0, -2.0 ]
+
+
+{{alias}}.ndarray( N, order, x, strideX, offsetX, workspace, strideW, offsetW )
+ Sorts a double-precision floating-point strided array using merge sort and
+ 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.
+
+ order: number
+ Sort order. If `order < 0`, the function sorts `x` in decreasing order.
+ If `order > 0`, the function sorts `x` in increasing order.
+
+ x: Float64Array
+ Input array.
+
+ strideX: integer
+ Stride length for `x`.
+
+ offsetX: integer
+ Starting index for `x`.
+
+ workspace: Float64Array
+ Workspace array. Must have at least `N` indexed elements.
+
+ strideW: integer
+ Stride length for `workspace`.
+
+ offsetW: integer
+ Starting index for `workspace`.
+
+ Returns
+ -------
+ x: Float64Array
+ Input array `x`.
+
+ Examples
+ --------
+ // Standard Usage:
+ > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
+ > var w = new {{alias:@stdlib/array/float64}}( x.length );
+ > {{alias}}.ndarray( x.length, 1, x, 1, 0, w, 1, 0 )
+ [ -4.0, -2.0, 1.0, 3.0 ]
+
+ // Using an index offset:
+ > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
+ > w = new {{alias:@stdlib/array/float64}}( 2 );
+ > {{alias}}.ndarray( 2, 1, x, 2, 1, w, 1, 0 )
+ [ 1.0, -4.0, 3.0, -2.0 ]
+
+ See Also
+ --------
+
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/docs/types/index.d.ts
new file mode 100644
index 000000000000..72d23fdb4391
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/docs/types/index.d.ts
@@ -0,0 +1,114 @@
+/*
+* @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
+
+/**
+* Interface describing `dsortmg`.
+*/
+interface Routine {
+ /**
+ * Sorts a double-precision floating-point strided array using merge sort.
+ *
+ * ## Notes
+ *
+ * - The `workspace` array must have at least `N` indexed elements.
+ *
+ * @param N - number of indexed elements
+ * @param order - sort order
+ * @param x - input array
+ * @param strideX - stride length for `x`
+ * @param workspace - workspace array
+ * @param strideW - stride length for `workspace`
+ * @returns `x`
+ *
+ * @example
+ * var Float64Array = require( '@stdlib/array/float64' );
+ *
+ * var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+ * var workspace = new Float64Array( x.length );
+ *
+ * dsortmg( x.length, 1, x, 1, workspace, 1 );
+ * // x => [ -4.0, -2.0, 1.0, 3.0 ]
+ */
+ ( N: number, order: number, x: Float64Array, strideX: number, workspace: Float64Array, strideW: number ): Float64Array;
+
+ /**
+ * Sorts a double-precision floating-point strided array using merge sort and alternative indexing semantics.
+ *
+ * ## Notes
+ *
+ * - The `workspace` array must have at least `N` indexed elements.
+ *
+ * @param N - number of indexed elements
+ * @param order - sort order
+ * @param x - input array
+ * @param strideX - stride length for `x`
+ * @param offsetX - starting index for `x`
+ * @param workspace - workspace array
+ * @param strideW - stride length for `workspace`
+ * @param offsetW - starting index for `workspace`
+ * @returns `x`
+ *
+ * @example
+ * var Float64Array = require( '@stdlib/array/float64' );
+ *
+ * var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+ * var workspace = new Float64Array( x.length );
+ *
+ * dsortmg.ndarray( x.length, 1, x, 1, 0, workspace, 1, 0 );
+ * // x => [ -4.0, -2.0, 1.0, 3.0 ]
+ */
+ ndarray( N: number, order: number, x: Float64Array, strideX: number, offsetX: number, workspace: Float64Array, strideW: number, offsetW: number ): Float64Array;
+}
+
+/**
+* Sorts a double-precision floating-point strided array using merge sort.
+*
+* @param N - number of indexed elements
+* @param order - sort order
+* @param x - input array
+* @param strideX - stride length for `x`
+* @param workspace - workspace array
+* @param strideW - stride length for `workspace`
+* @returns `x`
+*
+* @example
+* var Float64Array = require( '@stdlib/array/float64' );
+*
+* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+* var workspace = new Float64Array( x.length );
+*
+* dsortmg( x.length, 1, x, 1, workspace, 1 );
+* // x => [ -4.0, -2.0, 1.0, 3.0 ]
+*
+* @example
+* var Float64Array = require( '@stdlib/array/float64' );
+*
+* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+* var workspace = new Float64Array( x.length );
+*
+* dsortmg.ndarray( x.length, 1, x, 1, 0, workspace, 1, 0 );
+* // x => [ -4.0, -2.0, 1.0, 3.0 ]
+*/
+declare var dsortmg: Routine;
+
+
+// EXPORTS //
+
+export = dsortmg;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/docs/types/test.ts
new file mode 100644
index 000000000000..4fb0c1afe640
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/docs/types/test.ts
@@ -0,0 +1,280 @@
+/*
+* @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 dsortmg = require( './index' );
+
+
+// TESTS //
+
+// The function returns a Float64Array...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg( x.length, 1, x, 1, w, 1 ); // $ExpectType Float64Array
+}
+
+// The compiler throws an error if the function is provided a first argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg( '10', 1, x, 1, w, 1 ); // $ExpectError
+ dsortmg( true, 1, x, 1, w, 1 ); // $ExpectError
+ dsortmg( false, 1, x, 1, w, 1 ); // $ExpectError
+ dsortmg( null, 1, x, 1, w, 1 ); // $ExpectError
+ dsortmg( undefined, 1, x, 1, w, 1 ); // $ExpectError
+ dsortmg( [], 1, x, 1, w, 1 ); // $ExpectError
+ dsortmg( {}, 1, x, 1, w, 1 ); // $ExpectError
+ dsortmg( ( x: number ): number => x, 1, x, 1, w, 1 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a second argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg( x.length, '10', x, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, true, x, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, false, x, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, null, x, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, undefined, x, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, [], x, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, {}, x, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, ( x: number ): number => x, x, 1, w, 1 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a third argument which is not a Float64Array...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg( x.length, 1, 10, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, '10', 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, true, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, false, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, null, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, undefined, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, [], 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, {}, 1, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, ( x: number ): number => x, 1, w, 1 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a fourth argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg( x.length, 1, x, '10', w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, true, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, false, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, null, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, undefined, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, [], w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, {}, w, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, ( x: number ): number => x, w, 1 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a fifth argument which is not a Float64Array...
+{
+ const x = new Float64Array( 10 );
+
+ dsortmg( x.length, 1, x, 1, 10, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, '10', 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, true, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, false, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, null, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, undefined, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, [], 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, {}, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, ( x: number ): number => x, 1 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a sixth argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg( x.length, 1, x, 1, w, '10' ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, w, true ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, w, false ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, w, null ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, w, undefined ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, w, [] ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, w, {} ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, w, ( x: number ): number => x ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided an unsupported number of arguments...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg(); // $ExpectError
+ dsortmg( x.length ); // $ExpectError
+ dsortmg( x.length, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x ); // $ExpectError
+ dsortmg( x.length, 1, x, 1 ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, w ); // $ExpectError
+ dsortmg( x.length, 1, x, 1, w, 1, 10 ); // $ExpectError
+}
+
+// Attached to main export is an `ndarray` method which returns a Float64Array...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, 0 ); // $ExpectType Float64Array
+}
+
+// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg.ndarray( '10', 1, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( true, 1, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( false, 1, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( null, 1, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( undefined, 1, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( [], 1, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( {}, 1, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( ( x: number ): number => x, 1, x, 1, 0, w, 1, 0 ); // $ExpectError
+}
+
+// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg.ndarray( x.length, '10', x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, true, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, false, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, null, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, undefined, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, [], x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, {}, x, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, ( x: number ): number => x, x, 1, 0, w, 1, 0 ); // $ExpectError
+}
+
+// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float64Array...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg.ndarray( x.length, 1, 10, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, '10', 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, true, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, false, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, null, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, undefined, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, [], 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, {}, 1, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, ( x: number ): number => x, 1, 0, w, 1, 0 ); // $ExpectError
+}
+
+// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg.ndarray( x.length, 1, x, '10', 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, true, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, false, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, null, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, undefined, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, [], 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, {}, 0, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, ( x: number ): number => x, 0, w, 1, 0 ); // $ExpectError
+}
+
+// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg.ndarray( x.length, 1, x, 1, '10', w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, true, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, false, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, null, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, undefined, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, [], w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, {}, w, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, ( x: number ): number => x, w, 1, 0 ); // $ExpectError
+}
+
+// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a Float64Array...
+{
+ const x = new Float64Array( 10 );
+
+ dsortmg.ndarray( x.length, 1, x, 1, 0, 10, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, '10', 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, true, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, false, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, null, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, undefined, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, [], 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, {}, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError
+}
+
+// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, '10', 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, true, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, false, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, null, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, undefined, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, [], 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, {}, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, ( x: number ): number => x, 0 ); // $ExpectError
+}
+
+// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, '10' ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, true ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, false ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, null ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, undefined ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, [] ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, {} ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, ( x: number ): number => x ); // $ExpectError
+}
+
+// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments...
+{
+ const x = new Float64Array( 10 );
+ const w = new Float64Array( 10 );
+
+ dsortmg.ndarray(); // $ExpectError
+ dsortmg.ndarray( x.length ); // $ExpectError
+ dsortmg.ndarray( x.length, 1 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1 ); // $ExpectError
+ dsortmg.ndarray( x.length, 1, x, 1, 0, w, 1, 0, 10 ); // $ExpectError
+}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/examples/index.js
new file mode 100644
index 000000000000..b18094ba3f87
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/examples/index.js
@@ -0,0 +1,33 @@
+/**
+* @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 Float64Array = require( '@stdlib/array/float64' );
+var dsortmg = require( './../lib' );
+
+var x = discreteUniform( 10, -100, 100, {
+ 'dtype': 'float64'
+});
+console.log( x );
+
+var workspace = new Float64Array( x.length );
+
+dsortmg( x.length, -1.0, x, -1, workspace, 1 );
+console.log( x );
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/lib/index.js
new file mode 100644
index 000000000000..ab6d32e4c8b3
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/lib/index.js
@@ -0,0 +1,61 @@
+/**
+* @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';
+
+/**
+* Sort a double-precision floating-point strided array using merge sort.
+*
+* @module @stdlib/blas/ext/base/dsortmg
+*
+* @example
+* var Float64Array = require( '@stdlib/array/float64' );
+* var dsortmg = require( '@stdlib/blas/ext/base/dsortmg' );
+*
+* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+* var workspace = new Float64Array( x.length );
+*
+* dsortmg( x.length, 1.0, x, 1, workspace, 1 );
+* // x => [ -4.0, -2.0, 1.0, 3.0 ]
+*
+* @example
+* var Float64Array = require( '@stdlib/array/float64' );
+* var dsortmg = require( '@stdlib/blas/ext/base/dsortmg' );
+*
+* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+* var workspace = new Float64Array( x.length );
+*
+* dsortmg.ndarray( x.length, 1.0, x, 1, 0, workspace, 1, 0 );
+* // x => [ -4.0, -2.0, 1.0, 3.0 ]
+*/
+
+// MODULES //
+
+var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
+var main = require( './main.js' );
+var ndarray = require( './ndarray.js' );
+
+
+// MAIN //
+
+setReadOnly( main, 'ndarray', ndarray );
+
+
+// EXPORTS //
+
+module.exports = main;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/lib/main.js
new file mode 100644
index 000000000000..d158d3a1a513
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/lib/main.js
@@ -0,0 +1,60 @@
+/**
+* @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 //
+
+/**
+* Sorts a double-precision floating-point strided array using merge sort.
+*
+* ## Notes
+*
+* - This implementation uses a bottom-up iterative merge sort which requires a workspace array having at least `N` indexed elements.
+*
+* @param {PositiveInteger} N - number of indexed elements
+* @param {number} order - sort order
+* @param {Float64Array} x - input array
+* @param {integer} strideX - stride length for `x`
+* @param {Float64Array} workspace - workspace array
+* @param {integer} strideW - stride length for `workspace`
+* @returns {Float64Array} input array
+*
+* @example
+* var Float64Array = require( '@stdlib/array/float64' );
+*
+* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+* var workspace = new Float64Array( x.length );
+*
+* dsortmg( x.length, 1.0, x, 1, workspace, 1 );
+* // x => [ -4.0, -2.0, 1.0, 3.0 ]
+*/
+function dsortmg( N, order, x, strideX, workspace, strideW ) {
+ return ndarray( N, order, x, strideX, stride2offset( N, strideX ), workspace, strideW, stride2offset( N, strideW ) ); // eslint-disable-line max-len
+}
+
+
+// EXPORTS //
+
+module.exports = dsortmg;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/lib/ndarray.js
new file mode 100644
index 000000000000..1f67e0910ce7
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/lib/ndarray.js
@@ -0,0 +1,135 @@
+/**
+* @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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
+var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+
+
+// MAIN //
+
+/**
+* Sorts a double-precision floating-point strided array using merge sort.
+*
+* ## Notes
+*
+* - This implementation uses a bottom-up iterative merge sort which requires a workspace array having at least `N` indexed elements.
+*
+* @param {PositiveInteger} N - number of indexed elements
+* @param {number} order - sort order
+* @param {Float64Array} x - input array
+* @param {integer} strideX - stride length for `x`
+* @param {NonNegativeInteger} offsetX - starting index for `x`
+* @param {Float64Array} workspace - workspace array
+* @param {integer} strideW - stride length for `workspace`
+* @param {NonNegativeInteger} offsetW - starting index for `workspace`
+* @returns {Float64Array} input array
+*
+* @example
+* var Float64Array = require( '@stdlib/array/float64' );
+*
+* var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] );
+* var workspace = new Float64Array( x.length );
+*
+* dsortmg( x.length, 1.0, x, 1, 0, workspace, 1, 0 );
+* // x => [ -4.0, -2.0, 1.0, 3.0 ]
+*/
+function dsortmg( N, order, x, strideX, offsetX, workspace, strideW, offsetW ) {
+ var mid;
+ var v1;
+ var v2;
+ var hi;
+ var lo;
+ var ix;
+ var iw;
+ var jx;
+ var kx;
+ var i;
+ var j;
+ var w;
+
+ if ( N <= 0 || order === 0.0 ) {
+ return x;
+ }
+ // For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order...
+ if ( order < 0.0 ) {
+ strideX *= -1;
+ offsetX -= (N-1) * strideX;
+ }
+ // Iteratively merge adjacent runs of doubling width until the array is sorted...
+ for ( w = 1; w < N; w *= 2 ) {
+ // Merge adjacent pairs of runs...
+ for ( lo = 0; lo < N-w; lo += 2*w ) {
+ // Compute the index separating the "left" and "right" runs:
+ mid = lo + w;
+
+ // Compute the (exclusive) end index of the "right" run, being careful to avoid exceeding array bounds:
+ hi = mid + w;
+ if ( hi > N ) {
+ hi = N;
+ }
+ // Copy the "left" run to the workspace array in order to make room for merged elements:
+ ix = offsetX + (lo*strideX);
+ iw = offsetW;
+ for ( i = 0; i < w; i++ ) {
+ workspace[ iw ] = x[ ix ];
+ ix += strideX;
+ iw += strideW;
+ }
+ // Merge the runs...
+ i = 0;
+ j = mid;
+ iw = offsetW;
+ jx = offsetX + (j*strideX);
+ kx = offsetX + (lo*strideX);
+ while ( i < w && j < hi ) {
+ v1 = workspace[ iw ];
+ v2 = x[ jx ];
+
+ // Take from the "right" run only when its next value is strictly "less" than the next value of the "left" run, thus ensuring sort stability...
+ if ( v2 < v1 || ( isnan( v1 ) && !isnan( v2 ) ) || ( v1 === v2 && isNegativeZero( v2 ) && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len
+ x[ kx ] = v2;
+ j += 1;
+ jx += strideX;
+ } else {
+ x[ kx ] = v1;
+ i += 1;
+ iw += strideW;
+ }
+ kx += strideX;
+ }
+ // Copy any remaining "left" run elements (any remaining "right" run elements are already in place):
+ while ( i < w ) {
+ x[ kx ] = workspace[ iw ];
+ i += 1;
+ iw += strideW;
+ kx += strideX;
+ }
+ }
+ }
+ return x;
+}
+
+
+// EXPORTS //
+
+module.exports = dsortmg;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/package.json b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/package.json
new file mode 100644
index 000000000000..22d6eb8e7994
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/package.json
@@ -0,0 +1,73 @@
+{
+ "name": "@stdlib/blas/ext/base/dsortmg",
+ "version": "0.0.0",
+ "description": "Sort a double-precision floating-point strided array using merge 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",
+ "browser": "./lib/main.js",
+ "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",
+ "sort",
+ "order",
+ "arrange",
+ "permute",
+ "merge",
+ "mergesort",
+ "strided",
+ "array",
+ "ndarray",
+ "float64",
+ "double",
+ "float64array"
+ ],
+ "__stdlib__": {}
+}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/fixtures/ascending.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/fixtures/ascending.js
new file mode 100644
index 000000000000..d67b3f475d99
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/fixtures/ascending.js
@@ -0,0 +1,75 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2026 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var isnan = require( '@stdlib/math/base/assert/is-nan' );
+var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
+
+
+// MAIN //
+
+/**
+* Determines sort order by comparing two values.
+*
+* ## Notes
+*
+* - Return values are as follows:
+*
+* - `-1`: sort `a` to a lower index than `b` (i.e., `a` comes first)
+* - `1`: sort `b` to a lower index than `a` (i.e., `b` comes first)
+* - `0`: leave the order of `a` and `b` unchanged with respect to one another
+*
+* @private
+* @param {number} a - first value
+* @param {number} b - second value
+* @returns {integer} value indicating sort order
+*/
+function ascending( a, b ) {
+ // Sort NaNs to the end...
+ if ( isnan( a ) ) {
+ return 1;
+ }
+ if ( isnan( b ) ) {
+ return -1;
+ }
+ // Sort negative 0s to the left...
+ if ( a === b && a === 0 ) {
+ if ( isNegativeZero( a ) ) {
+ return -1;
+ }
+ if ( isNegativeZero( b ) ) {
+ return 1;
+ }
+ return 0;
+ }
+ if ( a > b ) {
+ return 1;
+ }
+ if ( a < b ) {
+ return -1;
+ }
+ return 0;
+}
+
+
+// EXPORTS //
+
+module.exports = ascending;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/fixtures/num2str.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/fixtures/num2str.js
new file mode 100644
index 000000000000..d4bce1cee666
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/fixtures/num2str.js
@@ -0,0 +1,45 @@
+/**
+* @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 isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
+
+
+// MAIN //
+
+/**
+* Converts a number to a string.
+*
+* @private
+* @param {number} value - input value
+* @returns {string} string representation
+*/
+function num2str( value ) {
+ if ( isNegativeZero( value ) ) {
+ return '-0';
+ }
+ return value.toString();
+}
+
+
+// EXPORTS //
+
+module.exports = num2str;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/test.js
new file mode 100644
index 000000000000..cfbdae1dddc5
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/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 dsortmg = require( './../lib' );
+
+
+// TESTS //
+
+tape( 'main export is a function', function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof dsortmg, '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 dsortmg.ndarray, 'function', 'method is a function' );
+ t.end();
+});
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/test.main.js
new file mode 100644
index 000000000000..a9b4b7e00302
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/test.main.js
@@ -0,0 +1,642 @@
+/**
+* @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 isnan = require( '@stdlib/math/base/assert/is-nan' );
+var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
+var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
+var randu = require( '@stdlib/random/base/randu' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var ascending = require( './fixtures/ascending.js' );
+var num2str = require( './fixtures/num2str.js' );
+var dsortmg = require( './../lib/main.js' );
+
+
+// TESTS //
+
+tape( 'main export is a function', function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof dsortmg, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'the function has an arity of 6', function test( t ) {
+ t.strictEqual( dsortmg.length, 6, 'has expected arity' );
+ t.end();
+});
+
+tape( 'the function sorts a strided array (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var i;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ x[ i ] = (randu()*20.0) - 10.0;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var i;
+ var j;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ x[ i ] = (randu()*20.0) - 10.0;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array which includes NaNs (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var v;
+ var i;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ if ( randu() < 0.2 ) {
+ v = NaN;
+ } else {
+ v = (randu()*20.0) - 10.0;
+ }
+ x[ i ] = v;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array which includes NaNs (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var v;
+ var i;
+ var j;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ if ( randu() < 0.2 ) {
+ v = NaN;
+ } else {
+ v = (randu()*20.0) - 10.0;
+ }
+ x[ i ] = v;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array which includes positive and negative zeros (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var v;
+ var i;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ if ( randu() < 0.5 ) {
+ v = -0.0;
+ } else {
+ v = 0.0;
+ }
+ x[ i ] = v;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array which includes positive and negative zeros (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var v;
+ var i;
+ var j;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ if ( randu() < 0.5 ) {
+ v = -0.0;
+ } else {
+ v = 0.0;
+ }
+ x[ i ] = v;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array (increasing order; special cases)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var i;
+
+ x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+
+ x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+
+ x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array (decreasing order; special cases)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var i;
+ var j;
+
+ x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+
+ x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+
+ x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, w, 1 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function returns a reference to the input array', function test( t ) {
+ var out;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
+ w = new Float64Array( x.length );
+ out = dsortmg( x.length, 1.0, x, 1, w, 1 );
+
+ t.strictEqual( out, x, 'same reference' );
+ t.end();
+});
+
+tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 3.0, -4.0, 1.0 ] );
+ w = new Float64Array( x.length );
+ expected = new Float64Array( [ 3.0, -4.0, 1.0 ] );
+
+ dsortmg( 0, 1.0, x, 1, w, 1 );
+ t.deepEqual( x, expected, 'returns expected value' );
+
+ dsortmg( -4, 1.0, x, 1, w, 1 );
+ t.deepEqual( x, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'if `order` equals `0`, the function returns `x` unchanged', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] );
+ w = new Float64Array( x.length );
+ expected = new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] );
+
+ dsortmg( x.length, 0.0, x, 1, w, 1 );
+ t.deepEqual( x, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function supports specifying a stride (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 2.0, // 0
+ -3.0,
+ -5.0, // 1
+ 7.0,
+ 6.0 // 2
+ ]);
+ expected = new Float64Array([
+ -5.0, // 0
+ -3.0,
+ 2.0, // 1
+ 7.0,
+ 6.0 // 2
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, 1.0, x, 2, w, 1 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a stride (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 2.0, // 0
+ -3.0,
+ -5.0, // 1
+ 7.0,
+ 6.0 // 2
+ ]);
+ expected = new Float64Array([
+ 6.0, // 0
+ -3.0,
+ 2.0, // 1
+ 7.0,
+ -5.0 // 2
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, -1.0, x, 2, w, 1 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a negative stride (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 2.0, // 2
+ -3.0,
+ -5.0, // 1
+ 7.0,
+ 6.0 // 0
+ ]);
+ expected = new Float64Array([
+ 6.0, // 2
+ -3.0,
+ 2.0, // 1
+ 7.0,
+ -5.0 // 0
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, 1.0, x, -2, w, 1 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a negative stride (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 2.0, // 2
+ -3.0,
+ -5.0, // 1
+ 7.0,
+ 6.0 // 0
+ ]);
+ expected = new Float64Array([
+ -5.0, // 2
+ -3.0,
+ 2.0, // 1
+ 7.0,
+ 6.0 // 0
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, -1.0, x, -2, w, 1 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a workspace stride', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 2.0, -3.0, -5.0, 7.0, 6.0 ] );
+ expected = new Float64Array( [ -5.0, -3.0, 2.0, 6.0, 7.0 ] );
+ w = new Float64Array( ( x.length*2 ) - 1 );
+
+ dsortmg( x.length, 1.0, x, 1, w, 2 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a negative workspace stride', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 2.0, -3.0, -5.0, 7.0, 6.0 ] );
+ expected = new Float64Array( [ -5.0, -3.0, 2.0, 6.0, 7.0 ] );
+ w = new Float64Array( x.length );
+
+ dsortmg( x.length, 1.0, x, 1, w, -1 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports view offsets (increasing order)', function test( t ) {
+ var expected;
+ var x0;
+ var x1;
+ var w;
+
+ x0 = new Float64Array([
+ 1.0,
+ -2.0, // 0
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -6.0 // 2
+ ]);
+ expected = new Float64Array([
+ 1.0,
+ -6.0, // 0
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -2.0 // 2
+ ]);
+ w = new Float64Array( 3 );
+
+ x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
+
+ dsortmg( 3, 1.0, x1, 2, w, 1 );
+ t.deepEqual( x0, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports view offsets (decreasing order)', function test( t ) {
+ var expected;
+ var x0;
+ var x1;
+ var w;
+
+ x0 = new Float64Array([
+ 1.0,
+ -6.0, // 0
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -2.0 // 2
+ ]);
+ expected = new Float64Array([
+ 1.0,
+ -2.0, // 0
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -6.0 // 2
+ ]);
+ w = new Float64Array( 3 );
+
+ x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
+
+ dsortmg( 3, -1.0, x1, 2, w, 1 );
+ t.deepEqual( x0, expected, 'returns expected value' );
+ t.end();
+});
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/test.ndarray.js
new file mode 100644
index 000000000000..49848ef20119
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsortmg/test/test.ndarray.js
@@ -0,0 +1,706 @@
+/**
+* @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 isnan = require( '@stdlib/math/base/assert/is-nan' );
+var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
+var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
+var randu = require( '@stdlib/random/base/randu' );
+var Float64Array = require( '@stdlib/array/float64' );
+var dcopy = require( '@stdlib/blas/base/dcopy' );
+var ascending = require( './fixtures/ascending.js' );
+var num2str = require( './fixtures/num2str.js' );
+var dsortmg = require( './../lib/ndarray.js' );
+
+
+// TESTS //
+
+tape( 'main export is a function', function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof dsortmg, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'the function has an arity of 8', function test( t ) {
+ t.strictEqual( dsortmg.length, 8, 'has expected arity' );
+ t.end();
+});
+
+tape( 'the function sorts a strided array (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var i;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ x[ i ] = (randu()*20.0) - 10.0;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var i;
+ var j;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ x[ i ] = (randu()*20.0) - 10.0;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array which includes NaNs (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var v;
+ var i;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ if ( randu() < 0.2 ) {
+ v = NaN;
+ } else {
+ v = (randu()*20.0) - 10.0;
+ }
+ x[ i ] = v;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array which includes NaNs (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var v;
+ var i;
+ var j;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ if ( randu() < 0.2 ) {
+ v = NaN;
+ } else {
+ v = (randu()*20.0) - 10.0;
+ }
+ x[ i ] = v;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array which includes positive and negative zeros (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var v;
+ var i;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ if ( randu() < 0.5 ) {
+ v = -0.0;
+ } else {
+ v = 0.0;
+ }
+ x[ i ] = v;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array which includes positive and negative zeros (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var v;
+ var i;
+ var j;
+
+ x = new Float64Array( 1e2 );
+ for ( i = 0; i < x.length; i++ ) {
+ if ( randu() < 0.5 ) {
+ v = -0.0;
+ } else {
+ v = 0.0;
+ }
+ x[ i ] = v;
+ }
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array (increasing order; special cases)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var i;
+
+ x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+
+ x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+
+ x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, 1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ if ( isnan( expected[ i ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ } else if ( isNegativeZero( expected[ i ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[i] )+'.' );
+ } else if ( isPositiveZero( expected[ i ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[i]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ i ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[i]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function sorts a strided array (decreasing order; special cases)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+ var i;
+ var j;
+
+ x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0 ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+
+ x = new Float64Array( [ 1.0, -1.0, 2.0, 2.0, NaN ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+
+ x = new Float64Array( [ NaN, 1.0, -1.0, 2.0, 2.0, NaN ] );
+ w = new Float64Array( x.length );
+
+ // Note: we assume that the built-in sort returns a correctly sorted result
+ expected = dcopy( x.length, x, 1, new Float64Array( x.length ), 1 );
+ expected.sort( ascending );
+
+ dsortmg( x.length, -1.0, x, 1, 0, w, 1, 0 );
+ for ( i = 0; i < expected.length; i++ ) {
+ j = expected.length - i - 1;
+ if ( isnan( expected[ j ] ) ) {
+ t.strictEqual( isnan( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ } else if ( isNegativeZero( expected[ j ] ) ) {
+ t.strictEqual( isNegativeZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+num2str( expected[j] )+'.' );
+ } else if ( isPositiveZero( expected[ j ] ) ) {
+ t.strictEqual( isPositiveZero( x[ i ] ), true, 'returns expected value. index: '+i+'. actual: '+num2str( x[i] )+'. expected: '+expected[j]+'.' );
+ } else {
+ t.strictEqual( x[ i ], expected[ j ], 'returns expected value. index: '+i+' actual: '+x[i]+'. expected: '+expected[j]+'.' );
+ }
+ }
+ t.end();
+});
+
+tape( 'the function returns a reference to the input array', function test( t ) {
+ var out;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
+ w = new Float64Array( x.length );
+ out = dsortmg( x.length, 1.0, x, 1, 0, w, 1, 0 );
+
+ t.strictEqual( out, x, 'same reference' );
+ t.end();
+});
+
+tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 3.0, -4.0, 1.0 ] );
+ w = new Float64Array( x.length );
+ expected = new Float64Array( [ 3.0, -4.0, 1.0 ] );
+
+ dsortmg( 0, 1.0, x, 1, 0, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+
+ dsortmg( -4, 1.0, x, 1, 0, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'if `order` equals `0`, the function returns `x` unchanged', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] );
+ w = new Float64Array( x.length );
+ expected = new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] );
+
+ dsortmg( x.length, 0.0, x, 1, 0, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function supports specifying a stride (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 2.0, // 0
+ -3.0,
+ -5.0, // 1
+ 7.0,
+ 6.0 // 2
+ ]);
+ expected = new Float64Array([
+ -5.0, // 0
+ -3.0,
+ 2.0, // 1
+ 7.0,
+ 6.0 // 2
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, 1.0, x, 2, 0, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a stride (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 2.0, // 0
+ -3.0,
+ -5.0, // 1
+ 7.0,
+ 6.0 // 2
+ ]);
+ expected = new Float64Array([
+ 6.0, // 0
+ -3.0,
+ 2.0, // 1
+ 7.0,
+ -5.0 // 2
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, -1.0, x, 2, 0, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a negative stride (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 2.0, // 2
+ -3.0,
+ -5.0, // 1
+ 7.0,
+ 6.0 // 0
+ ]);
+ expected = new Float64Array([
+ 6.0, // 2
+ -3.0,
+ 2.0, // 1
+ 7.0,
+ -5.0 // 0
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, 1.0, x, -2, x.length-1, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a negative stride (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 2.0, // 2
+ -3.0,
+ -5.0, // 1
+ 7.0,
+ 6.0 // 0
+ ]);
+ expected = new Float64Array([
+ -5.0, // 2
+ -3.0,
+ 2.0, // 1
+ 7.0,
+ 6.0 // 0
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, -1.0, x, -2, x.length-1, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying an offset (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 1.0,
+ -2.0, // 0
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -6.0 // 2
+ ]);
+ expected = new Float64Array([
+ 1.0,
+ -6.0, // 0
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -2.0 // 2
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, 1.0, x, 2, 1, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying an offset (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 1.0,
+ -6.0, // 0
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -2.0 // 2
+ ]);
+ expected = new Float64Array([
+ 1.0,
+ -2.0, // 0
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -6.0 // 2
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, -1.0, x, 2, 1, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a workspace stride', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 2.0, -3.0, -5.0, 7.0, 6.0 ] );
+ expected = new Float64Array( [ -5.0, -3.0, 2.0, 6.0, 7.0 ] );
+ w = new Float64Array( ( x.length*2 ) - 1 );
+
+ dsortmg( x.length, 1.0, x, 1, 0, w, 2, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a negative workspace stride', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 2.0, -3.0, -5.0, 7.0, 6.0 ] );
+ expected = new Float64Array( [ -5.0, -3.0, 2.0, 6.0, 7.0 ] );
+ w = new Float64Array( x.length );
+
+ dsortmg( x.length, 1.0, x, 1, 0, w, -1, x.length-1 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying a workspace offset', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array( [ 2.0, -3.0, -5.0, 7.0, 6.0 ] );
+ expected = new Float64Array( [ -5.0, -3.0, 2.0, 6.0, 7.0 ] );
+ w = new Float64Array( x.length+2 );
+
+ dsortmg( x.length, 1.0, x, 1, 0, w, 1, 2 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports complex access patterns (increasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 1.0,
+ -4.0, // 2
+ 3.0,
+ -2.0, // 1
+ 5.0,
+ -6.0 // 0
+ ]);
+ expected = new Float64Array([
+ 1.0,
+ -2.0, // 2
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -6.0 // 0
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, 1.0, x, -2, x.length-1, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports complex access patterns (decreasing order)', function test( t ) {
+ var expected;
+ var x;
+ var w;
+
+ x = new Float64Array([
+ 1.0,
+ -2.0, // 2
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -6.0 // 0
+ ]);
+ expected = new Float64Array([
+ 1.0,
+ -6.0, // 2
+ 3.0,
+ -4.0, // 1
+ 5.0,
+ -2.0 // 0
+ ]);
+ w = new Float64Array( 3 );
+
+ dsortmg( 3, -1.0, x, -2, x.length-1, w, 1, 0 );
+ t.deepEqual( x, expected, 'returns expected value' );
+ t.end();
+});