From 5e251fe9bce5913d0fbc8682ec9b53a9963ced05 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 2 Feb 2025 22:41:33 +0530 Subject: [PATCH 1/8] feat: add C ndarray interface and refactor implementation --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- .../@stdlib/blas/ext/base/dsortins/README.md | 136 ++++++- .../ext/base/dsortins/benchmark/c/Makefile | 146 +++++++ .../c/benchmark.unsorted_random.length.c | 381 ++++++++++++++++++ .../blas/ext/base/dsortins/docs/repl.txt | 25 +- .../ext/base/dsortins/docs/types/index.d.ts | 12 +- .../ext/base/dsortins/examples/c/example.c | 2 +- .../include/stdlib/blas/ext/base/dsortins.h | 9 +- .../blas/ext/base/dsortins/lib/dsortins.js | 105 +---- .../ext/base/dsortins/lib/dsortins.native.js | 6 +- .../blas/ext/base/dsortins/lib/ndarray.js | 46 +-- .../ext/base/dsortins/lib/ndarray.native.js | 18 +- .../blas/ext/base/dsortins/manifest.json | 43 +- .../blas/ext/base/dsortins/src/addon.c | 23 +- .../base/dsortins/src/{dsortins.c => main.c} | 77 ++-- 14 files changed, 814 insertions(+), 215 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c rename lib/node_modules/@stdlib/blas/ext/base/dsortins/src/{dsortins.c => main.c} (68%) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md index ee99f20c46ed..b9f163684777 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md @@ -30,9 +30,9 @@ limitations under the License. var dsortins = require( '@stdlib/blas/ext/base/dsortins' ); ``` -#### dsortins( N, order, x, stride ) +#### dsortins( N, order, x, strideX ) -Sorts a double-precision floating-point strided array `x` using insertion sort. +Sorts a double-precision floating-point strided array using insertion sort. ```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 `x` are accessed at runtime. For example, to sort every other element ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -77,9 +77,9 @@ dsortins( 2, -1.0, x1, 2 ); // x0 => [ 1.0, 4.0, 3.0, 2.0 ] ``` -#### dsortins.ndarray( N, order, x, stride, offset ) +#### dsortins.ndarray( N, order, x, strideX, offsetX ) -Sorts a double-precision floating-point strided array `x` using insertion sort and alternative indexing semantics. +Sorts a double-precision floating-point strided array using insertion sort and alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -92,9 +92,9 @@ dsortins.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' ); @@ -153,6 +153,126 @@ console.log( x ); * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dsortins.h" +``` + +#### stdlib_strided_dsortins( N, order, \*X, strideX ) + +Sorts a double-precision floating-point strided array using insertion sort. + +```c +double x[] = { 1.0, -2.0, 3.0, -4.0 }; + +stdlib_strided_dsortins( 2, -1, 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 for `X`. + +```c +stdlib_strided_dsortins( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX ); +``` + + + +#### stdlib_strided_dsortins_ndarray( N, order, \*X, strideX, offsetX ) + + + +Sorts a double-precision floating-point strided array using insertion sort and alternative indexing semantics. + +```c +double x[] = { 1.0, -2.0, 3.0, -4.0 }; + +stdlib_strided_dsortins_ndarray( 4, 1, x, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **order**: `[in] CBLAS_INT` sort order. +- **X**: `[inout] double*` input array. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +stdlib_strided_dsortins_ndarray( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dsortins.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: + API_SUFFIX(stdlib_strided_dsortins)( 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/dsort2ins`][@stdlib/blas/ext/base/dsort2ins]: simultaneously sort two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort. diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/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/dsortins/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c new file mode 100644 index 000000000000..af5d2c0e4757 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c @@ -0,0 +1,381 @@ +/** +* @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/dsortins.h" +#include +#include +#include +#include +#include + +#define NAME "dsortins" +#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_dsortins( len, 1, 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_dsortins_ndarray( len, 1, 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 ); +}/** +* @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/dsortins.h" +#include +#include +#include +#include +#include + +#define NAME "dsortins" +#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_dsortins( len, 1, 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_dsortins_ndarray( len, 1, 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/dsortins/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt index 2d2f69a1ad51..a0ee32fb397d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt @@ -1,8 +1,8 @@ -{{alias}}( N, order, x, stride ) +{{alias}}( N, order, x, strideX ) Sorts a double-precision floating-point strided array using insertion sort. - The `N` and `stride` parameters determine which elements in `x` are accessed + The `N` and `stride` parameters determine which elements in are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed @@ -44,8 +44,8 @@ x: Float64Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. Returns ------- @@ -61,8 +61,7 @@ // 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: @@ -74,12 +73,13 @@ > 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 insertion sort 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 + buffer, the `offsetX` parameter supports indexing semantics based on a starting index. Parameters @@ -94,10 +94,10 @@ x: Float64Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index of `x`. Returns @@ -114,8 +114,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/dsortins/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/types/index.d.ts index ff4e24a8aa59..8c987447ebd5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/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 { * dsortins( 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 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 `x` * * @example @@ -59,7 +59,7 @@ interface Routine { * dsortins.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/dsortins/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/c/example.c index 767594ad6685..70f2f004fb4c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/c/example.c @@ -30,7 +30,7 @@ int main( void ) { int strideX = 1; // Sort the array: - c_dsortins( N, 1.0, x, strideX ); + API_SUFFIX(stdlib_strided_dsortins)( 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/dsortins/include/stdlib/blas/ext/base/dsortins.h b/lib/node_modules/@stdlib/blas/ext/base/dsortins/include/stdlib/blas/ext/base/dsortins.h index 8bb6ba45cb4e..de6895c0e6d7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/include/stdlib/blas/ext/base/dsortins.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/include/stdlib/blas/ext/base/dsortins.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DSORTINS_H #define STDLIB_BLAS_EXT_BASE_DSORTINS_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 insertion sort. */ -void c_dsortins( const int64_t N, const double order, double *X, const int64_t stride ); +void API_SUFFIX(stdlib_strided_dsortins)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX ); + +/** +* Sorts a double-precision floating-point strided array using insertion sort and alternative indexing semantics. +*/ +void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js index 8c3741abd45f..3c2c7a02f331 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js @@ -20,8 +20,8 @@ // MODULES // -var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -32,7 +32,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); * @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 @@ -43,101 +43,10 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); * dsortins( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function dsortins( 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 ( isnan( 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 = isNegativeZero( 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 && isNegativeZero( 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 ( isnan( 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 = isNegativeZero( 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 && isNegativeZero( 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 dsortins( N, order, x, strideX ) { + var offsetX; + offsetX = stride2offset( N, strideX ); + return ndarray( N, order, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.native.js index 2e322f3e4d79..cf5a4e3c2ab7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.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' ); * dsortins( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function dsortins( N, order, x, stride ) { - addon( N, order, x, stride ); +function dsortins( N, order, x, strideX ) { + addon( N, order, x, strideX ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.js index f7f9a27e3cc6..def7935f4624 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.js @@ -32,8 +32,8 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); * @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 @@ -44,7 +44,7 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); * dsortins( x.length, 1.0, x, 1, 0 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function dsortins( N, order, x, stride, offset ) { +function dsortins( N, order, x, strideX, offsetX ) { var flg; var ix; var jx; @@ -59,14 +59,14 @@ function dsortins( 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 dsortins( 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 = isNegativeZero( 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 dsortins( 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 dsortins( 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 = isNegativeZero( 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 dsortins( 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/dsortins/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.native.js index 96103583e94f..493cd70a25fb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dsortins.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,8 +31,8 @@ var addon = require( './dsortins.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,15 +42,8 @@ var addon = require( './dsortins.native.js' ); * * dsortins( x.length, 1.0, x, 1, 0 ); */ -function dsortins( 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 dsortins( N, order, x, strideX, offsetX ) { + addon.ndarray( N, order, x, strideX, offsetX); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dsortins/manifest.json index f391bd9be441..392b362f2465 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/manifest.json @@ -28,40 +28,57 @@ { "task": "build", "src": [ - "./src/dsortins.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/argv-double", + "@stdlib/napi/argv-int64", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-negative-zero", + "@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/napi/argv", - "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-double", - "@stdlib/napi/argv-strided-float64array", - "@stdlib/napi/export" + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] }, { "task": "examples", "src": [ - "./src/dsortins.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-negative-zero", - "@stdlib/math/base/assert/is-nan" + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/addon.c index 74b779e033bb..74c9c6efb5be 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/addon.c @@ -38,8 +38,27 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, order, argv, 2 ); - c_dsortins( N, order, X, strideX ); + API_SUFFIX(stdlib_strided_dsortins)( 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_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, order, argv, 2 ); + API_SUFFIX(stdlib_strided_dsortins_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/dsortins/src/dsortins.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c similarity index 68% rename from lib/node_modules/@stdlib/blas/ext/base/dsortins/src/dsortins.c rename to lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c index 75e19a5eb906..513cd22e1b8d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/dsortins.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c @@ -19,7 +19,8 @@ #include "stdlib/blas/ext/base/dsortins.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 /** @@ -28,15 +29,28 @@ * @param N number of indexed elements * @param order sort order * @param X input array -* @param stride index increment +* @param strideX index increment */ -void c_dsortins( const int64_t N, const double order, double *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_dsortins)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dsortins_ndarray)( N, order, X, strideX, ox ); +} + +/** +* Sorts a double-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_dsortins_ndarray)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT jx; + CBLAS_INT fx; + CBLAS_INT lx; + CBLAS_INT i; double v; double u; bool flg; @@ -46,15 +60,15 @@ void c_dsortins( const int64_t N, const double order, double *X, const int64_t s } // For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order... if ( order < 0.0 ) { - sx = -stride; - } else { - sx = stride; + strideX *= -1; + offsetX = (N-1) * strideX; } - if ( sx < 0 ) { + fx = offsetX; + lx = fx + (N-1) * strideX; + ix = fx + strideX; + + if ( strideX < 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++ ) { @@ -66,13 +80,13 @@ void c_dsortins( const int64_t N, const double order, double *X, const int64_t s // Shift all values (including NaNs) to the left of the current element to the right... while ( jx > lx ) { - X[ jx ] = X[ jx+sx ]; - jx += sx; + X[ jx ] = X[ jx+strideX ]; + jx += strideX; } X[ lx ] = v; } else { flg = stdlib_base_is_negative_zero( v ); - jx = ix - sx; + jx = ix - strideX; // Shift all larger values to the right of the current element to the left... while ( jx <= fx ) { @@ -80,19 +94,16 @@ void c_dsortins( const int64_t N, const double order, double *X, const int64_t s if ( u <= v && !(flg && u == v && !stdlib_base_is_negative_zero( u )) ) { // Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left break; } - X[ jx+sx ] = u; - jx -= sx; + X[ jx+strideX ] = u; + jx -= strideX; } - X[ jx+sx ] = v; - ix += sx; + X[ jx+strideX ] = v; + ix += strideX; } } 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++ ) { @@ -104,13 +115,13 @@ void c_dsortins( const int64_t N, const double order, double *X, const int64_t s // Shift all values (including NaNs) to the right of the current element to the left... while ( jx < lx ) { - X[ jx ] = X[ jx+sx ]; - jx += sx; + X[ jx ] = X[ jx+strideX ]; + jx += strideX; } X[ lx ] = v; } else { flg = stdlib_base_is_negative_zero( v ); - jx = ix - sx; + jx = ix - strideX; // Shift all larger values to the left of the current element to the right... while ( jx >= fx ) { @@ -118,11 +129,11 @@ void c_dsortins( const int64_t N, const double order, double *X, const int64_t s if ( u <= v && !(flg && u == v && !stdlib_base_is_negative_zero( u )) ) { // Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right break; } - X[ jx+sx ] = u; - jx -= sx; + X[ jx+strideX ] = u; + jx -= strideX; } - X[ jx+sx ] = v; - ix += sx; + X[ jx+strideX ] = v; + ix += strideX; } } return; From adbc184d12dcab47cf28c2ef62b77e209c94cb8e Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:29:32 +0000 Subject: [PATCH 2/8] fix: resolve lint errors --- .../@stdlib/blas/ext/base/dsortins/README.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md index b9f163684777..68b8c1eb6e38 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md @@ -151,16 +151,6 @@ console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt index a0ee32fb397d..f4718cbc3fc6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt @@ -67,8 +67,7 @@ // 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 ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/index.js index 6d03bda2fa6d..76ac23252194 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/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 dsortins = require( './../lib' ); -var x = filledarrayBy( 100, 'float64', uniform( -100.0, 100.0 ) ); +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); dsortins( x.length, -1.0, x, -1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js index 3c2c7a02f331..dd4c7e9b838d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js @@ -44,8 +44,7 @@ var ndarray = require( './ndarray.js' ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ function dsortins( N, order, x, strideX ) { - var offsetX; - offsetX = stride2offset( N, strideX ); + var offsetX = stride2offset( N, strideX ); return ndarray( N, order, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/addon.c index 74c9c6efb5be..7ca367239b29 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/addon.c @@ -36,8 +36,7 @@ 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 ); - + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); API_SUFFIX(stdlib_strided_dsortins)( N, order, X, strideX ); return NULL; } @@ -52,12 +51,11 @@ static napi_value addon( napi_env env, napi_callback_info info ) { 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, order, argv, 2 ); + STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); API_SUFFIX(stdlib_strided_dsortins_ndarray)( N, order, X, strideX, offsetX ); - return NULL; } From 56a51b2f31b8bee0dab5d9f41cc3753ebb03b84d Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Mon, 3 Feb 2025 00:00:53 +0530 Subject: [PATCH 4/8] chore: updated copyright year --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: failed --- --- .../@stdlib/blas/ext/base/dsortins/examples/c/example.c | 2 +- lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/c/example.c index 70f2f004fb4c..3d17c5294263 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/examples/c/example.c @@ -30,7 +30,7 @@ int main( void ) { int strideX = 1; // Sort the array: - API_SUFFIX(stdlib_strided_dsortins)( N, 1.0, x, strideX ); + stdlib_strided_dsortins( 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/dsortins/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c index 513cd22e1b8d..b95137bc5f04 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/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. From 19b04e0545167c958dc2370495bdc43c46b99d54 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Mon, 3 Feb 2025 00:04:19 +0530 Subject: [PATCH 5/8] fix: remove return statement in stdlib_strided_dsortins function --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: failed --- --- lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c index b95137bc5f04..c1ec50c3d2bd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c @@ -33,7 +33,7 @@ */ void API_SUFFIX(stdlib_strided_dsortins)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX) { CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); - return API_SUFFIX(stdlib_strided_dsortins_ndarray)( N, order, X, strideX, ox ); + API_SUFFIX(stdlib_strided_dsortins_ndarray)( N, order, X, strideX, ox ); } /** From 9bf0b3c3d08068ee4b29a7ae7636379549aeb1d5 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Mon, 3 Feb 2025 15:50:24 +0530 Subject: [PATCH 6/8] fix: correct argument types and improve parameter descriptions in dsortins functions --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: failed --- --- .../@stdlib/blas/ext/base/dsortins/README.md | 8 +- .../c/benchmark.unsorted_random.length.c | 192 +----------------- .../blas/ext/base/dsortins/docs/repl.txt | 4 +- .../include/stdlib/blas/ext/base/dsortins.h | 4 +- .../blas/ext/base/dsortins/lib/dsortins.js | 3 +- .../ext/base/dsortins/lib/ndarray.native.js | 2 +- .../@stdlib/blas/ext/base/dsortins/src/main.c | 46 +++-- 7 files changed, 36 insertions(+), 223 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md index 779a7e4e7a70..482b9f62c134 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md @@ -174,7 +174,7 @@ Sorts a double-precision floating-point strided array using insertion sort. ```c double x[] = { 1.0, -2.0, 3.0, -4.0 }; -stdlib_strided_dsortins( 2, -1, x, 1 ); +stdlib_strided_dsortins( 2, -1.0, x, 1 ); ``` The function accepts the following arguments: @@ -199,14 +199,14 @@ Sorts a double-precision floating-point strided array using insertion sort and a ```c double x[] = { 1.0, -2.0, 3.0, -4.0 }; -stdlib_strided_dsortins_ndarray( 4, 1, x, 1, 0 ); +stdlib_strided_dsortins_ndarray( 4, 1.0, x, 1, 0 ); ``` The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. -- **order**: `[in] CBLAS_INT` sort order. -- **X**: `[inout] double*` input array. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. +- **order**: `[in] double` sort order. If `order < 0.0`, the input strided array `x` is sorted in **decreasing** order. If `order > 0.0`, the input strided array `x` is sorted in **increasing** order. If `order == 0.0`, the input strided arrays are left unchanged. +- **X**: `[inout] double*` input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. - **offsetX**: `[in] CBLAS_INT` starting index for `X`. diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c index af5d2c0e4757..bfac1eeb1d9d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c @@ -136,197 +136,7 @@ static double benchmark2( int iterations, int len ) { } t = tic(); for ( i = 0; i < iterations; i++ ) { - stdlib_strided_dsortins_ndarray( len, 1, 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 ); -}/** -* @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/dsortins.h" -#include -#include -#include -#include -#include - -#define NAME "dsortins" -#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_dsortins( len, 1, 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_dsortins_ndarray( len, 1, x, 1, 0); + stdlib_strided_dsortins_ndarray( len, 1.0, x, 1, 0); if ( x[ 0 ] != x[ 0 ] ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt index f4718cbc3fc6..b248b8937f3f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt @@ -2,7 +2,7 @@ {{alias}}( N, order, x, strideX ) Sorts a double-precision floating-point strided array using insertion sort. - The `N` and `stride` parameters determine which elements in are accessed + The `N` and stride parameters determine which elements in are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed @@ -78,7 +78,7 @@ and alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offsetX` parameter supports indexing semantics based on a + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/include/stdlib/blas/ext/base/dsortins.h b/lib/node_modules/@stdlib/blas/ext/base/dsortins/include/stdlib/blas/ext/base/dsortins.h index de6895c0e6d7..486c02d3909a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/include/stdlib/blas/ext/base/dsortins.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/include/stdlib/blas/ext/base/dsortins.h @@ -31,12 +31,12 @@ extern "C" { /** * Sorts a double-precision floating-point strided array using insertion sort. */ -void API_SUFFIX(stdlib_strided_dsortins)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX ); +void API_SUFFIX(stdlib_strided_dsortins)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ); /** * Sorts a double-precision floating-point strided array using insertion sort and alternative indexing semantics. */ -void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ); +void API_SUFFIX(stdlib_strided_dsortins_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/dsortins/lib/dsortins.js b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js index dd4c7e9b838d..1d577c7dd5ea 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/dsortins.js @@ -44,8 +44,7 @@ var ndarray = require( './ndarray.js' ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ function dsortins( N, order, x, strideX ) { - var offsetX = stride2offset( N, strideX ); - return ndarray( N, order, x, strideX, offsetX ); + return ndarray( N, order, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.native.js index 493cd70a25fb..46fb4276e083 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/lib/ndarray.native.js @@ -43,7 +43,7 @@ var addon = require( './../src/addon.node' ); * dsortins( x.length, 1.0, x, 1, 0 ); */ function dsortins( N, order, x, strideX, offsetX ) { - addon.ndarray( N, order, x, strideX, offsetX); + addon.ndarray( N, order, x, strideX, offsetX ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c index c1ec50c3d2bd..842e09eaa4f2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c @@ -50,6 +50,8 @@ void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const doubl CBLAS_INT jx; CBLAS_INT fx; CBLAS_INT lx; + CBLAS_INT sx; + CBLAS_INT ox; CBLAS_INT i; double v; double u; @@ -60,14 +62,16 @@ void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const doubl } // For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order... if ( order < 0.0 ) { - strideX *= -1; - offsetX = (N-1) * strideX; + sx = -strideX; + ox = offsetX - ( (N-1) * sx ); + } else { + sx = strideX; + ox = offsetX; } - fx = offsetX; - lx = fx + (N-1) * strideX; - ix = fx + strideX; - - if ( strideX < 0 ) { + fx = ox; + lx = fx + (N-1) * sx; + ix = fx + sx; + if ( sx < 0 ) { // Traverse the strided array from right-to-left... // Sort in increasing order... @@ -80,13 +84,13 @@ void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const doubl // Shift all values (including NaNs) to the left of the current element to the right... while ( jx > lx ) { - X[ jx ] = X[ jx+strideX ]; - jx += strideX; + X[ jx ] = X[ jx+sx ]; + jx += sx; } X[ lx ] = v; } else { flg = stdlib_base_is_negative_zero( v ); - jx = ix - strideX; + jx = ix - sx; // Shift all larger values to the right of the current element to the left... while ( jx <= fx ) { @@ -94,11 +98,11 @@ void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const doubl if ( u <= v && !(flg && u == v && !stdlib_base_is_negative_zero( u )) ) { // Note: positive zeros (and NaNs (e.g., when last element is NaN)) are sorted to the left break; } - X[ jx+strideX ] = u; - jx -= strideX; + X[ jx+sx ] = u; + jx -= sx; } - X[ jx+strideX ] = v; - ix += strideX; + X[ jx+sx ] = v; + ix += sx; } } return; @@ -115,13 +119,13 @@ void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const doubl // Shift all values (including NaNs) to the right of the current element to the left... while ( jx < lx ) { - X[ jx ] = X[ jx+strideX ]; - jx += strideX; + X[ jx ] = X[ jx+sx ]; + jx += sx; } X[ lx ] = v; } else { flg = stdlib_base_is_negative_zero( v ); - jx = ix - strideX; + jx = ix - sx; // Shift all larger values to the left of the current element to the right... while ( jx >= fx ) { @@ -129,11 +133,11 @@ void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const doubl if ( u <= v && !(flg && u == v && !stdlib_base_is_negative_zero( u )) ) { // Note: positive zeros (and NaNs (e.g., when first element is NaN)) are sorted to the right break; } - X[ jx+strideX ] = u; - jx -= strideX; + X[ jx+sx ] = u; + jx -= sx; } - X[ jx+strideX ] = v; - ix += strideX; + X[ jx+sx ] = v; + ix += sx; } } return; From 0a58419ba59fa723f163e3872c56d9166f65a7ed Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 4 Feb 2025 15:03:42 +0530 Subject: [PATCH 7/8] chore: updated files according to code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: failed --- --- .../@stdlib/blas/ext/base/dsortins/README.md | 13 +++++++------ .../benchmark/c/benchmark.unsorted_random.length.c | 2 +- .../@stdlib/blas/ext/base/dsortins/docs/repl.txt | 6 +++--- .../@stdlib/blas/ext/base/dsortins/src/main.c | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md index 482b9f62c134..592d8dd738aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md @@ -50,7 +50,7 @@ The function has the following parameters: - **x**: input [`Float64Array`][@stdlib/array/float64]. - **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' ); @@ -132,11 +132,12 @@ dsortins.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 dsortins = require( '@stdlib/blas/ext/base/dsortins' ); -var x = filledarrayBy( 100, 'float64', uniform( -100.0, 100.0 ) ); +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); dsortins( x.length, -1.0, x, -1 ); @@ -185,7 +186,7 @@ The function accepts the following arguments: - **strideX**: `[in] CBLAS_INT` stride length for `X`. ```c -stdlib_strided_dsortins( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX ); +stdlib_strided_dsortins( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ); ``` @@ -211,7 +212,7 @@ The function accepts the following arguments: - **offsetX**: `[in] CBLAS_INT` starting index for `X`. ```c -stdlib_strided_dsortins_ndarray( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ); +stdlib_strided_dsortins_ndarray( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c index bfac1eeb1d9d..6e760daa394e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c @@ -105,7 +105,7 @@ static double benchmark1( int iterations, int len ) { } t = tic(); for ( i = 0; i < iterations; i++ ) { - stdlib_strided_dsortins( len, 1, x, 1 ); + stdlib_strided_dsortins( len, 1.0, x, 1 ); if ( x[ 0 ] != x[ 0 ] ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt index b248b8937f3f..481e1a74cf50 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/docs/repl.txt @@ -2,8 +2,8 @@ {{alias}}( N, order, x, strideX ) Sorts a double-precision floating-point strided array using insertion sort. - The `N` and stride parameters determine which elements in 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. @@ -97,7 +97,7 @@ Stride length. offsetX: integer - Starting index of `x`. + Starting index. Returns ------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c index 842e09eaa4f2..8d39e192b0a7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/src/main.c @@ -31,7 +31,7 @@ * @param X input array * @param strideX index increment */ -void API_SUFFIX(stdlib_strided_dsortins)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX) { +void API_SUFFIX(stdlib_strided_dsortins)( 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_dsortins_ndarray)( N, order, X, strideX, ox ); } @@ -45,7 +45,7 @@ void API_SUFFIX(stdlib_strided_dsortins)( const CBLAS_INT N, const double order, * @param strideX index increment * @param offsetX starting index */ -void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ) { +void API_SUFFIX(stdlib_strided_dsortins_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { CBLAS_INT ix; CBLAS_INT jx; CBLAS_INT fx; From 5816d5f15d064227593a0aa84f0ffa93b0923669 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Wed, 5 Feb 2025 01:08:35 +0530 Subject: [PATCH 8/8] fix: remove API_SUFFIX macro in dsortins examples and benchmarks for clarity --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: failed --- --- lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md | 2 +- .../dsortins/benchmark/c/benchmark.unsorted_random.length.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md index 592d8dd738aa..d634316f4d5d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/README.md @@ -248,7 +248,7 @@ int main( void ) { int strideX = 1; // Sort the array: - API_SUFFIX(stdlib_strided_dsortins)( N, 1.0, x, strideX ); + stdlib_strided_dsortins( 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/dsortins/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c index 6e760daa394e..1ddcdd2c652b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsortins/benchmark/c/benchmark.unsorted_random.length.c @@ -136,7 +136,7 @@ static double benchmark2( int iterations, int len ) { } t = tic(); for ( i = 0; i < iterations; i++ ) { - stdlib_strided_dsortins_ndarray( len, 1.0, x, 1, 0); + stdlib_strided_dsortins_ndarray( len, 1.0, x, 1, 0 ); if ( x[ 0 ] != x[ 0 ] ) { printf( "should not return NaN\n" ); break;