From fb5713cfeeddaf1c098d39f1e301d22c1e63a91f Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sat, 8 Feb 2025 20:54:43 +0530 Subject: [PATCH 1/6] feat: add C ndarray interface and refactor implementation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/blas/ext/base/ssort2sh/README.md | 172 ++++++++++++--- .../ext/base/ssort2sh/benchmark/c/Makefile | 146 +++++++++++++ .../c/benchmark.unsorted_random.length.c | 203 ++++++++++++++++++ .../blas/ext/base/ssort2sh/docs/repl.txt | 8 +- .../ext/base/ssort2sh/docs/types/index.d.ts | 16 +- .../ext/base/ssort2sh/examples/c/example.c | 9 +- .../blas/ext/base/ssort2sh/examples/index.js | 31 +-- .../include/stdlib/blas/ext/base/ssort2sh.h | 9 +- .../blas/ext/base/ssort2sh/lib/ndarray.js | 8 +- .../ext/base/ssort2sh/lib/ndarray.native.js | 29 +-- .../blas/ext/base/ssort2sh/lib/ssort2sh.js | 70 +----- .../ext/base/ssort2sh/lib/ssort2sh.native.js | 4 +- .../blas/ext/base/ssort2sh/manifest.json | 28 +-- .../blas/ext/base/ssort2sh/src/addon.c | 26 ++- .../base/ssort2sh/src/{ssort2sh.c => main.c} | 80 ++++--- 15 files changed, 627 insertions(+), 212 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c rename lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/{ssort2sh.c => main.c} (58%) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md index 0cd09a49dd48..02bb973959d9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md @@ -32,7 +32,7 @@ var ssort2sh = require( '@stdlib/blas/ext/base/ssort2sh' ); #### ssort2sh( N, order, x, strideX, y, strideY ) -Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array `x` using Shellsort. +Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using Shellsort. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -54,9 +54,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **order**: sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. - **x**: first input [`Float32Array`][@stdlib/array/float32]. -- **strideX**: `x` index increment. +- **strideX**: stride length for `x`. - **y**: second input [`Float32Array`][@stdlib/array/float32]. -- **strideY**: `y` index increment. +- **strideY**: stride length for `y`. The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to sort every other element @@ -100,7 +100,7 @@ console.log( y0 ); #### ssort2sh.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY ) -Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array `x` using Shellsort and alternative indexing semantics. +Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using Shellsort and alternative indexing semantics. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -119,10 +119,10 @@ console.log( y ); The function has the following additional parameters: -- **offsetX**: `x` starting index. -- **offsetY**: `y` starting index. +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x` +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to access only the last three elements: ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -166,28 +166,15 @@ console.log( y ); ```javascript -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ssort2sh = require( '@stdlib/blas/ext/base/ssort2sh' ); -var rand; -var sign; -var i; - -var x = new Float32Array( 10 ); -var y = new Float32Array( 10 ); // index array -for ( i = 0; i < x.length; i++ ) { - rand = round( randu()*100.0 ); - sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - x[ i ] = sign * rand; - y[ i ] = i; -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +var y = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); console.log( x ); console.log( y ); @@ -202,6 +189,137 @@ console.log( y ); * * * + + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ssort2sh.h" +``` + +#### stdlib_strided_ssort2sh( N, order, \*X, strideX, \*Y, strideY ) + +Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using Shellsort. + +```c +float x[] = { 1.0f, -2.0f, 3.0f, -4.0f }; +float y[] = { 0.0f, 1.0f, 2.0f, 3.0f }; + +stdlib_strided_ssort2sh( 4, 1.0f, x, 1, y, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. +- **X**: `[inout] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **Y**: `[inout] float*` input array. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. + +```c +stdlib_strided_ssort2sh( const CBLAS_INT N, const float order, float *X, CBLAS_INT strideX, float *Y, CBLAS_INT strideY ); +``` + + + +#### stdlib_strided_ssort2sh_ndarray( N, order, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + + + +Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using Shellsort and alternative indexing semantics. + +```c +float x[] = { 1.0f, -2.0f, 3.0f, -4.0f }; +float y[] = { 0.0f, 1.0f, 2.0f, 3.0f }; + +stdlib_strided_ssort2sh_ndarray( 4, 1.0f, x, 1, 0, y, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] float` sort order. +- **X**: `[inout] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[inout] float*` input array. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. + +```c +stdlib_strided_ssort2sh_ndarray( const CBLAS_INT N, const float order, float *X, CBLAS_INT strideX, CBLAS_INT offsetX, float *Y, CBLAS_INT strideY, CBLAS_INT offsetY ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ssort2sh.h" +#include + +int main( void ) { + // Create strided arrays: + float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + float y[] = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f }; + + // Specify the number of elements: + int N = 8; + + // Specify the strides: + int strideX = 1; + int strideY = 1; + + // Sort the arrays: + stdlib_strided_ssort2sh( N, 1.0f, x, strideX, y, strideY ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %f\n", i, x[ i ] ); + printf( "y[ %i ] = %lf\n", i, y[ i ] ); + } +} +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/Makefile new file mode 100644 index 000000000000..88c218ce50fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.unsorted_random.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c new file mode 100644 index 000000000000..fc9e6f0c2785 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c @@ -0,0 +1,203 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/ext/base/ssort2sh.h" +#include +#include +#include +#include +#include + +#define NAME "ssort2sh" +#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_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.0f ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + double t; + float *x; + float *y; + int i; + + x = ( float * )malloc( len * sizeof(float) ); + y = ( float * )malloc( len * sizeof(float) ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*20.0f ) - 10.0f; + y[ i ] = ( rand_float()*20.0f ) - 10.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_ssort2sh( len, 1.0f, x, 1, y, 1 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( y ); + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double t; + float *x; + float *y; + int i; + + x = (float *)malloc( len * sizeof(float) ); + y = (float *)malloc( len * sizeof(float) ); + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*20.0f ) - 10.0f; + y[ i ] = ( rand_float()*20.0f ) - 10.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_ssort2sh_ndarray( len, 1.0f, x, 1, 0, y, 1, 0 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + } + free( x ); + free( y ); + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:unsorted,random:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:unsorted,random:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/repl.txt index c9ac32d03f0c..a262e1d7b084 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/repl.txt @@ -44,13 +44,13 @@ First input array. strideX: integer - Index increment for `x`. + Stride length for `x`. y: Float32Array Second input array. strideY: integer - Index increment for `y`. + Stride length for `y`. Returns ------- @@ -110,7 +110,7 @@ First input array. strideX: integer - Index increment for `x`. + Stride length for `x`. offsetX: integer Starting index of `x`. @@ -119,7 +119,7 @@ Second input array. strideY: integer - Index increment for `y`. + Stride length for `y`. offsetY: integer Starting index of `y`. diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/types/index.d.ts index 0b525486a5a7..4fa9892b9715 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/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 - first stride length +* @param strideX - stride length for `x` * @param y - second input array -* @param strideY - second stride length +* @param strideY - stride length for `y` * @returns `x` * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/c/example.c index 3c1ebb125089..cdae2adc6987 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/c/example.c @@ -18,12 +18,11 @@ #include "stdlib/blas/ext/base/ssort2sh.h" #include -#include int main( void ) { // Create strided arrays: - float x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; - float y[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }; + float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + float y[] = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f }; // Specify the number of elements: int N = 8; @@ -33,11 +32,11 @@ int main( void ) { int strideY = 1; // Sort the arrays: - c_ssort2sh( N, 1.0f, x, strideX, y, strideY ); + stdlib_strided_ssort2sh( N, 1.0f, x, strideX, y, strideY ); // Print the result: for ( int i = 0; i < 8; i++ ) { printf( "x[ %i ] = %f\n", i, x[ i ] ); - printf( "y[ %i ] = %"PRId64"\n", i, (int64_t)y[ i ] ); + printf( "y[ %i ] = %lf\n", i, y[ i ] ); } } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/index.js index 3328847d22a2..d654cdbc2841 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/index.js @@ -18,32 +18,15 @@ 'use strict'; -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var ssort2sh = require( './../lib' ); -var rand; -var sign; -var i; - -var x = new Float32Array( 10 ); -var y = new Float32Array( 10 ); // index array -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - rand = round( randu()*100.0 ); - sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - x[ i ] = sign * rand; - } - y[ i ] = i; -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); +var y = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/include/stdlib/blas/ext/base/ssort2sh.h b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/include/stdlib/blas/ext/base/ssort2sh.h index 984b78317bf0..f9fd56e46d5a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/include/stdlib/blas/ext/base/ssort2sh.h +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/include/stdlib/blas/ext/base/ssort2sh.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_SSORT2SH_H #define STDLIB_BLAS_EXT_BASE_SSORT2SH_H -#include +#include "stdlib/blas/base/shared.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,12 @@ extern "C" { /** * Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using Shellsort. */ -void c_ssort2sh( const int64_t N, const float order, float *X, const int64_t strideX, float *Y, const int64_t strideY ); +void API_SUFFIX(stdlib_strided_ssort2sh)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ); + +/** +* Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using Shellsort and alternative indexing semantics. +*/ +void API_SUFFIX(stdlib_strided_ssort2sh_ndarray)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ndarray.js index 9935a664306a..32206fd3ca5d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ndarray.js @@ -47,11 +47,11 @@ var NGAPS = GAPS.length; * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float32Array} x - first input array -* @param {integer} strideX - `x` index increment -* @param {NonNegativeInteger} offsetX - `x` starting index +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` * @param {Float32Array} y - second input array -* @param {integer} strideY - `y` index increment -* @param {NonNegativeInteger} offsetY - `y` starting index +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` * @returns {Float32Array} `x` * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ndarray.native.js index edef90289cae..6d68148d1c70 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float32Array = require( '@stdlib/array/float32' ); -var addon = require( './ssort2sh.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,11 +31,11 @@ var addon = require( './ssort2sh.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float32Array} x - first input array -* @param {integer} strideX - `x` index increment -* @param {NonNegativeInteger} offsetX - `x` starting index +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` * @param {Float32Array} y - second input array -* @param {integer} strideY - `y` index increment -* @param {NonNegativeInteger} offsetY - `y` starting index +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` * @returns {Float32Array} `x` * * @example @@ -54,23 +53,7 @@ var addon = require( './ssort2sh.native.js' ); * // => [ 3.0, 1.0, 0.0, 2.0 ] */ function ssort2sh( N, order, x, strideX, offsetX, y, strideY, offsetY ) { - var viewX; - var viewY; - var flg; - - flg = 1.0; - if ( strideX < 0 ) { - flg *= -1.0; // reversing order - order *= -1.0; - strideX *= -1; - offsetX -= (N-1) * strideX; - } - if ( strideY < 0 ) { - offsetY += (N-1) * strideY; - } - viewX = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len - viewY = new Float32Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len - addon( N, order, viewX, strideX, viewY, flg*strideY ); + addon.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ssort2sh.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ssort2sh.js index 21496d1b9158..feb5ae605402 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ssort2sh.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ssort2sh.js @@ -20,14 +20,8 @@ // MODULES // -var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var GAPS = require( './gaps.json' ); - - -// VARIABLES // - -var NGAPS = GAPS.length; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -47,9 +41,9 @@ var NGAPS = GAPS.length; * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float32Array} x - first input array -* @param {integer} strideX - `x` index increment +* @param {integer} strideX - stride length for `x` * @param {Float32Array} y - second input array -* @param {integer} strideY - `y` index increment +* @param {integer} strideY - stride length for `y` * @returns {Float32Array} `x` * * @example @@ -67,61 +61,7 @@ var NGAPS = GAPS.length; * // => [ 3.0, 1.0, 0.0, 2.0 ] */ function ssort2sh( N, order, x, strideX, y, strideY ) { - var offsetX; - var offsetY; - var flg; - var gap; - var vx; - var vy; - var ux; - var i; - 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; - } - for ( i = 0; i < NGAPS; i++ ) { - gap = GAPS[ i ]; - for ( j = gap; j < N; j++ ) { - vx = x[ offsetX+(j*strideX) ]; - - // If `NaN`, the current value is already sorted to its place... - if ( isnanf( vx ) ) { - continue; - } - vy = y[ offsetY+(j*strideY) ]; - - // Perform insertion sort on the "gapped" subarray... - flg = isNegativeZerof( vx ); - for ( k = j; k >= gap; k -= gap ) { - ux = x[ offsetX+((k-gap)*strideX) ]; - if ( ux <= vx && !(flg && ux === vx) ) { - break; - } - x[ offsetX+(k*strideX) ] = ux; - y[ offsetY+(k*strideY) ] = y[ offsetY+((k-gap)*strideY) ]; - } - x[ offsetX+(k*strideX) ] = vx; - y[ offsetY+(k*strideY) ] = vy; - } - } - return x; + return ndarray( N, order, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ssort2sh.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ssort2sh.native.js index e51f2ca82336..82e81ff64363 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ssort2sh.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/lib/ssort2sh.native.js @@ -31,9 +31,9 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float32Array} x - first input array -* @param {integer} strideX - `x` index increment +* @param {integer} strideX - stride length for `x` * @param {Float32Array} y - second input array -* @param {integer} strideY - `y` index increment +* @param {integer} strideY - stride length for `y` * @returns {Float32Array} `x` * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/manifest.json index d9e7dc0bcc24..0b3fc6abb88b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/manifest.json @@ -28,18 +28,18 @@ { "task": "build", "src": [ - "./src/ssort2sh.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nanf", "@stdlib/math/base/assert/is-negative-zerof", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-float", @@ -50,35 +50,35 @@ { "task": "benchmark", "src": [ - "./src/ssort2sh.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nanf", - "@stdlib/math/base/assert/is-negative-zerof" + "@stdlib/math/base/assert/is-negative-zerof", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] }, { "task": "examples", "src": [ - "./src/ssort2sh.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nanf", - "@stdlib/math/base/assert/is-negative-zerof" + "@stdlib/math/base/assert/is-negative-zerof", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/addon.c index 32a9cca3f3dd..afa7280558f3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/blas/ext/base/ssort2sh.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -39,8 +40,29 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); - c_ssort2sh( N, order, X, strideX, Y, strideY ); + API_SUFFIX(stdlib_strided_ssort2sh)( N, order, X, strideX, Y, strideY ); return NULL; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 8 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, order, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 5 ); + API_SUFFIX(stdlib_strided_ssort2sh_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/ssort2sh/src/ssort2sh.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c similarity index 58% rename from lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/ssort2sh.c rename to lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c index 600630340e58..ae3c5a780480 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/ssort2sh.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,13 @@ #include "stdlib/blas/ext/base/ssort2sh.h" #include "stdlib/math/base/assert/is_negative_zerof.h" #include "stdlib/math/base/assert/is_nanf.h" -#include +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/shared.h" #include /** * Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using Shellsort. +/** * * ## Notes * @@ -37,27 +39,46 @@ * @param N number of indexed elements * @param order sort order * @param X first input array -* @param strideX `X` index increment +* @param strideX stride length for `x` +* @param Y second input array +* @param strideY stride length for `y` +*/ +void API_SUFFIX(stdlib_strided_ssort2sh)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(stdlib_strided_ssort2sh_ndarray)( N, order, X, strideX, ox, Y, strideY, oy ); +} + + +/** +* Simultaneously sorts two signle-precision floating-point strided arrays based on the sort order of the first array using Shellsort and alternative indexing semantics. +* +* @param N number of indexed elements +* @param order sort order +* @param X first input array +* @param strideX stride length for `x` +* @param offsetX starting index for `x` * @param Y second input array -* @param strideY `Y` index increment +* @param strideY stride length for `y` +* @param offsetY starting index for `y` */ -void c_ssort2sh( const int64_t N, const float order, float *X, const int64_t strideX, float *Y, const int64_t strideY ) { - int64_t offsetX; - int64_t offsetY; - int64_t gap; - int64_t sx; - int64_t sy; - int64_t i; - int64_t j; - int64_t k; +void API_SUFFIX(stdlib_strided_ssort2sh_ndarray)( const CBLAS_INT N, const float order, float *X, CBLAS_INT strideX, CBLAS_INT offsetX, float *Y, CBLAS_INT strideY, CBLAS_INT offsetY ) { + CBLAS_INT gap; + CBLAS_INT sx; + CBLAS_INT sy; + CBLAS_INT ox; + CBLAS_INT oy; + CBLAS_INT i; + CBLAS_INT j; + CBLAS_INT k; float vx; float vy; float ux; bool flg; // Ciura's gap sequence: - const static int64_t GAPS[] = { 701, 301, 132, 57, 23, 10, 4, 1 }; - const static int64_t NGAPS = 8; + const static CBLAS_INT GAPS[] = { 701, 301, 132, 57, 23, 10, 4, 1 }; + const static CBLAS_INT NGAPS = 8; if ( N <= 0 || order == 0.0f ) { return; @@ -66,43 +87,38 @@ void c_ssort2sh( const int64_t N, const float order, float *X, const int64_t str if ( order < 0.0f ) { sx = -strideX; sy = -strideY; + oy = offsetY - ( (N-1) * sy ); + ox = offsetX - ( (N-1) * sx ); } else { sx = strideX; sy = strideY; + ox = offsetX; + oy = offsetY; } - if ( sx < 0 ) { - offsetX = (1-N) * sx; - } else { - offsetX = 0; - } - if ( sy < 0 ) { - offsetY = (1-N) * sy; - } else { - offsetY = 0; - } + for ( i = 0; i < NGAPS; i++ ) { gap = GAPS[ i ]; for ( j = gap; j < N; j++ ) { - vx = X[ offsetX+(j*sx) ]; + vx = X[ ox+(j*sx) ]; // If `NaN`, the current value is already sorted to its place... if ( stdlib_base_is_nanf( vx ) ) { continue; } - vy = Y[ offsetY+(j*sy) ]; + vy = Y[ oy+(j*sy) ]; // Perform insertion sort on the "gapped" subarray... flg = stdlib_base_is_negative_zerof( vx ); for ( k = j; k >= gap; k -= gap ) { - ux = X[ offsetX+((k-gap)*sx) ]; + ux = X[ ox+((k-gap)*sx) ]; if ( ux <= vx && !(flg && ux == vx) ) { break; } - X[ offsetX+(k*sx) ] = ux; - Y[ offsetY+(k*sy) ] = Y[ offsetY+((k-gap)*sy) ]; + X[ ox+(k*sx) ] = ux; + Y[ oy+(k*sy) ] = Y[ oy+((k-gap)*sy) ]; } - X[ offsetX+(k*sx) ] = vx; - Y[ offsetY+(k*sy) ] = vy; + X[ ox+(k*sx) ] = vx; + Y[ oy+(k*sy) ] = vy; } } return; From d6bdd2669563ad2f1d86c50f861fd547452ed532 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sat, 8 Feb 2025 21:19:06 +0530 Subject: [PATCH 2/6] docs: improve clarity in README and documentation for ssort2sh function --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/ssort2sh/README.md | 12 ++++++------ .../benchmark/c/benchmark.unsorted_random.length.c | 4 ++-- .../@stdlib/blas/ext/base/ssort2sh/docs/repl.txt | 4 ++-- .../blas/ext/base/ssort2sh/examples/c/example.c | 2 +- .../@stdlib/blas/ext/base/ssort2sh/src/main.c | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md index 02bb973959d9..856852354519 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md @@ -58,7 +58,7 @@ The function has the following parameters: - **y**: second input [`Float32Array`][@stdlib/array/float32]. - **strideY**: stride length for `y`. -The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to sort every other element +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to sort every other element: ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -228,9 +228,9 @@ The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. - **order**: `[in] float` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. -- **X**: `[inout] float*` input array. +- **X**: `[inout] float*` first input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. -- **Y**: `[inout] float*` input array. +- **Y**: `[inout] float*` second input array. - **strideY**: `[in] CBLAS_INT` stride length for `Y`. ```c @@ -256,10 +256,10 @@ The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. - **order**: `[in] float` sort order. -- **X**: `[inout] float*` input array. +- **X**: `[inout] float*` first input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. - **offsetX**: `[in] CBLAS_INT` starting index for `X`. -- **Y**: `[inout] float*` input array. +- **Y**: `[inout] float*` second input array. - **strideY**: `[in] CBLAS_INT` stride length for `Y`. - **offsetY**: `[in] CBLAS_INT` starting index for `Y`. @@ -307,7 +307,7 @@ int main( void ) { // Print the result: for ( int i = 0; i < 8; i++ ) { printf( "x[ %i ] = %f\n", i, x[ i ] ); - printf( "y[ %i ] = %lf\n", i, y[ i ] ); + printf( "y[ %i ] = %f\n", i, y[ i ] ); } } ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c index fc9e6f0c2785..450ac64246d8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c @@ -138,8 +138,8 @@ static double benchmark2( int iterations, int len ) { float *y; int i; - x = (float *)malloc( len * sizeof(float) ); - y = (float *)malloc( len * sizeof(float) ); + x = ( float * )malloc( len * sizeof(float) ); + y = ( float * )malloc( len * sizeof(float) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*20.0f ) - 10.0f; y[ i ] = ( rand_float()*20.0f ) - 10.0f; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/repl.txt index a262e1d7b084..b2a342f5ab87 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/docs/repl.txt @@ -113,7 +113,7 @@ Stride length for `x`. offsetX: integer - Starting index of `x`. + Starting index for `x`. y: Float32Array Second input array. @@ -122,7 +122,7 @@ Stride length for `y`. offsetY: integer - Starting index of `y`. + Starting index for `y`. Returns ------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/c/example.c index cdae2adc6987..004ad39f54e9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/examples/c/example.c @@ -37,6 +37,6 @@ int main( void ) { // Print the result: for ( int i = 0; i < 8; i++ ) { printf( "x[ %i ] = %f\n", i, x[ i ] ); - printf( "y[ %i ] = %lf\n", i, y[ i ] ); + printf( "y[ %i ] = %f\n", i, y[ i ] ); } } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c index ae3c5a780480..50d03e7b9361 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c @@ -39,9 +39,9 @@ * @param N number of indexed elements * @param order sort order * @param X first input array -* @param strideX stride length for `x` +* @param strideX stride length for `X` * @param Y second input array -* @param strideY stride length for `y` +* @param strideY stride length for `Y` */ void API_SUFFIX(stdlib_strided_ssort2sh)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ) { CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); @@ -56,11 +56,11 @@ void API_SUFFIX(stdlib_strided_ssort2sh)( const CBLAS_INT N, const float order, * @param N number of indexed elements * @param order sort order * @param X first input array -* @param strideX stride length for `x` -* @param offsetX starting index for `x` +* @param strideX stride length for `X` +* @param offsetX starting index for `X` * @param Y second input array -* @param strideY stride length for `y` -* @param offsetY starting index for `y` +* @param strideY stride length for `Y` +* @param offsetY starting index for `Y` */ void API_SUFFIX(stdlib_strided_ssort2sh_ndarray)( const CBLAS_INT N, const float order, float *X, CBLAS_INT strideX, CBLAS_INT offsetX, float *Y, CBLAS_INT strideY, CBLAS_INT offsetY ) { CBLAS_INT gap; From 07ffa31a7f6655fff2c660784d5230e29e3497cb Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 9 Feb 2025 19:28:51 +0530 Subject: [PATCH 3/6] fix: improve code formatting in benchmark C files --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../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/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c index 450ac64246d8..7c21cfba7075 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c @@ -101,8 +101,8 @@ static double benchmark1( int iterations, int len ) { float *y; int i; - x = ( float * )malloc( len * sizeof(float) ); - y = ( float * )malloc( len * sizeof(float) ); + x = (float *)malloc( len * sizeof(float) ); + y = (float *)malloc( len * sizeof(float) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*20.0f ) - 10.0f; y[ i ] = ( rand_float()*20.0f ) - 10.0f; @@ -138,8 +138,8 @@ static double benchmark2( int iterations, int len ) { float *y; int i; - x = ( float * )malloc( len * sizeof(float) ); - y = ( float * )malloc( len * sizeof(float) ); + x = (float *)malloc( len * sizeof(float) ); + y = (float *)malloc( len * sizeof(float) ); for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*20.0f ) - 10.0f; y[ i ] = ( rand_float()*20.0f ) - 10.0f; From 0cee5ff69825ab4ba86dedcc991978df1a492334 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Mon, 10 Feb 2025 15:30:57 +0530 Subject: [PATCH 4/6] docs: enhance README for ssort2sh function to clarify sort order behavior --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md index 856852354519..8687a2992773 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md @@ -255,7 +255,7 @@ stdlib_strided_ssort2sh_ndarray( 4, 1.0f, x, 1, 0, y, 1, 0 ); The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. -- **order**: `[in] float` sort order. +- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. - **X**: `[inout] float*` first input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. - **offsetX**: `[in] CBLAS_INT` starting index for `X`. From 408a6963b23075f5e63ecc16df5f8085c037e3bf Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 18:37:22 +0530 Subject: [PATCH 5/6] chore: updated comments --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/blas/ext/base/ssort2sh/README.md | 12 ++++++------ .../benchmark/c/benchmark.unsorted_random.length.c | 2 +- .../@stdlib/blas/ext/base/ssort2sh/src/main.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md index 8687a2992773..a41e47afb504 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/README.md @@ -52,7 +52,7 @@ console.log( y ); 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. +- **order**: sort order. If `order < 0.0`, the input strided array `X` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `X` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. - **x**: first input [`Float32Array`][@stdlib/array/float32]. - **strideX**: stride length for `x`. - **y**: second input [`Float32Array`][@stdlib/array/float32]. @@ -147,7 +147,7 @@ console.log( y ); ## Notes -- If `N <= 0` or `order == 0.0`, both functions leave `x` and `y` unchanged. +- If `N <= 0` or `order == 0.0`, both functions leave `X` and `X` unchanged. - The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. - The algorithm has space complexity `O(1)` and worst case time complexity `O(N^(4/3))`. @@ -227,14 +227,14 @@ stdlib_strided_ssort2sh( 4, 1.0f, x, 1, y, 1 ); The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. -- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. +- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array `X` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `X` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. - **X**: `[inout] float*` first input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. - **Y**: `[inout] float*` second input array. - **strideY**: `[in] CBLAS_INT` stride length for `Y`. ```c -stdlib_strided_ssort2sh( const CBLAS_INT N, const float order, float *X, CBLAS_INT strideX, float *Y, CBLAS_INT strideY ); +stdlib_strided_ssort2sh( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ); ``` @@ -255,7 +255,7 @@ stdlib_strided_ssort2sh_ndarray( 4, 1.0f, x, 1, 0, y, 1, 0 ); The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. -- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. +- **order**: `[in] float` sort order. If `order < 0.0`, the input strided array `X` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `X` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. - **X**: `[inout] float*` first input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. - **offsetX**: `[in] CBLAS_INT` starting index for `X`. @@ -264,7 +264,7 @@ The function accepts the following arguments: - **offsetY**: `[in] CBLAS_INT` starting index for `Y`. ```c -stdlib_strided_ssort2sh_ndarray( const CBLAS_INT N, const float order, float *X, CBLAS_INT strideX, CBLAS_INT offsetX, float *Y, CBLAS_INT strideY, CBLAS_INT offsetY ); +stdlib_strided_ssort2sh_ndarray( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); ```
diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c index 7c21cfba7075..0bfa2f45fcff 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/benchmark/c/benchmark.unsorted_random.length.c @@ -82,7 +82,7 @@ static double tic( void ) { * * @return random number */ -static double rand_float( void ) { +static float rand_float( void ) { int r = rand(); return (float)r / ( (float)RAND_MAX + 1.0f ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c index 50d03e7b9361..6b869d223ba3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c @@ -62,7 +62,7 @@ void API_SUFFIX(stdlib_strided_ssort2sh)( const CBLAS_INT N, const float order, * @param strideY stride length for `Y` * @param offsetY starting index for `Y` */ -void API_SUFFIX(stdlib_strided_ssort2sh_ndarray)( const CBLAS_INT N, const float order, float *X, CBLAS_INT strideX, CBLAS_INT offsetX, float *Y, CBLAS_INT strideY, CBLAS_INT offsetY ) { +void API_SUFFIX(stdlib_strided_ssort2sh_ndarray)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { CBLAS_INT gap; CBLAS_INT sx; CBLAS_INT sy; From 1d44c7502ece839c6ee7501d085fea727b0c7b3a Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 18:38:43 +0530 Subject: [PATCH 6/6] chore: updated comments --- lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c index 6b869d223ba3..5a956db580db 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssort2sh/src/main.c @@ -25,7 +25,6 @@ /** * Simultaneously sorts two single-precision floating-point strided arrays based on the sort order of the first array using Shellsort. -/** * * ## Notes *