From deabf5358fdce4a99aa6f060e3d296a69538ed24 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sun, 19 Jan 2025 13:48:21 +0530 Subject: [PATCH] feat: add C `ndarray` interface and refactor implementation for `stats/base/dsmeanpw` PR-URL: https://github.com/stdlib-js/stdlib/pull/4338 Reviewed-by: Athan Reines Co-authored-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> --- .../@stdlib/stats/base/dsmeanpw/README.md | 144 ++++++++++++++---- .../base/dsmeanpw/benchmark/benchmark.js | 18 +-- .../dsmeanpw/benchmark/benchmark.native.js | 14 +- .../dsmeanpw/benchmark/benchmark.ndarray.js | 18 +-- .../benchmark/benchmark.ndarray.native.js | 14 +- .../dsmeanpw/benchmark/c/benchmark.length.c | 49 +++++- .../@stdlib/stats/base/dsmeanpw/docs/repl.txt | 34 ++--- .../stats/base/dsmeanpw/docs/types/index.d.ts | 12 +- .../stats/base/dsmeanpw/examples/c/example.c | 9 +- .../stats/base/dsmeanpw/examples/index.js | 14 +- .../include/stdlib/stats/base/dsmeanpw.h | 9 +- .../stats/base/dsmeanpw/lib/dsmeanpw.js | 18 +-- .../base/dsmeanpw/lib/dsmeanpw.native.js | 9 +- .../@stdlib/stats/base/dsmeanpw/lib/index.js | 7 +- .../stats/base/dsmeanpw/lib/ndarray.js | 16 +- .../stats/base/dsmeanpw/lib/ndarray.native.js | 20 +-- .../@stdlib/stats/base/dsmeanpw/manifest.json | 53 +++++-- .../@stdlib/stats/base/dsmeanpw/src/addon.c | 27 +++- .../stats/base/dsmeanpw/src/dsmeanpw.c | 39 ----- .../@stdlib/stats/base/dsmeanpw/src/main.c | 54 +++++++ .../stats/base/dsmeanpw/test/test.dsmeanpw.js | 13 +- .../dsmeanpw/test/test.dsmeanpw.native.js | 13 +- .../stats/base/dsmeanpw/test/test.ndarray.js | 13 +- .../base/dsmeanpw/test/test.ndarray.native.js | 13 +- 24 files changed, 377 insertions(+), 253 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/dsmeanpw/src/dsmeanpw.c create mode 100644 lib/node_modules/@stdlib/stats/base/dsmeanpw/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/README.md b/lib/node_modules/@stdlib/stats/base/dsmeanpw/README.md index 08cb8e5b71c2..60cd2a7552ce 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/README.md +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/README.md @@ -51,7 +51,7 @@ The [arithmetic mean][arithmetic-mean] is defined as var dsmeanpw = require( '@stdlib/stats/base/dsmeanpw' ); ``` -#### dsmeanpw( N, x, stride ) +#### dsmeanpw( N, x, strideX ) Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array `x` using pairwise summation 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 = dsmeanpw( N, x, 1 ); +var v = dsmeanpw( 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`, ```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 = dsmeanpw( N, x, 2 ); +var v = dsmeanpw( 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 = dsmeanpw( N, x1, 2 ); +var v = dsmeanpw( 4, x1, 2 ); // returns 1.25 ``` -#### dsmeanpw.ndarray( N, x, stride, offset ) +#### dsmeanpw.ndarray( N, x, strideX, offsetX ) Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. @@ -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 = dsmeanpw.ndarray( N, x, 1, 0 ); +var v = dsmeanpw.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 = dsmeanpw.ndarray( N, x, 2, 1 ); +var v = dsmeanpw.ndarray( 4, x, 2, 1 ); // returns 1.25 ``` @@ -155,18 +146,12 @@ var v = dsmeanpw.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 dsmeanpw = require( '@stdlib/stats/base/dsmeanpw' ); -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 = dsmeanpw( x.length, x, 1 ); @@ -177,6 +162,107 @@ console.log( v ); + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dsmeanpw.h" +``` + +#### stdlib_strided_dsmeanpw( N, \*X, strideX ) + +Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation 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 }; + +double v = stdlib_strided_dsmeanpw( 4, x, 2 ); +// returns 4.0 +``` + +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_dsmeanpw( const CBLAS_INT N, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dsmeanpw_ndarray( N, \*X, strideX, offsetX ) + +Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation 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 }; + +double v = stdlib_strided_dsmeanpw_ndarray( 4, x, 2, 0 ); +// returns 4.0 +``` + +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_dsmeanpw_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dsmeanpw.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: + double v = stdlib_strided_dsmeanpw( N, x, strideX ); + + // Print the result: + printf( "mean: %lf\n", v ); +} +``` + +
+ + + + + + + * * *
diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/benchmark.js index 595f9577839d..33e6624bd039 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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 dsmeanpw = require( './../lib/dsmeanpw.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dsmeanpw = require( './../lib/dsmeanpw.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/dsmeanpw/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/benchmark.native.js index 5599ec545bce..c006a32f1264 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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 dsmeanpw = tryRequire( resolve( __dirname, './../lib/dsmeanpw.native.js' ) ) var opts = { 'skip': ( dsmeanpw 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/dsmeanpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/benchmark.ndarray.js index 36c729b1439a..4f2cfe31dd0c 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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 dsmeanpw = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dsmeanpw = 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/dsmeanpw/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/benchmark.ndarray.native.js index 30e5b9023736..261cf45f0562 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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 dsmeanpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dsmeanpw 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/dsmeanpw/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/c/benchmark.length.c index 2d580bf22b88..eadbf381da6d 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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 ]; double v; @@ -107,6 +107,7 @@ static double benchmark( int iterations, int len ) { v = 0.0; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_dsmeanpw( len, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -120,6 +121,39 @@ 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 ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_dsmeanpw_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/dsmeanpw/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dsmeanpw/docs/repl.txt index 7f1540e314a6..2e84eb006a13 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/docs/repl.txt @@ -1,11 +1,11 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation with extended accumulation and returning an extended precision result. - 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. @@ -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 ) + > {{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 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 - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -87,8 +84,7 @@ // 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/dsmeanpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dsmeanpw/docs/types/index.d.ts index 144e85d015d0..d0550d56a129 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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 = dsmeanpw( 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 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 = dsmeanpw.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/dsmeanpw/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dsmeanpw/examples/c/example.c index 5d71b2ea2480..f1af15a83567 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dsmeanpw.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_dsmeanpw( N, x, stride ); + double v = stdlib_strided_dsmeanpw( N, x, strideX ); // Print the result: printf( "mean: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/examples/index.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/examples/index.js index 1a12da96b044..12699b5238c6 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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 dsmeanpw = 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 = dsmeanpw( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/include/stdlib/stats/base/dsmeanpw.h b/lib/node_modules/@stdlib/stats/base/dsmeanpw/include/stdlib/stats/base/dsmeanpw.h index a466312b32f8..692870e186c1 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/include/stdlib/stats/base/dsmeanpw.h +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/include/stdlib/stats/base/dsmeanpw.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DSMEANPW_H #define STDLIB_STATS_BASE_DSMEANPW_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 with extended accumulation and returning an extended precision result. */ -double stdlib_strided_dsmeanpw( const int64_t N, const float *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dsmeanpw)( 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 with extended accumulation and alternative indexing semantics and returning an extended precision result. +*/ +double API_SUFFIX(stdlib_strided_dsmeanpw_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/dsmeanpw/lib/dsmeanpw.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/dsmeanpw.js index c777e92bfbdc..63f0f41dec90 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/dsmeanpw.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/dsmeanpw.js @@ -20,7 +20,8 @@ // MODULES // -var dssumpw = require( '@stdlib/blas/ext/base/dssumpw' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -30,26 +31,19 @@ var dssumpw = require( '@stdlib/blas/ext/base/dssumpw' ); * * @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 = dsmeanpw( N, x, 1 ); +* var v = dsmeanpw( x.length, x, 1 ); * // returns ~0.3333 */ -function dsmeanpw( N, x, stride ) { - if ( N <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - return x[ 0 ]; - } - return dssumpw( N, x, stride ) / N; +function dsmeanpw( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/dsmeanpw.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/dsmeanpw.native.js index a6a00fa12e23..5ad94060c750 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/dsmeanpw.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/dsmeanpw.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 = dsmeanpw( N, x, 1 ); +* var v = dsmeanpw( x.length, x, 1 ); * // returns ~0.3333 */ -function dsmeanpw( N, x, stride ) { - return addon( N, x, stride ); +function dsmeanpw( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/index.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/index.js index cee16d6f7c5d..86fe54eb58a6 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/index.js @@ -28,20 +28,17 @@ * var dsmeanpw = require( '@stdlib/stats/base/dsmeanpw' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dsmeanpw( N, x, 1 ); +* var v = dsmeanpw( x.length, x, 1 ); * // returns ~0.3333 * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var dsmeanpw = require( '@stdlib/stats/base/dsmeanpw' ); * * 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 = dsmeanpw.ndarray( N, x, 2, 1 ); +* var v = dsmeanpw.ndarray( 4, x, 2, 1 ); * // returns 1.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/ndarray.js index 9402aa032639..668c099fd327 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/ndarray.js @@ -30,28 +30,26 @@ var dssumpw = require( '@stdlib/blas/ext/base/dssumpw' ).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 = dsmeanpw( N, x, 2, 1 ); +* var v = dsmeanpw( 4, x, 2, 1 ); * // returns 1.25 */ -function dsmeanpw( N, x, stride, offset ) { +function dsmeanpw( 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 dssumpw( N, x, stride, offset ) / N; + return dssumpw( N, x, strideX, offsetX ) / N; } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/ndarray.native.js index 4a1dc9f50804..a4cd2a3f8125 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float32Array = require( '@stdlib/array/float32' ); -var addon = require( './dsmeanpw.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -31,27 +30,20 @@ var addon = require( './dsmeanpw.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 = dsmeanpw( N, x, 2, 1 ); +* var v = dsmeanpw( 4, x, 2, 1 ); * // returns 1.25 */ -function dsmeanpw( 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 dsmeanpw( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/manifest.json b/lib/node_modules/@stdlib/stats/base/dsmeanpw/manifest.json index b2ab2be740bf..ff2f26c0a708 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/manifest.json @@ -1,5 +1,8 @@ { - "options": {}, + "options": { + "task": "build", + "wasm": false + }, "fields": [ { "field": "src", @@ -25,18 +28,19 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ - "./src/dsmeanpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dssum", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/ext/base/dssumpw", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -46,34 +50,53 @@ }, { "task": "benchmark", + "wasm": false, "src": [ - "./src/dsmeanpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dssum" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/ext/base/dssumpw" ] }, { "task": "examples", + "wasm": false, "src": [ - "./src/dsmeanpw.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/ext/base/dssumpw" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dssum" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/blas/ext/base/dssumpw" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/src/addon.c b/lib/node_modules/@stdlib/stats/base/dsmeanpw/src/addon.c index 9d47b1042080..b7a0bbf9e160 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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. @@ -34,10 +34,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, stdlib_strided_dsmeanpw( 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, API_SUFFIX(stdlib_strided_dsmeanpw)( 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, API_SUFFIX(stdlib_strided_dsmeanpw_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/dsmeanpw/src/dsmeanpw.c b/lib/node_modules/@stdlib/stats/base/dsmeanpw/src/dsmeanpw.c deleted file mode 100644 index 679904b23e70..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/src/dsmeanpw.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/dsmeanpw.h" -#include "stdlib/blas/ext/base/dssum.h" -#include - -/** -* Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation with extended accumulation and returning an extended precision result. -* -* @param N number of indexed elements -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dsmeanpw( const int64_t N, const float *X, const int64_t stride ) { - if ( N <= 0 ) { - return 0.0 / 0.0; // NaN - } - if ( N == 1 || stride == 0 ) { - return X[ 0 ]; - } - return stdlib_strided_dssum( N, X, stride ) / (double)N; -} diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/src/main.c b/lib/node_modules/@stdlib/stats/base/dsmeanpw/src/main.c new file mode 100644 index 000000000000..277c63176be2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/src/main.c @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dsmeanpw.h" +#include "stdlib/blas/ext/base/dssumpw.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 with extended accumulation and returning an extended precision result. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dsmeanpw)( 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_dsmeanpw_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the arithmetic mean of a single-precision floating-point strided array using pairwise summation with extended accumulation and alternative indexing semantics and returning an extended precision result. +* +* @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_dsmeanpw_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + if ( N <= 0 ) { + return 0.0 / 0.0; // NaN + } + if ( N == 1 || strideX == 0 ) { + return X[ offsetX ]; + } + return stdlib_strided_dssumpw_ndarray( N, X, strideX, offsetX ) / (double)N; +} diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.dsmeanpw.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.dsmeanpw.js index d6afb34e9ba3..77de914f2d98 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.dsmeanpw.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.dsmeanpw.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 dsmeanpw = require( './../lib/dsmeanpw.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 = dsmeanpw( N, x, 2 ); + v = dsmeanpw( 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 = dsmeanpw( N, x, -2 ); + v = dsmeanpw( 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 = dsmeanpw( N, x1, 2 ); + v = dsmeanpw( 4, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.dsmeanpw.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.dsmeanpw.native.js index 39896d88a42a..0876072e69c8 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.dsmeanpw.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.dsmeanpw.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 = dsmeanpw( N, x, 2 ); + v = dsmeanpw( 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 = dsmeanpw( N, x, -2 ); + v = dsmeanpw( 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 = dsmeanpw( N, x1, 2 ); + v = dsmeanpw( 4, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.ndarray.js index 50f5a9d634e0..c4b6a28bb0dd 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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 dsmeanpw = 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 = dsmeanpw( N, x, 2, 0 ); + v = dsmeanpw( 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 = dsmeanpw( N, x, -2, 6 ); + v = dsmeanpw( 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 = dsmeanpw( N, x, 2, 1 ); + v = dsmeanpw( 4, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.ndarray.native.js index 35df641f4ce5..b01b351ccb9b 100644 --- a/lib/node_modules/@stdlib/stats/base/dsmeanpw/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dsmeanpw/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 = dsmeanpw( N, x, 2, 0 ); + v = dsmeanpw( 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 = dsmeanpw( N, x, -2, 6 ); + v = dsmeanpw( 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 = dsmeanpw( N, x, 2, 1 ); + v = dsmeanpw( 4, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end();