From 2aef0f341c7e8cc222b066038650bed5ccb7f08a Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 2 Feb 2025 12:26:12 +0530 Subject: [PATCH 1/7] feat: add C ndarray interface and refactor implementation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- .../@stdlib/blas/ext/base/dsorthp/README.md | 159 ++++++++++++--- .../ext/base/dsorthp/benchmark/c/Makefile | 146 +++++++++++++ .../c/benchmark.unsorted_random.length.c | 191 ++++++++++++++++++ .../blas/ext/base/dsorthp/docs/repl.txt | 28 ++- .../ext/base/dsorthp/docs/types/index.d.ts | 12 +- .../ext/base/dsorthp/examples/c/example.c | 2 +- .../blas/ext/base/dsorthp/examples/index.js | 27 +-- .../include/stdlib/blas/ext/base/dsorthp.h | 9 +- .../blas/ext/base/dsorthp/lib/dsorthp.js | 101 +-------- .../ext/base/dsorthp/lib/dsorthp.native.js | 6 +- .../blas/ext/base/dsorthp/lib/ndarray.js | 26 +-- .../ext/base/dsorthp/lib/ndarray.native.js | 20 +- .../blas/ext/base/dsorthp/manifest.json | 53 ++++- .../@stdlib/blas/ext/base/dsorthp/src/addon.c | 26 ++- .../base/dsorthp/src/{dsorthp.c => main.c} | 78 ++++--- 15 files changed, 643 insertions(+), 241 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c rename lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/{dsorthp.c => main.c} (63%) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md index 2fdd0e87234c..9d9987f37a6c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md @@ -30,9 +30,9 @@ limitations under the License. var dsorthp = require( '@stdlib/blas/ext/base/dsorthp' ); ``` -#### dsorthp( N, order, x, stride ) +#### dsorthp( N, order, x, strideX ) -Sorts a double-precision floating-point strided array `x` using heapsort. +Sorts a double-precision floating-point strided array using heapsort. ```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 @@ dsorthp( 2, -1.0, x1, 2 ); // x0 => [ 1.0, 4.0, 3.0, 2.0 ] ``` -#### dsorthp.ndarray( N, order, x, stride, offset ) +#### dsorthp.ndarray( N, order, x, strideX, offsetX ) -Sorts a double-precision floating-point strided array `x` using heapsort and alternative indexing semantics. +Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -92,9 +92,9 @@ dsorthp.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 parameters support indexing semantics based on starting indices. For example, to access only the last three elements: ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -131,27 +131,12 @@ dsorthp.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 Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dsorthp = require( '@stdlib/blas/ext/base/dsorthp' ); -var rand; -var sign; -var x; -var i; - -x = new Float64Array( 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': 'float64' +}); console.log( x ); dsorthp( x.length, -1.0, x, -1 ); @@ -164,6 +149,126 @@ console.log( x ); * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dsorthp.h" +``` + +#### stdlib_strided_dsorthp( N, order, \*X, strideX ) + +Sorts a double-precision floating-point strided array using heapsort. + +```c +double x[] = { 1.0, -2.0, 3.0, -4.0 }; + +stdlib_strided_dsorthp( 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_dsorthp( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX ); +``` + + + +#### stdlib_strided_dsorthp_ndarray( N, order, \*X, strideX, offsetX ) + + + +Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics. + +```c +double x[] = { 1.0, -2.0, 3.0, -4.0 }; + +stdlib_strided_dsorthp_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_dsorthp_ndarray( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dsorthp.h" +#include + +int main( void ) { + // Create a strided array: + double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 }; + + // Specify the number of elements: + int N = 8; + + // Specify a stride: + int strideX = 1; + + // Sort the array: + stdlib_strided_dsorthp( N, 1.0, x, strideX ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "x[ %i ] = %lf\n", i, x[ i ] ); + } +} + +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/Makefile b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/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/dsorthp/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c new file mode 100644 index 000000000000..caa59f7a5945 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c @@ -0,0 +1,191 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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/dsorthp.h" +#include +#include +#include +#include +#include + +#define NAME "dsorthp" +#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_dsorthp( 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_dsorthp_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/dsorthp/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/docs/repl.txt index 930581e1ee20..2bb01ec38c61 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/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 heapsort. - The `N` and `stride` parameters determine which elements in `x` are accessed + The `N` and stride parameters determine which elements in `x` are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed @@ -39,8 +39,8 @@ x: Float64Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. Returns ------- @@ -56,25 +56,24 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, -1, x, 2 ) + > {{alias}}( 2, -1, x, 2 ) [ 3.0, -2.0, 1.0, -4.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > {{alias}}( N, 1, x1, 2 ) + > {{alias}}( 2, 1, x1, 2 ) [ -4.0, 3.0, -2.0 ] > x0 [ 1.0, -4.0, 3.0, -2.0 ] -{{alias}}.ndarray( N, order, x, stride, offset ) + +{{alias}}.ndarray( N, order, x, strideX, offsetX ) Sorts a double-precision floating-point strided array using heapsort 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 @@ -89,10 +88,10 @@ x: Float64Array Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index of `x`. Returns @@ -109,8 +108,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/dsorthp/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/docs/types/index.d.ts index 2b74d44b068c..5783c63fd864 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/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 { * dsorthp( 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 heapsort 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 { * dsorthp.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/dsorthp/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/examples/c/example.c index 6c46709d84ec..4d0f39df2b65 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/examples/c/example.c @@ -30,7 +30,7 @@ int main( void ) { int strideX = 1; // Sort the array: - c_dsorthp( N, 1.0, x, strideX ); + stdlib_strided_dsorthp( 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/dsorthp/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/examples/index.js index 923f48c39d7b..f8219b480e0b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/examples/index.js @@ -18,31 +18,12 @@ 'use strict'; -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dsorthp = require( './../lib' ); -var rand; -var sign; -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - rand = round( randu()*100.0 ); - sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - x[ i ] = sign * rand; - } -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); dsorthp( x.length, -1.0, x, -1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/include/stdlib/blas/ext/base/dsorthp.h b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/include/stdlib/blas/ext/base/dsorthp.h index dbf27f002eea..6df24c80d4dd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/include/stdlib/blas/ext/base/dsorthp.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/include/stdlib/blas/ext/base/dsorthp.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DSORTHP_H #define STDLIB_BLAS_EXT_BASE_DSORTHP_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 heapsort. */ -void c_dsorthp( const int64_t N, const double order, double *X, const int64_t stride ); +void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX ); + +/** +* Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics. +*/ +void API_SUFFIX(stdlib_strided_dsorthp_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/dsorthp/lib/dsorthp.js b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.js index f41d78cd3f6e..fa3b5ea90c3e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.js @@ -20,9 +20,8 @@ // MODULES // -var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var floor = require( '@stdlib/math/base/special/floor' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -42,7 +41,7 @@ var floor = require( '@stdlib/math/base/special/floor' ); * @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 @@ -53,96 +52,10 @@ var floor = require( '@stdlib/math/base/special/floor' ); * dsorthp( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function dsorthp( N, order, x, stride ) { - var offset; - var parent; - var child; - var v1; - var v2; - var n; - var t; - var i; - var j; - var k; - - if ( N <= 0 || order === 0.0 ) { - return x; - } - // For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order... - if ( order < 0.0 ) { - stride *= -1; - } - if ( stride < 0 ) { - offset = (1-N) * stride; - } else { - offset = 0; - } - // Set the initial heap size: - n = N; - - // Specify an initial "parent" index for building the heap: - parent = floor( N / 2 ); - - // Continue looping until the array is sorted... - while ( true ) { - if ( parent > 0 ) { - // We need to build the heap... - parent -= 1; - t = x[ offset+(parent*stride) ]; - } else { - // Reduce the heap size: - n -= 1; - - // Check if the heap is empty, and, if so, we are finished sorting... - if ( n === 0 ) { - return x; - } - // Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position: - i = offset + (n*stride); - t = x[ i ]; - - // Move the heap root to its sorted position: - x[ i ] = x[ offset ]; - } - // We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property... - - // Start at the parent index: - j = parent; - - // Get the "left" child index: - child = (j*2) + 1; - - while ( child < n ) { - // Find the largest child... - k = child + 1; - if ( k < n ) { - v1 = x[ offset+(k*stride) ]; - v2 = x[ offset+(child*stride) ]; - - // Check if a "right" child exists and is "bigger"... - if ( v1 > v2 || isnan( v1 ) || (v1 === v2 && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len - child += 1; - } - } - // Check if the largest child is bigger than `t`... - v1 = x[ offset+(child*stride) ]; - if ( v1 > t || isnan( v1 ) || ( v1 === t && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len - // Insert the larger child value: - x[ offset+(j*stride) ] = v1; - - // Update `j` to point to the child index: - j = child; - - // Get the "left" child index and repeat... - child = (j*2) + 1; - } else { - // We've found `t`'s place in the heap... - break; - } - } - // Insert `t` into the heap: - x[ offset+(j*stride) ] = t; - } +function dsorthp( 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/dsorthp/lib/dsorthp.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.native.js index b759b88e32c1..52214a499466 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.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' ); * dsorthp( x.length, 1.0, x, 1 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function dsorthp( N, order, x, stride ) { - addon( N, order, x, stride ); +function dsorthp( N, order, x, strideX ) { + addon( N, order, x, strideX ); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.js index d8f6d2993b89..918bf2ae045f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.js @@ -42,8 +42,8 @@ var floor = require( '@stdlib/math/base/special/floor' ); * @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 @@ -54,7 +54,7 @@ var floor = require( '@stdlib/math/base/special/floor' ); * dsorthp( x.length, 1.0, x, 1, 0 ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ -function dsorthp( N, order, x, stride, offset ) { +function dsorthp( N, order, x, strideX, offsetX ) { var parent; var child; var v1; @@ -70,8 +70,8 @@ function dsorthp( 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; } // Set the initial heap size: n = N; @@ -84,7 +84,7 @@ function dsorthp( N, order, x, stride, offset ) { if ( parent > 0 ) { // We need to build the heap... parent -= 1; - t = x[ offset+(parent*stride) ]; + t = x[ offsetX+(parent*strideX) ]; } else { // Reduce the heap size: n -= 1; @@ -94,11 +94,11 @@ function dsorthp( N, order, x, stride, offset ) { return x; } // Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position: - i = offset + (n*stride); + i = offsetX + (n*strideX); t = x[ i ]; // Move the heap root to its sorted position: - x[ i ] = x[ offset ]; + x[ i ] = x[ offsetX ]; } // We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property... @@ -112,8 +112,8 @@ function dsorthp( N, order, x, stride, offset ) { // Find the largest child... k = child + 1; if ( k < n ) { - v1 = x[ offset+(k*stride) ]; - v2 = x[ offset+(child*stride) ]; + v1 = x[ offsetX+(k*strideX) ]; + v2 = x[ offsetX+(child*strideX) ]; // Check if a "right" child exists and is "bigger"... if ( v1 > v2 || isnan( v1 ) || (v1 === v2 && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len @@ -121,10 +121,10 @@ function dsorthp( N, order, x, stride, offset ) { } } // Check if the largest child is bigger than `t`... - v1 = x[ offset+(child*stride) ]; + v1 = x[ offsetX+(child*strideX) ]; if ( v1 > t || isnan( v1 ) || ( v1 === t && isPositiveZero( v1 ) ) ) { // eslint-disable-line max-len // Insert the larger child value: - x[ offset+(j*stride) ] = v1; + x[ offsetX+(j*strideX) ] = v1; // Update `j` to point to the child index: j = child; @@ -137,7 +137,7 @@ function dsorthp( N, order, x, stride, offset ) { } } // Insert `t` into the heap: - x[ offset+(j*stride) ] = t; + x[ offsetX+(j*strideX) ] = t; } } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.native.js index 76b79be77df1..725830a94c83 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/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( './dsorthp.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -33,8 +31,8 @@ var addon = require( './dsorthp.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 @@ -44,16 +42,8 @@ var addon = require( './dsorthp.native.js' ); * * dsorthp( x.length, 1.0, x, 1, 0 ); */ -function dsorthp( N, order, x, stride, offset ) { - var view; - offset = minViewBufferIndex( N, stride, offset ); - if ( stride < 0 ) { - order *= -1.0; - stride *= -1; - } - view = offsetView( x, offset ); - - addon( N, order, view, stride ); +function dsorthp( N, order, x, strideX, offsetX ) { + addon.ndarray( N, order, x, strideX, offsetX); return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json index 9b9ce0027c23..edbbe9b49d56 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json @@ -28,23 +28,60 @@ { "task": "build", "src": [ - "./src/dsorthp.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/assert/is-positive-zero", "@stdlib/napi/export", "@stdlib/napi/argv", - "@stdlib/napi/argv-double", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/assert/is-positive-zero", + "@stdlib/napi/create-double", + "@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/special/floor", + "@stdlib/math/base/assert/is-positive-zero", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/floor", + "@stdlib/math/base/assert/is-positive-zero", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/base/shared" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/addon.c index ed7031339319..48cc1a6db818 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/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_DOUBLE( env, order, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); - c_dsorthp( N, order, X, stride ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_dsorthp)( 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_DOUBLE( env, order, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(stdlib_strided_dsorthp_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/dsorthp/src/dsorthp.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c similarity index 63% rename from lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/dsorthp.c rename to lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c index f69d92150454..8cca6f2bd349 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/dsorthp.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/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,9 +19,12 @@ #include "stdlib/blas/ext/base/dsorthp.h" #include "stdlib/math/base/assert/is_positive_zero.h" #include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" #include #include + /** * Sorts a double-precision floating-point strided array using heapsort. * @@ -34,20 +37,41 @@ * - Williams, John William Joseph. 1964. "Algorithm 232: Heapsort." _Communications of the ACM_ 7 (6). New York, NY, USA: Association for Computing Machinery: 347–49. doi:[10.1145/512274.512284](https://doi.org/10.1145/512274.512284). * - Floyd, Robert W. 1964. "Algorithm 245: Treesort." _Communications of the ACM_ 7 (12). New York, NY, USA: Association for Computing Machinery: 701. doi:[10.1145/355588.365103](https://doi.org/10.1145/355588.365103). * -* @param N number of indexed elements -* @param order sort order -* @param X input array -* @param stride index increment +* @param N number of indexed elements +* @param order sort order +* @param X input array +* @param strideX stride length +*/ +void API_SUFFIX(stdlib_strided_dsorthp)( 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_dsorthp_ndarray)( N, order, X, strideX, ox ); +} + +/** +* Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics. +* +* ## Notes +* +* - This implementation uses an in-place algorithm derived from the work of Floyd (1964). +* +* ## References +* +* - Williams, John William Joseph. 1964. "Algorithm 232: Heapsort." _Communications of the ACM_ 7 (6). New York, NY, USA: Association for Computing Machinery: 347–49. doi:[10.1145/512274.512284](https://doi.org/10.1145/512274.512284). +* - Floyd, Robert W. 1964. "Algorithm 245: Treesort." _Communications of the ACM_ 7 (12). New York, NY, USA: Association for Computing Machinery: 701. doi:[10.1145/355588.365103](https://doi.org/10.1145/355588.365103). +* +* @param N number of indexed elements +* @param order sort order +* @param X input array +* @param strideX stride length +* @param offsetX starting index */ -void c_dsorthp( const int64_t N, const double order, double *X, const int64_t stride ) { - int64_t offset; - int64_t parent; - int64_t child; - int64_t sx; - int64_t n; - int64_t i; - int64_t j; - int64_t k; +void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ) { + CBLAS_INT parent; + CBLAS_INT child; + CBLAS_INT n; + CBLAS_INT i; + CBLAS_INT j; + CBLAS_INT k; double v1; double v2; double t; @@ -57,14 +81,8 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st } // For a positive stride, sorting in decreasing order is equivalent to providing a negative stride and sorting in increasing order, and, for a negative stride, sorting in decreasing order is equivalent to providing a positive stride and sorting in increasing order... if ( order < 0.0 ) { - sx = -stride; - } else { - sx = stride; - } - if ( sx < 0 ) { - offset = (1-N) * sx; - } else { - offset = 0; + strideX *= -1; + offsetX -= (N-1) * strideX; } // Set the initial heap size: n = N; @@ -77,7 +95,7 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st if ( parent > 0 ) { // We need to build the heap... parent -= 1; - t = X[ offset+(parent*sx) ]; + t = X[ offsetX+(parent*strideX) ]; } else { // Reduce the heap size: n -= 1; @@ -87,11 +105,11 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st return; } // Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position: - i = offset + (n*sx); + i = offsetX + (n*strideX); t = X[ i ]; // Move the heap root to its sorted position: - X[ i ] = X[ offset ]; + X[ i ] = X[ offsetX ]; } // We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property... @@ -105,8 +123,8 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st // Find the largest child... k = child + 1; if ( k < n ) { - v1 = X[ offset+(k*sx) ]; - v2 = X[ offset+(child*sx) ]; + v1 = X[ offsetX+(k*strideX) ]; + v2 = X[ offsetX+(child*strideX) ]; // Check if a "right" child exists and is "bigger"... if ( v1 > v2 || stdlib_base_is_nan( v1 ) || (v1 == v2 && stdlib_base_is_positive_zero( v1 ) ) ) { @@ -114,10 +132,10 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st } } // Check if the largest child is bigger than `t`... - v1 = X[ offset+(child*sx) ]; + v1 = X[ offsetX+(child*strideX) ]; if ( v1 > t || stdlib_base_is_nan( v1 ) || ( v1 == t && stdlib_base_is_positive_zero( v1 ) ) ) { // Insert the larger child value: - X[ offset+(j*sx) ] = v1; + X[ offsetX+(j*strideX) ] = v1; // Update `j` to point to the child index: j = child; @@ -130,6 +148,6 @@ void c_dsorthp( const int64_t N, const double order, double *X, const int64_t st } } // Insert `t` into the heap: - X[ offset+(j*sx) ] = t; + X[ offsetX+(j*strideX) ] = t; } } From b21af25928957244f10bb3c19c3d0324c0319ff9 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sun, 2 Feb 2025 07:03:59 +0000 Subject: [PATCH 2/7] chore: update copyright years --- .../base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c index caa59f7a5945..dd7fac9fcbf9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 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 9dfc6ffadbe5ae91935f7a68c71220247e0a5611 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 2 Feb 2025 17:58:20 +0530 Subject: [PATCH 3/7] chore: remove unwanted include --- 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: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c index 8cca6f2bd349..54aff4d73130 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c @@ -21,10 +21,8 @@ #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" -#include #include - /** * Sorts a double-precision floating-point strided array using heapsort. * From a9cfe1352b508b1c47458b37c1c6fbb063ba5018 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 2 Feb 2025 18:14:42 +0530 Subject: [PATCH 4/7] chore: updated manifest file --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: 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: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json index edbbe9b49d56..cb0be6897a23 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json @@ -39,11 +39,10 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-double", "@stdlib/napi/argv-strided-float64array", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/floor", "@stdlib/math/base/assert/is-positive-zero", - "@stdlib/napi/create-double", "@stdlib/strided/base/stride2offset", "@stdlib/blas/base/shared" ] @@ -60,7 +59,6 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/floor", "@stdlib/math/base/assert/is-positive-zero", "@stdlib/strided/base/stride2offset", "@stdlib/blas/base/shared" @@ -78,7 +76,6 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/floor", "@stdlib/math/base/assert/is-positive-zero", "@stdlib/strided/base/stride2offset", "@stdlib/blas/base/shared" From 8a4ff43dabdcfaae0527e95e92c598601160b391 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 4 Feb 2025 15:34:51 +0530 Subject: [PATCH 5/7] fix: update documentation and benchmarks to use double for order parameter --- .../@stdlib/blas/ext/base/dsorthp/README.md | 18 ++++++------- .../c/benchmark.unsorted_random.length.c | 4 +-- .../blas/ext/base/dsorthp/docs/repl.txt | 10 +++---- .../include/stdlib/blas/ext/base/dsorthp.h | 4 +-- .../blas/ext/base/dsorthp/lib/dsorthp.js | 4 +-- .../ext/base/dsorthp/lib/ndarray.native.js | 2 +- .../@stdlib/blas/ext/base/dsorthp/src/main.c | 26 ++++++++++--------- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md index 9d9987f37a6c..de48cfe0ec27 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/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' ); @@ -94,7 +94,7 @@ The function has the following additional parameters: - **offsetX**: starting index. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to access only the last three elements: +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on starting a index. For example, to access only the last three elements: ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -178,7 +178,7 @@ Sorts a double-precision floating-point strided array using heapsort. ```c double x[] = { 1.0, -2.0, 3.0, -4.0 }; -stdlib_strided_dsorthp( 2, -1, x, 1 ); +stdlib_strided_dsorthp( 2, -1.0, x, 1 ); ``` The function accepts the following arguments: @@ -189,7 +189,7 @@ The function accepts the following arguments: - **strideX**: `[in] CBLAS_INT` stride length for `X`. ```c -stdlib_strided_dsorthp( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX ); +stdlib_strided_dsorthp( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ); ``` @@ -203,19 +203,19 @@ Sorts a double-precision floating-point strided array using heapsort and alterna ```c double x[] = { 1.0, -2.0, 3.0, -4.0 }; -stdlib_strided_dsorthp_ndarray( 4, 1, x, 1, 0 ); +stdlib_strided_dsorthp_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. +- **order**: `[in] double` 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`. +- **strideX**: `[in] CBLAS_INT` stride length. +- **offsetX**: `[in] CBLAS_INT` starting index. ```c -stdlib_strided_dsorthp_ndarray( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ); +stdlib_strided_dsorthp_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/dsorthp/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c index dd7fac9fcbf9..68dc49300738 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/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_dsorthp( len, 1, x, 1 ); + stdlib_strided_dsorthp( len, 1.0, x, 1 ); if ( x[ 0 ] != x[ 0 ] ) { printf( "should not return NaN\n" ); break; @@ -136,7 +136,7 @@ static double benchmark2( int iterations, int len ) { } t = tic(); for ( i = 0; i < iterations; i++ ) { - stdlib_strided_dsorthp_ndarray( len, 1, x, 1, 0); + stdlib_strided_dsorthp_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/dsorthp/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/docs/repl.txt index 2bb01ec38c61..d67428b1843d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/docs/repl.txt @@ -2,8 +2,8 @@ {{alias}}( N, order, x, strideX ) Sorts a double-precision floating-point strided array using heapsort. - The `N` and stride parameters determine which elements in `x` are accessed - at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. @@ -73,8 +73,8 @@ 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 - starting index. + buffer, the offset parameter supports indexing semantics based on a starting + index. Parameters ---------- @@ -92,7 +92,7 @@ Stride length. offsetX: integer - Starting index of `x`. + Starting index. Returns ------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/include/stdlib/blas/ext/base/dsorthp.h b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/include/stdlib/blas/ext/base/dsorthp.h index 6df24c80d4dd..872f3385085b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/include/stdlib/blas/ext/base/dsorthp.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/include/stdlib/blas/ext/base/dsorthp.h @@ -31,12 +31,12 @@ extern "C" { /** * Sorts a double-precision floating-point strided array using heapsort. */ -void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX ); +void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ); /** * Sorts a double-precision floating-point strided array using heapsort and alternative indexing semantics. */ -void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ); +void API_SUFFIX(stdlib_strided_dsorthp_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/dsorthp/lib/dsorthp.js b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.js index fa3b5ea90c3e..791d35440287 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/dsorthp.js @@ -53,9 +53,7 @@ var ndarray = require( './ndarray.js' ); * // x => [ -4.0, -2.0, 1.0, 3.0 ] */ function dsorthp( N, order, x, strideX ) { - var offsetX; - 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/dsorthp/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.native.js index 725830a94c83..931368fe1a98 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/lib/ndarray.native.js @@ -43,7 +43,7 @@ var addon = require( './../src/addon.node' ); * dsorthp( x.length, 1.0, x, 1, 0 ); */ function dsorthp( 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/dsorthp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c index 54aff4d73130..db6da3c1c796 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c @@ -40,7 +40,7 @@ * @param X input array * @param strideX stride length */ -void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX) { +void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX) { CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); return API_SUFFIX(stdlib_strided_dsorthp_ndarray)( N, order, X, strideX, ox ); } @@ -63,9 +63,11 @@ void API_SUFFIX(stdlib_strided_dsorthp)( const CBLAS_INT N, const double order, * @param strideX stride length * @param offsetX starting index */ -void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, CBLAS_INT strideX, CBLAS_INT offsetX ) { +void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { CBLAS_INT parent; CBLAS_INT child; + CBLAS_INT ox; + CBLAS_INT sx; CBLAS_INT n; CBLAS_INT i; CBLAS_INT j; @@ -79,8 +81,8 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double } // 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 ); } // Set the initial heap size: n = N; @@ -93,7 +95,7 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double if ( parent > 0 ) { // We need to build the heap... parent -= 1; - t = X[ offsetX+(parent*strideX) ]; + t = X[ ox+(parent*sx) ]; } else { // Reduce the heap size: n -= 1; @@ -103,11 +105,11 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double return; } // Store the last heap value in a temporary variable in order to make room for the heap root being placed into its sorted position: - i = offsetX + (n*strideX); + i = ox + (n*sx); t = X[ i ]; // Move the heap root to its sorted position: - X[ i ] = X[ offsetX ]; + X[ i ] = X[ ox ]; } // We need to "sift down", pushing `t` down the heap to in order to replace the parent and satisfy the heap property... @@ -121,8 +123,8 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double // Find the largest child... k = child + 1; if ( k < n ) { - v1 = X[ offsetX+(k*strideX) ]; - v2 = X[ offsetX+(child*strideX) ]; + v1 = X[ ox+(k*sx) ]; + v2 = X[ ox+(child*sx) ]; // Check if a "right" child exists and is "bigger"... if ( v1 > v2 || stdlib_base_is_nan( v1 ) || (v1 == v2 && stdlib_base_is_positive_zero( v1 ) ) ) { @@ -130,10 +132,10 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double } } // Check if the largest child is bigger than `t`... - v1 = X[ offsetX+(child*strideX) ]; + v1 = X[ ox+(child*sx) ]; if ( v1 > t || stdlib_base_is_nan( v1 ) || ( v1 == t && stdlib_base_is_positive_zero( v1 ) ) ) { // Insert the larger child value: - X[ offsetX+(j*strideX) ] = v1; + X[ ox+(j*sx) ] = v1; // Update `j` to point to the child index: j = child; @@ -146,6 +148,6 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double } } // Insert `t` into the heap: - X[ offsetX+(j*strideX) ] = t; + X[ ox+(j*sx) ] = t; } } From d2584c540350a72d0dd2955b4de6358e4c1bc882 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 4 Feb 2025 15:54:29 +0530 Subject: [PATCH 6/7] feat: add floor function dependency and refactor sorting logic in dsorthp --- 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: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/blas/ext/base/dsorthp/manifest.json | 3 +++ lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json index cb0be6897a23..2dd9efaba5ed 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/manifest.json @@ -42,6 +42,7 @@ "@stdlib/napi/argv-double", "@stdlib/napi/argv-strided-float64array", "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/floor", "@stdlib/math/base/assert/is-positive-zero", "@stdlib/strided/base/stride2offset", "@stdlib/blas/base/shared" @@ -59,6 +60,7 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/floor", "@stdlib/math/base/assert/is-positive-zero", "@stdlib/strided/base/stride2offset", "@stdlib/blas/base/shared" @@ -76,6 +78,7 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/floor", "@stdlib/math/base/assert/is-positive-zero", "@stdlib/strided/base/stride2offset", "@stdlib/blas/base/shared" diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c index db6da3c1c796..2b5647c3a8aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c @@ -21,6 +21,7 @@ #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" +#include "stdlib/math/base/special/floor.h" #include /** @@ -81,14 +82,17 @@ void API_SUFFIX(stdlib_strided_dsorthp_ndarray)( const CBLAS_INT N, const double } // 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 = -strideX; + sx = strideX * -1; ox = offsetX - ( (N-1)*sx ); + }else{ + sx = strideX; + ox = offsetX; } // Set the initial heap size: n = N; // Specify an initial "parent" index for building the heap: - parent = floor( N / 2 ); + parent = stdlib_base_floor( N / 2 ); // Continue looping until the array is sorted... while ( true ) { From d7bea9f59263ef250e04d496fb6b2b351b715bd1 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Wed, 5 Feb 2025 01:06:11 +0530 Subject: [PATCH 7/7] fix: update README and benchmark for strideX parameter description --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- 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/dsorthp/README.md | 2 +- .../base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c | 2 +- lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md index de48cfe0ec27..1b84c98f7d19 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/README.md @@ -186,7 +186,7 @@ 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`. +- **strideX**: `[in] CBLAS_INT` stride length. ```c stdlib_strided_dsorthp( const CBLAS_INT N, const double order, double *X, const CBLAS_INT strideX ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c index 68dc49300738..a92dfd1db8a1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/benchmark/c/benchmark.unsorted_random.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/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_dsorthp_ndarray( len, 1.0, x, 1, 0); + stdlib_strided_dsorthp_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/dsorthp/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c index 2b5647c3a8aa..4d1bca561f72 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dsorthp/src/main.c @@ -22,7 +22,6 @@ #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" #include "stdlib/math/base/special/floor.h" -#include /** * Sorts a double-precision floating-point strided array using heapsort.