From ae9fb37702fd1e7d556bd02b6f325d57e0a1f447 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:44:16 +0000 Subject: [PATCH 1/3] feat: add C ndarray API and refactor --- .../@stdlib/blas/ext/base/dnansumpw/README.md | 136 ++++++++++++++++-- .../ext/base/dnansumpw/benchmark/benchmark.js | 22 +-- .../dnansumpw/benchmark/benchmark.native.js | 22 +-- .../dnansumpw/benchmark/benchmark.ndarray.js | 22 +-- .../benchmark/benchmark.ndarray.native.js | 22 +-- .../dnansumpw/benchmark/c/benchmark.length.c | 54 ++++++- .../blas/ext/base/dnansumpw/docs/repl.txt | 29 ++-- .../ext/base/dnansumpw/docs/types/index.d.ts | 12 +- .../ext/base/dnansumpw/examples/c/example.c | 7 +- .../blas/ext/base/dnansumpw/examples/index.js | 4 +- .../include/stdlib/blas/ext/base/dnansumpw.h | 9 +- .../blas/ext/base/dnansumpw/lib/dnansumpw.js | 42 +----- .../base/dnansumpw/lib/dnansumpw.native.js | 9 +- .../blas/ext/base/dnansumpw/lib/index.js | 3 +- .../blas/ext/base/dnansumpw/lib/ndarray.js | 54 +++---- .../ext/base/dnansumpw/lib/ndarray.native.js | 15 +- .../blas/ext/base/dnansumpw/manifest.json | 43 ++++-- .../blas/ext/base/dnansumpw/src/addon.c | 26 +++- .../dnansumpw/src/{dnansumpw.c => main.c} | 81 +++++------ .../ext/base/dnansumpw/test/test.dnansumpw.js | 4 +- .../dnansumpw/test/test.dnansumpw.native.js | 4 +- .../ext/base/dnansumpw/test/test.ndarray.js | 4 +- .../dnansumpw/test/test.ndarray.native.js | 4 +- 23 files changed, 405 insertions(+), 223 deletions(-) rename lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/{dnansumpw.c => main.c} (73%) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/README.md index e8c3943ccf1b..5da44e732b3f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/README.md @@ -36,7 +36,7 @@ limitations under the License. var dnansumpw = require( '@stdlib/blas/ext/base/dnansumpw' ); ``` -#### dnansumpw( N, x, stride ) +#### dnansumpw( N, x, strideX ) Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. @@ -44,9 +44,8 @@ Computes the sum of double-precision floating-point strided array elements, igno var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = dnansumpw( N, x, 1 ); +var v = dnansumpw( x.length, x, 1 ); // returns 1.0 ``` @@ -54,9 +53,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: stride length for `x`. -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element: ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -81,7 +80,7 @@ var v = dnansumpw( 4, x1, 2 ); // returns 5.0 ``` -#### dnansumpw.ndarray( N, x, stride, offset ) +#### dnansumpw.ndarray( N, x, strideX, offsetX ) Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation and alternative indexing semantics. @@ -90,15 +89,15 @@ var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var v = dnansumpw.ndarray( 4, x, 1, 0 ); +var v = dnansumpw.ndarray( x.length, x, 1, 0 ); // returns 1.0 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to 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`, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the sum of every other element starting from the second element: ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -136,14 +135,14 @@ var bernoulli = require( '@stdlib/random/base/bernoulli' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); var dnansumpw = require( '@stdlib/blas/ext/base/dnansumpw' ); -function clbk() { +function rand() { if ( bernoulli( 0.7 ) > 0 ) { return discreteUniform( 0, 100 ); } return NaN; } -var x = filledarrayBy( 10, 'float64', clbk ); +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = dnansumpw( x.length, x, 1 ); @@ -154,8 +153,123 @@ console.log( v ); + + * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dnansumpw.h" +``` + +#### stdlib_strided_dnansumpw( N, \*X, strideX ) + +Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; + +double v = stdlib_strided_dnansumpw( 4, x, 1 ); +// 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` stride length for `X`. + +```c +double stdlib_strided_dnansumpw( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnansumpw_ndarray( N, \*X, strideX, offsetX ) + +Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation and alternative indexing semantics. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; + +double v = stdlib_strided_dnansumpw_ndarray( 4, x, 1, 0 ); +// 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` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dnansumpw_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dnansumpw.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; + + // Compute the sum: + double v = stdlib_strided_dnansumpw( N, x, strideX ); + + // Print the result: + printf( "sum: %lf\n", v ); +} +``` + +
+ + + +
+ + +
## References diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.js index 5b7185350a29..33fa10a009f3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.js @@ -32,6 +32,19 @@ var dnansumpw = require( './../lib/dnansumpw.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -40,16 +53,9 @@ var dnansumpw = require( './../lib/dnansumpw.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', clbk ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; - function clbk() { - if ( bernoulli( 0.7 ) > 0 ) { - return uniform( -100.0, 100.0 ); - } - return NaN; - } - function benchmark( b ) { var v; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.native.js index 6f7b3bcb347d..0a3a80408a6b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.native.js @@ -41,6 +41,19 @@ var opts = { // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -49,16 +62,9 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', clbk ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; - function clbk() { - if ( bernoulli( 0.7 ) > 0 ) { - return uniform( -100.0, 100.0 ); - } - return NaN; - } - function benchmark( b ) { var v; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.ndarray.js index 304ce5655c40..9ba176c17dbe 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.ndarray.js @@ -32,6 +32,19 @@ var dnansumpw = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -40,16 +53,9 @@ var dnansumpw = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', clbk ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; - function clbk() { - if ( bernoulli( 0.7 ) > 0 ) { - return uniform( -100.0, 100.0 ); - } - return NaN; - } - function benchmark( b ) { var v; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.ndarray.native.js index b53d32e4f7de..48cd347faf15 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/benchmark.ndarray.native.js @@ -41,6 +41,19 @@ var opts = { // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -49,16 +62,9 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', clbk ); + var x = filledarrayBy( len, 'float64', rand ); return benchmark; - function clbk() { - if ( bernoulli( 0.7 ) > 0 ) { - return uniform( -100.0, 100.0 ); - } - return NaN; - } - function benchmark( b ) { var v; var i; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/c/benchmark.length.c index 47b7439b9989..acd164f61688 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ 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 ]; double v; @@ -111,6 +111,7 @@ static double benchmark( int iterations, int len ) { v = 0.0; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_dnansumpw( len, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -124,6 +125,44 @@ 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 ]; + 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; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_dnansumpw_ndarray( len, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -146,7 +185,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/dnansumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/repl.txt index ca8c49551592..685eccdf97df 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. - 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 a typed @@ -19,8 +19,8 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -34,28 +34,29 @@ > {{alias}}( x.length, x, 1 ) 1.0 - // 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 ] ); > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > var strideX = 2; + > {{alias}}( N, x, strideX ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > strideX = 2; + > {{alias}}( N, x1, strideX ) -1.0 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation 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 offset parameter supports indexing semantics based on a starting index. Parameters @@ -66,10 +67,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/types/index.d.ts index b106721e0d98..5a98ea210a94 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/types/index.d.ts @@ -27,7 +27,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -38,15 +38,15 @@ interface Routine { * var v = dnansumpw( x.length, x, 1 ); * // returns 1.0 */ - ( N: number, x: Float64Array, stride: number ): number; + ( N: number, x: Float64Array, strideX: number ): number; /** * Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation and alternative indexing semantics. * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns sum * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = dnansumpw.ndarray( x.length, x, 1, 0 ); * // returns 1.0 */ - ndarray( N: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** @@ -65,7 +65,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns sum * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/examples/c/example.c index d85c4d3fe975..68ae6c07eede 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/examples/c/example.c @@ -17,7 +17,6 @@ */ #include "stdlib/blas/ext/base/dnansumpw.h" -#include #include int main( void ) { @@ -25,13 +24,13 @@ int main( void ) { 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; // Compute the sum: - double v = stdlib_strided_dnansumpw( N, x, stride ); + double v = stdlib_strided_dnansumpw( N, x, strideX ); // Print the result: printf( "sum: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/examples/index.js index 36e1fc90bf17..0b7e2965268f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/examples/index.js @@ -23,14 +23,14 @@ var bernoulli = require( '@stdlib/random/base/bernoulli' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); var dnansumpw = require( './../lib' ); -function clbk() { +function rand() { if ( bernoulli( 0.7 ) > 0 ) { return discreteUniform( -100, 100 ); } return NaN; } -var x = filledarrayBy( 10, 'float64', clbk ); +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = dnansumpw( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/include/stdlib/blas/ext/base/dnansumpw.h b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/include/stdlib/blas/ext/base/dnansumpw.h index f921e9ff50d0..a8b93f7167b7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/include/stdlib/blas/ext/base/dnansumpw.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/include/stdlib/blas/ext/base/dnansumpw.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DNANSUMPW_H #define STDLIB_BLAS_EXT_BASE_DNANSUMPW_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 pairwise summation. */ -double stdlib_strided_dnansumpw( const int64_t N, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnansumpw)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); + +/** +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation and alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dnansumpw_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/dnansumpw.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/dnansumpw.js index 9c456dbf730a..9f3a2ea5e9ad 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/dnansumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/dnansumpw.js @@ -20,8 +20,8 @@ // MODULES // -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var sum = require( './ndarray.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -39,49 +39,19 @@ var sum = require( './ndarray.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnansumpw( N, x, 1 ); +* var v = dnansumpw( x.length, x, 1 ); * // returns 1.0 */ -function dnansumpw( N, x, stride ) { - var ix; - var s; - var i; - - if ( N <= 0 ) { - return 0.0; - } - if ( N === 1 || stride === 0 ) { - if ( isnan( x[ 0 ] ) ) { - return 0.0; - } - return x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - if ( N < 8 ) { - // Use simple summation... - s = 0.0; - for ( i = 0; i < N; i++ ) { - if ( isnan( x[ ix ] ) === false ) { - s += x[ ix ]; - } - ix += stride; - } - return s; - } - return sum( N, x, stride, ix ); +function dnansumpw( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/dnansumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/dnansumpw.native.js index 8af375770899..237e3f8bed17 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/dnansumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/dnansumpw.native.js @@ -30,20 +30,19 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnansumpw( N, x, 1 ); +* var v = dnansumpw( x.length, x, 1 ); * // returns 1.0 */ -function dnansumpw( N, x, stride ) { - return addon( N, x, stride ); +function dnansumpw( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/index.js index 908d07c4a6ae..d80715047c0b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/index.js @@ -28,9 +28,8 @@ * var dnansumpw = require( '@stdlib/blas/ext/base/dnansumpw' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnansumpw( N, x, 1 ); +* var v = dnansumpw( x.length, x, 1 ); * // returns 1.0 * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/ndarray.js index 8887b15d7f6b..a00d5e940cf9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/ndarray.js @@ -45,8 +45,8 @@ var BLOCKSIZE = 128; * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -57,7 +57,7 @@ var BLOCKSIZE = 128; * var v = dnansumpw( 5, x, 2, 1 ); * // returns 5.0 */ -function dnansumpw( N, x, stride, offset ) { +function dnansumpw( N, x, strideX, offsetX ) { var ix; var s0; var s1; @@ -75,13 +75,13 @@ function dnansumpw( N, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { - if ( isnan( x[ offset ] ) ) { + if ( strideX === 0 ) { + if ( isnan( x[ offsetX ] ) ) { return 0.0; } - return x[ offset ]; + return x[ offsetX ] * N; } - ix = offset; + ix = offsetX; if ( N < 8 ) { // Use simple summation... s = 0.0; @@ -89,64 +89,64 @@ function dnansumpw( N, x, stride, offset ) { if ( isnan( x[ ix ] ) === false ) { s += x[ ix ]; } - ix += stride; + ix += strideX; } return s; } if ( N <= BLOCKSIZE ) { // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... s0 = ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s1 = ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s2 = ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s3 = ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s4 = ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s5 = ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s6 = ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s7 = ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; M = N % 8; for ( i = 8; i < N-M; i += 8 ) { s0 += ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s1 += ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s2 += ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s3 += ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s4 += ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s5 += ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s6 += ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; s7 += ( isnan( x[ ix ] ) ) ? 0.0 : x[ ix ]; - ix += stride; + ix += strideX; } // Pairwise sum the accumulators: - s = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); + s = ( (s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7) ); // Clean-up loop... for ( i; i < N; i++ ) { if ( isnan( x[ ix ] ) === false ) { s += x[ ix ]; } - ix += stride; + ix += strideX; } return s; } // Recurse by dividing by two, but avoiding non-multiples of unroll factor... n = floor( N/2 ); n -= n % 8; - return dnansumpw( n, x, stride, ix ) + dnansumpw( N-n, x, stride, ix+(n*stride) ); // eslint-disable-line max-len + return dnansumpw( n, x, strideX, ix ) + dnansumpw( N-n, x, strideX, ix+(n*strideX) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/ndarray.native.js index 27d6152a7c69..968d186c5c12 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/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( './dnansumpw.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,8 +30,8 @@ var addon = require( './dnansumpw.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -44,11 +42,8 @@ var addon = require( './dnansumpw.native.js' ); * var v = dnansumpw( 5, x, 2, 1 ); * // returns 5.0 */ -function dnansumpw( N, x, stride, offset ) { - var view; - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - return addon( N, view, stride ); +function dnansumpw( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/manifest.json index 70ae9b685b11..46468a5a5332 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/manifest.json @@ -27,36 +27,55 @@ "confs": [ { "task": "build", - "src": ["./src/dnansumpw.c"], - "include": ["./include"], - "libraries": ["-lm"], + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-strided-float64array" + "@stdlib/napi/argv-strided-float64array", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/napi/create-double" ] }, { "task": "benchmark", - "src": ["./src/dnansumpw.c"], - "include": ["./include"], - "libraries": ["-lm"], + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nan" + "@stdlib/math/base/assert/is-nan", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { "task": "examples", - "src": ["./src/dnansumpw.c"], - "include": ["./include"], - "libraries": ["-lm"], + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nan" + "@stdlib/math/base/assert/is-nan", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/addon.c index 10126a65865c..763abb610c62 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/addon.c @@ -17,12 +17,13 @@ */ #include "stdlib/blas/ext/base/dnansumpw.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 "stdlib/napi/create_double.h" #include -#include /** * Receives JavaScript callback invocation data. @@ -36,12 +37,25 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnansumpw)( N, X, strideX ), v ); + return v; +} - napi_value v; - napi_status status = napi_create_double( env, stdlib_strided_dnansumpw( N, X, strideX ), &v ); - assert( status == napi_ok ); - +/** +* 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, 4 ); + 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_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnansumpw_ndarray)( N, X, strideX, offsetX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/dnansumpw.c b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/main.c similarity index 73% rename from lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/dnansumpw.c rename to lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/main.c index 95a9f6c49b20..8c152f4ccbee 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/src/dnansumpw.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/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. @@ -18,7 +18,8 @@ #include "stdlib/blas/ext/base/dnansumpw.h" #include "stdlib/math/base/assert/is_nan.h" -#include +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/shared.h" /** * Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. @@ -33,17 +34,20 @@ * * @param N number of indexed elements * @param X input array -* @param stride stride length +* @param strideX stride length * @return output value */ -double stdlib_strided_dnansumpw( const int64_t N, const double *X, const int64_t stride ) { - double *xp1; - double *xp2; +double API_SUFFIX(stdlib_strided_dnansumpw)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dnansumpw_ndarray)( N, X, strideX, ox ); +} + +double API_SUFFIX(stdlib_strided_dnansumpw_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT M; + CBLAS_INT n; + CBLAS_INT i; double sum; - int64_t ix; - int64_t M; - int64_t n; - int64_t i; double s0; double s1; double s2; @@ -56,17 +60,13 @@ double stdlib_strided_dnansumpw( const int64_t N, const double *X, const int64_t if ( N <= 0 ) { return 0.0; } - if ( N == 1 || stride == 0 ) { + if ( strideX == 0 ) { if ( stdlib_base_is_nan( X[ 0 ] ) ) { return 0.0; } - return X[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; + return X[ 0 ] * N; } + ix = offsetX; if ( N < 8 ) { // Use simple summation... sum = 0.0; @@ -74,7 +74,7 @@ double stdlib_strided_dnansumpw( const int64_t N, const double *X, const int64_t if ( !stdlib_base_is_nan( X[ ix ] ) ) { sum += X[ ix ]; } - ix += stride; + ix += strideX; } return sum; } @@ -82,62 +82,55 @@ double stdlib_strided_dnansumpw( const int64_t N, const double *X, const int64_t if ( N <= 128 ) { // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... s0 = ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s1 = ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s2 = ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s3 = ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s4 = ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s5 = ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s6 = ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s7 = ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; M = N % 8; for ( i = 8; i < N-M; i += 8 ) { s0 += ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s1 += ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s2 += ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s3 += ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s4 += ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s5 += ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s6 += ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; s7 += ( stdlib_base_is_nan( X[ ix ] ) ) ? 0.0 : X[ ix ]; - ix += stride; + ix += strideX; } // Pairwise sum the accumulators: - sum = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); + sum = ( (s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7) ); // Clean-up loop... for (; i < N; i++ ) { if ( !stdlib_base_is_nan( X[ ix ] ) ) { sum += X[ ix ]; } - ix += stride; + ix += strideX; } return sum; } // Recurse by dividing by two, but avoiding non-multiples of unroll factor... n = N / 2; n -= n % 8; - if ( stride < 0 ) { - xp1 = (double *)X + ( (n-N)*stride ); - xp2 = (double *)X; - } else { - xp1 = (double *)X; - xp2 = (double *)X + ( n*stride ); - } - return stdlib_strided_dnansumpw( n, xp1, stride ) + stdlib_strided_dnansumpw( N-n, xp2, stride ); + return API_SUFFIX(stdlib_strided_dnansumpw_ndarray)( n, X, strideX, ix ) + API_SUFFIX(stdlib_strided_dnansumpw_ndarray)( N-n, X, strideX, ix+(n*strideX) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.js index 4537d39f75ed..d1892db54df2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.js @@ -182,14 +182,14 @@ 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 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 x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnansumpw( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.native.js index 9e718b7ddc5c..b262d087a231 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.native.js @@ -273,14 +273,14 @@ 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 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 x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnansumpw( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.js index 136f51561205..67d40d689cff 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.js @@ -182,14 +182,14 @@ 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 x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnansumpw( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.native.js index 6609c34dcb42..2a611a44a9fe 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.native.js @@ -191,14 +191,14 @@ 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 x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnansumpw( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); From ea5a2b7ff573da8ba4d828d25283f1fb0aca13f6 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:06:02 +0000 Subject: [PATCH 2/3] test: add missing test cases --- .../blas/ext/base/dnansumpw/test/test.dnansumpw.js | 12 ++++++++++++ .../ext/base/dnansumpw/test/test.dnansumpw.native.js | 12 ++++++++++++ .../blas/ext/base/dnansumpw/test/test.ndarray.js | 12 ++++++++++++ .../ext/base/dnansumpw/test/test.ndarray.native.js | 12 ++++++++++++ 4 files changed, 48 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.js index d1892db54df2..ae567a059d23 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.js @@ -194,6 +194,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the s t.end(); }); +tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0', function test( t ) { + var x; + var v; + + x = new Float64Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnansumpw( x.length, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports view offsets', function test( t ) { var x0; var x1; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.native.js index b262d087a231..f7169c7066c0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.dnansumpw.native.js @@ -285,6 +285,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the s t.end(); }); +tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0', opts, function test( t ) { + var x; + var v; + + x = new Float64Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnansumpw( x.length, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.js index 67d40d689cff..f793af10aba3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.js @@ -194,6 +194,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the s t.end(); }); +tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0', function test( t ) { + var x; + var v; + + x = new Float64Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnansumpw( x.length, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports an `offset` parameter', function test( t ) { var N; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.native.js index 2a611a44a9fe..69161e7b1743 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/test/test.ndarray.native.js @@ -203,6 +203,18 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the s t.end(); }); +tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0', opts, function test( t ) { + var x; + var v; + + x = new Float64Array( [ NaN, -2.0, -4.0, 5.0, 3.0 ] ); + + v = dnansumpw( x.length, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function supports an `offset` parameter', opts, function test( t ) { var N; var x; From 44c890af74ccd3b6bfc9ed1bda9f2f27c9b97d49 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Thu, 21 Nov 2024 06:46:26 +0000 Subject: [PATCH 3/3] docs: apply review suggestions --- .../@stdlib/blas/ext/base/dnansumpw/docs/repl.txt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/repl.txt index 685eccdf97df..c2018b1ce94c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnansumpw/docs/repl.txt @@ -36,17 +36,13 @@ // 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 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var strideX = 2; - > {{alias}}( N, x, strideX ) + > {{alias}}( 4, x, 2 ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > strideX = 2; - > {{alias}}( N, x1, strideX ) + > {{alias}}( 4, x1, 2 ) -1.0 @@ -87,8 +83,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 4, x, 2, 1 ) -1.0 See Also