From f9fa8d7a291cca1f8eb3454a3c137f65e5e11f8c Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 28 Nov 2024 18:37:47 +0500 Subject: [PATCH 01/20] feat: add C ndarray API and refactor --- .../@stdlib/blas/ext/base/dsort2hp/README.md | 143 ++++++++++++- .../ext/base/dsort2hp/benchmark/c/Makefile | 146 +++++++++++++ .../c/benchmark.unsorted_random.length.c | 195 ++++++++++++++++++ .../blas/ext/base/dsort2hp/docs/repl.txt | 22 +- .../ext/base/dsort2hp/examples/c/example.c | 7 +- .../include/stdlib/blas/ext/base/dsort2hp.h | 9 +- .../blas/ext/base/dsort2hp/lib/dsort2hp.js | 113 +--------- .../ext/base/dsort2hp/lib/dsort2hp.native.js | 4 +- .../blas/ext/base/dsort2hp/lib/ndarray.js | 5 +- .../ext/base/dsort2hp/lib/ndarray.native.js | 25 +-- .../blas/ext/base/dsort2hp/manifest.json | 127 ++++++++---- .../blas/ext/base/dsort2hp/src/addon.c | 67 ++++++ .../blas/ext/base/dsort2hp/src/addon.cpp | 164 --------------- .../base/dsort2hp/src/{dsort2hp.c => main.c} | 104 ++++++---- 14 files changed, 726 insertions(+), 405 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/benchmark.unsorted_random.length.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.c delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.cpp rename lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/{dsort2hp.c => main.c} (58%) 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..3b530ee97353 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**: `x` stride length. - **y**: second input [`Float64Array`][@stdlib/array/float64]. -- **strideY**: `y` index increment. +- **strideY**: `y` stride length. -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 `x` and `y` 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' ); @@ -126,7 +126,7 @@ The function has the following additional parameters: - **offsetX**: `x` starting index. - **offsetY**: `y` starting index. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `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' ); @@ -205,8 +205,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, x, 1, y, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] CBLAS_INT` 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 CBLAS_INT order, double *X, const CBLAS_INT strideX, double *Y, const 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, x, 1, 0, y, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] CBLAS_INT` sort order. +- **X**: `[inout] double*` input array. 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. +- **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 CBLAS_INT order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const 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..e1d379c468ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# 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. +# 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..7d74bd3c6ec0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/benchmark.unsorted_random.length.c @@ -0,0 +1,195 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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[ len ]; + double y[ len ]; + double t; + int i; + + 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, x, 1, y, 1 ); + if ( y[ i%len ] != y[ i%len ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ i%len ] != y[ i%len ] ) { + printf( "should not return NaN\n" ); + } + 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[ len ]; + double y[ len ]; + double t; + int i; + + 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, x, 1, 0, y, 1, 0 ); + if ( y[ i%len ] != y[ i%len ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ i%len ] != y[ i%len ] ) { + printf( "should not return NaN\n" ); + } + 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..b4517aa5e3aa 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,7 +3,7 @@ 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 + The `N` and stride parameters determine which elements in `x` and `y` are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed @@ -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,14 +77,14 @@ > 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 @@ -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/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/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..5c675f28ec49 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 CBLAS_INT order, double *X, CBLAS_INT strideX, double *Y, 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 CBLAS_INT order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX, double *Y, CBLAS_INT strideY, 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..47cb53b56ed7 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 - `x` stride length * @param {Float64Array} y - second input array -* @param {integer} strideY - `y` index increment +* @param {integer} strideY - `y` stride length * @returns {Float64Array} `x` * * @example @@ -64,108 +63,10 @@ var floor = require( '@stdlib/math/base/special/floor' ); 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; - } + offsetX = stride2offset( N, strideX ); + offsetY = stride2offset( N, strideY ); + return ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY ); } 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..2a09f0d786cd 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 - `x` stride length * @param {Float64Array} y - second input array -* @param {integer} strideY - `y` index increment +* @param {integer} strideY - `y` stride length * @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..db9792aba94b 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,10 +42,10 @@ 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 - `x` stride length * @param {NonNegativeInteger} offsetX - `x` starting index * @param {Float64Array} y - second input array -* @param {integer} strideY - `y` index increment +* @param {integer} strideY - `y` stride length * @param {NonNegativeInteger} offsetY - `y` starting index * @returns {Float64Array} `x` * @@ -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..05408c64eb3c 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,10 +31,10 @@ 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 {integer} strideX - `x` stride length * @param {NonNegativeInteger} offsetX - `x` starting index * @param {Float64Array} y - second input array -* @param {integer} strideY - `y` index increment +* @param {integer} strideY - `y` stride length * @param {NonNegativeInteger} offsetY - `y` starting index * @returns {Float64Array} `x` * @@ -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..edbbe9b49d56 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,88 @@ { - "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/special/floor", + "@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/special/floor", + "@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/special/floor", + "@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..40939834ea7e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.c @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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 58% 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..35da0f552623 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,12 @@ */ #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" +#include "stdlib/math/base/special/floor.h" + /** * Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using heapsort. @@ -37,22 +39,45 @@ * @param N number of indexed elements * @param order sort order * @param X first input array -* @param strideX `X` index increment +* @param strideX stride length of `X` * @param Y second input array -* @param strideY `Y` index increment +* @param strideY stride length of `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 CBLAS_INT order, double *X, CBLAS_INT strideX, double *Y, CBLAS_INT strideY ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + return 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 of `X` +* @param offsetX starting index of `X` +* @param Y second input array +* @param strideY stride length of `Y` +* @param offsetY starting index of `Y` +*/ +void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX, double *Y, CBLAS_INT strideY, CBLAS_INT offsetY ) { + CBLAS_INT parent; + CBLAS_INT child; + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT n; + CBLAS_INT j; + CBLAS_INT k; double v1; double v2; double tx; @@ -63,35 +88,24 @@ void c_dsort2hp( const int64_t N, const double order, double *X, const int64_t s } // 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 ) { - sx = -strideX; - sy = -strideY; - } 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; + strideX *= -1; + strideY *= -1; + offsetX -= (N-1) * strideX; + offsetY -= (N-1) * strideY; } // Set the initial heap size: n = N; // Specify an initial "parent" index for building the heap: - parent = floor( N / 2 ); + parent = stdlib_base_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*sx) ]; - ty = Y[ offsetY+(parent*sy) ]; + tx = X[ offsetX+(parent*strideX) ]; + ty = Y[ offsetY+(parent*strideY) ]; } else { // Reduce the heap size: n -= 1; @@ -101,9 +115,9 @@ 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 = offsetX + (n*strideX); tx = X[ ix ]; - iy = offsetY + (n*sy); + iy = offsetY + (n*strideY); ty = Y[ iy ]; // Move the heap root to its sorted position: @@ -122,8 +136,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[ offsetX+(k*strideX) ]; + v2 = X[ offsetX+(child*strideX) ]; // 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 +145,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[ offsetX+(child*strideX) ]; 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[ offsetX+(j*strideX) ] = v1; + Y[ offsetY+(j*strideY) ] = Y[ offsetY+(child*strideY) ]; // Update `j` to point to the child index: j = child; @@ -148,7 +162,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[ offsetX+(j*strideX) ] = tx; + Y[ offsetY+(j*strideY) ] = ty; } } From dc519edb7b4f02fdc9900159d6d624c33aa8fce5 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:55:08 +0500 Subject: [PATCH 02/20] fix: apply review suggestions Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c index 35da0f552623..aec40ae7a0ac 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c @@ -46,7 +46,7 @@ void API_SUFFIX(stdlib_strided_dsort2hp)( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, double *Y, CBLAS_INT strideY ) { CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); - return API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( N, order, X, strideX, ox, Y, strideY, oy ); + API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( N, order, X, strideX, ox, Y, strideY, oy ); } /** From fa616a39a0a222f8be123849d6123c72dfa46471 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:55:23 +0500 Subject: [PATCH 03/20] docs: apply review suggestion Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/base/dsort2hp/src/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c index aec40ae7a0ac..8a1854e33840 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c @@ -64,11 +64,11 @@ void API_SUFFIX(stdlib_strided_dsort2hp)( const CBLAS_INT N, const CBLAS_INT ord * @param N number of indexed elements * @param order sort order * @param X first input array -* @param strideX stride length of `X` -* @param offsetX starting index of `X` +* @param strideX `X` stride length +* @param offsetX `X` starting index * @param Y second input array -* @param strideY stride length of `Y` -* @param offsetY starting index of `Y` +* @param strideY `Y` stride length +* @param offsetY `Y` starting index */ void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX, double *Y, CBLAS_INT strideY, CBLAS_INT offsetY ) { CBLAS_INT parent; From e53859defed709554e83f1b5cb94af2acb5f2048 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:55:33 +0500 Subject: [PATCH 04/20] docs: apply review suggestion Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c index 8a1854e33840..461e040da543 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c @@ -39,7 +39,7 @@ * @param N number of indexed elements * @param order sort order * @param X first input array -* @param strideX stride length of `X` +* @param strideX `X` stride length * @param Y second input array * @param strideY stride length of `Y` */ From c9f0e6187653d9243d85884a22aa257ec7e243c3 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 28 Nov 2024 18:55:42 +0500 Subject: [PATCH 05/20] docs: apply review suggestion Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c index 461e040da543..2147b79ad3d0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c @@ -41,7 +41,7 @@ * @param X first input array * @param strideX `X` stride length * @param Y second input array -* @param strideY stride length of `Y` +* @param strideY `Y` stride length */ void API_SUFFIX(stdlib_strided_dsort2hp)( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, double *Y, CBLAS_INT strideY ) { CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); From ebfe4fab0cf5760ee81fc5f4c7810a1471e4e68f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:22:30 +0500 Subject: [PATCH 06/20] docs: apply review suggestion Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3b530ee97353..f7cefd12cfbe 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md @@ -252,7 +252,7 @@ The function accepts the following arguments: - **strideY**: `[in] CBLAS_INT` stride length for `Y`. ```c -stdlib_strided_dsort2hp( const CBLAS_INT N, const CBLAS_INT order, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY ); +stdlib_strided_dsort2hp( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, double *Y, CBLAS_INT strideY ); ``` From e7e26af9de61d8ed09944dfdabaea6b2f437521f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:22:42 +0500 Subject: [PATCH 07/20] docs: apply review suggestion Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f7cefd12cfbe..672b7f2829db 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md @@ -282,7 +282,7 @@ The function accepts the following arguments: - **offsetY**: `[in] CBLAS_INT` starting index for `Y`. ```c -stdlib_strided_dsort2hp_ndarray( const CBLAS_INT N, const CBLAS_INT order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +stdlib_strided_dsort2hp_ndarray( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX, double *Y, CBLAS_INT strideY, CBLAS_INT offsetY ); ```
From add5315ae0a30f9e26b23e58cb70372ff4dbd11a Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:23:08 +0500 Subject: [PATCH 08/20] refactor: apply review suggestion Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../dsort2hp/benchmark/c/benchmark.unsorted_random.length.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 7d74bd3c6ec0..6c283319bf85 100644 --- 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 @@ -108,13 +108,13 @@ static double benchmark1( int iterations, int len ) { t = tic(); for ( i = 0; i < iterations; i++ ) { stdlib_strided_dsort2hp( len, 1, x, 1, y, 1 ); - if ( y[ i%len ] != y[ i%len ] ) { + if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( y[ i%len ] != y[ i%len ] ) { + if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } return elapsed; From 807d7c92e7dbea96cd211bc618e041429a378a84 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Fri, 29 Nov 2024 13:23:22 +0500 Subject: [PATCH 09/20] refactor: apply review suggestion Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../dsort2hp/benchmark/c/benchmark.unsorted_random.length.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 6c283319bf85..286dccc07db1 100644 --- 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 @@ -141,13 +141,13 @@ static double benchmark2( int iterations, int len ) { t = tic(); for ( i = 0; i < iterations; i++ ) { stdlib_strided_dsort2hp_ndarray( len, 1, x, 1, 0, y, 1, 0 ); - if ( y[ i%len ] != y[ i%len ] ) { + if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( y[ i%len ] != y[ i%len ] ) { + if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } return elapsed; From b2c2989e532748b5e7a73eff0b39524f51e0ad59 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 29 Nov 2024 21:33:51 +0500 Subject: [PATCH 10/20] refactor: update javascript examples --- .../@stdlib/blas/ext/base/dsort2hp/README.md | 29 ++++----------- .../blas/ext/base/dsort2hp/examples/index.js | 35 +++++-------------- 2 files changed, 15 insertions(+), 49 deletions(-) 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 672b7f2829db..e2098c02a093 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md @@ -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 ); 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 ); From 975ce529bc059b54470537f0b63dd90da1682659 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 4 Feb 2025 02:15:55 +0500 Subject: [PATCH 11/20] refactor: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/base/dsort2hp/README.md | 24 +++++++++---------- .../c/benchmark.unsorted_random.length.c | 4 ++-- .../blas/ext/base/dsort2hp/docs/repl.txt | 2 +- .../include/stdlib/blas/ext/base/dsort2hp.h | 4 ++-- .../blas/ext/base/dsort2hp/lib/dsort2hp.js | 10 +++----- .../ext/base/dsort2hp/lib/dsort2hp.native.js | 4 ++-- .../blas/ext/base/dsort2hp/lib/ndarray.js | 8 +++---- .../ext/base/dsort2hp/lib/ndarray.native.js | 8 +++---- .../@stdlib/blas/ext/base/dsort2hp/src/main.c | 16 ++++++------- 9 files changed, 38 insertions(+), 42 deletions(-) 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 e2098c02a093..1ce9e50f24d4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md @@ -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` stride length. +- **strideX**: stride length for `x`. - **y**: second input [`Float64Array`][@stdlib/array/float64]. -- **strideY**: `y` stride length. +- **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' ); @@ -123,8 +123,8 @@ 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 parameters support indexing semantics based on starting indices. For example, to access only the last three elements: @@ -224,20 +224,20 @@ Simultaneously sorts two double-precision floating-point strided arrays based on 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, x, 1, y, 1 ); +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] CBLAS_INT` 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. +- **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 CBLAS_INT order, double *X, CBLAS_INT strideX, double *Y, CBLAS_INT strideY ); +stdlib_strided_dsort2hp( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, double *Y, CBLAS_INT strideY ); ``` @@ -252,14 +252,14 @@ Simultaneously sorts two double-precision floating-point strided arrays based on 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, x, 1, 0, y, 1, 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] CBLAS_INT` sort order. -- **X**: `[inout] double*` input array. 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. +- **order**: `[in] double` sort order. +- **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. @@ -267,7 +267,7 @@ The function accepts the following arguments: - **offsetY**: `[in] CBLAS_INT` starting index for `Y`. ```c -stdlib_strided_dsort2hp_ndarray( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX, double *Y, CBLAS_INT strideY, CBLAS_INT offsetY ); +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 ); ``` 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 index 286dccc07db1..18c73a4bc9b7 100644 --- 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 @@ -107,7 +107,7 @@ static double benchmark1( int iterations, int len ) { } t = tic(); for ( i = 0; i < iterations; i++ ) { - stdlib_strided_dsort2hp( len, 1, x, 1, y, 1 ); + stdlib_strided_dsort2hp( len, 1.0, x, 1, y, 1 ); if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); break; @@ -140,7 +140,7 @@ static double benchmark2( int iterations, int len ) { } t = tic(); for ( i = 0; i < iterations; i++ ) { - stdlib_strided_dsort2hp_ndarray( len, 1, x, 1, 0, y, 1, 0 ); + 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; 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 b4517aa5e3aa..7688b23859d6 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,7 +3,7 @@ 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 + The `N` and stride parameters determine which elements in the strided arrays accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed 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 5c675f28ec49..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 @@ -31,12 +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 API_SUFFIX(stdlib_strided_dsort2hp)( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, double *Y, CBLAS_INT 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 CBLAS_INT order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX, double *Y, CBLAS_INT strideY, CBLAS_INT offsetY ); +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 47cb53b56ed7..0d062ba6af0e 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 @@ -41,9 +41,9 @@ var ndarray = require( './ndarray.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float64Array} x - first input array -* @param {integer} strideX - `x` stride length +* @param {integer} strideX - stride length for `x` * @param {Float64Array} y - second input array -* @param {integer} strideY - `y` stride length +* @param {integer} strideY - stride length for `y` * @returns {Float64Array} `x` * * @example @@ -61,12 +61,8 @@ var ndarray = require( './ndarray.js' ); * // => [ 3.0, 1.0, 0.0, 2.0 ] */ function dsort2hp( N, order, x, strideX, y, strideY ) { - var offsetX; - var offsetY; - offsetX = stride2offset( N, strideX ); - offsetY = stride2offset( N, strideY ); - return ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY ); + return ndarray( N, order, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); } 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 2a09f0d786cd..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` stride length +* @param {integer} strideX - stride length for `x` * @param {Float64Array} y - second input array -* @param {integer} strideY - `y` stride length +* @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 db9792aba94b..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` stride length -* @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` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` * @returns {Float64Array} `x` * * @example 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 05408c64eb3c..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 @@ -31,11 +31,11 @@ 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` stride length -* @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` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` * @returns {Float64Array} `x` * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c index 2147b79ad3d0..32fb04d59a0c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c @@ -39,11 +39,11 @@ * @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` */ -void API_SUFFIX(stdlib_strided_dsort2hp)( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, double *Y, CBLAS_INT 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 ) { 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 ); @@ -64,13 +64,13 @@ void API_SUFFIX(stdlib_strided_dsort2hp)( const CBLAS_INT N, const CBLAS_INT ord * @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` */ -void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const CBLAS_INT order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX, double *Y, CBLAS_INT strideY, CBLAS_INT offsetY ) { +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; From 23fa6a02b6608b365bafe30fcbf86886cd71beac Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Mon, 3 Feb 2025 21:17:52 +0000 Subject: [PATCH 12/20] chore: update copyright years --- .../@stdlib/blas/ext/base/dsort2hp/benchmark/c/Makefile | 2 +- .../dsort2hp/benchmark/c/benchmark.unsorted_random.length.c | 2 +- lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 index e1d379c468ad..88c218ce50fa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/Makefile +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/benchmark/c/Makefile @@ -1,7 +1,7 @@ #/ # @license Apache-2.0 # -# Copyright (c) 2024 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. 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 index 18c73a4bc9b7..c334456a4eb8 100644 --- 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 @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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. 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 index 40939834ea7e..381c85a0fd15 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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. From 4dda49ddd8fb6be0a0a164fca4e53bd072cea47f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 3 Feb 2025 22:51:08 +0000 Subject: [PATCH 13/20] fix: lint, benchmarks and test errors --- .../c/benchmark.unsorted_random.length.c | 16 +++++-- .../blas/ext/base/dsort2hp/docs/repl.txt | 6 +-- .../@stdlib/blas/ext/base/dsort2hp/src/main.c | 43 +++++++++++-------- 3 files changed, 41 insertions(+), 24 deletions(-) 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 index c334456a4eb8..5c3d2e8bd071 100644 --- 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 @@ -96,11 +96,13 @@ static double rand_double( void ) { */ static double benchmark1( int iterations, int len ) { double elapsed; - double x[ len ]; - double y[ len ]; + 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; @@ -117,6 +119,8 @@ static double benchmark1( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); + free( y ); return elapsed; } @@ -129,11 +133,13 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - double x[ len ]; - double y[ len ]; + 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; @@ -150,6 +156,8 @@ static double benchmark2( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + free( x ); + free( y ); return elapsed; } 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 7688b23859d6..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 @@ -4,7 +4,7 @@ based on the sort order of the first array using heapsort. The `N` and stride parameters determine which elements in the strided arrays - accessed at runtime. + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. @@ -91,8 +91,8 @@ 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 ---------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c index 32fb04d59a0c..ae4443b0f615 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c @@ -75,6 +75,10 @@ void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const doubl 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; @@ -88,10 +92,15 @@ void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const doubl } // 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; - offsetX -= (N-1) * strideX; - offsetY -= (N-1) * strideY; + sx = -strideX; + sy = -strideY; + ox = offsetX - (N-1) * sx; + oy = offsetY - (N-1) * sy; + } else { + sx = strideX; + sy = strideY; + ox = offsetX; + oy = offsetY; } // Set the initial heap size: n = N; @@ -104,8 +113,8 @@ void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const doubl if ( parent > 0 ) { // We need to build the heap... parent -= 1; - tx = X[ offsetX+(parent*strideX) ]; - ty = Y[ offsetY+(parent*strideY) ]; + tx = X[ ox+(parent*sx) ]; + ty = Y[ oy+(parent*sy) ]; } else { // Reduce the heap size: n -= 1; @@ -115,14 +124,14 @@ void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const doubl 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*strideX); + ix = ox + (n*sx); tx = X[ ix ]; - iy = offsetY + (n*strideY); + 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... @@ -136,8 +145,8 @@ void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const doubl // Find the largest child... k = child + 1; if ( k < n ) { - v1 = X[ offsetX+(k*strideX) ]; - v2 = X[ offsetX+(child*strideX) ]; + 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 ) ) ) { @@ -145,11 +154,11 @@ void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const doubl } } // Check if the largest child is bigger than `t`... - v1 = X[ offsetX+(child*strideX) ]; + 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*strideX) ] = v1; - Y[ offsetY+(j*strideY) ] = Y[ offsetY+(child*strideY) ]; + X[ ox+(j*sx) ] = v1; + Y[ oy+(j*sy) ] = Y[ oy+(child*sy) ]; // Update `j` to point to the child index: j = child; @@ -162,7 +171,7 @@ void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const doubl } } // Insert `t` into the heap: - X[ offsetX+(j*strideX) ] = tx; - Y[ offsetY+(j*strideY) ] = ty; + X[ ox+(j*sx) ] = tx; + Y[ oy+(j*sy) ] = ty; } } From 92bbba4964cb5f5c18fc633ae414c2778609a8d6 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 3 Feb 2025 23:06:20 +0000 Subject: [PATCH 14/20] chore: disable max-len lint rule --- .../@stdlib/blas/ext/base/dsort2hp/lib/dsort2hp.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 0d062ba6af0e..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 @@ -61,8 +61,7 @@ var ndarray = require( './ndarray.js' ); * // => [ 3.0, 1.0, 0.0, 2.0 ] */ function dsort2hp( N, order, x, strideX, y, strideY ) { - - return ndarray( N, order, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); + return ndarray( N, order, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); // eslint-disable-line max-len } From 507e35b0c6184896a8115ae3703bd39f0813183d Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 3 Feb 2025 23:15:27 +0000 Subject: [PATCH 15/20] fix: use tabs instead of spaces --- .../benchmark/c/benchmark.unsorted_random.length.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 index 5c3d2e8bd071..5b6c6d74dbdb 100644 --- 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 @@ -116,9 +116,9 @@ static double benchmark1( int iterations, int len ) { } } elapsed = tic() - t; - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - } + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } free( x ); free( y ); return elapsed; @@ -153,9 +153,9 @@ static double benchmark2( int iterations, int len ) { } } elapsed = tic() - t; - if ( y[ 0 ] != y[ 0 ] ) { - printf( "should not return NaN\n" ); - } + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } free( x ); free( y ); return elapsed; From 4b22b40facbb187f051d080a4018317d8b8fed95 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 4 Feb 2025 08:18:55 +0000 Subject: [PATCH 16/20] docs: update typescript docs --- .../blas/ext/base/dsort2hp/docs/types/index.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 From 90a4feb393dcf2f88fbade600cc89e3a6413ae43 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 8 Feb 2025 19:28:59 +0500 Subject: [PATCH 17/20] refactor: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../dsort2hp/benchmark/c/benchmark.unsorted_random.length.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 5b6c6d74dbdb..fb9a6e20b0d5 100644 --- 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 @@ -138,8 +138,8 @@ static double benchmark2( int iterations, int len ) { double t; int i; - x = (double *)malloc( len * sizeof(double) ); - y = (double *)malloc( len * sizeof(double) ); + 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; From d9a6825008f51da477853b3213115f01d0aa7038 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 9 Feb 2025 01:15:47 +0500 Subject: [PATCH 18/20] refactor: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../benchmark/c/benchmark.unsorted_random.length.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 index fb9a6e20b0d5..9b862c5286dd 100644 --- 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 @@ -101,8 +101,8 @@ static double benchmark1( int iterations, int len ) { double t; int i; - x = ( double * )malloc( len * sizeof(double) ); - y = ( double * )malloc( len * sizeof(double) ); + 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; @@ -138,8 +138,8 @@ static double benchmark2( int iterations, int len ) { double t; int i; - x = ( double * )malloc( len * sizeof(double) ); - y = ( double * )malloc( len * sizeof(double) ); + 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; From d345efdbfeb8f1e5626f9451931882448d6b6aa1 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 9 Feb 2025 11:59:55 +0500 Subject: [PATCH 19/20] docs: apply review suggestion Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1ce9e50f24d4..87e9ecafe4aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/README.md @@ -258,7 +258,7 @@ 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. +- **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`. From 801569ae143891f8f0ec1cac79338a62eaee7130 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sun, 9 Feb 2025 12:03:14 +0500 Subject: [PATCH 20/20] refactor: remove the use of floor Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/blas/ext/base/dsort2hp/manifest.json | 3 --- lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) 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 edbbe9b49d56..d9a356e30bd1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/manifest.json @@ -41,7 +41,6 @@ "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/floor", "@stdlib/math/base/assert/is-positive-zero", "@stdlib/napi/create-double", "@stdlib/strided/base/stride2offset", @@ -60,7 +59,6 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/floor", "@stdlib/math/base/assert/is-positive-zero", "@stdlib/strided/base/stride2offset", "@stdlib/blas/base/shared" @@ -78,7 +76,6 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/floor", "@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/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c index ae4443b0f615..a00f005cac1e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2hp/src/main.c @@ -21,7 +21,6 @@ #include "stdlib/math/base/assert/is_positive_zero.h" #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" -#include "stdlib/math/base/special/floor.h" /** @@ -106,7 +105,7 @@ void API_SUFFIX(stdlib_strided_dsort2hp_ndarray)( const CBLAS_INT N, const doubl n = N; // Specify an initial "parent" index for building the heap: - parent = stdlib_base_floor( N / 2 ); + parent = N / 2 ; // Continue looping until the array is sorted... while ( true ) {