diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/README.md index 069608bf7ddb..2f9625ee1c38 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/README.md @@ -30,9 +30,9 @@ limitations under the License. var ssortsh = require( '@stdlib/blas/ext/base/ssortsh' ); ``` -#### ssortsh( N, order, x, stride ) +#### ssortsh( N, order, x, strideX ) -Sorts a single-precision floating-point strided array `x` using Shellsort. +Sorts a single-precision floating-point strided array using Shellsort. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -48,9 +48,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **order**: sort order. If `order < 0.0`, the input strided array is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged. - **x**: input [`Float32Array`][@stdlib/array/float32]. -- **stride**: index increment. +- **strideX**: stride length. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to sort every other element +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to sort every other element: ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -81,9 +81,9 @@ ssortsh( N, -1.0, x1, 2 ); // x0 => [ 1.0, 4.0, 3.0, 2.0 ] ``` -#### ssortsh.ndarray( N, order, x, stride, offset ) +#### ssortsh.ndarray( N, order, x, strideX, offsetX ) -Sorts a single-precision floating-point strided array `x` using Shellsort and alternative indexing semantics. +Sorts a single-precision floating-point strided array using Shellsort and alternative indexing semantics. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -96,9 +96,9 @@ ssortsh.ndarray( x.length, 1.0, x, 1, 0 ); The function has the following additional parameters: -- **offset**: starting index. +- **offsetX**: 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 parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -117,7 +117,7 @@ ssortsh.ndarray( 3, 1.0, x, 1, x.length-3 ); ## Notes -- If `N <= 0` or `order == 0.0`, both functions return `x` unchanged. +- If `N <= 0` or `order == 0.0`, both functions return `X` unchanged. - The algorithm distinguishes between `-0` and `+0`. When sorted in increasing order, `-0` is sorted before `+0`. When sorted in decreasing order, `-0` is sorted after `+0`. - The algorithm sorts `NaN` values to the end. When sorted in increasing order, `NaN` values are sorted last. When sorted in decreasing order, `NaN` values are sorted first. - The algorithm has space complexity `O(1)` and worst case time complexity `O(N^(4/3))`. @@ -136,27 +136,12 @@ ssortsh.ndarray( 3, 1.0, x, 1, x.length-3 ); ```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 ssortsh = require( '@stdlib/blas/ext/base/ssortsh' ); -var rand; -var sign; -var x; -var i; - -x = new Float32Array( 10 ); -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; -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float32' +}); console.log( x ); ssortsh( x.length, -1.0, x, -1 ); @@ -169,6 +154,125 @@ console.log( x ); * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ssortsh.h" +``` + +#### stdlib_strided_ssortsh( N, order, \*X, strideX ) + +Sorts a single-precision floating-point strided array using Shellsort. + +```c +float x[] = { 1.0f, -2.0f, 3.0f, -4.0f }; + +stdlib_strided_ssortsh( 2, -1.0f, x, 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 is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged. +- **X**: `[inout] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length. + +```c +stdlib_strided_ssortsh( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX ); +``` + + + +#### stdlib_strided_ssortsh_ndarray( N, order, \*X, strideX, offsetX ) + + + +Sorts a single-precision floating-point strided array using Shellsort and alternative indexing semantics. + +```c +float x[] = { 1.0f, -2.0f, 3.0f, -4.0f }; + +stdlib_strided_ssortsh_ndarray( 4, 1.0f, x, 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 is sorted in **decreasing** order. If `order > 0.0`, the input strided array is sorted in **increasing** order. If `order == 0.0`, the input strided array is left unchanged. +- **X**: `[inout] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length. +- **offsetX**: `[in] CBLAS_INT` starting index. + +```c +stdlib_strided_ssortsh_ndarray( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/ssortsh.h" +#include + +int main( void ) { + // Create a strided array: + float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; + + // Specify the number of elements: + int N = 8; + + // Specify a stride: + int strideX = 1; + + // Sort the array: + stdlib_strided_ssortsh( N, 1.0f, x, strideX ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %f\n", i, x[ i ] ); + } +} +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/benchmark/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/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 := example.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 examples. +# +# @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/ssortsh/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/benchmark/c/benchmark.unsorted_random.length.c new file mode 100644 index 000000000000..160c1a53b7bd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/benchmark/c/benchmark.unsorted_random.length.c @@ -0,0 +1,191 @@ +/** +* @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/ssortsh.h" +#include +#include +#include +#include +#include + +#define NAME "ssortsh" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static float rand_float( void ) { + int r = rand(); + return (float)r / ( (float)RAND_MAX + 1.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; + float x[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*20.0f ) - 10.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_ssortsh( len, 1.0f, x, 1 ); + if ( x[ 0 ] != x[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( x[ 0 ] != x[ 0 ] ) { + 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; + float x[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float()*20.0f ) - 10.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_ssortsh_ndarray( len, 1.0f, x, 1, 0 ); + if ( x[ 0 ] != x[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( x[ 0 ] != x[ 0 ] ) { + 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/ssortsh/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/docs/repl.txt index b24a9329b773..086f9fda39a4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, order, x, stride ) +{{alias}}( N, order, x, strideX ) Sorts a single-precision floating-point strided array using Shellsort. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. @@ -42,13 +42,13 @@ x: Float32Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. Returns ------- x: Float32Array - Input array `x`. + Input array. Examples -------- @@ -57,7 +57,7 @@ > {{alias}}( x.length, 1, x, 1 ) [ -4.0, -2.0, 1.0, 3.0 ] - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0 ] ); > {{alias}}( 2, -1, x, 2 ) [ 3.0, -2.0, 1.0, -4.0 ] @@ -71,7 +71,7 @@ [ 1.0, -4.0, 3.0, -2.0 ] -{{alias}}.ndarray( N, order, x, stride, offset ) +{{alias}}.ndarray( N, order, x, strideX, offsetX ) Sorts a single-precision floating-point strided array using Shellsort and alternative indexing semantics. @@ -91,16 +91,16 @@ x: Float32Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index of `x`. Returns ------- x: Float32Array - Input array `x`. + Input array. Examples -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/docs/types/index.d.ts index 5d32b492fd59..80fc8518f315 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/docs/types/index.d.ts @@ -28,7 +28,7 @@ interface Routine { * @param N - number of indexed elements * @param order - sort order * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns `x` * * @example @@ -39,7 +39,7 @@ interface Routine { * ssortsh( x.length, 1, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ - ( N: number, order: number, x: Float32Array, stride: number ): Float32Array; + ( N: number, order: number, x: Float32Array, strideX: number ): Float32Array; /** * Sorts a single-precision floating-point strided array using Shellsort and alternative indexing semantics. @@ -47,8 +47,8 @@ interface Routine { * @param N - number of indexed elements * @param order - sort order * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns `x` * * @example @@ -59,7 +59,7 @@ interface Routine { * ssortsh.ndarray( x.length, 1, x, 1, 0 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ - ndarray( N: number, order: number, x: Float32Array, stride: number, offset: number ): Float32Array; + ndarray( N: number, order: number, x: Float32Array, strideX: number, offsetX: number ): Float32Array; } /** @@ -68,7 +68,7 @@ interface Routine { * @param N - number of indexed elements * @param order - sort order * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns `x` * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/examples/c/example.c index e927fb7ec077..2f4f105099c5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/examples/c/example.c @@ -21,7 +21,7 @@ int main( void ) { // Create a strided array: - float x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f }; // Specify the number of elements: int N = 8; @@ -30,7 +30,7 @@ int main( void ) { int strideX = 1; // Sort the array: - c_ssortsh( N, 1.0f, x, strideX ); + stdlib_strided_ssortsh( N, 1.0f, x, strideX ); // Print the result: for ( int i = 0; i < 8; i++ ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/examples/index.js index bd02c14c1ded..26d0f89818c2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/examples/index.js @@ -18,31 +18,12 @@ '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 ssortsh = require( './../lib' ); -var rand; -var sign; -var x; -var i; - -x = new Float32Array( 10 ); -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; - } -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); ssortsh( x.length, -1.0, x, -1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/include/stdlib/blas/ext/base/ssortsh.h b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/include/stdlib/blas/ext/base/ssortsh.h index cd08d8f8f840..361c8c496a87 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/include/stdlib/blas/ext/base/ssortsh.h +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/include/stdlib/blas/ext/base/ssortsh.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_SSORTSH_H #define STDLIB_BLAS_EXT_BASE_SSORTSH_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" { /** * Sorts a single-precision floating-point strided array using Shellsort. */ -void c_ssortsh( const int64_t N, const float order, float *X, const int64_t stride ); +void API_SUFFIX(stdlib_strided_ssortsh)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX ); + +/** +* Sorts a single-precision floating-point strided array using Shellsort and alternative indexing semantics. +*/ +void API_SUFFIX(stdlib_strided_ssortsh_ndarray)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ndarray.js index 949a4927125e..7a93daea3d3f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ndarray.js @@ -47,8 +47,8 @@ var NGAPS = GAPS.length; * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float32Array} x - input array -* @param {integer} stride - index increment -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {Float32Array} input array * * @example @@ -59,7 +59,7 @@ var NGAPS = GAPS.length; * ssortsh( x.length, 1.0, x, 1, 0 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function ssortsh( N, order, x, stride, offset ) { +function ssortsh( N, order, x, strideX, offsetX ) { var flg; var gap; var v; @@ -73,13 +73,13 @@ function ssortsh( N, order, x, stride, offset ) { } // 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 ) { - stride *= -1; - offset -= (N-1) * stride; + strideX *= -1; + offsetX -= (N-1) * strideX; } for ( i = 0; i < NGAPS; i++ ) { gap = GAPS[ i ]; for ( j = gap; j < N; j++ ) { - v = x[ offset+(j*stride) ]; + v = x[ offsetX+(j*strideX) ]; // If `NaN`, the current value is already sorted to its place... if ( isnanf( v ) ) { @@ -88,13 +88,13 @@ function ssortsh( N, order, x, stride, offset ) { // Perform insertion sort on the "gapped" subarray... flg = isNegativeZerof( v ); for ( k = j; k >= gap; k -= gap ) { - u = x[ offset+((k-gap)*stride) ]; + u = x[ offsetX+((k-gap)*strideX) ]; if ( u <= v && !(flg && u === v) ) { break; } - x[ offset+(k*stride) ] = u; + x[ offsetX+(k*strideX) ] = u; } - x[ offset+(k*stride) ] = v; + x[ offsetX+(k*strideX) ] = v; } } return x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ndarray.native.js index 6f7b57fea00f..d8d36efc166b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './ssortsh.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -33,8 +31,8 @@ var addon = require( './ssortsh.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float32Array} x - input array -* @param {integer} stride - index increment -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {Float32Array} input array * * @example @@ -44,15 +42,8 @@ var addon = require( './ssortsh.native.js' ); * * ssortsh( x.length, 1.0, x, 1, 0 ); */ -function ssortsh( N, order, x, stride, offset ) { - var view; - offset = minViewBufferIndex( N, stride, offset ); - if ( stride < 0 ) { - order *= -1.0; - stride *= -1; - } - view = offsetView( x, offset ); - addon( N, order, view, stride ); +function ssortsh( N, order, x, strideX, offsetX ) { + addon.ndarray( N, order, x, strideX, offsetX ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ssortsh.js b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ssortsh.js index 8c5ce897d896..067fcfd32c24 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ssortsh.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ssortsh.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,7 +41,7 @@ var NGAPS = GAPS.length; * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float32Array} x - input array -* @param {integer} stride - index increment +* @param {integer} strideX - stride length * @returns {Float32Array} input array * * @example @@ -58,50 +52,8 @@ var NGAPS = GAPS.length; * ssortsh( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function ssortsh( N, order, x, stride ) { - var offset; - var flg; - var gap; - var v; - var u; - 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 ) { - stride *= -1; - } - if ( stride < 0 ) { - offset = (1-N) * stride; - } else { - offset = 0; - } - for ( i = 0; i < NGAPS; i++ ) { - gap = GAPS[ i ]; - for ( j = gap; j < N; j++ ) { - v = x[ offset+(j*stride) ]; - - // If `NaN`, the current value is already sorted to its place... - if ( isnanf( v ) ) { - continue; - } - // Perform insertion sort on the "gapped" subarray... - flg = isNegativeZerof( v ); - for ( k = j; k >= gap; k -= gap ) { - u = x[ offset+((k-gap)*stride) ]; - if ( u <= v && !(flg && u === v) ) { - break; - } - x[ offset+(k*stride) ] = u; - } - x[ offset+(k*stride) ] = v; - } - } - return x; +function ssortsh( N, order, x, strideX ) { + return ndarray( N, order, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ssortsh.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ssortsh.native.js index 4fd7fac1cc0d..f35ae0db43d1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ssortsh.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/lib/ssortsh.native.js @@ -31,7 +31,7 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float32Array} x - input array -* @param {integer} stride - index increment +* @param {integer} strideX - stride length * @returns {Float32Array} input array * * @example @@ -42,8 +42,8 @@ var addon = require( './../src/addon.node' ); * ssortsh( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function ssortsh( N, order, x, stride ) { - addon( N, order, x, stride ); +function ssortsh( N, order, x, strideX ) { + addon( N, order, x, strideX ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/manifest.json index 4245202a19e7..7928264142fc 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,15 +26,14 @@ ], "confs": [ { + "task": "build", "src": [ - "./src/ssortsh.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nanf", @@ -41,7 +42,43 @@ "@stdlib/napi/argv", "@stdlib/napi/argv-float", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array" + "@stdlib/napi/argv-strided-float32array", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/assert/is-negative-zerof", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/assert/is-negative-zerof", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/addon.c index 9545ef904d05..67410f083861 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/addon.c @@ -24,14 +24,39 @@ #include "stdlib/napi/argv_strided_float32array.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, 4 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_FLOAT( env, order, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); - c_ssortsh( N, order, X, stride ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_ssortsh)( N, order, X, strideX ); + 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, 5 ); + 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_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_ssortsh_ndarray)( N, order, X, strideX, offsetX ); return NULL; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/ssortsh.c b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/main.c similarity index 66% rename from lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/ssortsh.c rename to lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/main.c index 2d8c42777bfe..911ca7fb8539 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortsh/src/ssortsh.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortsh/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,7 +19,8 @@ #include "stdlib/blas/ext/base/ssortsh.h" #include "stdlib/math/base/assert/is_negative_zerof.h" #include "stdlib/math/base/assert/is_nanf.h" -#include +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" #include /** @@ -39,39 +40,51 @@ * @param X input array * @param stride index increment */ -void c_ssortsh( const int64_t N, const float order, float *X, const int64_t stride ) { - int64_t offset; - int64_t gap; - int64_t sx; - int64_t i; - int64_t j; - int64_t k; +void API_SUFFIX(stdlib_strided_ssortsh)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + API_SUFFIX(stdlib_strided_ssortsh_ndarray)( N, order, X, strideX, ox ); +} + +/** +* Sorts a single-precision floating-point strided array using Shellsort and alternative indexing semantics. +* +* @param N number of indexed elements +* @param order sort order +* @param X input array +* @param strideX stride length +* @param offsetX starting index +*/ +void API_SUFFIX(stdlib_strided_ssortsh_ndarray)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT gap; + CBLAS_INT sx; + CBLAS_INT ox; + CBLAS_INT i; + CBLAS_INT j; + CBLAS_INT k; bool flg; float v; float u; // 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; } // 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.0f ) { - sx = -stride; - } else { - sx = stride; - } - if ( sx < 0 ) { - offset = (1-N) * sx; + sx = -strideX; + ox = offsetX - ( (N-1) * sx ); } else { - offset = 0; + sx = strideX; + ox = offsetX; } + for ( i = 0; i < NGAPS; i++ ) { gap = GAPS[ i ]; for ( j = gap; j < N; j++ ) { - v = X[ offset+(j*sx) ]; + v = X[ ox+(j*sx) ]; // If `NaN`, the current value is already sorted to its place... if ( stdlib_base_is_nanf( v ) ) { @@ -80,13 +93,13 @@ void c_ssortsh( const int64_t N, const float order, float *X, const int64_t stri // Perform insertion sort on the "gapped" subarray... flg = stdlib_base_is_negative_zerof( v ); for ( k = j; k >= gap; k -= gap ) { - u = X[ offset+((k-gap)*sx) ]; + u = X[ ox+((k-gap)*sx) ]; if ( u <= v && !(flg && u == v) ) { break; } - X[ offset+(k*sx) ] = u; + X[ ox+(k*sx) ] = u; } - X[ offset+(k*sx) ] = v; + X[ ox+(k*sx) ] = v; } } return;