diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md
index 11740f4e8611..87e9ecafe4aa 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md
@@ -32,7 +32,7 @@ var dsort2hp = require( '@stdlib/blas/ext/base/dsort2hp' );
#### dsort2hp( N, order, x, strideX, y, strideY )
-Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array `x` using heapsort.
+Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort.
```javascript
var Float64Array = require( '@stdlib/array/float64' );
@@ -54,11 +54,11 @@ The function has the following parameters:
- **N**: number of indexed elements.
- **order**: sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged.
- **x**: first input [`Float64Array`][@stdlib/array/float64].
-- **strideX**: `x` index increment.
+- **strideX**: stride length for `x`.
- **y**: second input [`Float64Array`][@stdlib/array/float64].
-- **strideY**: `y` index increment.
+- **strideY**: stride length for `y`.
-The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to sort every other element
+The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to sort every other element:
```javascript
var Float64Array = require( '@stdlib/array/float64' );
@@ -104,7 +104,7 @@ console.log( y0 );
#### dsort2hp.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY )
-Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array `x` using heapsort and alternative indexing semantics.
+Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort and alternative indexing semantics.
```javascript
var Float64Array = require( '@stdlib/array/float64' );
@@ -123,10 +123,10 @@ console.log( y );
The function has the following additional parameters:
-- **offsetX**: `x` starting index.
-- **offsetY**: `y` starting index.
+- **offsetX**: starting index for `x`.
+- **offsetY**: starting index for `y`.
-While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x`
+While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to access only the last three elements:
```javascript
var Float64Array = require( '@stdlib/array/float64' );
@@ -169,30 +169,15 @@ console.log( y );
```javascript
-var round = require( '@stdlib/math/base/special/round' );
-var randu = require( '@stdlib/random/base/randu' );
-var Float64Array = require( '@stdlib/array/float64' );
+var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var dsort2hp = require( '@stdlib/blas/ext/base/dsort2hp' );
-var rand;
-var sign;
-var x;
-var y;
-var i;
-
-x = new Float64Array( 10 );
-y = new Float64Array( 10 ); // index array
-for ( i = 0; i < x.length; i++ ) {
- rand = round( randu()*100.0 );
- sign = randu();
- if ( sign < 0.5 ) {
- sign = -1.0;
- } else {
- sign = 1.0;
- }
- x[ i ] = sign * rand;
- y[ i ] = i;
-}
+var x = discreteUniform( 10, -100, 100, {
+ 'dtype': 'float64'
+});
+var y = discreteUniform( 10, -100, 100, {
+ 'dtype': 'float64'
+});
console.log( x );
console.log( y );
@@ -205,8 +190,139 @@ console.log( y );
+
+
* * *
+
+
+## C APIs
+
+
+
+
+
+
+
+
+
+
+
+### Usage
+
+```c
+#include "stdlib/blas/ext/base/dsort2hp.h"
+```
+
+#### stdlib_strided_dsort2hp( N, order, \*X, strideX, \*Y, strideY )
+
+Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort.
+
+```c
+double x[] = { 1.0, -2.0, 3.0, -4.0 };
+double y[] = { 0.0, 1.0, 2.0, 3.0 };
+
+stdlib_strided_dsort2hp( 4, 1.0, x, 1, y, 1 );
+```
+
+The function accepts the following arguments:
+
+- **N**: `[in] CBLAS_INT` number of indexed elements.
+- **order**: `[in] double` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged.
+- **X**: `[inout] double*` input array.
+- **strideX**: `[in] CBLAS_INT` stride length for `X`.
+- **Y**: `[inout] double*` input array.
+- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
+
+```c
+stdlib_strided_dsort2hp( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, double *Y, CBLAS_INT strideY );
+```
+
+
+
+#### stdlib_strided_dsort2hp_ndarray( N, order, \*X, strideX, offsetX, \*Y, strideY, offsetY )
+
+
+
+Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort and alternative indexing semantics.
+
+```c
+double x[] = { 1.0, -2.0, 3.0, -4.0 };
+double y[] = { 0.0, 1.0, 2.0, 3.0 };
+
+stdlib_strided_dsort2hp_ndarray( 4, 1.0, x, 1, 0, y, 1, 0 );
+```
+
+The function accepts the following arguments:
+
+- **N**: `[in] CBLAS_INT` number of indexed elements.
+- **order**: `[in] double` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged..
+- **X**: `[inout] double*` input array.
+- **strideX**: `[in] CBLAS_INT` stride length for `X`.
+- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
+- **Y**: `[inout] double*` input array.
+- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
+- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
+
+```c
+stdlib_strided_dsort2hp_ndarray( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX, double *Y, CBLAS_INT strideY, CBLAS_INT offsetY );
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+### Examples
+
+```c
+#include "stdlib/blas/ext/base/dsort2hp.h"
+#include
+
+int main( void ) {
+ // Create strided arrays:
+ double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 };
+ double y[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 };
+
+ // Specify the number of elements:
+ int N = 8;
+
+ // Specify the strides:
+ int strideX = 1;
+ int strideY = 1;
+
+ // Sort the arrays:
+ stdlib_strided_dsort2hp( N, 1.0, x, strideX, y, strideY );
+
+ // Print the result:
+ for ( int i = 0; i < 8; i++ ) {
+ printf( "x[ %i ] = %lf\n", i, x[ i ] );
+ printf( "y[ %i ] = %lf\n", i, y[ i ] );
+ }
+}
+```
+
+
+
+
+
+
+
+
+
## References
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/Makefile
new file mode 100644
index 000000000000..88c218ce50fa
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/Makefile
@@ -0,0 +1,146 @@
+#/
+# @license Apache-2.0
+#
+# Copyright (c) 2025 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.
+#/
+
+# VARIABLES #
+
+ifndef VERBOSE
+ QUIET := @
+else
+ QUIET :=
+endif
+
+# Determine the OS ([1][1], [2][2]).
+#
+# [1]: https://en.wikipedia.org/wiki/Uname#Examples
+# [2]: http://stackoverflow.com/a/27776822/2225624
+OS ?= $(shell uname)
+ifneq (, $(findstring MINGW,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring MSYS,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring CYGWIN,$(OS)))
+ OS := WINNT
+else
+ifneq (, $(findstring Windows_NT,$(OS)))
+ OS := WINNT
+endif
+endif
+endif
+endif
+
+# Define the program used for compiling C source files:
+ifdef C_COMPILER
+ CC := $(C_COMPILER)
+else
+ CC := gcc
+endif
+
+# Define the command-line options when compiling C files:
+CFLAGS ?= \
+ -std=c99 \
+ -O3 \
+ -Wall \
+ -pedantic
+
+# Determine whether to generate position independent code ([1][1], [2][2]).
+#
+# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
+# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
+ifeq ($(OS), WINNT)
+ fPIC ?=
+else
+ fPIC ?= -fPIC
+endif
+
+# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
+INCLUDE ?=
+
+# List of source files:
+SOURCE_FILES ?=
+
+# List of libraries (e.g., `-lopenblas -lpthread`):
+LIBRARIES ?=
+
+# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
+LIBPATH ?=
+
+# List of C targets:
+c_targets := benchmark.unsorted_random.length.out
+
+
+# RULES #
+
+#/
+# Compiles source files.
+#
+# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
+# @param {string} [CFLAGS] - C compiler options
+# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
+# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
+# @param {string} [SOURCE_FILES] - list of source files
+# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
+# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
+#
+# @example
+# make
+#
+# @example
+# make all
+#/
+all: $(c_targets)
+
+.PHONY: all
+
+#/
+# Compiles C source files.
+#
+# @private
+# @param {string} CC - C compiler (e.g., `gcc`)
+# @param {string} CFLAGS - C compiler options
+# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
+# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
+# @param {string} SOURCE_FILES - list of source files
+# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
+# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
+#/
+$(c_targets): %.out: %.c
+ $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
+
+#/
+# Runs compiled benchmarks.
+#
+# @example
+# make run
+#/
+run: $(c_targets)
+ $(QUIET) ./$<
+
+.PHONY: run
+
+#/
+# Removes generated files.
+#
+# @example
+# make clean
+#/
+clean:
+ $(QUIET) -rm -f *.o *.out
+
+.PHONY: clean
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/benchmark.unsorted_random.length.c
new file mode 100644
index 000000000000..9b862c5286dd
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/benchmark.unsorted_random.length.c
@@ -0,0 +1,203 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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.
+*/
+
+#include "stdlib/blas/ext/base/dsort2hp.h"
+#include
+#include
+#include
+#include
+#include
+
+#define NAME "dsort2hp"
+#define ITERATIONS 10000000
+#define REPEATS 3
+#define MIN 1
+#define MAX 6
+
+/**
+* Prints the TAP version.
+*/
+static void print_version( void ) {
+ printf( "TAP version 13\n" );
+}
+
+/**
+* Prints the TAP summary.
+*
+* @param total total number of tests
+* @param passing total number of passing tests
+*/
+static void print_summary( int total, int passing ) {
+ printf( "#\n" );
+ printf( "1..%d\n", total ); // TAP plan
+ printf( "# total %d\n", total );
+ printf( "# pass %d\n", passing );
+ printf( "#\n" );
+ printf( "# ok\n" );
+}
+
+/**
+* Prints benchmarks results.
+*
+* @param iterations number of iterations
+* @param elapsed elapsed time in seconds
+*/
+static void print_results( int iterations, double elapsed ) {
+ double rate = (double)iterations / elapsed;
+ printf( " ---\n" );
+ printf( " iterations: %d\n", iterations );
+ printf( " elapsed: %0.9f\n", elapsed );
+ printf( " rate: %0.9f\n", rate );
+ printf( " ...\n" );
+}
+
+/**
+* Returns a clock time.
+*
+* @return clock time
+*/
+static double tic( void ) {
+ struct timeval now;
+ gettimeofday( &now, NULL );
+ return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
+}
+
+/**
+* Generates a random number on the interval [0,1).
+*
+* @return random number
+*/
+static double rand_double( void ) {
+ int r = rand();
+ return (double)r / ( (double)RAND_MAX + 1.0 );
+}
+
+/**
+* Runs a benchmark.
+*
+* @param iterations number of iterations
+* @param len array length
+* @return elapsed time in seconds
+*/
+static double benchmark1( int iterations, int len ) {
+ double elapsed;
+ double *x;
+ double *y;
+ double t;
+ int i;
+
+ x = (double *)malloc( len * sizeof(double) );
+ y = (double *)malloc( len * sizeof(double) );
+ for ( i = 0; i < len; i++ ) {
+ x[ i ] = ( rand_double()*20.0 ) - 10.0;
+ y[ i ] = ( rand_double()*20.0 ) - 10.0;
+ }
+ t = tic();
+ for ( i = 0; i < iterations; i++ ) {
+ stdlib_strided_dsort2hp( len, 1.0, x, 1, y, 1 );
+ if ( y[ 0 ] != y[ 0 ] ) {
+ printf( "should not return NaN\n" );
+ break;
+ }
+ }
+ elapsed = tic() - t;
+ if ( y[ 0 ] != y[ 0 ] ) {
+ printf( "should not return NaN\n" );
+ }
+ free( x );
+ free( y );
+ return elapsed;
+}
+
+/**
+* Runs a benchmark.
+*
+* @param iterations number of iterations
+* @param len array length
+* @return elapsed time in seconds
+*/
+static double benchmark2( int iterations, int len ) {
+ double elapsed;
+ double *x;
+ double *y;
+ double t;
+ int i;
+
+ x = (double *)malloc( len * sizeof(double) );
+ y = (double *)malloc( len * sizeof(double) );
+ for ( i = 0; i < len; i++ ) {
+ x[ i ] = ( rand_double()*20.0 ) - 10.0;
+ y[ i ] = ( rand_double()*20.0 ) - 10.0;
+ }
+ t = tic();
+ for ( i = 0; i < iterations; i++ ) {
+ stdlib_strided_dsort2hp_ndarray( len, 1.0, x, 1, 0, y, 1, 0 );
+ if ( y[ 0 ] != y[ 0 ] ) {
+ printf( "should not return NaN\n" );
+ break;
+ }
+ }
+ elapsed = tic() - t;
+ if ( y[ 0 ] != y[ 0 ] ) {
+ printf( "should not return NaN\n" );
+ }
+ free( x );
+ free( y );
+ return elapsed;
+}
+
+/**
+* Main execution sequence.
+*/
+int main( void ) {
+ double elapsed;
+ int count;
+ int iter;
+ int len;
+ int i;
+ int j;
+
+ // Use the current time to seed the random number generator:
+ srand( time( NULL ) );
+
+ print_version();
+ count = 0;
+ for ( i = MIN; i <= MAX; i++ ) {
+ len = pow( 10, i );
+ iter = ITERATIONS / pow( 10, i-1 );
+ for ( j = 0; j < REPEATS; j++ ) {
+ count += 1;
+ printf( "# c::%s:unsorted,random:len=%d\n", NAME, len );
+ elapsed = benchmark1( iter, len );
+ print_results( iter, elapsed );
+ printf( "ok %d benchmark finished\n", count );
+ }
+ }
+ for ( i = MIN; i <= MAX; i++ ) {
+ len = pow( 10, i );
+ iter = ITERATIONS / pow( 10, i-1 );
+ for ( j = 0; j < REPEATS; j++ ) {
+ count += 1;
+ printf( "# c::%s:ndarray:unsorted,random:len=%d\n", NAME, len );
+ elapsed = benchmark2( iter, len );
+ print_results( iter, elapsed );
+ printf( "ok %d benchmark finished\n", count );
+ }
+ }
+ print_summary( count, count );
+}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/docs/repl.txt
index 9a7a56b1d6b4..1100cfa9997d 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/docs/repl.txt
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/docs/repl.txt
@@ -3,8 +3,8 @@
Simultaneously sorts two double-precision floating-point strided arrays
based on the sort order of the first array using heapsort.
- The `N` and `stride` parameters determine which elements in `x` and `y` are
- accessed at runtime.
+ The `N` and stride parameters determine which elements in the strided arrays
+ are accessed at runtime.
Indexing is relative to the first index. To introduce an offset, use typed
array views.
@@ -41,13 +41,13 @@
First input array.
strideX: integer
- Index increment for `x`.
+ Stride length for `x`.
y: Float64Array
Second input array.
strideY: integer
- Index increment for `y`.
+ Stride length for `y`.
Returns
-------
@@ -64,11 +64,10 @@
> y
[ 3.0, 1.0, 0.0, 2.0 ]
- // Using `N` and `stride` parameters:
+ // Using `N` and stride parameters:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> y = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] );
- > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
- > {{alias}}( N, -1, x, 2, y, 2 )
+ > {{alias}}( 2, -1, x, 2, y, 2 )
[ 3.0, -2.0, 1.0, -4.0 ]
> y
[ 2.0, 1.0, 0.0, 3.0 ]
@@ -78,22 +77,22 @@
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var y0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] );
> var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 );
- > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
- > {{alias}}( N, 1, x1, 2, y1, 2 )
+ > {{alias}}( 2, 1, x1, 2, y1, 2 )
[ -4.0, 3.0, -2.0 ]
> x0
[ 1.0, -4.0, 3.0, -2.0 ]
> y0
[ 0.0, 3.0, 2.0, 1.0 ]
+
{{alias}}.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY )
Simultaneously sorts two double-precision floating-point strided arrays
based on the sort order of the first array using heapsort 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.
+ buffer, the offset parameters support indexing semantics based on starting
+ indices.
Parameters
----------
@@ -108,7 +107,7 @@
First input array.
strideX: integer
- Index increment for `x`.
+ Stride length for `x`.
offsetX: integer
Starting index of `x`.
@@ -117,7 +116,7 @@
Second input array.
strideY: integer
- Index increment for `y`.
+ Stride length for `y`.
offsetY: integer
Starting index of `y`.
@@ -140,8 +139,7 @@
// Using an index offset:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> y = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] );
- > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
- > {{alias}}.ndarray( N, 1, x, 2, 1, y, 2, 1 )
+ > {{alias}}.ndarray( 2, 1, x, 2, 1, y, 2, 1 )
[ 1.0, -4.0, 3.0, -2.0 ]
> y
[ 0.0, 3.0, 2.0, 1.0 ]
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/docs/types/index.d.ts
index c713f4618027..19e4097d507e 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/docs/types/index.d.ts
@@ -28,9 +28,9 @@ interface Routine {
* @param N - number of indexed elements
* @param order - sort order
* @param x - first input array
- * @param strideX - `x` stride length
+ * @param strideX - stride length for `x`
* @param y - second input array
- * @param strideY - `y` stride length
+ * @param strideY - stride length for `y`
* @returns `x`
*
* @example
@@ -55,11 +55,11 @@ interface Routine {
* @param N - number of indexed elements
* @param order - sort order
* @param x - first input array
- * @param strideX - `x` stride length
- * @param offsetX - `x` starting index
+ * @param strideX - stride length for `x`
+ * @param offsetX - starting index for `x`
* @param y - second input array
- * @param strideY - `y` stride length
- * @param offsetY - `y` starting index
+ * @param strideY - stride length for `y`
+ * @param offsetY - starting index for `y`
* @returns `x`
*
* @example
@@ -85,9 +85,9 @@ interface Routine {
* @param N - number of indexed elements
* @param order - sort order
* @param x - first input array
-* @param strideX - `x` stride length
+* @param strideX - stride length for `x`
* @param y - second input array
-* @param strideY - `y` stride length
+* @param strideY - stride length for `y`
* @returns `x`
*
* @example
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/examples/c/example.c
index adcd4788c1aa..e792d68ec63d 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/examples/c/example.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/examples/c/example.c
@@ -18,7 +18,6 @@
#include "stdlib/blas/ext/base/dsort2hp.h"
#include
-#include
int main( void ) {
// Create strided arrays:
@@ -28,16 +27,16 @@ int main( void ) {
// Specify the number of elements:
int N = 8;
- // Specify strides:
+ // Specify the strides:
int strideX = 1;
int strideY = 1;
// Sort the arrays:
- c_dsort2hp( N, 1.0, x, strideX, y, strideY );
+ stdlib_strided_dsort2hp( N, 1.0, x, strideX, y, strideY );
// Print the result:
for ( int i = 0; i < 8; i++ ) {
printf( "x[ %i ] = %lf\n", i, x[ i ] );
- printf( "y[ %i ] = %"PRId64"\n", i, (int64_t)y[ i ] );
+ printf( "y[ %i ] = %lf\n", i, y[ i ] );
}
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/examples/index.js
index 9c5c6e5041bb..fefb61da32ea 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/examples/index.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/examples/index.js
@@ -18,34 +18,15 @@
'use strict';
-var round = require( '@stdlib/math/base/special/round' );
-var randu = require( '@stdlib/random/base/randu' );
-var Float64Array = require( '@stdlib/array/float64' );
-var dsort2hp = require( './../lib' );
+var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
+var dsort2hp = require( '@stdlib/blas/ext/base/dsort2hp' );
-var rand;
-var sign;
-var x;
-var y;
-var i;
-
-x = new Float64Array( 10 );
-y = new Float64Array( 10 ); // index array
-for ( i = 0; i < x.length; i++ ) {
- if ( randu() < 0.2 ) {
- x[ i ] = NaN;
- } else {
- rand = round( randu()*100.0 );
- sign = randu();
- if ( sign < 0.5 ) {
- sign = -1.0;
- } else {
- sign = 1.0;
- }
- x[ i ] = sign * rand;
- }
- y[ i ] = i;
-}
+var x = discreteUniform( 10, -100, 100, {
+ 'dtype': 'float64'
+});
+var y = discreteUniform( 10, -100, 100, {
+ 'dtype': 'float64'
+});
console.log( x );
console.log( y );
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/include/stdlib/blas/ext/base/dsort2hp.h b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/include/stdlib/blas/ext/base/dsort2hp.h
index 13a24f084e86..a911b4fe228a 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/include/stdlib/blas/ext/base/dsort2hp.h
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/include/stdlib/blas/ext/base/dsort2hp.h
@@ -19,7 +19,7 @@
#ifndef STDLIB_BLAS_EXT_BASE_DSORT2HP_H
#define STDLIB_BLAS_EXT_BASE_DSORT2HP_H
-#include
+#include "stdlib/blas/base/shared.h"
/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
@@ -31,7 +31,12 @@ extern "C" {
/**
* Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort.
*/
-void c_dsort2hp( const int64_t N, const double order, double *X, const int64_t strideX, double *Y, const int64_t strideY );
+void API_SUFFIX(stdlib_strided_dsort2hp)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
+
+/**
+* Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort and alternative indexing semantics.
+*/
+void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
#ifdef __cplusplus
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/dsort2hp.js b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/dsort2hp.js
index fcb8747f097e..6f154eb96db2 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/dsort2hp.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/dsort2hp.js
@@ -20,9 +20,8 @@
// MODULES //
-var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
-var isnan = require( '@stdlib/math/base/assert/is-nan' );
-var floor = require( '@stdlib/math/base/special/floor' );
+var stride2offset = require( '@stdlib/strided/base/stride2offset' );
+var ndarray = require( './ndarray.js' );
// MAIN //
@@ -42,9 +41,9 @@ var floor = require( '@stdlib/math/base/special/floor' );
* @param {PositiveInteger} N - number of indexed elements
* @param {number} order - sort order
* @param {Float64Array} x - first input array
-* @param {integer} strideX - `x` index increment
+* @param {integer} strideX - stride length for `x`
* @param {Float64Array} y - second input array
-* @param {integer} strideY - `y` index increment
+* @param {integer} strideY - stride length for `y`
* @returns {Float64Array} `x`
*
* @example
@@ -62,110 +61,7 @@ var floor = require( '@stdlib/math/base/special/floor' );
* // => [ 3.0, 1.0, 0.0, 2.0 ]
*/
function dsort2hp( N, order, x, strideX, y, strideY ) {
- var offsetX;
- var offsetY;
- var parent;
- var child;
- var v1;
- var v2;
- var tx;
- var ty;
- var ix;
- var iy;
- var n;
- var j;
- var k;
-
- 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;
- strideY *= -1;
- }
- if ( strideX < 0 ) {
- offsetX = (1-N) * strideX;
- } else {
- offsetX = 0;
- }
- if ( strideY < 0 ) {
- offsetY = (1-N) * strideY;
- } else {
- offsetY = 0;
- }
- // Set the initial heap size:
- n = N;
-
- // Specify an initial "parent" index for building the heap:
- parent = floor( N / 2 );
-
- // Continue looping until the array is sorted...
- while ( true ) {
- if ( parent > 0 ) {
- // We need to build the heap...
- parent -= 1;
- tx = x[ offsetX+(parent*strideX) ];
- ty = y[ offsetY+(parent*strideY) ];
- } else {
- // Reduce the heap size:
- n -= 1;
-
- // Check if the heap is empty, and, if so, we are finished sorting...
- if ( n === 0 ) {
- return x;
- }
- // Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position:
- ix = offsetX + (n*strideX);
- tx = x[ ix ];
- iy = offsetY + (n*strideY);
- ty = y[ iy ];
-
- // Move the heap root to its sorted position:
- x[ ix ] = x[ offsetX ];
- y[ iy ] = y[ offsetY ];
- }
- // We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property...
-
- // Start at the parent index:
- j = parent;
-
- // Get the "left" child index:
- child = (j*2) + 1;
-
- while ( child < n ) {
- // Find the largest child...
- k = child + 1;
- if ( k < n ) {
- v1 = x[ offsetX+(k*strideX) ];
- v2 = x[ offsetX+(child*strideX) ];
-
- // Check if a "right" child exists and is "bigger"...
- if ( v1 > v2 || isnan( v1 ) || (v1 === v2 && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len
- child += 1;
- }
- }
- // Check if the largest child is bigger than `t`...
- v1 = x[ offsetX+(child*strideX) ];
- if ( v1 > tx || isnan( v1 ) || ( v1 === tx && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len
- // Insert the larger child value:
- x[ offsetX+(j*strideX) ] = v1;
- y[ offsetY+(j*strideY) ] = y[ offsetY+(child*strideY) ];
-
- // Update `j` to point to the child index:
- j = child;
-
- // Get the "left" child index and repeat...
- child = (j*2) + 1;
- } else {
- // We've found `t`'s place in the heap...
- break;
- }
- }
- // Insert `t` into the heap:
- x[ offsetX+(j*strideX) ] = tx;
- y[ offsetY+(j*strideY) ] = ty;
- }
+ return ndarray( N, order, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); // eslint-disable-line max-len
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/dsort2hp.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/dsort2hp.native.js
index 50ee3ab4572f..410b047872b7 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/dsort2hp.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/dsort2hp.native.js
@@ -31,9 +31,9 @@ var addon = require( './../src/addon.node' );
* @param {PositiveInteger} N - number of indexed elements
* @param {number} order - sort order
* @param {Float64Array} x - first input array
-* @param {integer} strideX - `x` index increment
+* @param {integer} strideX - stride length for `x`
* @param {Float64Array} y - second input array
-* @param {integer} strideY - `y` index increment
+* @param {integer} strideY - stride length for `y`
* @returns {Float64Array} `x`
*
* @example
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/ndarray.js
index f90bd667f33a..d1bb75ff1432 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/ndarray.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/ndarray.js
@@ -42,11 +42,11 @@ var floor = require( '@stdlib/math/base/special/floor' );
* @param {PositiveInteger} N - number of indexed elements
* @param {number} order - sort order
* @param {Float64Array} x - first input array
-* @param {integer} strideX - `x` index increment
-* @param {NonNegativeInteger} offsetX - `x` starting index
+* @param {integer} strideX - stride length for `x`
+* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {Float64Array} y - second input array
-* @param {integer} strideY - `y` index increment
-* @param {NonNegativeInteger} offsetY - `y` starting index
+* @param {integer} strideY - stride length for `y`
+* @param {NonNegativeInteger} offsetY - starting index for `y`
* @returns {Float64Array} `x`
*
* @example
@@ -154,6 +154,7 @@ function dsort2hp( N, order, x, strideX, offsetX, y, strideY, offsetY ) {
break;
}
}
+
// Insert `t` into the heap:
x[ offsetX+(j*strideX) ] = tx;
y[ offsetY+(j*strideY) ] = ty;
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/ndarray.native.js
index b679af1b89ed..6fa6c8cd3534 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/ndarray.native.js
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/lib/ndarray.native.js
@@ -20,8 +20,7 @@
// MODULES //
-var Float64Array = require( '@stdlib/array/float64' );
-var addon = require( './dsort2hp.native.js' );
+var addon = require( './../src/addon.node' );
// MAIN //
@@ -32,11 +31,11 @@ var addon = require( './dsort2hp.native.js' );
* @param {PositiveInteger} N - number of indexed elements
* @param {number} order - sort order
* @param {Float64Array} x - first input array
-* @param {integer} strideX - `x` index increment
-* @param {NonNegativeInteger} offsetX - `x` starting index
+* @param {integer} strideX - stride length for `x`
+* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {Float64Array} y - second input array
-* @param {integer} strideY - `y` index increment
-* @param {NonNegativeInteger} offsetY - `y` starting index
+* @param {integer} strideY - stride length for `y`
+* @param {NonNegativeInteger} offsetY - starting index for `y`
* @returns {Float64Array} `x`
*
* @example
@@ -54,23 +53,7 @@ var addon = require( './dsort2hp.native.js' );
* // => [ 3.0, 1.0, 0.0, 2.0 ]
*/
function dsort2hp( N, order, x, strideX, offsetX, y, strideY, offsetY ) {
- var viewX;
- var viewY;
- var flg;
-
- flg = 1.0;
- if ( strideX < 0 ) {
- flg *= -1.0; // reversing order
- order *= -1.0;
- strideX *= -1;
- offsetX -= (N-1) * strideX;
- }
- if ( strideY < 0 ) {
- offsetY += (N-1) * strideY;
- }
- viewX = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len
- viewY = new Float64Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len
- addon( N, order, viewX, strideX, viewY, flg*strideY );
+ addon.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY );
return x;
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/manifest.json
index 7405c35b17e2..d9a356e30bd1 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/manifest.json
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/manifest.json
@@ -1,43 +1,85 @@
{
- "options": {},
- "fields": [
- {
- "field": "src",
- "resolve": true,
- "relative": true
- },
- {
- "field": "include",
- "resolve": true,
- "relative": true
- },
- {
- "field": "libraries",
- "resolve": false,
- "relative": false
- },
- {
- "field": "libpath",
- "resolve": true,
- "relative": false
- }
- ],
- "confs": [
- {
- "src": [
- "./src/dsort2hp.c"
- ],
- "include": [
- "./include"
- ],
- "libraries": [
- "-lm"
- ],
- "libpath": [],
- "dependencies": [
- "@stdlib/math/base/assert/is-nan",
- "@stdlib/math/base/assert/is-positive-zero"
- ]
- }
- ]
+ "options": {
+ "task": "build"
+ },
+ "fields": [
+ {
+ "field": "src",
+ "resolve": true,
+ "relative": true
+ },
+ {
+ "field": "include",
+ "resolve": true,
+ "relative": true
+ },
+ {
+ "field": "libraries",
+ "resolve": false,
+ "relative": false
+ },
+ {
+ "field": "libpath",
+ "resolve": true,
+ "relative": false
+ }
+ ],
+ "confs": [
+ {
+ "task": "build",
+ "src": [
+ "./src/main.c"
+ ],
+ "include": [
+ "./include"
+ ],
+ "libraries": [],
+ "libpath": [],
+ "dependencies": [
+ "@stdlib/napi/export",
+ "@stdlib/napi/argv",
+ "@stdlib/napi/argv-int64",
+ "@stdlib/napi/argv-strided-float64array",
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/assert/is-positive-zero",
+ "@stdlib/napi/create-double",
+ "@stdlib/strided/base/stride2offset",
+ "@stdlib/blas/base/shared"
+ ]
+ },
+ {
+ "task": "benchmark",
+ "src": [
+ "./src/main.c"
+ ],
+ "include": [
+ "./include"
+ ],
+ "libraries": [],
+ "libpath": [],
+ "dependencies": [
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/assert/is-positive-zero",
+ "@stdlib/strided/base/stride2offset",
+ "@stdlib/blas/base/shared"
+ ]
+ },
+ {
+ "task": "examples",
+ "src": [
+ "./src/main.c"
+ ],
+ "include": [
+ "./include"
+ ],
+ "libraries": [],
+ "libpath": [],
+ "dependencies": [
+ "@stdlib/math/base/assert/is-nan",
+ "@stdlib/math/base/assert/is-positive-zero",
+ "@stdlib/strided/base/stride2offset",
+ "@stdlib/blas/base/shared"
+ ]
+ }
+ ]
}
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.c
new file mode 100644
index 000000000000..381c85a0fd15
--- /dev/null
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.c
@@ -0,0 +1,67 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 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.
+*/
+
+#include "stdlib/blas/ext/base/dsort2hp.h"
+#include "stdlib/blas/base/shared.h"
+#include "stdlib/napi/export.h"
+#include "stdlib/napi/argv.h"
+#include "stdlib/napi/argv_int64.h"
+#include "stdlib/napi/argv_strided_float64array.h"
+#include
+
+/**
+* Receives JavaScript callback invocation data.
+*
+* @param env environment under which the function is invoked
+* @param info callback data
+* @return Node-API value
+*/
+static napi_value addon( napi_env env, napi_callback_info info ) {
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 6 );
+ STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
+ STDLIB_NAPI_ARGV_INT64( env, order, argv, 1 );
+ STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
+ STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 );
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 );
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 );
+ API_SUFFIX(stdlib_strided_dsort2hp)( N, order, X, strideX, Y, strideY );
+ return NULL;
+}
+
+/**
+* Receives JavaScript callback invocation data.
+*
+* @param env environment under which the function is invoked
+* @param info callback data
+* @return Node-API value
+*/
+static napi_value addon_method( napi_env env, napi_callback_info info ) {
+ STDLIB_NAPI_ARGV( env, info, argv, argc, 8 );
+ STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 );
+ STDLIB_NAPI_ARGV_INT64( env, order, argv, 1 );
+ STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 );
+ STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 );
+ STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 6 );
+ STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 7 );
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 );
+ STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 5 );
+ API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( N, order, X, strideX, offsetX, Y, strideY, offsetY );
+ return NULL;
+}
+
+STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method );
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.cpp
deleted file mode 100644
index 84e4cacc9ab4..000000000000
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
-* @license Apache-2.0
-*
-* Copyright (c) 2020 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.
-*/
-
-#include "stdlib/blas/ext/base/dsort2hp.h"
-#include
-#include
-#include
-#include
-#include
-
-/**
-* Add-on namespace.
-*/
-namespace stdlib_blas_ext_base_dsort2hp {
-
- /**
- * Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort.
- *
- * ## Notes
- *
- * - When called from JavaScript, the function expects six arguments:
- *
- * - `N`: number of indexed elements
- * - `order`: sort order
- * - `X`: first input array
- * - `strideX`: `X` stride length
- * - `Y`: second input array
- * - `strideY`: `Y` stride length
- */
- napi_value node_dsort2hp( napi_env env, napi_callback_info info ) {
- napi_status status;
-
- size_t argc = 6;
- napi_value argv[ 6 ];
- status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr );
- assert( status == napi_ok );
-
- if ( argc < 6 ) {
- napi_throw_error( env, nullptr, "invalid invocation. Must provide 6 arguments." );
- return nullptr;
- }
-
- napi_valuetype vtype0;
- status = napi_typeof( env, argv[ 0 ], &vtype0 );
- assert( status == napi_ok );
- if ( vtype0 != napi_number ) {
- napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." );
- return nullptr;
- }
-
- napi_valuetype vtype1;
- status = napi_typeof( env, argv[ 1 ], &vtype1 );
- assert( status == napi_ok );
- if ( vtype1 != napi_number ) {
- napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." );
- return nullptr;
- }
-
- bool res2;
- status = napi_is_typedarray( env, argv[ 2 ], &res2 );
- assert( status == napi_ok );
- if ( res2 == false ) {
- napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." );
- return nullptr;
- }
-
- napi_valuetype vtype3;
- status = napi_typeof( env, argv[ 3 ], &vtype3 );
- assert( status == napi_ok );
- if ( vtype3 != napi_number ) {
- napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." );
- return nullptr;
- }
-
- bool res4;
- status = napi_is_typedarray( env, argv[ 4 ], &res4 );
- assert( status == napi_ok );
- if ( res4 == false ) {
- napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float64Array." );
- return nullptr;
- }
-
- napi_valuetype vtype5;
- status = napi_typeof( env, argv[ 5 ], &vtype5 );
- assert( status == napi_ok );
- if ( vtype5 != napi_number ) {
- napi_throw_type_error( env, nullptr, "invalid argument. Sixth argument must be a number." );
- return nullptr;
- }
-
- int64_t N;
- status = napi_get_value_int64( env, argv[ 0 ], &N );
- assert( status == napi_ok );
-
- double order;
- status = napi_get_value_double( env, argv[ 1 ], &order );
- assert( status == napi_ok );
-
- int64_t strideX;
- status = napi_get_value_int64( env, argv[ 3 ], &strideX );
- assert( status == napi_ok );
-
- int64_t strideY;
- status = napi_get_value_int64( env, argv[ 5 ], &strideY );
- assert( status == napi_ok );
-
- napi_typedarray_type vtype2;
- size_t xlen;
- void *X;
- status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr );
- assert( status == napi_ok );
- if ( vtype2 != napi_float64_array ) {
- napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." );
- return nullptr;
- }
- if ( (N-1)*llabs(strideX) >= (int64_t)xlen ) {
- napi_throw_range_error( env, nullptr, "invalid argument. Third argument has insufficient elements based on the associated stride and the number of indexed elements." );
- return nullptr;
- }
-
- napi_typedarray_type vtype4;
- size_t ylen;
- void *Y;
- status = napi_get_typedarray_info( env, argv[ 4 ], &vtype4, &ylen, &Y, nullptr, nullptr );
- assert( status == napi_ok );
- if ( vtype4 != napi_float64_array ) {
- napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float64Array." );
- return nullptr;
- }
- if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) {
- napi_throw_range_error( env, nullptr, "invalid argument. Fifth argument has insufficient elements based on the associated stride and the number of indexed elements." );
- return nullptr;
- }
-
- c_dsort2hp( N, order, (double *)X, strideX, (double *)Y, strideY );
-
- return nullptr;
- }
-
- napi_value Init( napi_env env, napi_value exports ) {
- napi_status status;
- napi_value fcn;
- status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dsort2hp, NULL, &fcn );
- assert( status == napi_ok );
- return fcn;
- }
-
- NAPI_MODULE( NODE_GYP_MODULE_NAME, Init )
-} // end namespace stdlib_blas_ext_base_dsort2hp
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/dsort2hp.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c
similarity index 59%
rename from lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/dsort2hp.c
rename to lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c
index 88675585aa84..a00f005cac1e 100644
--- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/dsort2hp.c
+++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2024 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.
@@ -17,10 +17,11 @@
*/
#include "stdlib/blas/ext/base/dsort2hp.h"
-#include "stdlib/math/base/assert/is_positive_zero.h"
#include "stdlib/math/base/assert/is_nan.h"
-#include
-#include
+#include "stdlib/math/base/assert/is_positive_zero.h"
+#include "stdlib/blas/base/shared.h"
+#include "stdlib/strided/base/stride2offset.h"
+
/**
* Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort.
@@ -37,22 +38,49 @@
* @param N number of indexed elements
* @param order sort order
* @param X first input array
-* @param strideX `X` index increment
+* @param strideX stride length for `X`
* @param Y second input array
-* @param strideY `Y` index increment
+* @param strideY stride length for `Y`
*/
-void c_dsort2hp( const int64_t N, const double order, double *X, const int64_t strideX, double *Y, const int64_t strideY ) {
- int64_t offsetX;
- int64_t offsetY;
- int64_t parent;
- int64_t child;
- int64_t sx;
- int64_t sy;
- int64_t ix;
- int64_t iy;
- int64_t n;
- int64_t j;
- int64_t k;
+void API_SUFFIX(stdlib_strided_dsort2hp)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY ) {
+ CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX );
+ CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY );
+ API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( N, order, X, strideX, ox, Y, strideY, oy );
+}
+
+/**
+* Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort and alternative indexing semantics.
+*
+* ## Notes
+*
+* - This implementation uses an in-place algorithm derived from the work of Floyd (1964).
+*
+* ## References
+*
+* - Williams, John William Joseph. 1964. "Algorithm 232: Heapsort." _Communications of the ACM_ 7 (6). New York, NY, USA: Association for Computing Machinery: 347–49. doi:[10.1145/512274.512284](https://doi.org/10.1145/512274.512284).
+* - Floyd, Robert W. 1964. "Algorithm 245: Treesort." _Communications of the ACM_ 7 (12). New York, NY, USA: Association for Computing Machinery: 701. doi:[10.1145/355588.365103](https://doi.org/10.1145/355588.365103).
+*
+* @param N number of indexed elements
+* @param order sort order
+* @param X first input array
+* @param strideX stride length for `X`
+* @param offsetX starting index for `X`
+* @param Y second input array
+* @param strideY stride length for `Y`
+* @param offsetY starting index for `Y`
+*/
+void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) {
+ CBLAS_INT parent;
+ CBLAS_INT child;
+ CBLAS_INT ix;
+ CBLAS_INT iy;
+ CBLAS_INT sx;
+ CBLAS_INT sy;
+ CBLAS_INT ox;
+ CBLAS_INT oy;
+ CBLAS_INT n;
+ CBLAS_INT j;
+ CBLAS_INT k;
double v1;
double v2;
double tx;
@@ -65,33 +93,27 @@ void c_dsort2hp( const int64_t N, const double order, double *X, const int64_t s
if ( order < 0.0 ) {
sx = -strideX;
sy = -strideY;
+ ox = offsetX - (N-1) * sx;
+ oy = offsetY - (N-1) * sy;
} else {
sx = strideX;
sy = strideY;
- }
- if ( sx < 0 ) {
- offsetX = (1-N) * sx;
- } else {
- offsetX = 0;
- }
- if ( sy < 0 ) {
- offsetY = (1-N) * sy;
- } else {
- offsetY = 0;
+ ox = offsetX;
+ oy = offsetY;
}
// Set the initial heap size:
n = N;
// Specify an initial "parent" index for building the heap:
- parent = floor( N / 2 );
+ parent = N / 2 ;
// Continue looping until the array is sorted...
while ( true ) {
if ( parent > 0 ) {
// We need to build the heap...
parent -= 1;
- tx = X[ offsetX+(parent*sx) ];
- ty = Y[ offsetY+(parent*sy) ];
+ tx = X[ ox+(parent*sx) ];
+ ty = Y[ oy+(parent*sy) ];
} else {
// Reduce the heap size:
n -= 1;
@@ -101,14 +123,14 @@ void c_dsort2hp( const int64_t N, const double order, double *X, const int64_t s
return;
}
// Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position:
- ix = offsetX + (n*sx);
+ ix = ox + (n*sx);
tx = X[ ix ];
- iy = offsetY + (n*sy);
+ iy = oy + (n*sy);
ty = Y[ iy ];
// Move the heap root to its sorted position:
- X[ ix ] = X[ offsetX ];
- Y[ iy ] = Y[ offsetY ];
+ X[ ix ] = X[ ox ];
+ Y[ iy ] = Y[ oy ];
}
// We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property...
@@ -122,8 +144,8 @@ void c_dsort2hp( const int64_t N, const double order, double *X, const int64_t s
// Find the largest child...
k = child + 1;
if ( k < n ) {
- v1 = X[ offsetX+(k*sx) ];
- v2 = X[ offsetX+(child*sx) ];
+ v1 = X[ ox+(k*sx) ];
+ v2 = X[ ox+(child*sx) ];
// Check if a "right" child exists and is "bigger"...
if ( v1 > v2 || stdlib_base_is_nan( v1 ) || (v1 == v2 && stdlib_base_is_positive_zero( v1 ) ) ) {
@@ -131,11 +153,11 @@ void c_dsort2hp( const int64_t N, const double order, double *X, const int64_t s
}
}
// Check if the largest child is bigger than `t`...
- v1 = X[ offsetX+(child*sx) ];
+ v1 = X[ ox+(child*sx) ];
if ( v1 > tx || stdlib_base_is_nan( v1 ) || ( v1 == tx && stdlib_base_is_positive_zero( v1 ) ) ) {
// Insert the larger child value:
- X[ offsetX+(j*sx) ] = v1;
- Y[ offsetY+(j*sy) ] = Y[ offsetY+(child*sy) ];
+ X[ ox+(j*sx) ] = v1;
+ Y[ oy+(j*sy) ] = Y[ oy+(child*sy) ];
// Update `j` to point to the child index:
j = child;
@@ -148,7 +170,7 @@ void c_dsort2hp( const int64_t N, const double order, double *X, const int64_t s
}
}
// Insert `t` into the heap:
- X[ offsetX+(j*sx) ] = tx;
- Y[ offsetY+(j*sy) ] = ty;
+ X[ ox+(j*sx) ] = tx;
+ Y[ oy+(j*sy) ] = ty;
}
}