diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/README.md index af9e422f3c61..1ce8c391d5cc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/README.md @@ -32,7 +32,7 @@ var ssort2hp = require( '@stdlib/blas/ext/base/ssort2hp' ); #### ssort2hp( N, order, x, strideX, y, strideY ) -Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array `x` using heapsort. +Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using heapsort. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -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 [`Float32Array`][@stdlib/array/float32]. -- **strideX**: `x` index increment. +- **strideX**: stride length for `x`. - **y**: second input [`Float32Array`][@stdlib/array/float32]. -- **strideY**: `y` index increment. +- **strideY**: stride length for `y`. -The `N` and stride parameters determine which elements in the strided arrays 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 Float32Array = require( '@stdlib/array/float32' ); @@ -100,7 +100,7 @@ console.log( y0 ); #### ssort2hp.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY ) -Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array `x` using heapsort and alternative indexing semantics. +Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using heapsort and alternative indexing semantics. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -119,10 +119,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 Float32Array = require( '@stdlib/array/float32' ); @@ -165,28 +165,15 @@ console.log( y ); ```javascript -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ssort2hp = require( '@stdlib/blas/ext/base/ssort2hp' ); -var rand; -var sign; -var i; - -var x = new Float32Array( 10 ); -var y = new Float32Array( 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 ); @@ -201,6 +188,137 @@ console.log( y ); * * * + + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ssort2hp.h" +``` + +#### stdlib_strided_ssort2hp( N, order, \*X, strideX, \*Y, strideY ) + +Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using heapsort. + +```c +float x[] = { 1.0f, -2.0f, 3.0f, -4.0f }; +float y[] = { 0.0f, 1.0f, 2.0f, 3.0f }; + +stdlib_strided_ssort2hp( 4, 1.0f, x, 1, y, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] float` 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] float*` first input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **Y**: `[inout] float*` second input array. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. + +```c +stdlib_strided_ssort2hp( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ); +``` + + + +#### stdlib_strided_ssort2hp_ndarray( N, order, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + + + +Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using heapsort and alternative indexing semantics. + +```c +float x[] = { 1.0f, -2.0f, 3.0f, -4.0f }; +float y[] = { 0.0f, 1.0f, 2.0f, 3.0f }; + +stdlib_strided_ssort2hp_ndarray( 4, 1.0f, x, 1, 0, y, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] float` 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] float*` first input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[inout] float*` second input array. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. + +```c +stdlib_strided_ssort2hp_ndarray( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ssort2hp.h" +#include + +int main( void ) { + // Create strided arrays: + float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + float y[] = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f }; + + // Specify the number of elements: + int N = 8; + + // Specify the strides: + int strideX = 1; + int strideY = 1; + + // Sort the arrays: + stdlib_strided_ssort2hp( N, 1.0f, x, strideX, y, strideY ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %f\n", i, x[ i ] ); + printf( "y[ %i ] = %f\n", i, y[ i ] ); + } +} +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/benchmark/c/Makefile new file mode 100644 index 000000000000..88c218ce50fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/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/ssort2hp/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/benchmark/c/benchmark.unsorted_random.length.c new file mode 100644 index 000000000000..59de3a3cb960 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/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/ssort2hp.h" +#include +#include +#include +#include +#include + +#define NAME "ssort2hp" +#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 float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* 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 t; + float *x; + float *y; + int i; + + x = (float *)malloc( len * sizeof(float) ); + y = (float *)malloc( len * sizeof(float) ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*20.0f ) - 10.0f; + y[ i ] = ( rand_float()*20.0f ) - 10.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_ssort2hp( len, 1.0f, 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 t; + float *x; + float *y; + int i; + + x = (float *)malloc( len * sizeof(float) ); + y = (float *)malloc( len * sizeof(float) ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*20.0f ) - 10.0f; + y[ i ] = ( rand_float()*20.0f ) - 10.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_ssort2hp_ndarray( len, 1.0f, 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/ssort2hp/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/docs/repl.txt index 59b450eeea7d..f7b5c26ff838 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/docs/repl.txt @@ -3,8 +3,8 @@ Simultaneously sorts two single-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 the strided - arrays 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: Float32Array Second input array. strideY: integer - Index increment for `y`. + Stride length for `y`. Returns ------- @@ -64,7 +64,7 @@ > y [ 3.0, 1.0, 0.0, 2.0 ] - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] ); > y = new {{alias:@stdlib/array/float32}}( [ 0.0, 1.0, 2.0, 3.0 ] ); > {{alias}}( 2, -1, x, 2, y, 2 ) @@ -107,19 +107,19 @@ First input array. strideX: integer - Index increment for `x`. + Stride length for `x`. offsetX: integer - Starting index of `x`. + Starting index for `x`. y: Float32Array Second input array. strideY: integer - Index increment for `y`. + Stride length for `y`. offsetY: integer - Starting index of `y`. + Starting index for `y`. Returns ------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/docs/types/index.d.ts index 92597151cefd..8947e6ea05d5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/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 - first stride length + * @param strideX - stride length for `x` * @param y - second input array - * @param strideY - second 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/ssort2hp/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/examples/c/example.c index 20002fe25e93..ad8cd58012cc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/examples/c/example.c @@ -18,26 +18,25 @@ #include "stdlib/blas/ext/base/ssort2hp.h" #include -#include int main( void ) { // Create strided arrays: - float x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; - float y[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }; + float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + float y[] = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f }; // Specify the number of elements: int N = 8; - // Specify strides: + // Specify the strides: int strideX = 1; int strideY = 1; // Sort the arrays: - c_ssort2hp( N, 1.0f, x, strideX, y, strideY ); + stdlib_strided_ssort2hp( N, 1.0f, x, strideX, y, strideY ); // Print the result: for ( int i = 0; i < 8; i++ ) { printf( "x[ %i ] = %f\n", i, x[ i ] ); - printf( "y[ %i ] = %"PRId64"\n", i, (int64_t)y[ i ] ); + printf( "y[ %i ] = %f\n", i, y[ i ] ); } } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/examples/index.js index a15594687155..53cd682c0e4c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/examples/index.js @@ -18,32 +18,15 @@ 'use strict'; -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ssort2hp = require( './../lib' ); -var rand; -var sign; -var i; - -var x = new Float32Array( 10 ); -var y = new Float32Array( 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': 'float32' +}); +var y = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/include/stdlib/blas/ext/base/ssort2hp.h b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/include/stdlib/blas/ext/base/ssort2hp.h index 016ef2d7aa2e..62095322ef41 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/include/stdlib/blas/ext/base/ssort2hp.h +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/include/stdlib/blas/ext/base/ssort2hp.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_SSORT2HP_H #define STDLIB_BLAS_EXT_BASE_SSORT2HP_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 single-precision floating-point strided arrays based on the sort order of the first array using heapsort. */ -void c_ssort2hp( const int64_t N, const float order, float *X, const int64_t strideX, float *Y, const int64_t strideY ); +void API_SUFFIX(stdlib_strided_ssort2hp)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ); + +/** +* Simultaneously sorts two single-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_ssort2hp_ndarray)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ndarray.js index 2fa0e054fd2c..ff2782e9cfa8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/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 {Float32Array} 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 {Float32Array} 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 {Float32Array} `x` * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ndarray.native.js index cf5bf52935d8..d8656a4b140c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float32Array = require( '@stdlib/array/float32' ); -var addon = require( './ssort2hp.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,11 +31,11 @@ var addon = require( './ssort2hp.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float32Array} 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 {Float32Array} 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 {Float32Array} `x` * * @example @@ -54,23 +53,7 @@ var addon = require( './ssort2hp.native.js' ); * // => [ 3.0, 1.0, 0.0, 2.0 ] */ function ssort2hp( 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 Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len - viewY = new Float32Array( 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/ssort2hp/lib/ssort2hp.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ssort2hp.js index c72137325fd3..da2542f64aac 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ssort2hp.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ssort2hp.js @@ -20,9 +20,8 @@ // MODULES // -var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -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 {Float32Array} x - first input array -* @param {integer} strideX - `x` index increment +* @param {integer} strideX - stride length for `x` * @param {Float32Array} y - second input array -* @param {integer} strideY - `y` index increment +* @param {integer} strideY - stride length for `y` * @returns {Float32Array} `x` * * @example @@ -62,110 +61,7 @@ var floor = require( '@stdlib/math/base/special/floor' ); * // => [ 3.0, 1.0, 0.0, 2.0 ] */ function ssort2hp( 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 || isnanf( v1 ) || (v1 === v2 && isPositiveZerof( 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 || isnanf( v1 ) || ( v1 === tx && isPositiveZerof( 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/ssort2hp/lib/ssort2hp.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ssort2hp.native.js index f89104b21228..691e2e603ca6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ssort2hp.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/lib/ssort2hp.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 {Float32Array} x - first input array -* @param {integer} strideX - `x` index increment +* @param {integer} strideX - stride length for `x` * @param {Float32Array} y - second input array -* @param {integer} strideY - `y` index increment +* @param {integer} strideY - stride length for `y` * @returns {Float32Array} `x` * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/manifest.json index 5f32abffc071..bd8976e17df4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/manifest.json @@ -28,18 +28,18 @@ { "task": "build", "src": [ - "./src/ssort2hp.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/assert/is-positive-zerof", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-float", @@ -48,20 +48,37 @@ ] }, { - "task": "examples", + "task": "benchmark", "src": [ - "./src/ssort2hp.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/assert/is-positive-zerof", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" ], + "include": [ + "./include" + ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nanf", - "@stdlib/math/base/assert/is-positive-zerof" + "@stdlib/math/base/assert/is-positive-zerof", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/src/addon.c index 41dec5e7994b..feed8f01563f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/blas/ext/base/ssort2hp.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -39,8 +40,29 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); - c_ssort2hp( N, order, X, strideX, Y, strideY ); + API_SUFFIX(stdlib_strided_ssort2hp)( N, order, X, strideX, Y, strideY ); return NULL; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* 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_FLOAT( 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_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 5 ); + API_SUFFIX(stdlib_strided_ssort2hp_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/ssort2hp/src/ssort2hp.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/src/main.c similarity index 65% rename from lib/node_modules/@stdlib/blas/ext/base/ssort2hp/src/ssort2hp.c rename to lib/node_modules/@stdlib/blas/ext/base/ssort2hp/src/main.c index 6319465e642c..7b42acee7f68 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/src/ssort2hp.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2hp/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -19,8 +19,8 @@ #include "stdlib/blas/ext/base/ssort2hp.h" #include "stdlib/math/base/assert/is_positive_zerof.h" #include "stdlib/math/base/assert/is_nanf.h" -#include -#include +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/shared.h" /** * Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using heapsort. @@ -37,22 +37,41 @@ * @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_ssort2hp( const int64_t N, const float order, float *X, const int64_t strideX, float *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_ssort2hp)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, float *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_ssort2hp_ndarray)( N, order, X, strideX, ox, Y, strideY, oy ); +} + + +/** +* Simultaneously sorts two signle-precision floating-point strided arrays based on the sort order of the first array using heapsort and alternative indexing semantics. +* +* @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_ssort2hp_ndarray)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + CBLAS_INT parent; + CBLAS_INT child; + CBLAS_INT sx; + CBLAS_INT sy; + CBLAS_INT ox; + CBLAS_INT oy; + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT n; + CBLAS_INT j; + CBLAS_INT k; float v1; float v2; float tx; @@ -65,33 +84,27 @@ void c_ssort2hp( const int64_t N, const float order, float *X, const int64_t str if ( order < 0.0f ) { 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 = floorf( 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 +114,14 @@ void c_ssort2hp( const int64_t N, const float order, float *X, const int64_t str 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 +135,8 @@ void c_ssort2hp( const int64_t N, const float order, float *X, const int64_t str // 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_nanf( v1 ) || (v1 == v2 && stdlib_base_is_positive_zerof( v1 ) ) ) { @@ -131,11 +144,11 @@ void c_ssort2hp( const int64_t N, const float order, float *X, const int64_t str } } // 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_nanf( v1 ) || ( v1 == tx && stdlib_base_is_positive_zerof( 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 +161,7 @@ void c_ssort2hp( const int64_t N, const float order, float *X, const int64_t str } } // 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; } }