diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/README.md index 26a73d85ee9d..281fe373c3ea 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/README.md @@ -30,9 +30,9 @@ limitations under the License. var dsortsh = require( '@stdlib/blas/ext/base/dsortsh' ); ``` -#### dsortsh( N, order, x, stride ) +#### dsortsh( N, order, x, strideX ) -Sorts a double-precision floating-point strided array `x` using Shellsort. +Sorts a double-precision floating-point strided array using Shellsort. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -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 [`Float64Array`][@stdlib/array/float64]. -- **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 Float64Array = require( '@stdlib/array/float64' ); @@ -77,9 +77,9 @@ dsortsh( 2, -1.0, x1, 2 ); // x0 => [ 1.0, 4.0, 3.0, 2.0 ] ``` -#### dsortsh.ndarray( N, order, x, stride, offset ) +#### dsortsh.ndarray( N, order, x, strideX, offsetX ) -Sorts a double-precision floating-point strided array `x` using Shellsort and alternative indexing semantics. +Sorts a double-precision floating-point strided array using Shellsort and alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -92,9 +92,9 @@ dsortsh.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 Float64Array = require( '@stdlib/array/float64' ); @@ -132,11 +132,12 @@ dsortsh.ndarray( 3, 1.0, x, 1, x.length-3 ); ```javascript -var filledarrayBy = require( '@stdlib/array/filled-by' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dsortsh = require( '@stdlib/blas/ext/base/dsortsh' ); -var x = filledarrayBy( 100, 'float64', uniform( -100.0, 100.0 ) ); +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); dsortsh( x.length, -1.0, x, -1 ); @@ -167,6 +168,126 @@ console.log( x ); * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dsortsh.h" +``` + +#### stdlib_strided_dsortsh( N, order, \*X, strideX ) + +Sorts a double-precision floating-point strided array using Shellsort. + +```c +double x[] = { 1.0, -2.0, 3.0, -4.0 }; + +stdlib_strided_dsortsh( 2, -1.0, x, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] double` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. +- **X**: `[inout] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length. + +```c +stdlib_strided_dsortsh( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ); +``` + + + +#### stdlib_strided_dsortsh_ndarray( N, order, \*X, strideX, offsetX ) + + + +Sorts a double-precision floating-point strided array using Shellsort and alternative indexing semantics. + +```c +double x[] = { 1.0, -2.0, 3.0, -4.0 }; + +stdlib_strided_dsortsh_ndarray( 4, 1.0, x, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] double` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. +- **strideX**: `[in] CBLAS_INT` stride length. +- **X**: `[inout] double*` input array. +- **offsetX**: `[in] CBLAS_INT` starting index. + +```c +stdlib_strided_dsortsh_ndarray( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dsortsh.h" +#include + +int main( void ) { + // Create a strided array: + double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + + // Specify the number of elements: + int N = 8; + + // Specify a stride: + int strideX = 1; + + // Sort the array: + stdlib_strided_dsortsh( N, 1.0, x, strideX ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + } +} + +``` + +
+ + + +
+ + + ## See Also - [`@stdlib/blas/ext/base/dsort2sh`][@stdlib/blas/ext/base/dsort2sh]: simultaneously sort two double-precision floating-point strided arrays based on the sort order of the first array using Shellsort. diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/benchmark/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/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/dsortsh/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/benchmark/c/benchmark.unsorted_random.length.c new file mode 100644 index 000000000000..6f36c2b4832c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/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/dsortsh.h" +#include +#include +#include +#include +#include + +#define NAME "dsortsh" +#define ITERATIONS 10000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [0,1). +* +* @return random number +*/ +static double rand_double( void ) { + int r = rand(); + return (double)r / ( (double)RAND_MAX + 1.0 ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + double x[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*20.0 ) - 10.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_dsortsh( len, 1.0, 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; + double x[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_double()*20.0 ) - 10.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + stdlib_strided_dsortsh_ndarray( len, 1.0, 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/dsortsh/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/docs/repl.txt index 7f0915abd0c7..e6e7182e3067 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, order, x, stride ) +{{alias}}( N, order, x, strideX ) Sorts a double-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: Float64Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. Returns ------- x: Float64Array - Input array `x`. + Input array. Examples -------- @@ -59,26 +59,25 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, -1, x, 2 ) + > {{alias}}( 2, -1, x, 2 ) [ 3.0, -2.0, 1.0, -4.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > {{alias}}( N, 1, x1, 2 ) + > {{alias}}( 2, 1, x1, 2 ) [ -4.0, 3.0, -2.0 ] > x0 [ 1.0, -4.0, 3.0, -2.0 ] -{{alias}}.ndarray( N, order, x, stride, offset ) + +{{alias}}.ndarray( N, order, x, strideX, offsetX ) Sorts a double-precision floating-point strided array using Shellsort and alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. + buffer, the offset parameter supports indexing semantics based on a starting + index. Parameters ---------- @@ -92,16 +91,16 @@ x: Float64Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index of `x`. Returns ------- x: Float64Array - Input array `x`. + Input array. Examples -------- @@ -112,8 +111,7 @@ // Using an index offset: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, 1, x, 2, 1 ) + > {{alias}}.ndarray( 2, 1, x, 2, 1 ) [ 1.0, -4.0, 3.0, -2.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/docs/types/index.d.ts index 196e7051f4fb..260c564e9767 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/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 { * dsortsh( x.length, 1, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ - ( N: number, order: number, x: Float64Array, stride: number ): Float64Array; + ( N: number, order: number, x: Float64Array, strideX: number ): Float64Array; /** * Sorts a double-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 { * dsortsh.ndarray( x.length, 1, x, 1, 0 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ - ndarray( N: number, order: number, x: Float64Array, stride: number, offset: number ): Float64Array; + ndarray( N: number, order: number, x: Float64Array, strideX: number, offsetX: number ): Float64Array; } /** @@ -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/dsortsh/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/examples/c/example.c index 76ec1c849d71..80c83f937ca3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/examples/c/example.c @@ -30,7 +30,7 @@ int main( void ) { int strideX = 1; // Sort the array: - c_dsortsh( N, 1.0, x, strideX ); + API_SUFFIX(stdlib_strided_dsortsh)( N, 1.0, x, strideX ); // Print the result: for ( int i = 0; i < 8; i++ ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/examples/index.js index a036fb73dc8a..b4c2c1920948 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/examples/index.js @@ -18,11 +18,12 @@ 'use strict'; -var filledarrayBy = require( '@stdlib/array/filled-by' ); -var uniform = require( '@stdlib/random/base/uniform' ).factory; +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dsortsh = require( './../lib' ); -var x = filledarrayBy( 100, 'float64', uniform( -100.0, 100.0 ) ); +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); dsortsh( x.length, -1.0, x, -1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/include/stdlib/blas/ext/base/dsortsh.h b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/include/stdlib/blas/ext/base/dsortsh.h index a7fea982abda..c142542b1c09 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/include/stdlib/blas/ext/base/dsortsh.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/include/stdlib/blas/ext/base/dsortsh.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DSORTSH_H #define STDLIB_BLAS_EXT_BASE_DSORTSH_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 double-precision floating-point strided array using Shellsort. */ -void c_dsortsh( const int64_t N, const double order, double *X, const int64_t stride ); +void API_SUFFIX(stdlib_strided_dsortsh)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ); + +/** +* Sorts a double-precision floating-point strided array using Shellsort and alternative indexing semantics. +*/ +void API_SUFFIX(stdlib_strided_dsortsh_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/dsortsh.js b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/dsortsh.js index 4bf00d9e0b4e..81ab03353448 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/dsortsh.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/dsortsh.js @@ -20,14 +20,8 @@ // MODULES // -var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -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 {Float64Array} x - input array -* @param {integer} stride - index increment +* @param {integer} strideX - stride length * @returns {Float64Array} input array * * @example @@ -58,50 +52,8 @@ var NGAPS = GAPS.length; * dsortsh( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function dsortsh( 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 ( isnan( v ) ) { - continue; - } - // Perform insertion sort on the "gapped" subarray... - flg = isNegativeZero( 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 dsortsh( N, order, x, strideX ) { + return ndarray( N, order, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/dsortsh.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/dsortsh.native.js index 70b36372020e..a67388a737d0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/dsortsh.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/dsortsh.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 {Float64Array} x - input array -* @param {integer} stride - index increment +* @param {integer} strideX - stride length * @returns {Float64Array} input array * * @example @@ -42,8 +42,8 @@ var addon = require( './../src/addon.node' ); * dsortsh( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function dsortsh( N, order, x, stride ) { - addon( N, order, x, stride ); +function dsortsh( N, order, x, strideX ) { + addon( N, order, x, strideX ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/ndarray.js index 6a664fa8a2c7..6c167928081b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/ndarray.js @@ -47,8 +47,8 @@ var NGAPS = GAPS.length; * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float64Array} x - input array -* @param {integer} stride - index increment -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {Float64Array} input array * * @example @@ -59,7 +59,7 @@ var NGAPS = GAPS.length; * dsortsh( x.length, 1.0, x, 1, 0 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function dsortsh( N, order, x, stride, offset ) { +function dsortsh( N, order, x, strideX, offsetX ) { var flg; var gap; var v; @@ -73,13 +73,13 @@ function dsortsh( 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 ( isnan( v ) ) { @@ -88,13 +88,13 @@ function dsortsh( N, order, x, stride, offset ) { // Perform insertion sort on the "gapped" subarray... flg = isNegativeZero( 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/dsortsh/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/ndarray.native.js index 04a4826ca225..67df06c5f25c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dsortsh.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,8 +31,8 @@ var addon = require( './dsortsh.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} order - sort order * @param {Float64Array} x - input array -* @param {integer} stride - index increment -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {Float64Array} input array * * @example @@ -43,16 +42,8 @@ var addon = require( './dsortsh.native.js' ); * * dsortsh( x.length, 1.0, x, 1, 0 ); */ -function dsortsh( N, order, x, stride, offset ) { - var view; - if ( stride < 0 ) { - order *= -1.0; - stride *= -1; - offset -= (N-1) * stride; - } - view = offsetView( x, offset ); - addon( N, order, view, stride ); - +function dsortsh( N, order, x, strideX, offsetX ) { + addon.ndarray( N, order, x, strideX, offsetX ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/manifest.json index c1abfaef7028..348693c06e61 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", @@ -24,15 +26,14 @@ ], "confs": [ { + "task": "build", "src": [ - "./src/dsortsh.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/napi/export", @@ -41,7 +42,43 @@ "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "benchmark", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-negative-zero", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-negative-zero", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/addon.c index 74c6dc94bf47..31d0834147f3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/addon.c @@ -36,11 +36,27 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, order, argv, 2 ); - - c_dsortsh( N, order, X, strideX ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_dsortsh)( 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_DOUBLE( env, order, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_dsortsh_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/dsortsh/src/dsortsh.c b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/main.c similarity index 65% rename from lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/dsortsh.c rename to lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/main.c index 76479745876d..f8c7c6e0006a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortsh/src/dsortsh.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortsh/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/dsortsh.h" #include "stdlib/math/base/assert/is_negative_zero.h" #include "stdlib/math/base/assert/is_nan.h" -#include +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" #include /** @@ -34,18 +35,32 @@ * - Shell, Donald L. 1959. "A High-Speed Sorting Procedure." _Communications of the ACM_ 2 (7). Association for Computing Machinery: 30–32. doi:[10.1145/368370.368387](https://doi.org/10.1145/368370.368387). * - Ciura, Marcin. 2001. "Best Increments for the Average Case of Shellsort." In _Fundamentals of Computation Theory_, 106–17. Springer Berlin Heidelberg. doi:[10.1007/3-540-44669-9\_12](https://doi.org/10.1007/3-540-44669-9_12). * -* @param N number of indexed elements -* @param order sort order -* @param X input array -* @param stride index increment +* @param N number of indexed elements +* @param order sort order +* @param X input array +* @param strideX stride length */ -void c_dsortsh( const int64_t N, const double order, double *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_dsortsh)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + API_SUFFIX(stdlib_strided_dsortsh_ndarray)( N, order, X, strideX, ox ); +} + +/** +* Sorts a double-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_dsortsh_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT gap; + CBLAS_INT ox; + CBLAS_INT sx; + CBLAS_INT i; + CBLAS_INT j; + CBLAS_INT k; double v; double u; bool flg; @@ -59,19 +74,17 @@ void c_dsortsh( const int64_t N, const double order, double *X, const int64_t st } // For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order... if ( order < 0.0 ) { - sx = -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_nan( v ) ) { @@ -80,13 +93,13 @@ void c_dsortsh( const int64_t N, const double order, double *X, const int64_t st // Perform insertion sort on the "gapped" subarray... flg = stdlib_base_is_negative_zero( 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;