From d44927cfc1d6228fe6db2f828a5a3264ee4c20ae Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 14 Jan 2025 23:28:41 +0530 Subject: [PATCH 1/8] feat: updated stats/base/smeanpw native addon from C++ to C --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/stats/base/smeanpw/README.md | 163 ++++++++++++++---- .../stats/base/smeanpw/benchmark/benchmark.js | 18 +- .../smeanpw/benchmark/benchmark.native.js | 14 +- .../smeanpw/benchmark/benchmark.ndarray.js | 18 +- .../benchmark/benchmark.ndarray.native.js | 14 +- .../smeanpw/benchmark/c/benchmark.length.c | 50 +++++- .../@stdlib/stats/base/smeanpw/docs/repl.txt | 33 ++-- .../stats/base/smeanpw/docs/types/index.d.ts | 12 +- .../stats/base/smeanpw/examples/c/example.c | 9 +- .../include/stdlib/stats/base/smeanpw.h | 9 +- .../@stdlib/stats/base/smeanpw/lib/index.js | 7 +- .../@stdlib/stats/base/smeanpw/lib/ndarray.js | 16 +- .../stats/base/smeanpw/lib/ndarray.native.js | 20 +-- .../@stdlib/stats/base/smeanpw/lib/smeanpw.js | 19 +- .../stats/base/smeanpw/lib/smeanpw.native.js | 9 +- .../@stdlib/stats/base/smeanpw/manifest.json | 49 ++++-- .../@stdlib/stats/base/smeanpw/src/addon.c | 26 ++- .../@stdlib/stats/base/smeanpw/src/main.c | 54 ++++++ .../@stdlib/stats/base/smeanpw/src/smeanpw.c | 39 ----- .../stats/base/smeanpw/test/test.ndarray.js | 13 +- .../base/smeanpw/test/test.ndarray.native.js | 13 +- .../stats/base/smeanpw/test/test.smeanpw.js | 13 +- .../base/smeanpw/test/test.smeanpw.native.js | 13 +- 23 files changed, 387 insertions(+), 244 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c delete mode 100644 lib/node_modules/@stdlib/stats/base/smeanpw/src/smeanpw.c diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/README.md b/lib/node_modules/@stdlib/stats/base/smeanpw/README.md index 299dbd72be49..844c74b7a821 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/README.md +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/README.md @@ -51,7 +51,7 @@ The [arithmetic mean][arithmetic-mean] is defined as var smeanpw = require( '@stdlib/stats/base/smeanpw' ); ``` -#### smeanpw( N, x, stride ) +#### smeanpw( N, x, strideX ) Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array `x` using pairwise summation. @@ -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 = smeanpw( N, x, 1 ); +var v = smeanpw( 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 the strided array 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 = smeanpw( N, x, 2 ); +var v = smeanpw( 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 = smeanpw( N, x1, 2 ); +var v = smeanpw( 4, x1, 2 ); // returns 1.25 ``` -#### smeanpw.ndarray( N, x, stride, offset ) +#### smeanpw.ndarray( N, x, strideX, offsetX ) Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using pairwise summation and alternative indexing semantics. @@ -109,26 +103,23 @@ 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 = smeanpw.ndarray( N, x, 1, 0 ); +var v = smeanpw.ndarray( x.length, x, 1, 0 ); // returns ~0.33333 ``` 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 [arithmetic mean][arithmetic-mean] for 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 [arithmetic mean][arithmetic-mean] for every other element in `x` starting from the second element ```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 = smeanpw.ndarray( N, x, 2, 1 ); +var v = smeanpw.ndarray( 4, x, 2, 1 ); // returns 1.25 ``` @@ -141,7 +132,6 @@ var v = smeanpw.ndarray( N, x, 2, 1 ); ## Notes - If `N <= 0`, both functions return `NaN`. -- In general, pairwise summation is more numerically stable than ordinary recursive summation (i.e., "simple" summation), with slightly worse performance. While not the most numerically stable summation technique (e.g., compensated summation techniques such as the Kahan–Babuška-Neumaier algorithm are generally more numerically stable), pairwise summation strikes a reasonable balance between numerical stability and performance. If either numerical stability or performance is more desirable for your use case, consider alternative summation techniques. @@ -154,18 +144,12 @@ var v = smeanpw.ndarray( N, 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 smeanpw = require( '@stdlib/stats/base/smeanpw' ); -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 = smeanpw( x.length, x, 1 ); @@ -176,6 +160,123 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/smeanpw.h" +``` + +#### stdlib_strided_smeanpw( N, \*X, strideX ) + +Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using pairwise summation. + +```c +const float x[] = { 1.0f, 2.0f, 3.0f }; + +float v = stdlib_strided_smeanpw( 3, x, 1 ); +// returns 2.0f +``` + +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 +float stdlib_strided_smeanpw( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_smeanpw_ndarray( N, \*X, strideX, offsetX ) + +Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using pairwise summation and 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_smeanpw_ndarray( 4, x, 2, 0 ); +// returns 4.0f +``` + +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 +float stdlib_strided_smeanpw_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/smeanpw.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_smeanpw( N, x, strideX ); + + // Print the result: + printf( "mean: %f\n", v ); +} +``` + +
+ + + +
+ + + * * *
diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/benchmark.js index 3c49647ac5a1..271f3ee630ef 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/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 smeanpw = require( './../lib/smeanpw.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var smeanpw = require( './../lib/smeanpw.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/smeanpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/benchmark.native.js index 0cbf8e512115..98f8ddd53373 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/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 smeanpw = tryRequire( resolve( __dirname, './../lib/smeanpw.native.js' ) ); var opts = { 'skip': ( smeanpw 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/smeanpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/benchmark.ndarray.js index b37453a4c021..535750176952 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/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 smeanpw = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var smeanpw = 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/smeanpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/benchmark.ndarray.native.js index 915b252b3a2b..211ea8e3206b 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/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 smeanpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( smeanpw 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/smeanpw/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/c/benchmark.length.c index 27d12356a966..3e1486ff4a6f 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ 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 ]; float v; @@ -107,6 +107,7 @@ static double benchmark( int iterations, int len ) { v = 0.0f; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_smeanpw( len, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -120,6 +121,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_smeanpw_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 +177,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/smeanpw/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt index 4fc52798b3cc..89002dd86173 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/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 pairwise summation. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -19,8 +19,8 @@ x: Float32Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. Returns ------- @@ -34,22 +34,19 @@ > {{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 ) + > {{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 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 3, x1, 2 ) ~-0.3333 -{{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 pairwise summation and alternative indexing semantics. @@ -65,10 +62,10 @@ x: Float32Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. - offset: integer + offsetX: integer Starting index. Returns @@ -85,10 +82,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 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) ~-0.3333 See Also -------- - diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/smeanpw/docs/types/index.d.ts index 5fe427e62183..c7e919a84da9 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/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 = smeanpw( 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 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 arithmetic mean * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = smeanpw.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/smeanpw/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/smeanpw/examples/c/example.c index 09667f9f3bb3..65a3c89263f5 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/smeanpw.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: - float v = stdlib_strided_smeanpw( N, x, stride ); + float v = stdlib_strided_smeanpw( N, x, strideX ); // Print the result: printf( "mean: %f\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/include/stdlib/stats/base/smeanpw.h b/lib/node_modules/@stdlib/stats/base/smeanpw/include/stdlib/stats/base/smeanpw.h index 757aeadceff3..ec6f9641f0e7 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/include/stdlib/stats/base/smeanpw.h +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/include/stdlib/stats/base/smeanpw.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_SMEANPW_H #define STDLIB_STATS_BASE_SMEANPW_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 arithmetic mean of a single-precision floating-point strided array using pairwise summation. */ -float stdlib_strided_smeanpw( const int64_t N, const float *X, const int64_t stride ); +float API_SUFFIX(stdlib_strided_smeanpw)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); + +/** +* Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation and alternative indexing semantics. +*/ +float API_SUFFIX(stdlib_strided_smeanpw_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/smeanpw/lib/index.js b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/index.js index 713801fbbe47..a016a61d403f 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/index.js @@ -28,20 +28,17 @@ * var smeanpw = require( '@stdlib/stats/base/smeanpw' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = smeanpw( N, x, 1 ); +* var v = smeanpw( x.length, x, 1 ); * // returns ~0.3333 * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var smeanpw = require( '@stdlib/stats/base/smeanpw' ); * * 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 = smeanpw.ndarray( N, x, 2, 1 ); +* var v = smeanpw.ndarray( 4, x, 2, 1 ); * // returns 1.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/ndarray.js index a1b80c13dddb..e9ef4e45f2b8 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/ndarray.js @@ -31,28 +31,26 @@ var ssumpw = require( '@stdlib/blas/ext/base/ssumpw' ).ndarray; * * @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 = smeanpw( N, x, 2, 1 ); +* var v = smeanpw( 4, x, 2, 1 ); * // returns 1.25 */ -function smeanpw( N, x, stride, offset ) { +function smeanpw( N, x, strideX, offsetX ) { if ( N <= 0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { - return x[ offset ]; + if ( N === 1 || strideX === 0 ) { + return x[ offsetX ]; } - return float64ToFloat32( ssumpw( N, x, stride, offset ) / N ); + return float64ToFloat32( ssumpw( N, x, strideX, offsetX ) / N ); } diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/ndarray.native.js index a3783c149cd4..0e0995cd4d2d 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float32Array = require( '@stdlib/array/float32' ); -var addon = require( './smeanpw.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -31,27 +30,20 @@ var addon = require( './smeanpw.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 = smeanpw( N, x, 2, 1 ); +* var v = smeanpw( 4, x, 2, 1 ); * // returns 1.25 */ -function smeanpw( 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 smeanpw( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/lib/smeanpw.js b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/smeanpw.js index 051b0138797c..fdb7afc59fcc 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/lib/smeanpw.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/smeanpw.js @@ -20,8 +20,8 @@ // MODULES // -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var ssumpw = require( '@stdlib/blas/ext/base/ssumpw' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -31,26 +31,19 @@ var ssumpw = require( '@stdlib/blas/ext/base/ssumpw' ); * * @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 = smeanpw( N, x, 1 ); +* var v = smeanpw( x.length, x, 1 ); * // returns ~0.3333 */ -function smeanpw( N, x, stride ) { - if ( N <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - return x[ 0 ]; - } - return float64ToFloat32( ssumpw( N, x, stride ) / N ); +function smeanpw( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/lib/smeanpw.native.js b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/smeanpw.native.js index c450f022a637..9a32b737b57f 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/lib/smeanpw.native.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/lib/smeanpw.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 = smeanpw( N, x, 1 ); +* var v = smeanpw( x.length, x, 1 ); * // returns ~0.3333 */ -function smeanpw( N, x, stride ) { - return addon( N, x, stride ); +function smeanpw( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/manifest.json b/lib/node_modules/@stdlib/stats/base/smeanpw/manifest.json index 6670885e20df..9f90f847102a 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/manifest.json @@ -1,6 +1,7 @@ { "options": { - "task": "build" + "task": "build", + "wasm": false }, "fields": [ { @@ -27,18 +28,19 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ - "./src/smeanpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/blas/ext/base/ssumpw", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -48,34 +50,53 @@ }, { "task": "benchmark", + "wasm": false, "src": [ - "./src/smeanpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/ssumpw" + "@stdlib/blas/ext/base/ssumpw", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { "task": "examples", + "wasm": false, "src": [ - "./src/smeanpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/ext/base/ssumpw", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/ssumpw" + "@stdlib/blas/ext/base/ssumpw", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/src/addon.c b/lib/node_modules/@stdlib/stats/base/smeanpw/src/addon.c index a5531789ae49..6c3186b18860 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/stats/base/smeanpw.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -34,10 +35,27 @@ 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, stride, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); - STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_smeanpw( N, X, stride ), v ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)API_SUFFIX(stdlib_strided_smeanpw)( N, X, strideX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 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, (double)API_SUFFIX(stdlib_strided_smeanpw_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/smeanpw/src/main.c b/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c new file mode 100644 index 000000000000..d9d8f6f4f83d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c @@ -0,0 +1,54 @@ +/** +* @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/smeanpw.h" +#include "stdlib/blas/ext/base/ssumpw.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @return output value +*/ +float API_SUFFIX(stdlib_strided_smeanpw)( 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_smeanpw_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation and 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 +*/ +float API_SUFFIX(stdlib_strided_smeanpw_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + if ( N <= 0 ) { + return 0.0f / 0.0f; // NaN + } + if ( N == 1 || strideX == 0 ) { + return X[ 0 ]; + } + return API_SUFFIX(stdlib_strided_ssumpw_ndarray)( N, X, strideX, offsetX ) / (double)N; +} diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/src/smeanpw.c b/lib/node_modules/@stdlib/stats/base/smeanpw/src/smeanpw.c deleted file mode 100644 index 2e7b56264c91..000000000000 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/src/smeanpw.c +++ /dev/null @@ -1,39 +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/smeanpw.h" -#include "stdlib/blas/ext/base/ssumpw.h" -#include - -/** -* Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation. -* -* @param N number of indexed elements -* @param X input array -* @param stride stride length -* @return output value -*/ -float stdlib_strided_smeanpw( const int64_t N, const float *X, const int64_t stride ) { - if ( N <= 0 ) { - return 0.0f / 0.0f; // NaN - } - if ( N == 1 || stride == 0 ) { - return X[ 0 ]; - } - return (double)stdlib_strided_ssumpw( N, X, stride ) / (double)N; -} diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.ndarray.js index 21336f336390..2ba10f7781f7 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/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 smeanpw = 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 = smeanpw( N, x, 2, 0 ); + v = smeanpw( 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 = smeanpw( N, x, -2, 6 ); + v = smeanpw( 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 = smeanpw( N, x, 2, 1 ); + v = smeanpw( 4, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.ndarray.native.js index d02b89c4f91f..4b6da6714dc6 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/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 = smeanpw( N, x, 2, 0 ); + v = smeanpw( 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 = smeanpw( N, x, -2, 6 ); + v = smeanpw( 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 = smeanpw( N, x, 2, 1 ); + v = smeanpw( 4, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.smeanpw.js b/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.smeanpw.js index 0ddece4c57cd..d4140e595873 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.smeanpw.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.smeanpw.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 smeanpw = require( './../lib/smeanpw.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 = smeanpw( N, x, 2 ); + v = smeanpw( 4, x, 2 ); 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 = smeanpw( N, x, -2 ); + v = smeanpw( 4, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -147,7 +142,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 +157,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 = smeanpw( N, x1, 2 ); + v = smeanpw( 4, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.smeanpw.native.js b/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.smeanpw.native.js index 74fe25aa707c..cc4037195579 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.smeanpw.native.js +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/test/test.smeanpw.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 = smeanpw( N, x, 2 ); + v = smeanpw( 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 = smeanpw( N, x, -2 ); + v = smeanpw( 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 = smeanpw( N, x1, 2 ); + v = smeanpw( 4, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); From 7069d758e6629ba18c565d26510b3ffdf0d400f4 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 14 Jan 2025 23:33:59 +0530 Subject: [PATCH 2/8] chore: updated copyright year --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c b/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c index d9d8f6f4f83d..dc6e947268c2 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 071c2c0eab10db0d2c3ab0f4bd48a9dd95e6158f Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Fri, 14 Mar 2025 17:23:29 +0530 Subject: [PATCH 3/8] chore: minor changes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/base/smeanpw/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/manifest.json b/lib/node_modules/@stdlib/stats/base/smeanpw/manifest.json index 9f90f847102a..a64c3df0f221 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/manifest.json @@ -83,7 +83,7 @@ ] }, { - "task": "", + "task": "build", "wasm": true, "src": [ "./src/main.c" From d8f760fd4958749e682840041ef65f462e7eebf8 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 15 Mar 2025 00:22:04 -0700 Subject: [PATCH 4/8] docs: update description Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/smeanpw/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/README.md b/lib/node_modules/@stdlib/stats/base/smeanpw/README.md index 844c74b7a821..a9e24da699e8 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/README.md +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/README.md @@ -53,7 +53,7 @@ var smeanpw = require( '@stdlib/stats/base/smeanpw' ); #### smeanpw( N, x, strideX ) -Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array `x` using pairwise summation. +Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using pairwise summation. ```javascript var Float32Array = require( '@stdlib/array/float32' ); From e79948586d6cc5cb1a944e151490c87992722e15 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 15 Mar 2025 01:23:12 -0700 Subject: [PATCH 5/8] docs: revert note removal Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/smeanpw/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/README.md b/lib/node_modules/@stdlib/stats/base/smeanpw/README.md index a9e24da699e8..87684011a453 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/README.md +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/README.md @@ -132,6 +132,7 @@ var v = smeanpw.ndarray( 4, x, 2, 1 ); ## Notes - If `N <= 0`, both functions return `NaN`. +- In general, pairwise summation is more numerically stable than ordinary recursive summation (i.e., "simple" summation), with slightly worse performance. While not the most numerically stable summation technique (e.g., compensated summation techniques such as the Kahan–Babuška-Neumaier algorithm are generally more numerically stable), pairwise summation strikes a reasonable balance between numerical stability and performance. If either numerical stability or performance is more desirable for your use case, consider alternative summation techniques.
From 898f2e45ed91dfa6070fbc6351d58c6a91a90d49 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 15 Mar 2025 01:25:25 -0700 Subject: [PATCH 6/8] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt index 89002dd86173..268891925e82 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt @@ -20,7 +20,7 @@ Input array. strideX: integer - Stride Length. + Stride length. Returns ------- @@ -63,7 +63,7 @@ Input array. strideX: integer - Stride Length. + Stride length. offsetX: integer Starting index. From 04af6d3bbfa0b500cb53e5b077227fc1df98fac8 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 15 Mar 2025 01:26:24 -0700 Subject: [PATCH 7/8] docs: revert removal of empty line Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt index 268891925e82..b325751db75b 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/docs/repl.txt @@ -87,3 +87,4 @@ See Also -------- + From d1323a4ba8e8351483e0e8d8ff494328aac04923 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 15 Mar 2025 01:29:12 -0700 Subject: [PATCH 8/8] fix: perform explicit cast as done previously Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c b/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c index dc6e947268c2..57e20e1eb838 100644 --- a/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/smeanpw/src/main.c @@ -50,5 +50,5 @@ float API_SUFFIX(stdlib_strided_smeanpw_ndarray)( const CBLAS_INT N, const float if ( N == 1 || strideX == 0 ) { return X[ 0 ]; } - return API_SUFFIX(stdlib_strided_ssumpw_ndarray)( N, X, strideX, offsetX ) / (double)N; + return (double)API_SUFFIX(stdlib_strided_ssumpw_ndarray)( N, X, strideX, offsetX ) / (double)N; }