diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/README.md b/lib/node_modules/@stdlib/blas/ext/base/ssortins/README.md index 20d57a82e474..fb8cc07aa8b5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/README.md @@ -30,9 +30,9 @@ limitations under the License. var ssortins = require( '@stdlib/blas/ext/base/ssortins' ); ``` -#### ssortins( N, order, x, stride ) +#### ssortins( N, order, x, strideX ) -Sorts a single-precision floating-point strided array `x` using insertion sort. +Sorts a single-precision floating-point strided array using insertion sort. ```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 the strided array 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' ); @@ -77,9 +77,9 @@ ssortins( 2, -1.0, x1, 2 ); // x0 => [ 1.0, 4.0, 3.0, 2.0 ] ``` -#### ssortins.ndarray( N, order, x, stride, offset ) +#### ssortins.ndarray( N, order, x, strideX, offsetX ) -Sorts a single-precision floating-point strided array `x` using insertion sort and alternative indexing semantics. +Sorts a single-precision floating-point strided array using insertion sort and alternative indexing semantics. ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -92,9 +92,9 @@ ssortins.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' ); @@ -132,26 +132,12 @@ ssortins.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 ssortins = require( '@stdlib/blas/ext/base/ssortins' ); -var rand; -var sign; -var i; - -var 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 ); ssortins( x.length, -1.0, x, -1 ); @@ -168,6 +154,125 @@ console.log( x ); * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/ssortins.h" +``` + +#### stdlib_strided_ssortins( N, order, \*X, strideX ) + +Sorts a single-precision floating-point strided array using insertion sort. + +```c +float x[] = { 1.0f, -2.0f, 3.0f, -4.0f }; + +stdlib_strided_ssortins( 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_ssortins( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX ); +``` + + + +#### stdlib_strided_ssortins_ndarray( N, order, \*X, strideX, offsetX ) + + + +Sorts a single-precision floating-point strided array using insertion sort and alternative indexing semantics. + +```c +float x[] = { 1.0f, -2.0f, 3.0f, -4.0f }; + +stdlib_strided_ssortins_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_ssortins_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/ssortins.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_ssortins( N, 1.0f, x, strideX ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %f\n", i, x[ i ] ); + } +} +``` + +
+ + + +
+ + + ## See Also - [`@stdlib/blas/ext/base/dsortins`][@stdlib/blas/ext/base/dsortins]: sort a double-precision floating-point strided array using insertion sort. diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/ssortins/benchmark/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/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/ssortins/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/ssortins/benchmark/c/benchmark.unsorted_random.length.c new file mode 100644 index 000000000000..1b9854a8ac7e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/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/ssortins.h" +#include +#include +#include +#include +#include + +#define NAME "ssortins" +#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_ssortins( 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_ssortins_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/ssortins/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/ssortins/docs/repl.txt index e8f88d6523f8..8505e86c01de 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( N, order, x, stride ) +{{alias}}( N, order, x, strideX ) Sorts a single-precision floating-point strided array using insertion sort. The `N` and stride parameters determine which elements in the strided array @@ -44,8 +44,8 @@ x: Float32Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. Returns ------- @@ -73,7 +73,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 insertion sort and alternative indexing semantics. @@ -93,10 +93,10 @@ x: Float32Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index of `x`. Returns diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/ssortins/docs/types/index.d.ts index 69820975f993..d78be9152f34 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/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 input array * * @example @@ -39,7 +39,7 @@ interface Routine { * ssortins( 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 insertion sort 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 input array * * @example @@ -59,7 +59,7 @@ interface Routine { * ssortins.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 input array * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/ssortins/examples/c/example.c index 076355d117b2..dd71b5387117 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/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_ssortins( N, 1.0f, x, strideX ); + stdlib_strided_ssortins( 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/ssortins/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/ssortins/examples/index.js index 4a5a36c9dc31..9e543e8c36df 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/examples/index.js @@ -18,30 +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 ssortins = require( './../lib' ); -var rand; -var sign; -var i; - -var 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': 'float32' +}); console.log( x ); ssortins( x.length, -1.0, x, -1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/include/stdlib/blas/ext/base/ssortins.h b/lib/node_modules/@stdlib/blas/ext/base/ssortins/include/stdlib/blas/ext/base/ssortins.h index 54c78e19d362..b327c7aceadd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/include/stdlib/blas/ext/base/ssortins.h +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/include/stdlib/blas/ext/base/ssortins.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_SSORTINS_H #define STDLIB_BLAS_EXT_BASE_SSORTINS_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 insertion sort. */ -void c_ssortins( const int64_t N, const float order, float *X, const int64_t stride ); +void API_SUFFIX(stdlib_strided_ssortins)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX ); + +/** +* Sorts a single-precision floating-point strided array using insertion sort and alternative indexing semantics. +*/ +void API_SUFFIX(stdlib_strided_ssortins_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/ssortins/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ndarray.js index d003d3d84c05..a8017b285f41 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ndarray.js @@ -32,8 +32,8 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); * @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,7 +44,7 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); * ssortins( x.length, 1.0, x, 1, 0 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function ssortins( N, order, x, stride, offset ) { +function ssortins( N, order, x, strideX, offsetX ) { var flg; var ix; var jx; @@ -59,14 +59,14 @@ function ssortins( 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; } - fx = offset; // first index - lx = fx + ((N-1)*stride); // last index - ix = fx + stride; + fx = offsetX; // first index + lx = fx + ((N-1)*strideX); // last index + ix = fx + strideX; - if ( stride < 0 ) { + if ( strideX < 0 ) { // Traverse the strided array from right-to-left... // Sort in increasing order... @@ -79,13 +79,13 @@ function ssortins( N, order, x, stride, offset ) { // Shift all values (including NaNs) to the left of the current element to the right... while ( jx > lx ) { - x[ jx ] = x[ jx+stride ]; - jx += stride; + x[ jx ] = x[ jx+strideX ]; + jx += strideX; } x[ lx ] = v; } else { flg = isNegativeZerof( v ); - jx = ix - stride; + jx = ix - strideX; // Shift all larger values to the right of the current element to the left... while ( jx <= fx ) { @@ -94,11 +94,11 @@ function ssortins( N, order, x, stride, offset ) { // Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left break; } - x[ jx+stride ] = u; - jx -= stride; + x[ jx+strideX ] = u; + jx -= strideX; } - x[ jx+stride ] = v; - ix += stride; + x[ jx+strideX ] = v; + ix += strideX; } } return x; @@ -115,13 +115,13 @@ function ssortins( N, order, x, stride, offset ) { // Shift all values (including NaNs) to the right of the current element to the left... while ( jx < lx ) { - x[ jx ] = x[ jx+stride ]; - jx += stride; + x[ jx ] = x[ jx+strideX ]; + jx += strideX; } x[ lx ] = v; } else { flg = isNegativeZerof( v ); - jx = ix - stride; + jx = ix - strideX; // Shift all larger values to the left of the current element to the right... while ( jx >= fx ) { @@ -130,11 +130,11 @@ function ssortins( N, order, x, stride, offset ) { // Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right break; } - x[ jx+stride ] = u; - jx -= stride; + x[ jx+strideX ] = u; + jx -= strideX; } - x[ jx+stride ] = v; - ix += stride; + x[ jx+strideX ] = v; + ix += strideX; } } return x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ndarray.native.js index fc86b3fec31a..ccece148ec8c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/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( './ssortins.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -33,8 +31,8 @@ var addon = require( './ssortins.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,13 +42,8 @@ var addon = require( './ssortins.native.js' ); * * ssortins( x.length, 1.0, x, 1, 0 ); */ -function ssortins( N, order, x, stride, offset ) { - var view; - - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - - addon( N, order, view, stride ); +function ssortins( N, order, x, strideX, offsetX ) { + addon.ndarray( N, order, x, strideX, offsetX ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ssortins.js b/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ssortins.js index 07636bf51e4d..95a1f9e66471 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ssortins.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ssortins.js @@ -20,8 +20,8 @@ // MODULES // -var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -32,7 +32,7 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); * @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 @@ -43,101 +43,8 @@ var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); * ssortins( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function ssortins( N, order, x, stride ) { - var flg; - var ix; - var jx; - var fx; - var lx; - var v; - var u; - var i; - - 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 ) { - // Traverse the strided array from right-to-left... - fx = (1-N) * stride; // first index - lx = 0; // last index - ix = fx + stride; - - // Sort in increasing order... - for ( i = 1; i < N; i++ ) { - v = x[ ix ]; - - // Sort `NaN` values to the end (i.e., the left)... - if ( isnanf( v ) ) { - jx = ix; - - // Shift all values (including NaNs) to the left of the current element to the right... - while ( jx > lx ) { - x[ jx ] = x[ jx+stride ]; - jx += stride; - } - x[ lx ] = v; - } else { - flg = isNegativeZerof( v ); - jx = ix - stride; - - // Shift all larger values to the right of the current element to the left... - while ( jx <= fx ) { - u = x[ jx ]; - if ( u <= v && !(flg && u === v && isNegativeZerof( u ) === false) ) { // eslint-disable-line max-len - // Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left - break; - } - x[ jx+stride ] = u; - jx -= stride; - } - x[ jx+stride ] = v; - ix += stride; - } - } - return x; - } - // Traverse the strided array from left-to-right... - fx = 0; // first index - lx = (N-1) * stride; // last index - ix = fx + stride; - - // Sort in increasing order... - for ( i = 1; i < N; i++ ) { - v = x[ ix ]; - - // Sort `NaN` values to the end... - if ( isnanf( v ) ) { - jx = ix; - - // Shift all values (including NaNs) to the right of the current element to the left... - while ( jx < lx ) { - x[ jx ] = x[ jx+stride ]; - jx += stride; - } - x[ lx ] = v; - } else { - flg = isNegativeZerof( v ); - jx = ix - stride; - - // Shift all larger values to the left of the current element to the right... - while ( jx >= fx ) { - u = x[ jx ]; - if ( u <= v && !(flg && u === v && isNegativeZerof( u ) === false) ) { // eslint-disable-line max-len - // Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right - break; - } - x[ jx+stride ] = u; - jx -= stride; - } - x[ jx+stride ] = v; - ix += stride; - } - } - return x; +function ssortins( N, order, x, strideX ) { + return ndarray( N, order, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ssortins.native.js b/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ssortins.native.js index 535eed3b0db2..8c54be0540ab 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ssortins.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/lib/ssortins.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' ); * ssortins( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function ssortins( N, order, x, stride ) { - addon( N, order, x, stride ); +function ssortins( N, order, x, strideX ) { + addon( N, order, x, strideX ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/ssortins/manifest.json index 26d087d7bc70..04f7a718eb24 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/manifest.json @@ -28,57 +28,57 @@ { "task": "build", "src": [ - "./src/ssortins.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/napi/export", - "@stdlib/napi/argv", "@stdlib/napi/argv-float", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float32array" + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/assert/is-negative-zerof", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] }, { "task": "benchmark", "src": [ - "./src/ssortins.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/ssortins.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/ssortins/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/ssortins/src/addon.c index 6e18ee541c3f..26d810f8a1b0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/src/addon.c @@ -35,10 +35,28 @@ 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_ssortins( 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_ssortins)( N, order, X, strideX ); 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, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_FLOAT( env, order, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_ssortins_ndarray)( N, order, X, strideX, offsetX ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/ssortins/src/ssortins.c b/lib/node_modules/@stdlib/blas/ext/base/ssortins/src/main.c similarity index 73% rename from lib/node_modules/@stdlib/blas/ext/base/ssortins/src/ssortins.c rename to lib/node_modules/@stdlib/blas/ext/base/ssortins/src/main.c index 5e52ef2a6fbd..2a90e0098230 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/ssortins/src/ssortins.c +++ b/lib/node_modules/@stdlib/blas/ext/base/ssortins/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/ssortins.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 /** @@ -28,15 +29,30 @@ * @param N number of indexed elements * @param order sort order * @param X input array -* @param stride index increment +* @param strideX index increment */ -void c_ssortins( const int64_t N, const float order, float *X, const int64_t stride ) { - int64_t ix; - int64_t jx; - int64_t fx; - int64_t lx; - int64_t sx; - int64_t i; +void API_SUFFIX(stdlib_strided_ssortins)( 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_ssortins_ndarray)( N, order, X, strideX, ox ); +} + +/** +* Sorts a single-precision floating-point strided array using insertion sort and alternative indexing semantics. +* +* @param N number of indexed elements +* @param order sort order +* @param X input array +* @param strideX index increment +* @param offsetX starting index +*/ +void API_SUFFIX(stdlib_strided_ssortins_ndarray)( const CBLAS_INT N, const float order, float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT jx; + CBLAS_INT fx; + CBLAS_INT lx; + CBLAS_INT sx; + CBLAS_INT ox; + CBLAS_INT i; bool flg; float v; float u; @@ -46,15 +62,18 @@ void c_ssortins( const int64_t N, const float order, float *X, const int64_t str } // 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; + sx = strideX * -1; + ox = offsetX - ( (N-1) * sx ); } else { - sx = stride; + sx = strideX; + ox = offsetX; } + fx = ox; // first index + lx = fx + ( (N-1) * sx ); // last index + ix = fx + sx; + if ( sx < 0 ) { // Traverse the strided array from right-to-left... - fx = (1-N) * sx; // first index - lx = 0; // last index - ix = fx + sx; // Sort in increasing order... for ( i = 1; i < N; i++ ) { @@ -90,9 +109,6 @@ void c_ssortins( const int64_t N, const float order, float *X, const int64_t str return; } // Traverse the strided array from left-to-right... - fx = 0; // first index - lx = (N-1) * sx; // last index - ix = fx + sx; // Sort in increasing order... for ( i = 1; i < N; i++ ) {