From 0ceb0184370ec22cfe8ba9441a948de796c5c979 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Jan 2025 06:43:09 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 13 ++- CONTRIBUTORS | 1 + NOTICE | 2 +- README.md | 150 +++++++++++++++++++++---- benchmark/benchmark.js | 30 ++--- benchmark/benchmark.native.js | 30 ++--- benchmark/benchmark.ndarray.js | 30 ++--- benchmark/benchmark.ndarray.native.js | 30 ++--- benchmark/c/benchmark.length.c | 54 ++++++++- dist/index.js | 14 +-- dist/index.js.map | 8 +- docs/repl.txt | 34 +++--- docs/types/index.d.ts | 12 +- examples/c/example.c | 9 +- include/stdlib/stats/base/dnanmeanwd.h | 9 +- lib/dnanmeanwd.js | 45 ++------ lib/dnanmeanwd.native.js | 9 +- lib/index.js | 7 +- lib/ndarray.js | 18 ++- lib/ndarray.native.js | 20 +--- manifest.json | 50 ++++++--- package.json | 6 +- src/addon.c | 28 ++++- src/{dnanmeanwd.c => main.c} | 46 +++++--- test/test.dnanmeanwd.js | 13 +-- test/test.dnanmeanwd.native.js | 13 +-- test/test.ndarray.js | 13 +-- test/test.ndarray.native.js | 13 +-- 28 files changed, 440 insertions(+), 267 deletions(-) rename src/{dnanmeanwd.c => main.c} (62%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5098c4c..b7e0568 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,17 @@
-## Unreleased (2024-12-24) +## Unreleased (2025-01-03) + +
+ +### Features + +- [`2832442`](https://github.com/stdlib-js/stdlib/commit/28324425c1a630bd52cccc75d4f4a2a72bbc9e01) - add C `ndarray` interface and refactor implementation for `stats/base/dnanmeanwd` [(#4251)](https://github.com/stdlib-js/stdlib/pull/4251) + +
+ +
@@ -12,6 +22,7 @@
+- [`2832442`](https://github.com/stdlib-js/stdlib/commit/28324425c1a630bd52cccc75d4f4a2a72bbc9e01) - **feat:** add C `ndarray` interface and refactor implementation for `stats/base/dnanmeanwd` [(#4251)](https://github.com/stdlib-js/stdlib/pull/4251) _(by Neeraj Pathak, Athan Reines)_ - [`70dde47`](https://github.com/stdlib-js/stdlib/commit/70dde4759fdc94408dc4ee058cd83e6edf6ebda7) - **refactor:** update `stats/base/dnanmeanwd` native addon from C++ to C [(#4157)](https://github.com/stdlib-js/stdlib/pull/4157) _(by Neeraj Pathak)_ - [`62364f6`](https://github.com/stdlib-js/stdlib/commit/62364f62ea823a3b52c2ad25660ecd80c71f8f36) - **style:** fix C comment alignment _(by Philipp Burckhardt)_ - [`9e689ff`](https://github.com/stdlib-js/stdlib/commit/9e689ffcb7c6223afc521f1e574b42f10921cf5e) - **chore:** fix indentation in manifest.json files _(by Philipp Burckhardt)_ diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 173c07b..a5f7aba 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -27,6 +27,7 @@ Daniel Killenberger Daniel Yu <40680511+Daniel777y@users.noreply.github.com> Debashis Maharana Desh Deepak Kant <118960904+DeshDeepakKant@users.noreply.github.com> +Dhruv/ <154677013+DhruvArvindSingh@users.noreply.github.com> Divyansh Seth <59174836+sethdivyansh@users.noreply.github.com> Dominic Lim <46486515+domlimm@users.noreply.github.com> Dominik Moritz diff --git a/NOTICE b/NOTICE index e6e7482..cbd3a29 100644 --- a/NOTICE +++ b/NOTICE @@ -1 +1 @@ -Copyright (c) 2016-2024 The Stdlib Authors. +Copyright (c) 2016-2025 The Stdlib Authors. diff --git a/README.md b/README.md index 9f17877..455b73e 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ To view installation and usage instructions specific to each branch build, be su var dnanmeanwd = require( '@stdlib/stats-base-dnanmeanwd' ); ``` -#### dnanmeanwd( N, x, stride ) +#### dnanmeanwd( N, x, strideX ) Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array `x`, using Welford's algorithm and ignoring `NaN` values. @@ -92,9 +92,8 @@ Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-p var Float64Array = require( '@stdlib/array-float64' ); var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = dnanmeanwd( N, x, 1 ); +var v = dnanmeanwd( x.length, x, 1 ); // returns ~0.3333 ``` @@ -102,18 +101,16 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: index increment 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 stride array are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`, ```javascript var Float64Array = require( '@stdlib/array-float64' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ] ); -var N = floor( x.length / 2 ); -var v = dnanmeanwd( N, x, 2 ); +var v = dnanmeanwd( 4, x, 2 ); // returns 1.25 ``` @@ -123,18 +120,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array-float64' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dnanmeanwd( N, x1, 2 ); +var v = dnanmeanwd( 4, x1, 2 ); // returns 1.25 ``` -#### dnanmeanwd.ndarray( N, x, stride, offset ) +#### dnanmeanwd.ndarray( N, x, strideX, offsetX ) Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. @@ -142,26 +136,23 @@ Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-p var Float64Array = require( '@stdlib/array-float64' ); var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = dnanmeanwd.ndarray( N, x, 1, 0 ); +var v = dnanmeanwd.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 Float64Array = require( '@stdlib/array-float64' ); -var floor = require( '@stdlib/math-base-special-floor' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); -var N = floor( x.length / 2 ); -var v = dnanmeanwd.ndarray( N, x, 2, 1 ); +var v = dnanmeanwd.ndarray( 4, x, 2, 1 ); // returns 1.25 ``` @@ -213,6 +204,123 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dnanmeanwd.h" +``` + +#### stdlib_strided_dnanmeanwd( N, \*X, strideX ) + +Computes the arithmetic mean of a double-precision floating-point strided array `x`, using Welford's algorithm and ignoring `NaN` values. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; + +double v = stdlib_strided_dnanmeanwd( 6, x, 2 ); +// returns 1.25 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +double stdlib_strided_dnanmeanwd( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnanmeanwd_ndarray( N, \*X, strideX, offsetX ) + +Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; + +double v = stdlib_strided_dnanmeanwd_ndarray( 6, x, 2, 0 ); +// returns 1.25 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dnanmeanwd_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dnanmeanwd.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; + + // Specify the number of elements: + const int N = 6; + + // Specify the stride length: + const int strideX = 2; + + // Compute the arithmetic mean: + double v = stdlib_strided_dnanmeanwd( N, x, strideX ); + + // Print the result: + printf( "mean: %lf\n", v ); +} +``` + +
+ + + +
+ + + * * *
@@ -269,7 +377,7 @@ See [LICENSE][stdlib-license]. ## Copyright -Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. +Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors].
diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js index 1430c8f..6d14505 100644 --- a/benchmark/benchmark.js +++ b/benchmark/benchmark.js @@ -21,16 +21,30 @@ // MODULES // var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-base-uniform' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +var filledarrayBy = require( '@stdlib/array-filled-by' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float64Array = require( '@stdlib/array-float64' ); var pkg = require( './../package.json' ).name; var dnanmeanwd = require( './../lib/dnanmeanwd.js' ); // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.2 ) ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -39,17 +53,7 @@ var dnanmeanwd = require( './../lib/dnanmeanwd.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.native.js b/benchmark/benchmark.native.js index 00af974..b0b3d2a 100644 --- a/benchmark/benchmark.native.js +++ b/benchmark/benchmark.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-base-uniform' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +var filledarrayBy = require( '@stdlib/array-filled-by' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float64Array = require( '@stdlib/array-float64' ); var tryRequire = require( '@stdlib/utils-try-require' ); var pkg = require( './../package.json' ).name; @@ -40,6 +41,19 @@ var opts = { // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.2 ) ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -48,17 +62,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js index cf09c18..bebe896 100644 --- a/benchmark/benchmark.ndarray.js +++ b/benchmark/benchmark.ndarray.js @@ -21,16 +21,30 @@ // MODULES // var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-base-uniform' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +var filledarrayBy = require( '@stdlib/array-filled-by' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float64Array = require( '@stdlib/array-float64' ); var pkg = require( './../package.json' ).name; var dnanmeanwd = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.2 ) ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -39,17 +53,7 @@ var dnanmeanwd = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/benchmark/benchmark.ndarray.native.js b/benchmark/benchmark.ndarray.native.js index 1231dad..29f92fb 100644 --- a/benchmark/benchmark.ndarray.native.js +++ b/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench-harness' ); -var randu = require( '@stdlib/random-base-randu' ); +var uniform = require( '@stdlib/random-base-uniform' ); +var bernoulli = require( '@stdlib/random-base-bernoulli' ); +var filledarrayBy = require( '@stdlib/array-filled-by' ); var isnan = require( '@stdlib/math-base-assert-is-nan' ); var pow = require( '@stdlib/math-base-special-pow' ); -var Float64Array = require( '@stdlib/array-float64' ); var tryRequire = require( '@stdlib/utils-try-require' ); var pkg = require( './../package.json' ).name; @@ -40,6 +41,19 @@ var opts = { // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.2 ) ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -48,17 +62,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/benchmark/c/benchmark.length.c b/benchmark/c/benchmark.length.c index 3dce6d5..7876ee3 100644 --- a/benchmark/c/benchmark.length.c +++ b/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double v; @@ -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_dnanmeanwd( len, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -120,6 +121,44 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + if ( rand_double() < 0.2 ) { + x[ i ] = 0.0 / 0.0; // NaN + } else { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_dnanmeanwd_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 +181,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/dist/index.js b/dist/index.js index c2ecb59..a9626cf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,9 +1,9 @@ -"use strict";var s=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var d=s(function(h,m){ -function j(r,a,v){var t,e,i,n,u;if(r<=0)return NaN;if(r===1||v===0)return a[0];for(v<0?e=(1-r)*v:e=0,t=0,n=0,u=0;u {{alias}}( x.length, x, 1 ) ~0.3333 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN ] ); - > 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/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 3, x1, 2 ) ~-0.3333 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters @@ -68,10 +65,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -88,8 +85,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] ); - > 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/docs/types/index.d.ts b/docs/types/index.d.ts index 02cfe80..76c4254 100644 --- a/docs/types/index.d.ts +++ b/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 = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 */ - ( N: number, x: Float64Array, stride: number ): number; + ( N: number, x: Float64Array, strideX: number ): number; /** * Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm 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 = dnanmeanwd.ndarray( x.length, x, 1, 0 ); * // returns ~0.3333 */ - ndarray( N: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** @@ -65,7 +65,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns arithmetic mean * * @example diff --git a/examples/c/example.c b/examples/c/example.c index 03e6af1..8d795c2 100644 --- a/examples/c/example.c +++ b/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dnanmeanwd.h" -#include #include int main( void ) { // Create a strided array: - double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; + const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; // Specify the number of elements: - int64_t N = 6; + const int N = 6; // Specify the stride length: - int64_t stride = 2; + const int strideX = 2; // Compute the arithmetic mean: - double v = stdlib_strided_dnanmeanwd( N, x, stride ); + double v = stdlib_strided_dnanmeanwd( N, x, strideX ); // Print the result: printf( "mean: %lf\n", v ); diff --git a/include/stdlib/stats/base/dnanmeanwd.h b/include/stdlib/stats/base/dnanmeanwd.h index aefd7c9..8cbe795 100644 --- a/include/stdlib/stats/base/dnanmeanwd.h +++ b/include/stdlib/stats/base/dnanmeanwd.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DNANMEANWD_H #define STDLIB_STATS_BASE_DNANMEANWD_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 double-precision floating-point strided array, using Welford's algorithm and ignoring `NaN` values. */ -double stdlib_strided_dnanmeanwd( const int64_t N, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnanmeanwd)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); + +/** +* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dnanmeanwd_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/dnanmeanwd.js b/lib/dnanmeanwd.js index 200ff7e..23a7a0d 100644 --- a/lib/dnanmeanwd.js +++ b/lib/dnanmeanwd.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var stride2offset = require( '@stdlib/strided-base-stride2offset' ); +var ndarray = require( './ndarray.js' ); + + // MAIN // /** @@ -43,50 +49,19 @@ * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} arithmetic mean * * @example * var Float64Array = require( '@stdlib/array-float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanmeanwd( N, x, 1 ); +* var v = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 */ -function dnanmeanwd( N, x, stride ) { - var mu; - var ix; - var v; - var n; - var i; - - if ( N <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - return x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - mu = 0.0; - n = 0; - for ( i = 0; i < N; i++ ) { - v = x[ ix ]; - if ( v === v ) { - n += 1; - mu += ( v-mu ) / n; - } - ix += stride; - } - if ( n === 0 ) { - return NaN; - } - return mu; +function dnanmeanwd( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/dnanmeanwd.native.js b/lib/dnanmeanwd.native.js index 723e7c9..3391417 100644 --- a/lib/dnanmeanwd.native.js +++ b/lib/dnanmeanwd.native.js @@ -30,20 +30,19 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} arithmetic mean * * @example * var Float64Array = require( '@stdlib/array-float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanmeanwd( N, x, 1 ); +* var v = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 */ -function dnanmeanwd( N, x, stride ) { - return addon( N, x, stride ); +function dnanmeanwd( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/index.js b/lib/index.js index cc52472..e2b163c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -28,20 +28,17 @@ * var dnanmeanwd = require( '@stdlib/stats-base-dnanmeanwd' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = 3; * -* var v = dnanmeanwd( N, x, 1 ); +* var v = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 * * @example * var Float64Array = require( '@stdlib/array-float64' ); -* var floor = require( '@stdlib/math-base-special-floor' ); * var dnanmeanwd = require( '@stdlib/stats-base-dnanmeanwd' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanmeanwd.ndarray( N, x, 2, 1 ); +* var v = dnanmeanwd.ndarray( 4, x, 2, 1 ); * // returns 1.25 */ diff --git a/lib/ndarray.js b/lib/ndarray.js index 8ca2b88..ec50ee3 100644 --- a/lib/ndarray.js +++ b/lib/ndarray.js @@ -43,21 +43,19 @@ * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} arithmetic mean * * @example * var Float64Array = require( '@stdlib/array-float64' ); -* var floor = require( '@stdlib/math-base-special-floor' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanmeanwd( N, x, 2, 1 ); +* var v = dnanmeanwd( 4, x, 2, 1 ); * // returns 1.25 */ -function dnanmeanwd( N, x, stride, offset ) { +function dnanmeanwd( N, x, strideX, offsetX ) { var mu; var ix; var v; @@ -67,10 +65,10 @@ function dnanmeanwd( N, x, stride, offset ) { if ( N <= 0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { - return x[ offset ]; + if ( N === 1 || strideX === 0 ) { + return x[ offsetX ]; } - ix = offset; + ix = offsetX; mu = 0.0; n = 0; for ( i = 0; i < N; i++ ) { @@ -79,7 +77,7 @@ function dnanmeanwd( N, x, stride, offset ) { n += 1; mu += ( v-mu ) / n; } - ix += stride; + ix += strideX; } if ( n === 0 ) { return NaN; diff --git a/lib/ndarray.native.js b/lib/ndarray.native.js index 9d81ae0..40f4bb2 100644 --- a/lib/ndarray.native.js +++ b/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float64Array = require( '@stdlib/array-float64' ); -var addon = require( './dnanmeanwd.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -31,27 +30,20 @@ var addon = require( './dnanmeanwd.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} arithmetic mean * * @example * var Float64Array = require( '@stdlib/array-float64' ); -* var floor = require( '@stdlib/math-base-special-floor' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanmeanwd( N, x, 2, 1 ); +* var v = dnanmeanwd( 4, x, 2, 1 ); * // returns 1.25 */ -function dnanmeanwd( N, x, stride, offset ) { - var view; - if ( stride < 0 ) { - offset += (N-1) * stride; - } - view = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len - return addon( N, view, stride ); +function dnanmeanwd( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/manifest.json b/manifest.json index a8cdc64..0fb7bf6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,7 @@ { "options": { - "task":"build" + "task": "build", + "wasm": false }, "fields": [ { @@ -27,17 +28,18 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ - "./src/dnanmeanwd.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset", "@stdlib/napi-export", "@stdlib/napi-argv", "@stdlib/napi-argv-int64", @@ -47,31 +49,51 @@ }, { "task": "benchmark", + "wasm": false, "src": [ - "./src/dnanmeanwd.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset" + ] }, { "task": "examples", + "wasm": false, "src": [ - "./src/dnanmeanwd.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" ], + "include": [ + "./include" + ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas-base-shared", + "@stdlib/strided-base-stride2offset" + ] } ] } diff --git a/package.json b/package.json index ee4f05f..6ee55d2 100644 --- a/package.json +++ b/package.json @@ -42,23 +42,27 @@ }, "dependencies": { "@stdlib/assert-is-error": "^0.2.2", + "@stdlib/blas-base-shared": "^0.1.0", "@stdlib/napi-argv": "^0.2.2", "@stdlib/napi-argv-int64": "^0.2.2", "@stdlib/napi-argv-strided-float64array": "^0.2.2", "@stdlib/napi-create-double": "^0.0.2", "@stdlib/napi-export": "^0.2.2", + "@stdlib/strided-base-stride2offset": "^0.1.0", "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2", "@stdlib/utils-library-manifest": "^0.2.2", "@stdlib/utils-try-require": "^0.2.2" }, "devDependencies": { + "@stdlib/array-filled-by": "^0.2.1", "@stdlib/array-float64": "^0.2.2", "@stdlib/assert-is-browser": "^0.2.2", "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-floor": "^0.2.3", "@stdlib/math-base-special-pow": "^0.3.0", "@stdlib/math-base-special-round": "^0.3.0", + "@stdlib/random-base-bernoulli": "^0.2.1", "@stdlib/random-base-randu": "^0.2.1", + "@stdlib/random-base-uniform": "^0.2.1", "proxyquire": "^2.0.0", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", diff --git a/src/addon.c b/src/addon.c index 89c2a60..222f988 100644 --- a/src/addon.c +++ b/src/addon.c @@ -17,12 +17,11 @@ */ #include "stdlib/stats/base/dnanmeanwd.h" +#include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float64array.h" #include "stdlib/napi/create_double.h" -#include "stdlib/napi/export.h" -#include /** * Receives JavaScript callback invocation data. @@ -34,10 +33,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_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanmeanwd( N, X, stride ), v ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanmeanwd( N, X, strideX ), v ); + return v; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanmeanwd_ndarray( N, X, strideX, offsetX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/src/dnanmeanwd.c b/src/main.c similarity index 62% rename from src/dnanmeanwd.c rename to src/main.c index ba1d54d..a0a7c9c 100644 --- a/src/dnanmeanwd.c +++ b/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. @@ -17,6 +17,8 @@ */ #include "stdlib/stats/base/dnanmeanwd.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" #include /** @@ -40,29 +42,39 @@ * - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). * - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). * -* @param N number of indexed elements -* @param X input array -* @param stride stride length -* @return output value +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @return output value */ -double stdlib_strided_dnanmeanwd( const int64_t N, const double *X, const int64_t stride ) { - int64_t ix; - int64_t i; - int64_t n; +double API_SUFFIX(stdlib_strided_dnanmeanwd)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dnanmeanwd_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm 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 +*/ +double API_SUFFIX(stdlib_strided_dnanmeanwd_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT i; + CBLAS_INT n; double mu; double v; if ( N <= 0 ) { return 0.0 / 0.0; // NaN } - if ( N == 1 || stride == 0 ) { - return X[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; + if ( N == 1 || strideX == 0 ) { + return X[ offsetX ]; } + ix = offsetX; mu = 0.0; n = 0; for ( i = 0; i < N; i++ ) { @@ -71,7 +83,7 @@ double stdlib_strided_dnanmeanwd( const int64_t N, const double *X, const int64_ n += 1; mu += ( v-mu ) / (double)n; } - ix += stride; + ix += strideX; } if ( n == 0 ) { return 0.0 / 0.0; // NaN; diff --git a/test/test.dnanmeanwd.js b/test/test.dnanmeanwd.js index 8522aad..75b5211 100644 --- a/test/test.dnanmeanwd.js +++ b/test/test.dnanmeanwd.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 Float64Array = require( '@stdlib/array-float64' ); var dnanmeanwd = require( './../lib/dnanmeanwd.js' ); @@ -90,7 +89,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; @@ -106,15 +104,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2 ); + v = dnanmeanwd( 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; @@ -130,8 +126,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) NaN // 0 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, -2 ); + v = dnanmeanwd( 4, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -152,7 +147,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 Float64Array([ @@ -169,9 +163,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dnanmeanwd( N, x1, 2 ); + v = dnanmeanwd( 5, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/test/test.dnanmeanwd.native.js b/test/test.dnanmeanwd.native.js index 5d29cd4..5922dc3 100644 --- a/test/test.dnanmeanwd.native.js +++ b/test/test.dnanmeanwd.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 Float64Array = require( '@stdlib/array-float64' ); var tryRequire = require( '@stdlib/utils-try-require' ); @@ -181,7 +180,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; @@ -197,15 +195,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2 ); + v = dnanmeanwd( 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; @@ -221,8 +217,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test NaN // 0 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, -2 ); + v = dnanmeanwd( 4, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -243,7 +238,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 Float64Array([ @@ -260,9 +254,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dnanmeanwd( N, x1, 2 ); + v = dnanmeanwd( 5, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/test/test.ndarray.js b/test/test.ndarray.js index 6aed8ba..76a6b39 100644 --- a/test/test.ndarray.js +++ b/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 Float64Array = require( '@stdlib/array-float64' ); var dnanmeanwd = require( './../lib/ndarray.js' ); @@ -90,7 +89,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; @@ -106,15 +104,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2, 0 ); + v = dnanmeanwd( 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; @@ -130,8 +126,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) NaN // 0 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, -2, 6 ); + v = dnanmeanwd( 4, x, -2, 6 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -150,7 +145,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; @@ -166,9 +160,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2, 1 ); + v = dnanmeanwd( 5, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/test/test.ndarray.native.js b/test/test.ndarray.native.js index b5171b3..b3ec94b 100644 --- a/test/test.ndarray.native.js +++ b/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 Float64Array = require( '@stdlib/array-float64' ); var tryRequire = require( '@stdlib/utils-try-require' ); @@ -99,7 +98,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; @@ -115,15 +113,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2, 0 ); + v = dnanmeanwd( 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; @@ -139,8 +135,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test NaN // 0 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, -2, 6 ); + v = dnanmeanwd( 4, x, -2, 6 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -159,7 +154,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; @@ -175,9 +169,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2, 1 ); + v = dnanmeanwd( 5, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end();