From 0a3d97a77d19d256177b22dedc500f5eb08855b2 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 5 Oct 2024 19:27:05 +0500 Subject: [PATCH 01/15] feat: add C ndarray API and refactor --- .../blas/ext/base/dnannsumkbn/README.md | 127 +++++++++++++++++- .../benchmark/c/benchmark.length.c | 56 +++++++- .../blas/ext/base/dnannsumkbn/docs/repl.txt | 6 +- .../ext/base/dnannsumkbn/examples/c/example.c | 12 +- .../stdlib/blas/ext/base/dnannsumkbn.h | 9 +- .../ext/base/dnannsumkbn/lib/dnannsumkbn.js | 52 +------ .../blas/ext/base/dnannsumkbn/lib/ndarray.js | 10 +- .../base/dnannsumkbn/lib/ndarray.native.js | 20 +-- .../blas/ext/base/dnannsumkbn/manifest.json | 33 ++--- .../blas/ext/base/dnannsumkbn/src/addon.c | 36 ++++- .../ext/base/dnannsumkbn/src/dnannsumkbn.c | 82 ----------- .../blas/ext/base/dnannsumkbn/src/main.c | 103 ++++++++++++++ .../base/dnannsumkbn/test/test.dnannsumkbn.js | 4 +- .../test/test.dnannsumkbn.native.js | 4 +- .../ext/base/dnannsumkbn/test/test.ndarray.js | 4 +- .../dnannsumkbn/test/test.ndarray.native.js | 4 +- 16 files changed, 366 insertions(+), 196 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/dnannsumkbn.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index 7c9708a4a43f..91473b128e60 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -58,7 +58,7 @@ The function has the following parameters: - **out**: output [`Float64Array`][@stdlib/array/float64] whose first element is the sum and whose second element is the number of non-NaN elements. - **strideOut**: index increment for `out`. -The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the sum of every other element in `x`, +The `N` and stride parameters determine which elements are accessed at runtime. For example, to compute the sum of every other element in `x`, ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -106,7 +106,7 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetOut**: starting index for `out`. -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 calculate the sum of every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting index. For example, to calculate the sum of every other value in `x` starting from the second value: ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -164,8 +164,131 @@ console.log( out ); + + * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dnannsumkbn.h" +``` + +#### stdlib_strided_dnannsumkbn( N, \*X, strideX, \*n ) + +Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; +int n = 0; + +double v = stdlib_strided_dnannsumkbn( 4, x, 1, &n ); +// returns 7.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **n**: `[out] CBLAS_INT*` number of non-NaN elements. + +```c +double stdlib_strided_dnannsumkbn( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ); +``` + +#### stdlib_strided_dnannsumkbn_ndarray( N, \*X, strideX, offsetX, \*n ) + +Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; +int n = 0; + +double v = stdlib_strided_dnannsumkbn_ndarray( 4, x, 1, 0, &n ); +// returns 7.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **n**: `[out] CBLAS_INT*` number of non-NaN elements. + +```c +double stdlib_strided_dnannsumkbn_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dnannsumkbn.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, 2.0, -3.0, -4.0, 5.0, -6.0, -7.0, 8.0, 0.0/0.0, 0.0/0.0 }; + + // Specify the number of elements: + const int N = 5; + + // Specify the stride length: + const int strideX = 2; + + // Initialize a variable for storing the number of non-NaN elements: + int n = 0; + + // Compute the sum: + double v = stdlib_strided_dnannsumkbn( N, x, strideX, &n ); + + // Print the result: + printf( "sum: %lf\n", v ); + printf( "n: %d\n", n ); +} +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c index 70171814fc49..82403a93f250 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c @@ -94,10 +94,10 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; - int64_t n; + int n; double v; double t; int i; @@ -126,6 +126,45 @@ static double benchmark( int iterations, int len ) { 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 ]; + int n; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + if ( rand_double() < 0.2 ) { + x[ i ] = 0.0 / 0.0; // NaN + } else { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + } + v = 0.0; + n = 0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + v = stdlib_strided_dnannsumkbn_ndarray( len, x, 1, 0, &n ); + if ( v != v || n < 0 ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v || n < 0 ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -148,7 +187,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, 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:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt index 14010bb16fb7..6fce738078b1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt @@ -3,7 +3,7 @@ Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm. - The `N` and `stride` parameters determine which elements in the strided + 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 a typed @@ -62,8 +62,8 @@ alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the offsetX and offsetY parameter supports indexing semantics - based on a starting index. + buffer, offset parameters support indexing semantics based on starting + index. Parameters ---------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c index 1aab6016b8a0..5d107ee17788 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c @@ -17,27 +17,25 @@ */ #include "stdlib/blas/ext/base/dnannsumkbn.h" -#include #include -#include int main( void ) { // Create a strided array: const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 }; // Specify the number of elements: - const int64_t N = 5; + const int N = 5; // Specify the stride length: - const int64_t stride = 2; + const int strideX = 2; // Initialize a variable for storing the number of non-NaN elements: - int64_t n = 0; + int n = 0; // Compute the sum: - double v = stdlib_strided_dnannsumkbn( N, x, stride, &n ); + double v = stdlib_strided_dnannsumkbn( N, x, strideX, &n ); // Print the result: printf( "sum: %lf\n", v ); - printf( "n: %"PRId64"\n", n ); + printf( "n: %d\n", n ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/include/stdlib/blas/ext/base/dnannsumkbn.h b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/include/stdlib/blas/ext/base/dnannsumkbn.h index 98733f05e7e7..d979309b2d2c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/include/stdlib/blas/ext/base/dnannsumkbn.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/include/stdlib/blas/ext/base/dnannsumkbn.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DNANNSUMKBN_H #define STDLIB_BLAS_EXT_BASE_DNANNSUMKBN_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" { /** * Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm. */ -double stdlib_strided_dnannsumkbn( const int64_t N, const double *X, const int64_t stride, int64_t *n ); +double API_SUFFIX(stdlib_strided_dnannsumkbn)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ); + +/** +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and using alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/dnannsumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/dnannsumkbn.js index 7149e76b9a00..913880ea312c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/dnannsumkbn.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/dnannsumkbn.js @@ -20,8 +20,8 @@ // MODULES // -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -54,60 +54,16 @@ var abs = require( '@stdlib/math/base/special/abs' ); * // returns [ 1.0, 3 ] */ function dnannsumkbn( N, x, strideX, out, strideOut ) { - var sum; var ix; var io; - var v; - var t; - var c; - var n; - var i; - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } + ix = stride2offset( N, strideX ); if ( strideOut < 0 ) { io = -strideOut; } else { io = 0; } - sum = 0.0; - if ( N <= 0 ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; - return out; - } - if ( N === 1 || strideX === 0 ) { - if ( isnan( x[ ix ] ) ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; - return out; - } - out[ io ] = x[ ix ]; - out[ io+strideOut ] = 1; - return out; - } - c = 0.0; - n = 0; - for ( i = 0; i < N; i++ ) { - v = x[ ix ]; - if ( isnan( v ) === false ) { - t = sum + v; - if ( abs( sum ) >= abs( v ) ) { - c += (sum-t) + v; - } else { - c += (v-t) + sum; - } - sum = t; - n += 1; - } - ix += strideX; - } - out[ io ] = sum + c; - out[ io+strideOut ] = n; - return out; + return ndarray( N, x, strideX, ix, out, strideOut, io ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js index 48c496820962..5b0c0e4a19ad 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js @@ -39,10 +39,10 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} strideX - `x` stride length +* @param {integer} strideX - `x` index increment * @param {NonNegativeInteger} offsetX - `x` starting index * @param {Float64Array} out - output array -* @param {integer} strideOut - `out` stride length +* @param {integer} strideOut - `out` index increment * @param {NonNegativeInteger} offsetOut - `out` starting index * @returns {Float64Array} output array * @@ -74,14 +74,14 @@ function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) { out[ io+strideOut ] = 0; return out; } - if ( N === 1 || strideX === 0 ) { + if ( strideX === 0 ) { if ( isnan( x[ ix ] ) ) { out[ io ] = sum; out[ io+strideOut ] = 0; return out; } - out[ io ] = x[ ix ]; - out[ io+strideOut ] = 1; + out[ io ] = abs( x[ ix ] ) * N; + out[ io+strideOut ] = N; return out; } c = 0.0; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.native.js index e8e546c448a7..9fa6120a1c18 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/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( './dnannsumkbn.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,10 +30,10 @@ var addon = require( './dnannsumkbn.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} strideX - `x` stride length +* @param {integer} strideX - `x` index increment * @param {NonNegativeInteger} offsetX - `x` starting index * @param {Float64Array} out - output array -* @param {integer} strideOut - `out` stride length +* @param {integer} strideOut - `out` index increment * @param {NonNegativeInteger} offsetOut - `out` starting index * @returns {Float64Array} output array * @@ -49,17 +47,7 @@ var addon = require( './dnannsumkbn.native.js' ); * // returns [ 5.0, 4 ] */ function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) { - var viewOut; - var viewX; - - offsetX = minViewBufferIndex( N, strideX, offsetX ); - if ( strideOut < 0 ) { - offsetOut += strideOut; - } - - viewX = offsetView( x, offsetX ); - viewOut = offsetView( out, offsetOut ); - addon( N, viewX, strideX, viewOut, strideOut ); + addon.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut ); return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/manifest.json index 718554dcf606..ef4d072fe70a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/manifest.json @@ -28,53 +28,56 @@ { "task": "build", "src": [ - "./src/dnannsumkbn.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", - "@stdlib/math/base/assert/is-nan" + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/abs", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { "task": "benchmark", "src": [ - "./src/dnannsumkbn.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nan" + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/abs", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { "task": "examples", "src": [ - "./src/dnannsumkbn.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nan" + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/abs", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c index 21a7deefb892..d71c394f8788 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c @@ -17,12 +17,12 @@ */ #include "stdlib/blas/ext/base/dnannsumkbn.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float64array.h" #include -#include /** * Receives JavaScript callback invocation data. @@ -39,7 +39,7 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 3 ); - int64_t io; + int io; if ( strideOut < 0 ) { io = -strideOut; } else { @@ -47,11 +47,37 @@ static napi_value addon( napi_env env, napi_callback_info info ) { } double *out = Out; - int64_t n; - out[ io ] = stdlib_strided_dnannsumkbn( N, X, strideX, &n ); + int n; + out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn)( N, X, strideX, &n ); out[ io+strideOut ] = (double)n; 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, 7 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideOut, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, offsetOut, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 4 ); + + int io = offsetOut; + double *out = Out; + int n; + out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( N, X, strideX, offsetX, &n ); + out[ io+strideOut ] = (double)n; + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/dnannsumkbn.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/dnannsumkbn.c deleted file mode 100644 index 8dc8dbad44de..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/dnannsumkbn.c +++ /dev/null @@ -1,82 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 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/dnannsumkbn.h" -#include "stdlib/math/base/assert/is_nan.h" -#include -#include - -/** -* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm. -* -* ## Method -* -* - This implementation uses an "improved Kahan–Babuška algorithm", as described by Neumaier (1974). -* -* ## References -* -* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106). -* -* @param N number of indexed elements -* @param X input array -* @param stride stride length -* @param n pointer for storing the number of non-NaN elements -* @return output value -*/ -double stdlib_strided_dnannsumkbn( const int64_t N, const double *X, const int64_t stride, int64_t *n ) { - double sum; - int64_t ix; - int64_t i; - double v; - double t; - double c; - - sum = 0.0; - *n = 0; - if ( N <= 0 ) { - return sum; - } - if ( N == 1 || stride == 0 ) { - if ( stdlib_base_is_nan( X[ 0 ] ) ) { - return sum; - } - *n += 1; - return X[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - c = 0.0; - for ( i = 0; i < N; i++ ) { - v = X[ ix ]; - if ( !stdlib_base_is_nan( v ) ) { - t = sum + v; - if ( fabs( sum ) >= fabs( v ) ) { - c += (sum-t) + v; - } else { - c += (v-t) + sum; - } - sum = t; - *n += 1; - } - ix += stride; - } - return sum + c; -} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c new file mode 100644 index 000000000000..b2950d428cce --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 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/strided/base/stride2offset.h" +#include "stdlib/blas/ext/base/dnannsumkbn.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/abs.h" +#include "stdlib/blas/base/shared.h" + +/** +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm. +* +* ## Method +* +* - This implementation uses an "improved Kahan–Babuška algorithm", as described by Neumaier (1974). +* +* ## References +* +* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106). +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @param n number of non-NaN elements +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnannsumkbn)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( N, X, strideX, ox, n ); +} + +/** +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics. +* +* ## Method +* +* - This implementation uses an "improved Kahan–Babuška algorithm", as described by Neumaier (1974). +* +* ## References +* +* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106). +* +* @param N number of indexed elements +* @param X input array +* @param strideX index increment +* @param offsetX starting index +* @param n number of non-NaN elements +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ) { + double sum; + CBLAS_INT ix; + CBLAS_INT i; + double v; + double t; + double c; + + sum = 0.0; + ix = offsetX; + *n = 0; + if ( N <= 0 ) { + return sum; + } + if ( strideX == 0 ) { + if ( stdlib_base_is_nan( X[ ix ] ) ) { + return sum; + } + sum = stdlib_base_abs( X[ ix ] ) * N; + *n += N; + return sum; + } + c = 0.0; + for ( i = 0; i < N; i++ ) { + v = X[ ix ]; + if ( !stdlib_base_is_nan( v ) ) { + t = sum + v; + if ( stdlib_base_abs( sum ) >= stdlib_base_abs( v ) ) { + c += (sum-t) + v; + } else { + c += (v-t) + sum; + } + sum = t; + *n += 1; + } + ix += strideX; + } + return sum + c; +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.dnannsumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.dnannsumkbn.js index 37f71ea7bd68..827fa8ef5c77 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.dnannsumkbn.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.dnannsumkbn.js @@ -215,7 +215,7 @@ tape( 'the function supports negative `stride` parameters', function test( t ) { t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns a sum equal to the first element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var expected; var out; var x; @@ -226,7 +226,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns a sum out = new Float64Array( 2 ); v = dnannsumkbn( x.length, x, 0, out, 1 ); - expected = new Float64Array( [ 1.0, 1.0 ] ); + expected = new Float64Array( [ 5.0, 5.0 ] ); t.deepEqual( v, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.dnannsumkbn.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.dnannsumkbn.native.js index 1cd6842af9b0..db71a389d272 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.dnannsumkbn.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.dnannsumkbn.native.js @@ -224,7 +224,7 @@ tape( 'the function supports negative `stride` parameters', opts, function test( t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns a sum equal to the first element', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', opts, function test( t ) { var expected; var out; var x; @@ -235,7 +235,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns a sum out = new Float64Array( 2 ); v = dnannsumkbn( x.length, x, 0, out, 1 ); - expected = new Float64Array( [ 1.0, 1.0 ] ); + expected = new Float64Array( [ 5.0, 5.0 ] ); t.deepEqual( v, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.ndarray.js index 97d2d396ca01..ba07429ebe6a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.ndarray.js @@ -215,7 +215,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var expected; var out; var x; @@ -226,7 +226,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f out = new Float64Array( 2 ); v = dnannsumkbn( x.length, x, 0, 0, out, 1, 0 ); - expected = new Float64Array( [ 1.0, 1.0 ] ); + expected = new Float64Array( [ 5.0, 5.0 ] ); t.deepEqual( v, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.ndarray.native.js index a44484c7456e..a9c95fe273ce 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/test/test.ndarray.native.js @@ -224,7 +224,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', opts, function test( t ) { var expected; var out; var x; @@ -235,7 +235,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f out = new Float64Array( 2 ); v = dnannsumkbn( x.length, x, 0, 0, out, 1, 0 ); - expected = new Float64Array( [ 1.0, 1.0 ] ); + expected = new Float64Array( [ 5.0, 5.0 ] ); t.deepEqual( v, expected, 'returns expected value' ); t.end(); From 6ed9368cd8415737f98391ec0f09e6c913add9bc Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 6 Oct 2024 12:11:15 +0500 Subject: [PATCH 02/15] fix: apply code review suggestion --- lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md | 2 +- .../@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index 91473b128e60..718283bf351d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -106,7 +106,7 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetOut**: starting index for `out`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting index. For example, to calculate the sum of every other value in `x` starting from the second value: +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to calculate the sum of every other value in `x` starting from the second value: ```javascript var Float64Array = require( '@stdlib/array/float64' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt index 6fce738078b1..70bd509e200a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt @@ -63,7 +63,7 @@ While typed array views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting - index. + indices. Parameters ---------- From 88d4913f2ac8f3ca00f1c02561a1ec724dea6cdb Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 6 Oct 2024 13:40:41 +0500 Subject: [PATCH 03/15] fix: apply code review suggestions --- .../@stdlib/blas/ext/base/dnannsumkbn/README.md | 7 ++++--- .../ext/base/dnannsumkbn/benchmark/c/benchmark.length.c | 5 +++-- .../@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c | 3 ++- .../@stdlib/blas/ext/base/dnannsumkbn/src/addon.c | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index 718283bf351d..9437a831ed4c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -196,7 +196,7 @@ Computes the sum of double-precision floating-point strided array elements, igno ```c const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; -int n = 0; +CBLAS_INT n = 0; double v = stdlib_strided_dnannsumkbn( 4, x, 1, &n ); // returns 7.0 @@ -219,7 +219,7 @@ Computes the sum of double-precision floating-point strided array elements, igno ```c const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; -int n = 0; +CBLAS_INT n = 0; double v = stdlib_strided_dnannsumkbn_ndarray( 4, x, 1, 0, &n ); // returns 7.0 @@ -257,6 +257,7 @@ double stdlib_strided_dnannsumkbn_ndarray( const CBLAS_INT N, const double *X, c ```c #include "stdlib/blas/ext/base/dnannsumkbn.h" +#include "stdlib/blase/base/shared.h" #include int main( void ) { @@ -270,7 +271,7 @@ int main( void ) { const int strideX = 2; // Initialize a variable for storing the number of non-NaN elements: - int n = 0; + CBLAS_INT n = 0; // Compute the sum: double v = stdlib_strided_dnannsumkbn( N, x, strideX, &n ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c index 82403a93f250..dc9c93374977 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c @@ -17,6 +17,7 @@ */ #include "stdlib/blas/ext/base/dnannsumkbn.h" +#include "stdlib/blas/base/shared.h" #include #include #include @@ -97,7 +98,7 @@ static double rand_double( void ) { static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; - int n; + CBLAS_INT n; double v; double t; int i; @@ -136,7 +137,7 @@ static double benchmark1( int iterations, int len ) { static double benchmark2( int iterations, int len ) { double elapsed; double x[ len ]; - int n; + CBLAS_INT n; double v; double t; int i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c index 5d107ee17788..4960d2720c65 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c @@ -17,6 +17,7 @@ */ #include "stdlib/blas/ext/base/dnannsumkbn.h" +#include "stdlib/blas/base/shared.h" #include int main( void ) { @@ -30,7 +31,7 @@ int main( void ) { const int strideX = 2; // Initialize a variable for storing the number of non-NaN elements: - int n = 0; + CBLAS_INT n = 0; // Compute the sum: double v = stdlib_strided_dnannsumkbn( N, x, strideX, &n ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c index d71c394f8788..fe59df4f0633 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c @@ -47,7 +47,7 @@ static napi_value addon( napi_env env, napi_callback_info info ) { } double *out = Out; - int n; + CBLAS_INT n; out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn)( N, X, strideX, &n ); out[ io+strideOut ] = (double)n; @@ -73,7 +73,7 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { int io = offsetOut; double *out = Out; - int n; + CBLAS_INT n; out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( N, X, strideX, offsetX, &n ); out[ io+strideOut ] = (double)n; From 644168b1bce712397eb1da0d812d453e623e0cb9 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 6 Oct 2024 13:55:16 +0500 Subject: [PATCH 04/15] fix: use correct specifier --- lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md | 2 +- .../@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index 9437a831ed4c..4295d2a9c78b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -278,7 +278,7 @@ int main( void ) { // Print the result: printf( "sum: %lf\n", v ); - printf( "n: %d\n", n ); + printf( "n: %ld\n", n ); } ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c index 4960d2720c65..e0fa95237d08 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c @@ -38,5 +38,5 @@ int main( void ) { // Print the result: printf( "sum: %lf\n", v ); - printf( "n: %d\n", n ); + printf( "n: %ld\n", n ); } From 40fe636fa33bdca9e9110ee00688b2652982cc1b Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 6 Oct 2024 14:24:05 +0500 Subject: [PATCH 05/15] fix: use CBLAS format specifier --- lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md | 2 +- .../@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index 4295d2a9c78b..dca1f204ef7a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -278,7 +278,7 @@ int main( void ) { // Print the result: printf( "sum: %lf\n", v ); - printf( "n: %ld\n", n ); + printf( "n: %"CBLAS_IFMT"\n", n ); } ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c index e0fa95237d08..165802a7eee1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/examples/c/example.c @@ -38,5 +38,5 @@ int main( void ) { // Print the result: printf( "sum: %lf\n", v ); - printf( "n: %ld\n", n ); + printf( "n: %"CBLAS_IFMT"\n", n ); } From 25ae71ade56e2e06e0af1aa8babf79cd9fef40da Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 7 Oct 2024 16:59:29 +0500 Subject: [PATCH 06/15] fix: remove use of abs to calculate sum --- .../@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js | 2 +- lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js index 5b0c0e4a19ad..c2178b0f09c2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js @@ -80,7 +80,7 @@ function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) { out[ io+strideOut ] = 0; return out; } - out[ io ] = abs( x[ ix ] ) * N; + out[ io ] = x[ ix ] * N; out[ io+strideOut ] = N; return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c index b2950d428cce..6ecd54fe35fd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c @@ -80,7 +80,7 @@ double API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( const CBLAS_INT N, const if ( stdlib_base_is_nan( X[ ix ] ) ) { return sum; } - sum = stdlib_base_abs( X[ ix ] ) * N; + sum = X[ ix ] * N; *n += N; return sum; } From 8770c239bbce3f6ea87d2a3a97b60b3cd730cbe7 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:05:47 +0000 Subject: [PATCH 07/15] fix: remove grammar mistake --- .../base/dnannsumkbn/include/stdlib/blas/ext/base/dnannsumkbn.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/include/stdlib/blas/ext/base/dnannsumkbn.h b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/include/stdlib/blas/ext/base/dnannsumkbn.h index d979309b2d2c..c84e4d30f221 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/include/stdlib/blas/ext/base/dnannsumkbn.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/include/stdlib/blas/ext/base/dnannsumkbn.h @@ -34,7 +34,7 @@ extern "C" { double API_SUFFIX(stdlib_strided_dnannsumkbn)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ); /** -* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and using alternative indexing semantics. +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics. */ double API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ); From d6045f15026d4ed599359c8e73c4893b62fbf90e Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 9 Oct 2024 04:41:50 +0000 Subject: [PATCH 08/15] fix: apply code review suggestion --- lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index dca1f204ef7a..30cc1d892286 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -262,7 +262,7 @@ double stdlib_strided_dnannsumkbn_ndarray( const CBLAS_INT N, const double *X, c int main( void ) { // Create a strided array: - const double x[] = { 1.0, 2.0, -3.0, -4.0, 5.0, -6.0, -7.0, 8.0, 0.0/0.0, 0.0/0.0 }; + const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 }; // Specify the number of elements: const int N = 5; From 6f328c9c71ad0c1cf8a4e97d339d64faff6c9cf6 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 11 Oct 2024 22:40:32 +0500 Subject: [PATCH 09/15] fix: apply code review suggestion --- .../@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js | 5 ++--- .../@stdlib/blas/ext/base/dnannsumkbn/src/main.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js index c2178b0f09c2..4b8d19fd6795 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js @@ -65,15 +65,14 @@ function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) { var n; var i; - ix = offsetX; - io = offsetOut; - sum = 0.0; + io = offsetOut; if ( N <= 0 ) { out[ io ] = sum; out[ io+strideOut ] = 0; return out; } + ix = offsetX; if ( strideX === 0 ) { if ( isnan( x[ ix ] ) ) { out[ io ] = sum; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c index 6ecd54fe35fd..6ed7e54f975f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c @@ -16,8 +16,8 @@ * limitations under the License. */ -#include "stdlib/strided/base/stride2offset.h" #include "stdlib/blas/ext/base/dnannsumkbn.h" +#include "stdlib/strided/base/stride2offset.h" #include "stdlib/math/base/assert/is_nan.h" #include "stdlib/math/base/special/abs.h" #include "stdlib/blas/base/shared.h" @@ -71,11 +71,11 @@ double API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( const CBLAS_INT N, const double c; sum = 0.0; - ix = offsetX; *n = 0; if ( N <= 0 ) { return sum; } + ix = offsetX; if ( strideX == 0 ) { if ( stdlib_base_is_nan( X[ ix ] ) ) { return sum; From 0da24049df8cb8136b04976cc1c5d4f1c4374a26 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 20 Oct 2024 23:06:00 +0500 Subject: [PATCH 10/15] fix: apply code review suggestion --- .../@stdlib/blas/ext/base/dnannsumkbn/README.md | 8 ++++---- .../@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt | 8 ++++---- .../@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js | 4 ++-- .../blas/ext/base/dnannsumkbn/lib/ndarray.native.js | 4 ++-- .../@stdlib/blas/ext/base/dnannsumkbn/src/main.c | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index 30cc1d892286..09603356a24c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -54,9 +54,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **strideX**: index increment for `x`. +- **strideX**: stride length for `x`. - **out**: output [`Float64Array`][@stdlib/array/float64] whose first element is the sum and whose second element is the number of non-NaN elements. -- **strideOut**: index increment for `out`. +- **strideOut**: stride length for `out`. The `N` and stride parameters determine which elements are accessed at runtime. For example, to compute the sum of every other element in `x`, @@ -206,7 +206,7 @@ The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. - **X**: `[in] double*` input array. -- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. - **n**: `[out] CBLAS_INT*` number of non-NaN elements. ```c @@ -229,7 +229,7 @@ The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. - **X**: `[in] double*` input array. -- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. - **offsetX**: `[in] CBLAS_INT` starting index for `X`. - **n**: `[out] CBLAS_INT*` number of non-NaN elements. diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt index 70bd509e200a..f6fc2a083de9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt @@ -20,13 +20,13 @@ Input array. strideX: integer - Index increment for `x`. + Stride length for `x`. out: Float64Array Output array. strideOut: integer - Index increment for `out`. + Stride length for `out`. Returns ------- @@ -74,7 +74,7 @@ Input array. strideX: integer - Index increment for `x`. + Stride length for `x`. offsetX: integer Starting index for `x`. @@ -83,7 +83,7 @@ Output array. strideOut: integer - Index increment for `out`. + Stride length for `out`. offsetOut: integer Starting index for `out`. diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js index 4b8d19fd6795..a50c41198b6c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js @@ -39,10 +39,10 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} strideX - `x` index increment +* @param {integer} strideX - `x` stride length * @param {NonNegativeInteger} offsetX - `x` starting index * @param {Float64Array} out - output array -* @param {integer} strideOut - `out` index increment +* @param {integer} strideOut - `out` stride length * @param {NonNegativeInteger} offsetOut - `out` starting index * @returns {Float64Array} output array * diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.native.js index 9fa6120a1c18..9c20e11b2a71 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.native.js @@ -30,10 +30,10 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} strideX - `x` index increment +* @param {integer} strideX - `x` stride length * @param {NonNegativeInteger} offsetX - `x` starting index * @param {Float64Array} out - output array -* @param {integer} strideOut - `out` index increment +* @param {integer} strideOut - `out` stride length * @param {NonNegativeInteger} offsetOut - `out` starting index * @returns {Float64Array} output array * diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c index 6ed7e54f975f..3edac870b3ff 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c @@ -57,7 +57,7 @@ double API_SUFFIX(stdlib_strided_dnannsumkbn)( const CBLAS_INT N, const double * * * @param N number of indexed elements * @param X input array -* @param strideX index increment +* @param strideX stride length * @param offsetX starting index * @param n number of non-NaN elements * @return output value From e5f1b44bbbc31acfb24203db28c74cc6b3f83819 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 27 Oct 2024 15:12:13 +0500 Subject: [PATCH 11/15] chore: add review suggestion --- .../blas/ext/base/dnannsumkbn/README.md | 2 +- .../base/dnannsumkbn/benchmark/benchmark.js | 19 ++++++++++++------ .../dnannsumkbn/benchmark/benchmark.native.js | 20 ++++++++++++------- .../benchmark/benchmark.ndarray.js | 20 ++++++++++++------- .../benchmark/benchmark.ndarray.native.js | 20 ++++++++++++------- .../blas/ext/base/dnannsumkbn/docs/repl.txt | 4 ++-- .../blas/ext/base/dnannsumkbn/src/main.c | 3 +-- 7 files changed, 56 insertions(+), 32 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index 09603356a24c..a6a5bf5b615a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -106,7 +106,7 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetOut**: starting index for `out`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to calculate the sum of every other value in `x` starting from the second value: +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to calculate the sum of every other element starting from the second element: ```javascript var Float64Array = require( '@stdlib/array/float64' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.js index 2850c16dd58a..81ae9d819649 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.js @@ -33,6 +33,19 @@ var dnannsumkbn = require( './../lib/dnannsumkbn.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -46,12 +59,6 @@ function createBenchmark( len ) { out = new Float64Array( 2 ); return benchmark; - function rand() { - if ( bernoulli( 0.7 ) > 0 ) { - return discreteUniform( -10, 10 ); - } - } - function benchmark( b ) { var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.native.js index 12f4a9059d81..bb96e0464bb2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.native.js @@ -42,6 +42,19 @@ var opts = { // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -55,13 +68,6 @@ function createBenchmark( len ) { out = new Float64Array( 2 ); return benchmark; - function rand() { - if ( bernoulli( 0.7 ) > 0 ) { - return discreteUniform( -10, 10 ); - } - return NaN; - } - function benchmark( b ) { var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.ndarray.js index b7c3c480c348..24d3008d88a4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.ndarray.js @@ -33,6 +33,19 @@ var dnannsumkbn = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -46,13 +59,6 @@ function createBenchmark( len ) { out = new Float64Array( 2 ); return benchmark; - function rand() { - if ( bernoulli( 0.7 ) > 0 ) { - return discreteUniform( -10, 10 ); - } - return NaN; - } - function benchmark( b ) { var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.ndarray.native.js index 37e59f79a795..8919083cf2d4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/benchmark.ndarray.native.js @@ -42,6 +42,19 @@ var opts = { // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -55,13 +68,6 @@ function createBenchmark( len ) { out = new Float64Array( 2 ); return benchmark; - function rand() { - if ( bernoulli( 0.7 ) > 0 ) { - return discreteUniform( -10, 10 ); - } - return NaN; - } - function benchmark( b ) { var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt index f6fc2a083de9..6e6664d2cf41 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt @@ -42,7 +42,7 @@ > {{alias}}( x.length, x, 1, out, 1 ) [ 1.0, 3 ] - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] ); > out = new {{alias:@stdlib/array/float64}}( 2 ); > {{alias}}( 4, x, 2, out, 1 ) @@ -99,7 +99,7 @@ // Standard Usage: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, NaN, 2.0 ] ); > var out = new {{alias:@stdlib/array/float64}}( 2 ); - > {{alias}}.ndarray( x.length, x, 1, 0, out, 1, 0 ) + > {{alias}}.ndarray( 4, x, 1, 0, out, 1, 0 ) [ 1.0, 3 ] // Using offset parameter: diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c index 3edac870b3ff..b232759fc728 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c @@ -80,9 +80,8 @@ double API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( const CBLAS_INT N, const if ( stdlib_base_is_nan( X[ ix ] ) ) { return sum; } - sum = X[ ix ] * N; *n += N; - return sum; + return X[ ix ] * N; } c = 0.0; for ( i = 0; i < N; i++ ) { From adfe97bfc2c7de2feddd294600eb71e35dbe0706 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:03:06 +0000 Subject: [PATCH 12/15] refactor: apply code review suggestions --- .../blas/ext/base/dnannsumkbn/README.md | 4 ++-- .../benchmark/c/benchmark.length.c | 2 ++ .../ext/base/dnannsumkbn/lib/dnannsumkbn.js | 6 +----- .../blas/ext/base/dnannsumkbn/lib/ndarray.js | 18 +++++++--------- .../blas/ext/base/dnannsumkbn/src/addon.c | 21 +++++++------------ .../blas/ext/base/dnannsumkbn/src/main.c | 6 +++--- 6 files changed, 23 insertions(+), 34 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index a6a5bf5b615a..b6c989737bae 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -207,7 +207,7 @@ The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. - **X**: `[in] double*` input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. -- **n**: `[out] CBLAS_INT*` number of non-NaN elements. +- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements. ```c double stdlib_strided_dnannsumkbn( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ); @@ -231,7 +231,7 @@ The function accepts the following arguments: - **X**: `[in] double*` input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. - **offsetX**: `[in] CBLAS_INT` starting index for `X`. -- **n**: `[out] CBLAS_INT*` number of non-NaN elements. +- **n**: `[out] CBLAS_INT*` pointer for storing the number of non-NaN elements. ```c double stdlib_strided_dnannsumkbn_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c index dc9c93374977..511533669c2b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/benchmark/c/benchmark.length.c @@ -114,6 +114,7 @@ static double benchmark1( int iterations, int len ) { n = 0; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_dnannsumkbn( len, x, 1, &n ); if ( v != v || n < 0 ) { printf( "should not return NaN\n" ); @@ -153,6 +154,7 @@ static double benchmark2( int iterations, int len ) { n = 0; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_dnannsumkbn_ndarray( len, x, 1, 0, &n ); if ( v != v || n < 0 ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/dnannsumkbn.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/dnannsumkbn.js index 913880ea312c..46f5d46ccce8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/dnannsumkbn.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/dnannsumkbn.js @@ -58,11 +58,7 @@ function dnannsumkbn( N, x, strideX, out, strideOut ) { var io; ix = stride2offset( N, strideX ); - if ( strideOut < 0 ) { - io = -strideOut; - } else { - io = 0; - } + io = stride2offset( 2, strideOut ); return ndarray( N, x, strideX, ix, out, strideOut, io ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js index a50c41198b6c..48b71c4fb84e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/lib/ndarray.js @@ -58,7 +58,6 @@ var abs = require( '@stdlib/math/base/special/abs' ); function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) { var sum; var ix; - var io; var v; var t; var c; @@ -66,21 +65,20 @@ function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) { var i; sum = 0.0; - io = offsetOut; if ( N <= 0 ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; + out[ offsetOut ] = sum; + out[ offsetOut+strideOut ] = 0; return out; } ix = offsetX; if ( strideX === 0 ) { if ( isnan( x[ ix ] ) ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; + out[ offsetOut ] = sum; + out[ offsetOut+strideOut ] = 0; return out; } - out[ io ] = x[ ix ] * N; - out[ io+strideOut ] = N; + out[ offsetOut ] = x[ ix ] * N; + out[ offsetOut+strideOut ] = N; return out; } c = 0.0; @@ -99,8 +97,8 @@ function dnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) { } ix += strideX; } - out[ io ] = sum + c; - out[ io+strideOut ] = n; + out[ offsetOut ] = sum + c; + out[ offsetOut+strideOut ] = n; return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c index fe59df4f0633..0e0e8718658f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/addon.c @@ -22,6 +22,8 @@ #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float64array.h" +#include "stdlib/strided/base/stride2offset.h" +#include #include /** @@ -39,17 +41,10 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 3 ); - int io; - if ( strideOut < 0 ) { - io = -strideOut; - } else { - io = 0; - } - - double *out = Out; + int64_t io = stdlib_strided_stride2offset( 2, strideOut ); CBLAS_INT n; - out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn)( N, X, strideX, &n ); - out[ io+strideOut ] = (double)n; + Out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn)( N, X, strideX, &n ); + Out[ io+strideOut ] = (double)n; return NULL; } @@ -71,11 +66,9 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Out, 2, strideOut, argv, 4 ); - int io = offsetOut; - double *out = Out; CBLAS_INT n; - out[ io ] = API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( N, X, strideX, offsetX, &n ); - out[ io+strideOut ] = (double)n; + Out[ offsetOut ] = API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( N, X, strideX, offsetX, &n ); + Out[ offsetOut+strideOut ] = (double)n; return NULL; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c index b232759fc728..6ab9a1aebc6b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c @@ -36,7 +36,7 @@ * @param N number of indexed elements * @param X input array * @param strideX stride length -* @param n number of non-NaN elements +* @param n pointer for storing the number of non-NaN elements * @return output value */ double API_SUFFIX(stdlib_strided_dnannsumkbn)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n ) { @@ -59,13 +59,13 @@ double API_SUFFIX(stdlib_strided_dnannsumkbn)( const CBLAS_INT N, const double * * @param X input array * @param strideX stride length * @param offsetX starting index -* @param n number of non-NaN elements +* @param n pointer for storing the number of non-NaN elements * @return output value */ double API_SUFFIX(stdlib_strided_dnannsumkbn_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n ) { - double sum; CBLAS_INT ix; CBLAS_INT i; + double sum; double v; double t; double c; From e4f8a11bb5d54da41d15031d27629b1605e53e3a Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:05:52 +0000 Subject: [PATCH 13/15] docs: fix copyright lint error --- lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c index 6ab9a1aebc6b..7459f10e6071 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. From 862be75104c55a54eebe6c539225da6fc101f3df Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:30:31 +0500 Subject: [PATCH 14/15] docs: apply review suggestion Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt index 6e6664d2cf41..da252628e372 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/docs/repl.txt @@ -3,8 +3,8 @@ Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm. - The `N` and stride parameters determine which elements in the strided - array 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 a typed array view. From e7a0f7a908d25c130a9692be98f8af4cb6ebd8a7 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:05:00 +0000 Subject: [PATCH 15/15] docs: apply review suggestions --- lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md index b6c989737bae..c039427b8926 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnannsumkbn/README.md @@ -195,6 +195,8 @@ console.log( out ); Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm. ```c +#include "stdlib/blas/base/shared.h" + const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; CBLAS_INT n = 0; @@ -218,6 +220,8 @@ double stdlib_strided_dnannsumkbn( const CBLAS_INT N, const double *X, const CBL Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm and alternative indexing semantics. ```c +#include "stdlib/blas/base/shared.h" + const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; CBLAS_INT n = 0;