From bf6ac725bce750edddd86d53103a60430e912c31 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sun, 29 Dec 2024 13:21:51 +0530 Subject: [PATCH 1/9] feat: ndarray-dsmeanwd --- .../@stdlib/stats/base/dsmeanwd/README.md | 130 +++++++++++++++--- .../base/dsmeanwd/benchmark/benchmark.js | 18 +-- .../dsmeanwd/benchmark/benchmark.native.js | 14 +- .../dsmeanwd/benchmark/benchmark.ndarray.js | 18 +-- .../benchmark/benchmark.ndarray.native.js | 14 +- .../dsmeanwd/benchmark/c/benchmark.length.c | 51 ++++++- .../@stdlib/stats/base/dsmeanwd/docs/repl.txt | 36 +++-- .../stats/base/dsmeanwd/docs/types/index.d.ts | 12 +- .../stats/base/dsmeanwd/examples/c/example.c | 9 +- .../stats/base/dsmeanwd/examples/index.js | 14 +- .../@stdlib/stats/base/dsmeanwd/include.gypi | 2 +- .../include/stdlib/stats/base/dsmeanwd.h | 10 +- .../stats/base/dsmeanwd/lib/dsmeanwd.js | 38 ++--- .../base/dsmeanwd/lib/dsmeanwd.native.js | 9 +- .../@stdlib/stats/base/dsmeanwd/lib/index.js | 7 +- .../stats/base/dsmeanwd/lib/ndarray.js | 18 ++- .../stats/base/dsmeanwd/lib/ndarray.native.js | 20 +-- .../@stdlib/stats/base/dsmeanwd/manifest.json | 77 ++++++++++- .../@stdlib/stats/base/dsmeanwd/src/addon.c | 60 ++++++++ .../@stdlib/stats/base/dsmeanwd/src/addon.cpp | 117 ---------------- .../base/dsmeanwd/src/{dsmeanwd.c => main.c} | 34 +++-- .../stats/base/dsmeanwd/test/test.dsmeanwd.js | 12 +- .../dsmeanwd/test/test.dsmeanwd.native.js | 13 +- .../stats/base/dsmeanwd/test/test.ndarray.js | 13 +- .../base/dsmeanwd/test/test.ndarray.native.js | 13 +- 25 files changed, 424 insertions(+), 335 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.cpp rename lib/node_modules/@stdlib/stats/base/dsmeanwd/src/{dsmeanwd.c => main.c} (67%) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md index 977729836d8f..d47ce5038169 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md @@ -51,7 +51,7 @@ The [arithmetic mean][arithmetic-mean] is defined as var dsmeanwd = require( '@stdlib/stats/base/dsmeanwd' ); ``` -#### dsmeanwd( N, x, stride ) +#### dsmeanwd( N, x, strideX ) Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array `x` using Welford's algorithm with extended accumulation and returning an extended precision result. @@ -59,9 +59,8 @@ Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-p var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dsmeanwd( N, x, 1 ); +var v = dsmeanwd( x.length, x, 1 ); // returns ~0.3333 ``` @@ -69,18 +68,16 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float32Array`][@stdlib/array/float32]. -- **stride**: index increment for `x`. +- **strideX**: Stride Length for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`, +The `N` and stride parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = dsmeanwd( N, x, 2 ); +var v = dsmeanwd( 4, x, 2 ); // returns 1.25 ``` @@ -90,18 +87,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dsmeanwd( N, x1, 2 ); +var v = dsmeanwd( 4, x1, 2 ); // returns 1.25 ``` -#### dsmeanwd.ndarray( N, x, stride, offset ) +#### dsmeanwd.ndarray( N, x, strideX, offsetX ) Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result. @@ -109,9 +103,8 @@ Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-p var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dsmeanwd.ndarray( N, x, 1, 0 ); +var v = dsmeanwd.ndarray( x.length, x, 1, 0 ); // returns ~0.33333 ``` @@ -123,12 +116,10 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = dsmeanwd.ndarray( N, x, 2, 1 ); +var v = dsmeanwd.ndarray( 4, x, 2, 1 ); // returns 1.25 ``` @@ -141,7 +132,7 @@ var v = dsmeanwd.ndarray( N, x, 2, 1 ); ## Notes - If `N <= 0`, both functions return `NaN`. -- Accumulated intermediate values are stored as double-precision floating-point numbers. +- Accumulated intermediate values are stored as double-precision floating-point numbers. @@ -176,6 +167,107 @@ console.log( v ); + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dsmeanwd.h" +``` + +#### stdlib_strided_dsmeanwd( N, \*X, strideX ) + +Calculate the mean value of a single-precision floating-point strided array, ignoring `NaN` values. + +```c +const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + +float v = stdlib_strided_dsmeanwd( 4, x, 2 ); +// returns 1.25 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +double stdlib_strided_dsmeanwd( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dsmeanwd_ndarray( N, \*X, strideX, offsetX ) + +Computes the mean value of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. + +```c +const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + +float v = stdlib_strided_dsmeanwd_ndarray( 4, x, 2, 0 ); +// returns 1.25 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dsmeanwd_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dsmeanwd.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the arithmetic mean: + float v = stdlib_strided_dsmeanwd( N, x, strideX ); + + // Print the result: + printf( "mean: %lf\n", v ); +} +``` + +
+ + + + + + + * * *
diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.js index d5e6790bd110..3fcdbf882bc4 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var dsmeanwd = require( './../lib/dsmeanwd.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dsmeanwd = require( './../lib/dsmeanwd.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.native.js index 479f0260c0f1..440108e0f4f7 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.native.js @@ -22,10 +22,9 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +35,9 @@ var dsmeanwd = tryRequire( resolve( __dirname, './../lib/dsmeanwd.native.js' ) ) var opts = { 'skip': ( dsmeanwd instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -48,13 +50,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.ndarray.js index b36bab63602a..86ef4e86f35a 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.ndarray.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var dsmeanwd = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dsmeanwd = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.ndarray.native.js index aad2a69676e3..cf0105580099 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,9 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +35,9 @@ var dsmeanwd = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dsmeanwd instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -48,13 +50,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c index 93ac2df49c90..d46a830b1dde 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c @@ -94,10 +94,10 @@ static float rand_float( 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; float x[ len ]; - double v; + float v; double t; int i; @@ -120,6 +120,40 @@ 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; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_dsmeanwd_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. */ @@ -142,7 +176,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/stats/base/dsmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/repl.txt index c849cc2c9c1f..7a1afd4a17cc 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and returning an extended precision result. - 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 @@ -20,8 +20,8 @@ x: Float32Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. Returns ------- @@ -35,28 +35,25 @@ > {{alias}}( x.length, x, 1 ) ~0.3333 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) - ~0.3333 + > {{alias}}( 4, x, 2 ) + NaN // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) - ~-0.3333 + > {{alias}}( 4, x1, 2 ) + NaN + -{{alias}}.ndarray( N, x, stride, offset ) +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result. 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 @@ -67,10 +64,10 @@ x: Float32Array Input array. - stride: integer + strideX: integer Index increment. - offset: integer + offsetX: integer Starting index. Returns @@ -87,9 +84,8 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) - ~-0.3333 + > {{alias}}.ndarray( 4, x, 2, 1 ) + NaN See Also -------- diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/types/index.d.ts index 0f5d86942a1f..df5079cad82c 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/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 arithmetic mean * * @example @@ -38,15 +38,15 @@ interface Routine { * var v = dsmeanwd( x.length, x, 1 ); * // returns ~0.3333 */ - ( N: number, x: Float32Array, stride: number ): number; + ( N: number, x: Float32Array, strideX: number ): number; /** * Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result. * * @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 arithmetic mean * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = dsmeanwd.ndarray( x.length, x, 1, 0 ); * // returns ~0.3333 */ - ndarray( N: number, x: Float32Array, stride: number, offset: number ): number; + ndarray( N: number, x: Float32Array, 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 arithmetic mean * * @example diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/c/example.c index c090beb38721..8d18f17c5f85 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dsmeanwd.h" -#include #include int main( void ) { // Create a strided array: - float x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; // Specify the number of elements: - int64_t N = 4; + const int N = 4; // Specify the stride length: - int64_t stride = 2; + const int strideX = 2; // Compute the arithmetic mean: - double v = stdlib_strided_dsmeanwd( N, x, stride ); + float v = stdlib_strided_dsmeanwd( N, x, strideX ); // Print the result: printf( "mean: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/index.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/index.js index 0f66c7a3c6bb..3ea2c89b12e7 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/index.js @@ -18,18 +18,12 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dsmeanwd = require( './../lib' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); console.log( x ); var v = dsmeanwd( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/include.gypi b/lib/node_modules/@stdlib/stats/base/dsmeanwd/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' - +#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 +30,12 @@ extern "C" { /** * Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and returning an extended precision result. */ -double stdlib_strided_dsmeanwd( const int64_t N, const float *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dsmeanwd)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); + +/** +* Computes the mean absolute value of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics . +*/ +double API_SUFFIX(stdlib_strided_dsmeanwd_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/dsmeanwd.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/dsmeanwd.js index 145f4703d966..371fa09b9999 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/dsmeanwd.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/dsmeanwd.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + // MAIN // /** @@ -43,43 +49,19 @@ * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} arithmetic mean * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dsmeanwd( N, x, 1 ); +* var v = dsmeanwd( x.length, x, 1 ); * // returns ~0.3333 */ -function dsmeanwd( N, x, stride ) { - var mu; - var ix; - var n; - var i; - - if ( N <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - return x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - mu = 0.0; - n = 0; - for ( i = 0; i < N; i++ ) { - n += 1; - mu += ( x[ix]-mu ) / n; - ix += stride; - } - return mu; +function dsmeanwd( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/dsmeanwd.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/dsmeanwd.native.js index 3098c6c9398d..a5021176773e 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/dsmeanwd.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/dsmeanwd.native.js @@ -30,20 +30,19 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} arithmetic mean * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dsmeanwd( N, x, 1 ); +* var v = dsmeanwd( x.length, x, 1 ); * // returns ~0.3333 */ -function dsmeanwd( N, x, stride ) { - return addon( N, x, stride ); +function dsmeanwd( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/index.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/index.js index 296a10b9071c..11cc615aad26 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/index.js @@ -28,20 +28,17 @@ * var dsmeanwd = require( '@stdlib/stats/base/dsmeanwd' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dsmeanwd( N, x, 1 ); +* var v = dsmeanwd( x.length, x, 1 ); * // returns ~0.3333 * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var dsmeanwd = require( '@stdlib/stats/base/dsmeanwd' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = dsmeanwd.ndarray( N, x, 2, 1 ); +* var v = dsmeanwd.ndarray( 4, x, 2, 1 ); * // returns 1.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/ndarray.js index 703769242ff2..d7451da49fb2 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/ndarray.js @@ -43,21 +43,19 @@ * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} 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} arithmetic mean * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = dsmeanwd( N, x, 2, 1 ); +* var v = dsmeanwd( 4, x, 2, 1 ); * // returns 1.25 */ -function dsmeanwd( N, x, stride, offset ) { +function dsmeanwd( N, x, strideX, offsetX ) { var mu; var ix; var n; @@ -66,16 +64,16 @@ function dsmeanwd( N, x, stride, offset ) { if ( N <= 0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { - return x[ offset ]; + if ( N === 1 || strideX === 0 ) { + return x[ offsetX ]; } - ix = offset; + ix = offsetX; mu = 0.0; n = 0; for ( i = 0; i < N; i++ ) { n += 1; mu += ( x[ix]-mu ) / n; - ix += stride; + ix += strideX; } return mu; } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/ndarray.native.js index 17fe07bab008..b20e79af3b75 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float32Array = require( '@stdlib/array/float32' ); -var addon = require( './dsmeanwd.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -31,27 +30,20 @@ var addon = require( './dsmeanwd.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float32Array} 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} arithmetic mean * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = dsmeanwd( N, x, 2, 1 ); +* var v = dsmeanwd( 4, x, 2, 1 ); * // returns 1.25 */ -function dsmeanwd( N, x, stride, offset ) { - var view; - if ( stride < 0 ) { - offset += (N-1) * stride; - } - view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len - return addon( N, view, stride ); +function dsmeanwd( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json b/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json index 6752f317467e..f3b060782431 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json @@ -1,5 +1,8 @@ { - "options": {}, + "options": { + "task": "build", + "wasm": false + }, "fields": [ { "field": "src", @@ -24,17 +27,81 @@ ], "confs": [ { + "task": "build", + "wasm": false, "src": [ - "./src/dsmeanwd.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-positive-zero", + "@stdlib/math/base/assert/is-nan", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/create-double" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-positive-zero" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-positive-zero" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-positive-zero" + ] } ] } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c new file mode 100644 index 000000000000..4eeaf1310951 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c @@ -0,0 +1,60 @@ +/** +* @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/stats/base/dsmeanwd.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float32array.h" +#include "stdlib/napi/create_double.h" +#include + +/** +* 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( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dsmeanwd( N, X, strideX ), v ); + return v; +} + +/** +* 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_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dsmeanwd_ndarray( N, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.cpp b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.cpp deleted file mode 100644 index 964fe15d4b98..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.cpp +++ /dev/null @@ -1,117 +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/stats/base/dsmeanwd.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_stats_base_dsmeanwd { - - /** - * Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and returning an extended precision result. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_dsmeanwd( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, stdlib_strided_dsmeanwd( N, (float *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dsmeanwd, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_stats_base_dsmeanwd diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/dsmeanwd.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c similarity index 67% rename from lib/node_modules/@stdlib/stats/base/dsmeanwd/src/dsmeanwd.c rename to lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c index 128c683c69b9..15544f1a9e59 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/dsmeanwd.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/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. @@ -17,6 +17,8 @@ */ #include "stdlib/stats/base/dsmeanwd.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" #include /** @@ -42,23 +44,37 @@ * * @param N number of indexed elements * @param X input array -* @param stride stride length +* @param strideX stride length * @return output value */ -double stdlib_strided_dsmeanwd( const int64_t N, const float *X, const int64_t stride ) { - int64_t ix; - int64_t i; - int64_t n; +double API_SUFFIX(stdlib_strided_dsmeanwd)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dsmeanwd_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the arithmetic mean of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @param offsetX starting index for X +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dsmeanwd_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT i; + CBLAS_INT n; double mu; if ( N <= 0 ) { return 0.0 / 0.0; // NaN } - if ( N == 1 || stride == 0 ) { + if ( N == 1 || strideX == 0 ) { return X[ 0 ]; } if ( stride < 0 ) { - ix = (1-N) * stride; + ix = (1-N) * strideX; } else { ix = 0; } @@ -67,7 +83,7 @@ double stdlib_strided_dsmeanwd( const int64_t N, const float *X, const int64_t s for ( i = 0; i < N; i++ ) { n += 1; mu += ( (double)X[ix]-mu ) / (double)n; - ix += stride; + ix += strideX; } return mu; } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.js index de59955668d4..557e63761f38 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var dsmeanwd = require( './../lib/dsmeanwd.js' ); @@ -87,7 +86,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -102,8 +100,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, 2 ); + v = dsmeanwd( 4, x, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -125,8 +122,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, -2 ); + v = dsmeanwd( 4, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -147,7 +143,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -163,9 +158,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dsmeanwd( N, x1, 2 ); + v = dsmeanwd( 4, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.native.js index 7794cc741c0a..db93db657a16 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -178,7 +177,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -193,15 +191,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, 2 ); + v = dsmeanwd( 4, x, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -216,8 +212,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, -2 ); + v = dsmeanwd( 4, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -238,7 +233,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -254,9 +248,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dsmeanwd( N, x1, 2 ); + v = dsmeanwd( 4, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.ndarray.js index fe5c62427148..dd9acd1c58b3 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var dsmeanwd = require( './../lib/ndarray.js' ); @@ -87,7 +86,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -102,15 +100,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, 2, 0 ); + v = dsmeanwd( 4, x, 2, 0 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -125,8 +121,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, -2, 6 ); + v = dsmeanwd( 4, x, -2, 6 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -145,7 +140,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -159,9 +153,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, 2, 1 ); + v = dsmeanwd( 4, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.ndarray.native.js index 35f0294e3f4a..41faa64f5f08 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.ndarray.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -96,7 +95,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -111,15 +109,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, 2, 0 ); + v = dsmeanwd( 4, x, 2, 0 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -134,8 +130,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, -2, 6 ); + v = dsmeanwd( 4, x, -2, 6 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -154,7 +149,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -168,9 +162,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dsmeanwd( N, x, 2, 1 ); + v = dsmeanwd( 4, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); From 0afa42280abc7b189b874d03f13271b54a6a6602 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sun, 29 Dec 2024 13:49:47 +0530 Subject: [PATCH 2/9] fix: CI errors --- .../@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c | 2 +- lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c | 2 +- lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c index d46a830b1dde..0e595e84dc8b 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c @@ -104,7 +104,7 @@ static double benchmark1( int iterations, int len ) { for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*20000.0f ) - 10000.0f; } - v = 0.0; + v = 0.0f; t = tic(); for ( i = 0; i < iterations; i++ ) { v = stdlib_strided_dsmeanwd( len, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c index 4eeaf1310951..b3f5b5b34130 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.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. diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c index 15544f1a9e59..58adf610bfa6 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c @@ -73,7 +73,7 @@ double API_SUFFIX(stdlib_strided_dsmeanwd_ndarray)( const CBLAS_INT N, const flo if ( N == 1 || strideX == 0 ) { return X[ 0 ]; } - if ( stride < 0 ) { + if ( strideX < 0 ) { ix = (1-N) * strideX; } else { ix = 0; From d3c674c35b8f1c8f98c6b6846cdf734038b87d32 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sun, 29 Dec 2024 14:29:08 +0530 Subject: [PATCH 3/9] fix: uninitvar --- .../@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c | 1 + .../@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.js | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c index 0e595e84dc8b..2adaacdf3878 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c @@ -107,6 +107,7 @@ static double benchmark1( int iterations, int len ) { v = 0.0f; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_dsmeanwd( len, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.js b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.js index 557e63761f38..fa8bc3d7051d 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/test/test.dsmeanwd.js @@ -107,7 +107,6 @@ tape( 'the function supports a `stride` parameter', function test( t ) { }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; From d27dd9a240c55da9a3cb811e739319874c709350 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Tue, 31 Dec 2024 21:19:40 +0530 Subject: [PATCH 4/9] fix: stuff from code review --- .../@stdlib/stats/base/dsmeanwd/README.md | 12 ++++++------ .../dsmeanwd/benchmark/c/benchmark.length.c | 8 ++++---- .../@stdlib/stats/base/dsmeanwd/docs/repl.txt | 17 +++++++++-------- .../stats/base/dsmeanwd/examples/c/example.c | 2 +- .../include/stdlib/stats/base/dsmeanwd.h | 4 ++-- .../@stdlib/stats/base/dsmeanwd/manifest.json | 14 +++----------- .../@stdlib/stats/base/dsmeanwd/src/main.c | 14 +++++--------- 7 files changed, 30 insertions(+), 41 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md index d47ce5038169..bc388a1e1597 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md @@ -68,7 +68,7 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float32Array`][@stdlib/array/float32]. -- **strideX**: Stride Length for `x`. +- **strideX**: stride Length for `x`. The `N` and stride parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`, @@ -179,12 +179,12 @@ console.log( v ); #### stdlib_strided_dsmeanwd( N, \*X, strideX ) -Calculate the mean value of a single-precision floating-point strided array, ignoring `NaN` values. +Computes the arithmetic mean of a single-precision floating-point strided array `x` using Welford's algorithm with extended accumulation and returning an extended precision result. ```c const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; -float v = stdlib_strided_dsmeanwd( 4, x, 2 ); +double v = stdlib_strided_dsmeanwd( 4, x, 2 ); // returns 1.25 ``` @@ -200,12 +200,12 @@ double stdlib_strided_dsmeanwd( const CBLAS_INT N, const float *X, const CBLAS_I #### stdlib_strided_dsmeanwd_ndarray( N, \*X, strideX, offsetX ) -Computes the mean value of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. +Computes the arithmetic mean of a single-precision floating-point strided array `x` using Welford's algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result. ```c const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; -float v = stdlib_strided_dsmeanwd_ndarray( 4, x, 2, 0 ); +double v = stdlib_strided_dsmeanwd_ndarray( 4, x, 2, 0 ); // returns 1.25 ``` @@ -253,7 +253,7 @@ int main( void ) { const int strideX = 2; // Compute the arithmetic mean: - float v = stdlib_strided_dsmeanwd( N, x, strideX ); + double v = stdlib_strided_dsmeanwd( N, x, strideX ); // Print the result: printf( "mean: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c index 2adaacdf3878..def4bfe5dc7c 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/benchmark/c/benchmark.length.c @@ -97,14 +97,14 @@ static float rand_float( void ) { static double benchmark1( int iterations, int len ) { double elapsed; float x[ len ]; - float v; + double v; double t; int i; for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float()*20000.0f ) - 10000.0f; } - v = 0.0f; + v = 0.0; t = tic(); for ( i = 0; i < iterations; i++ ) { // cppcheck-suppress uninitvar @@ -131,14 +131,14 @@ static double benchmark1( int iterations, int len ) { static double benchmark2( int iterations, int len ) { double elapsed; float x[ len ]; - float v; + double v; double t; int i; for ( i = 0; i < len; i++ ) { x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; } - v = 0.0f; + v = 0.0; t = tic(); for ( i = 0; i < iterations; i++ ) { // cppcheck-suppress uninitvar diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/repl.txt index 7a1afd4a17cc..97591d58be30 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/docs/repl.txt @@ -4,7 +4,8 @@ array using Welford's algorithm with extended accumulation and returning an extended precision result. - The `N` and stride parameters determine which elements in `x` are accessed + 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 @@ -21,7 +22,7 @@ Input array. strideX: integer - Stride Length. + Stride length. Returns ------- @@ -37,14 +38,14 @@ // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > {{alias}}( 4, x, 2 ) - NaN + > {{alias}}( 3, x, 2 ) + ~0.3333 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 4, x1, 2 ) - NaN + > {{alias}}( 3, x1, 2 ) + ~-0.3333 {{alias}}.ndarray( N, x, strideX, offsetX ) @@ -84,8 +85,8 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > {{alias}}.ndarray( 4, x, 2, 1 ) - NaN + > {{alias}}.ndarray( 3, x, 2, 1 ) + ~-0.3333 See Also -------- diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/c/example.c index 8d18f17c5f85..59dcd28b41cf 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/examples/c/example.c @@ -30,7 +30,7 @@ int main( void ) { const int strideX = 2; // Compute the arithmetic mean: - float v = stdlib_strided_dsmeanwd( N, x, strideX ); + double v = stdlib_strided_dsmeanwd( N, x, strideX ); // Print the result: printf( "mean: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/include/stdlib/stats/base/dsmeanwd.h b/lib/node_modules/@stdlib/stats/base/dsmeanwd/include/stdlib/stats/base/dsmeanwd.h index ad3e97575a57..e8e3fd7e4ec0 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/include/stdlib/stats/base/dsmeanwd.h +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/include/stdlib/stats/base/dsmeanwd.h @@ -28,12 +28,12 @@ extern "C" { #endif /** -* Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and returning an extended precision result. +* Computes the arithmetic mean of a single-precision floating-point strided array `x ` using Welford's algorithm with extended accumulation and returning an extended precision result. */ double API_SUFFIX(stdlib_strided_dsmeanwd)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); /** -* Computes the mean absolute value of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics . +* Computes the arithmetic mean of a single-precision floating-point strided array `x` using Welford's algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result. */ double API_SUFFIX(stdlib_strided_dsmeanwd_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json b/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json index f3b060782431..7a0fdb1d890b 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json @@ -40,8 +40,6 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/strided/base/stride2offset", - "@stdlib/math/base/assert/is-positive-zero", - "@stdlib/math/base/assert/is-nan", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -62,9 +60,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", - "@stdlib/strided/base/stride2offset", - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/assert/is-positive-zero" + "@stdlib/strided/base/stride2offset" ] }, { @@ -80,9 +76,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", - "@stdlib/strided/base/stride2offset", - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/assert/is-positive-zero" + "@stdlib/strided/base/stride2offset" ] }, { @@ -98,9 +92,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", - "@stdlib/strided/base/stride2offset", - "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/assert/is-positive-zero" + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c index 58adf610bfa6..b689bea75c99 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c @@ -42,10 +42,10 @@ * - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). * - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). * -* @param N number of indexed elements -* @param X input array +* @param N number of indexed elements +* @param X input array * @param strideX stride length -* @return output value +* @return output value */ double API_SUFFIX(stdlib_strided_dsmeanwd)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ) { const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); @@ -53,7 +53,7 @@ double API_SUFFIX(stdlib_strided_dsmeanwd)( const CBLAS_INT N, const float *X, c } /** -* Computes the arithmetic mean of a single-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. +* Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result. * * @param N number of indexed elements * @param X input array @@ -73,11 +73,7 @@ double API_SUFFIX(stdlib_strided_dsmeanwd_ndarray)( const CBLAS_INT N, const flo if ( N == 1 || strideX == 0 ) { return X[ 0 ]; } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } + ix = offsetX; mu = 0.0; n = 0; for ( i = 0; i < N; i++ ) { From d57726d0aa7502abdf737bf7b24b566cdfe88733 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Fri, 3 Jan 2025 14:21:51 +0530 Subject: [PATCH 5/9] chore: minor clean up --- .../@stdlib/stats/base/dsmeanwd/README.md | 14 ++++---------- .../@stdlib/stats/base/dsmeanwd/src/addon.c | 2 +- .../@stdlib/stats/base/dsmeanwd/src/main.c | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md index bc388a1e1597..bcc9ca788314 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md @@ -145,18 +145,12 @@ var v = dsmeanwd.ndarray( 4, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dsmeanwd = require( '@stdlib/stats/base/dsmeanwd' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); console.log( x ); var v = dsmeanwd( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c index b3f5b5b34130..36688371ce7b 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c index b689bea75c99..b594b282a2e8 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,7 +71,7 @@ double API_SUFFIX(stdlib_strided_dsmeanwd_ndarray)( const CBLAS_INT N, const flo return 0.0 / 0.0; // NaN } if ( N == 1 || strideX == 0 ) { - return X[ 0 ]; + return X[ offsetX ]; } ix = offsetX; mu = 0.0; From f8f7268373404714d8fa4225d9041b5d8d8f10e4 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 4 Jan 2025 23:14:29 +0530 Subject: [PATCH 6/9] chore: markdown clean up --- lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md index bcc9ca788314..94393808f547 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md @@ -179,7 +179,7 @@ Computes the arithmetic mean of a single-precision floating-point strided array const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; double v = stdlib_strided_dsmeanwd( 4, x, 2 ); -// returns 1.25 +// returns 4.0 ``` The function accepts the following arguments: @@ -200,7 +200,7 @@ Computes the arithmetic mean of a single-precision floating-point strided array const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; double v = stdlib_strided_dsmeanwd_ndarray( 4, x, 2, 0 ); -// returns 1.25 +// returns 4.0 ``` The function accepts the following arguments: diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c index b594b282a2e8..afb98a06b21f 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c @@ -19,7 +19,6 @@ #include "stdlib/stats/base/dsmeanwd.h" #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" -#include /** * Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and returning an extended precision result. From 4bf2298aa127806fd54d0ee2b9e10a342a0e5662 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 18 Jan 2025 18:16:11 +0530 Subject: [PATCH 7/9] chore: minor clean up --- lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md | 6 +++--- lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c | 4 ++-- lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md index 94393808f547..ae43d8291b6d 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/README.md @@ -68,7 +68,7 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float32Array`][@stdlib/array/float32]. -- **strideX**: stride Length for `x`. +- **strideX**: stride length for `x`. The `N` and stride parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`, @@ -173,7 +173,7 @@ console.log( v ); #### stdlib_strided_dsmeanwd( N, \*X, strideX ) -Computes the arithmetic mean of a single-precision floating-point strided array `x` using Welford's algorithm with extended accumulation and returning an extended precision result. +Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and returning an extended precision result. ```c const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; @@ -194,7 +194,7 @@ double stdlib_strided_dsmeanwd( const CBLAS_INT N, const float *X, const CBLAS_I #### stdlib_strided_dsmeanwd_ndarray( N, \*X, strideX, offsetX ) -Computes the arithmetic mean of a single-precision floating-point strided array `x` using Welford's algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result. +Computes the arithmetic mean of a single-precision floating-point strided array using Welford's algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result. ```c const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c index 36688371ce7b..52d5407df264 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c @@ -36,7 +36,7 @@ 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_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dsmeanwd( N, X, strideX ), v ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX( stdlib_strided_dsmeanwd)( N, X, strideX ), v ); return v; } @@ -53,7 +53,7 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dsmeanwd_ndarray( N, X, strideX, offsetX ), v ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX( stdlib_strided_dsmeanwd_ndarray )( N, X, strideX, offsetX ), v ); return v; } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c index afb98a06b21f..37aba94b00ef 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* 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. From 85db286fc159e0aae0e07700b11824bcd3290380 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 18 Jan 2025 22:14:48 +0530 Subject: [PATCH 8/9] chore: minor clean up --- lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json | 3 ++- lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json b/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json index 7a0fdb1d890b..8201d54893a3 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json @@ -44,7 +44,8 @@ "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/create-double" + "@stdlib/napi/create-double", + "@stdlib/blas/base/shared" ] }, { diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c index 52d5407df264..c36eb5b7ea34 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/src/addon.c @@ -22,7 +22,7 @@ #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float32array.h" #include "stdlib/napi/create_double.h" -#include +#include "stdlib/blas/base/shared.h" /** * Receives JavaScript callback invocation data. @@ -36,7 +36,7 @@ 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_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); - STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX( stdlib_strided_dsmeanwd)( N, X, strideX ), v ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsmeanwd)( N, X, strideX ), v ); return v; } @@ -53,7 +53,7 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); - STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX( stdlib_strided_dsmeanwd_ndarray )( N, X, strideX, offsetX ), v ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dsmeanwd_ndarray)( N, X, strideX, offsetX ), v ); return v; } From 2c4dbad953cb85476d510d868e64c372b5416fc3 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 18 Jan 2025 22:15:13 +0530 Subject: [PATCH 9/9] chore: update manifest --- lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json b/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json index 8201d54893a3..7a0fdb1d890b 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dsmeanwd/manifest.json @@ -44,8 +44,7 @@ "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/create-double", - "@stdlib/blas/base/shared" + "@stdlib/napi/create-double" ] }, {