From 15831b8ea722ac1de2c5171c3e866ec35d8924aa Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 23 Feb 2025 19:22:35 +0530 Subject: [PATCH 1/8] feat: add C ndarray interface and refactor implementation --- 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: passed - 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 --- --- .../@stdlib/stats/base/dnanvariance/README.md | 177 +++++++++++++++--- .../base/dnanvariance/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 | 60 +++++- .../stats/base/dnanvariance/docs/repl.txt | 38 ++-- .../base/dnanvariance/docs/types/index.d.ts | 12 +- .../base/dnanvariance/examples/c/example.c | 9 +- .../stats/base/dnanvariance/examples/index.js | 21 +-- .../include/stdlib/stats/base/dnanvariance.h | 9 +- .../base/dnanvariance/lib/dnanvariance.js | 12 +- .../dnanvariance/lib/dnanvariance.native.js | 9 +- .../stats/base/dnanvariance/lib/index.js | 7 +- .../stats/base/dnanvariance/lib/ndarray.js | 12 +- .../base/dnanvariance/lib/ndarray.native.js | 20 +- .../stats/base/dnanvariance/manifest.json | 45 +++-- .../stats/base/dnanvariance/src/addon.c | 27 ++- .../base/dnanvariance/src/dnanvariance.c | 34 ---- .../stats/base/dnanvariance/src/main.c | 51 +++++ .../dnanvariance/test/test.dnanvariance.js | 13 +- .../test/test.dnanvariance.native.js | 13 +- .../base/dnanvariance/test/test.ndarray.js | 13 +- .../dnanvariance/test/test.ndarray.native.js | 13 +- 24 files changed, 457 insertions(+), 258 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c create mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md index 9b125e03d9c2..a287d25e129a 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md @@ -98,9 +98,9 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); ``` -#### dnanvariance( N, correction, x, stride ) +#### dnanvariance( N, correction, x, strideX ) -Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values. +Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -116,41 +116,38 @@ The function has the following parameters: - **N**: number of indexed elements. - **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: stride length for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] 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 [variance][variance] 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 x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN, NaN ] ); -var v = dnanvariance( N, 1, x, 2 ); +var v = dnanvariance( 5, 1, x, 2 ); // returns 6.25 ``` Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - + ```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 x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dnanvariance( N, 1, x1, 2 ); +var v = dnanvariance( 5, 1, x1, 2 ); // returns 6.25 ``` -#### dnanvariance.ndarray( N, correction, x, stride, offset ) +#### dnanvariance.ndarray( N, correction, x, strideX, offsetX ) -Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. +Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -163,18 +160,18 @@ var v = dnanvariance.ndarray( x.length, 1, x, 1, 0 ); The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other value in `x` starting from the second value + + ```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 ] ); -var N = floor( x.length / 2 ); +var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); -var v = dnanvariance.ndarray( N, 1, x, 2, 1 ); +var v = dnanvariance.ndarray( 5, 1, x, 2, 1 ); // returns 6.25 ``` @@ -200,18 +197,19 @@ var v = dnanvariance.ndarray( N, 1, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); } + +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = dnanvariance( x.length, 1, x, 1 ); @@ -222,6 +220,125 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dnanvariance.h" +``` + +#### stdlib_strided_dnanvariance( N, correction, \*X, strideX ) + +Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values. + +```c +const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; + +double v = stdlib_strided_dnanvariance( 4, 1.0, x, 1 ); +// returns ~4.3333 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +double stdlib_strided_dnanvariance( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnanvariance_ndarray( N, correction, \*X, strideX, offsetX ) + +Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values and alternative indexing semantics. + +```c +const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; + +double v = stdlib_strided_dnanvariance_ndarray( 4, 1.0, x, 1, 0 ); +// returns ~4.3333 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **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_dnanvariance_ndarray( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dnanvariance.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 variance: + double v = stdlib_strided_dnanvariance( N, 1.0, x, strideX ); + + // Print the result: + printf( "sample variance: %lf\n", v ); +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js index d9a4d9e76d07..ac5a46043f47 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js @@ -21,16 +21,30 @@ // MODULES // var bench = require( '@stdlib/bench' ); -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 dnanvariance = require( './../lib/dnanvariance.js' ); // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -39,17 +53,7 @@ var dnanvariance = require( './../lib/dnanvariance.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/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js index bf78c30f9d31..36b4add230c7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -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.8 ) < 1 ) { + 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/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js index 94926c91a30f..9edb4ab1122d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js @@ -21,16 +21,30 @@ // MODULES // var bench = require( '@stdlib/bench' ); -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 dnanvariance = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -39,17 +53,7 @@ var dnanvariance = 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/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js index edd833823e73..bc51028c025d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -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.8 ) < 1 ) { + 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/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/c/benchmark.length.c index fa2512e14203..351f8629ebcc 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/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; @@ -102,11 +102,16 @@ static double benchmark( int iterations, int len ) { int i; for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + 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_dnanvariance( len, 1.0, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -120,6 +125,44 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + if ( rand_double() < 0.2 ) { + x[ i ] = 0.0 / 0.0; // NaN + } else { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_dnanvariance_ndarray( len, 1.0, 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 +185,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt index ab3ad6e335d2..72ea56e1862e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, correction, x, stride ) +{{alias}}( N, correction, x, strideX ) Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. - 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. @@ -34,8 +34,8 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -49,22 +49,19 @@ > {{alias}}( x.length, 1, x, 1 ) ~4.3333 - // Using `N` and `stride` parameters: - > x = new {{alias:@stdlib/array/float64}}( [ -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, 1, x, stride ) + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] ); + > {{alias}}( 4, 1, x, 2 ) ~4.3333 // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, 1, x1, stride ) + > {{alias}}( 4, 1, x1, 2 ) ~4.3333 -{{alias}}.ndarray( N, correction, x, stride, offset ) + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. @@ -93,10 +90,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -112,9 +109,8 @@ ~4.3333 // Using offset parameter: - > var x = new {{alias:@stdlib/array/float64}}( [ 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, 1, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); + > {{alias}}.ndarray( 4, 1, x, 2, 1 ) ~4.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts index 7bb2784d86fb..8ba39bcd9070 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts @@ -28,7 +28,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns variance * * @example @@ -39,7 +39,7 @@ interface Routine { * var v = dnanvariance( x.length, 1, x, 1 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: Float64Array, stride: number ): number; + ( N: number, correction: number, x: Float64Array, strideX: number ): number; /** * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. @@ -47,8 +47,8 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns variance * * @example @@ -59,7 +59,7 @@ interface Routine { * var v = dnanvariance.ndarray( x.length, 1, x, 1, 0 ); * // returns ~4.3333 */ - ndarray( N: number, correction: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, correction: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** @@ -68,7 +68,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns variance * * @example diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c index 0ad819ac00f1..823b22cacffb 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dnanvariance.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 variance: - double v = stdlib_strided_dnanvariance( N, 1, x, stride ); + double v = stdlib_strided_dnanvariance( N, 1.0, x, strideX ); // Print the result: printf( "sample variance: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js index 83755ce2d7fd..83a8e5dc2385 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js @@ -18,22 +18,19 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var dnanvariance = require( './../lib' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( (randu()*100.0) - 50.0 ); +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; } + return uniform( -50.0, 50.0 ); } + +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = dnanvariance( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h index b78e0d61d149..4663f0444a12 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DNANVARIANCE_H #define STDLIB_STATS_BASE_DNANVARIANCE_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 variance of a double-precision floating-point strided array ignoring `NaN` values. */ -double stdlib_strided_dnanvariance( const int64_t N, const double correction, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js index dc433d62c2ef..c9c3c5227fd4 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js @@ -20,7 +20,8 @@ // MODULES // -var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -31,20 +32,19 @@ var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} variance * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanvariance( N, 1, x, 1 ); +* var v = dnanvariance( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariance( N, correction, x, stride ) { - return dnanvariancepn( N, correction, x, stride ); +function dnanvariance( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js index 1e89d602c53e..ad3d7b4ddf9c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js @@ -31,20 +31,19 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} variance * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanvariance( N, 1, x, 1 ); +* var v = dnanvariance( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariance( N, correction, x, stride ) { - return addon( N, correction, x, stride ); +function dnanvariance( N, correction, x, strideX ) { + return addon( N, correction, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js index 47949c9cc894..285b59e96e18 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js @@ -28,20 +28,17 @@ * var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanvariance( N, 1, x, 1 ); +* var v = dnanvariance( x.length, 1, x, 1 ); * // returns ~4.3333 * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanvariance.ndarray( N, 1, x, 2, 1 ); +* var v = dnanvariance.ndarray( 5, 1, x, 2, 1 ); * // returns 6.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js index 78e383cc31b1..e2433522e480 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js @@ -31,22 +31,20 @@ var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ).ndarray; * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @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} variance * * @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, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanvariance( N, 1, x, 2, 1 ); +* var v = dnanvariance( 5, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariance( N, correction, x, stride, offset ) { - return dnanvariancepn( N, correction, x, stride, offset ); +function dnanvariance( N, correction, x, strideX, offsetX ) { + return dnanvariancepn( N, correction, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js index 6eb4a0ba435f..da5963fbc607 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float64Array = require( '@stdlib/array/float64' ); -var addon = require( './dnanvariance.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,27 +31,20 @@ var addon = require( './dnanvariance.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @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} variance * * @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, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanvariance( N, 1, x, 2, 1 ); +* var v = dnanvariance( 5, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariance( N, correction, 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, correction, view, stride ); +function dnanvariance( N, correction, x, strideX, offsetX ) { + return addon.ndarray( N, correction, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json index ca135dfb5608..4aca007424b6 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/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/dnanvariance.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/stats/base/dnanvariancepn", "@stdlib/napi/export", "@stdlib/napi/argv", @@ -49,33 +51,52 @@ }, { "task": "benchmark", + "wasm" : false, "src": [ - "./src/dnanvariance.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/stats/base/dnanvariancepn" ] }, { "task": "examples", + "wasm" : false, "src": [ - "./src/dnanvariance.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/stats/base/dnanvariancepn" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/stats/base/dnanvariancepn" ] } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c index ed817df01bed..b00fd7060521 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/stats/base/dnanvariance.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -35,11 +36,29 @@ static napi_value addon( 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, stride, argv, 3 ); STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanvariance( N, correction, X, stride ), v ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ) + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanvariance)( N, correction, 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, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( N, correction, 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/dnanvariance/src/dnanvariance.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c deleted file mode 100644 index 13375cf0580d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c +++ /dev/null @@ -1,34 +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/dnanvariance.h" -#include "stdlib/stats/base/dnanvariancepn.h" -#include - -/** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dnanvariance( const int64_t N, const double correction, const double *X, const int64_t stride ) { - return stdlib_strided_dnanvariancepn( N, correction, X, stride ); -} diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c new file mode 100644 index 000000000000..24693e756881 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c @@ -0,0 +1,51 @@ +/** +* @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/dnanvariance.h" +#include "stdlib/stats/base/dnanvariancepn.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dnanvariancepn_ndarray)( N, correction, X, strideX, ox ); +} + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and alternative indexing semantics. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @param offsetX starting index for X +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + return stdlib_strided_dnanvariancepn_ndarray( N, correction, X, strideX, offsetX ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js index 2ca3f359486f..ba861d5e0773 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.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 dnanvariance = require( './../lib/dnanvariance.js' ); @@ -213,7 +212,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -230,15 +228,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2 ); + v = dnanvariance( 5, 1, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -255,9 +251,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 4.0, // 0 2.0 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, -2 ); + v = dnanvariance( 5, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -295,7 +290,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -313,9 +307,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 = dnanvariance( N, 1, x1, 2 ); + v = dnanvariance( 5, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js index 5e485cb85641..1c24bf5141b2 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.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' ); @@ -222,7 +221,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -239,15 +237,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2 ); + v = dnanvariance( 5, 1, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; var i; @@ -264,9 +260,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 4.0, // 0 2.0 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, -2 ); + v = dnanvariance( 5, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -304,7 +299,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -322,9 +316,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 = dnanvariance( N, 1, x1, 2 ); + v = dnanvariance( 5, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js index 3e8dffe868f7..fdfbdb552e91 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/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 dnanvariance = require( './../lib/ndarray.js' ); @@ -213,7 +212,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -230,15 +228,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2, 0 ); + v = dnanvariance( 5, 1, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -255,9 +251,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 4.0, // 0 2.0 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, -2, 8 ); + v = dnanvariance( 5, 1, x, -2, 8 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -293,7 +288,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -309,9 +303,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2, 1 ); + v = dnanvariance( 5, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js index 3c6dc17258f4..6a525ab58914 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/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' ); @@ -222,7 +221,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -239,15 +237,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2, 0 ); + v = dnanvariance( 5, 1, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; var i; @@ -264,9 +260,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 4.0, // 0 2.0 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, -2, 8 ); + v = dnanvariance( 5, 1, x, -2, 8 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -302,7 +297,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -318,9 +312,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2, 1 ); + v = dnanvariance( 5, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From 1db2bc8fa900491023d07400f08c2d3e7c97a4ab Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 23 Feb 2025 19:24:36 +0530 Subject: [PATCH 2/8] Revert "feat: add C ndarray interface and refactor implementation" This reverts commit 15831b8ea722ac1de2c5171c3e866ec35d8924aa. --- .../@stdlib/stats/base/dnanvariance/README.md | 177 +++--------------- .../base/dnanvariance/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 | 60 +----- .../stats/base/dnanvariance/docs/repl.txt | 38 ++-- .../base/dnanvariance/docs/types/index.d.ts | 12 +- .../base/dnanvariance/examples/c/example.c | 9 +- .../stats/base/dnanvariance/examples/index.js | 21 ++- .../include/stdlib/stats/base/dnanvariance.h | 9 +- .../base/dnanvariance/lib/dnanvariance.js | 12 +- .../dnanvariance/lib/dnanvariance.native.js | 9 +- .../stats/base/dnanvariance/lib/index.js | 7 +- .../stats/base/dnanvariance/lib/ndarray.js | 12 +- .../base/dnanvariance/lib/ndarray.native.js | 20 +- .../stats/base/dnanvariance/manifest.json | 45 ++--- .../stats/base/dnanvariance/src/addon.c | 27 +-- .../base/dnanvariance/src/dnanvariance.c | 34 ++++ .../stats/base/dnanvariance/src/main.c | 51 ----- .../dnanvariance/test/test.dnanvariance.js | 13 +- .../test/test.dnanvariance.native.js | 13 +- .../base/dnanvariance/test/test.ndarray.js | 13 +- .../dnanvariance/test/test.ndarray.native.js | 13 +- 24 files changed, 258 insertions(+), 457 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md index a287d25e129a..9b125e03d9c2 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md @@ -98,9 +98,9 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); ``` -#### dnanvariance( N, correction, x, strideX ) +#### dnanvariance( N, correction, x, stride ) -Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values. +Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -116,38 +116,41 @@ The function has the following parameters: - **N**: number of indexed elements. - **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **strideX**: stride length for `x`. +- **stride**: index increment for `x`. -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, - - +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] 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, NaN ] ); +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 = dnanvariance( 5, 1, x, 2 ); +var v = dnanvariance( N, 1, x, 2 ); // returns 6.25 ``` Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - + ```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, NaN ] ); +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 v = dnanvariance( 5, 1, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = dnanvariance( N, 1, x1, 2 ); // returns 6.25 ``` -#### dnanvariance.ndarray( N, correction, x, strideX, offsetX ) +#### dnanvariance.ndarray( N, correction, x, stride, offset ) -Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. +Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -160,18 +163,18 @@ var v = dnanvariance.ndarray( x.length, 1, x, 1, 0 ); The function has the following additional parameters: -- **offsetX**: starting index for `x`. +- **offset**: 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 [variance][variance] for every other value in `x` starting from the second value - - ```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, NaN ] ); +var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var N = floor( x.length / 2 ); -var v = dnanvariance.ndarray( 5, 1, x, 2, 1 ); +var v = dnanvariance.ndarray( N, 1, x, 2, 1 ); // returns 6.25 ``` @@ -197,19 +200,18 @@ var v = dnanvariance.ndarray( 5, 1, x, 2, 1 ); ```javascript -var uniform = require( '@stdlib/random/base/uniform' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float64Array = require( '@stdlib/array/float64' ); var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); -function rand() { - if ( bernoulli( 0.8 ) < 1 ) { - return NaN; - } - return uniform( -50.0, 50.0 ); -} +var x; +var i; -var x = filledarrayBy( 10, 'float64', rand ); +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + x[ i ] = round( (randu()*100.0) - 50.0 ); +} console.log( x ); var v = dnanvariance( x.length, 1, x, 1 ); @@ -220,125 +222,6 @@ console.log( v ); - - -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/stats/base/dnanvariance.h" -``` - -#### stdlib_strided_dnanvariance( N, correction, \*X, strideX ) - -Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values. - -```c -const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; - -double v = stdlib_strided_dnanvariance( 4, 1.0, x, 1 ); -// returns ~4.3333 -``` - -The function accepts the following arguments: - -- **N**: `[in] CBLAS_INT` number of indexed elements. -- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **X**: `[in] double*` input array. -- **strideX**: `[in] CBLAS_INT` stride length for `X`. - -```c -double stdlib_strided_dnanvariance( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); -``` - -#### stdlib_strided_dnanvariance_ndarray( N, correction, \*X, strideX, offsetX ) - -Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values and alternative indexing semantics. - -```c -const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; - -double v = stdlib_strided_dnanvariance_ndarray( 4, 1.0, x, 1, 0 ); -// returns ~4.3333 -``` - -The function accepts the following arguments: - -- **N**: `[in] CBLAS_INT` number of indexed elements. -- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). -- **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_dnanvariance_ndarray( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); -``` - -
- - - - - -
- -
- - - - - -
- -### Examples - -```c -#include "stdlib/stats/base/dnanvariance.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 variance: - double v = stdlib_strided_dnanvariance( N, 1.0, x, strideX ); - - // Print the result: - printf( "sample variance: %lf\n", v ); -} -``` - -
- - - -
- - -
diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js index ac5a46043f47..d9a4d9e76d07 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js @@ -21,30 +21,16 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); 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 dnanvariance = require( './../lib/dnanvariance.js' ); // FUNCTIONS // -/** -* Returns a random value or `NaN`. -* -* @private -* @returns {number} random number or `NaN` -*/ -function rand() { - if ( bernoulli( 0.8 ) < 1 ) { - return NaN; - } - return uniform( -10.0, 10.0 ); -} - /** * Creates a benchmark function. * @@ -53,7 +39,17 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + 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; + } + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js index 36b4add230c7..bf78c30f9d31 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js @@ -22,11 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); 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; @@ -41,19 +40,6 @@ var opts = { // FUNCTIONS // -/** -* Returns a random value or `NaN`. -* -* @private -* @returns {number} random number or `NaN` -*/ -function rand() { - if ( bernoulli( 0.8 ) < 1 ) { - return NaN; - } - return uniform( -10.0, 10.0 ); -} - /** * Creates a benchmark function. * @@ -62,7 +48,17 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + 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; + } + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js index 9edb4ab1122d..94926c91a30f 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js @@ -21,30 +21,16 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); 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 dnanvariance = require( './../lib/ndarray.js' ); // FUNCTIONS // -/** -* Returns a random value or `NaN`. -* -* @private -* @returns {number} random number or `NaN` -*/ -function rand() { - if ( bernoulli( 0.8 ) < 1 ) { - return NaN; - } - return uniform( -10.0, 10.0 ); -} - /** * Creates a benchmark function. * @@ -53,7 +39,17 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + 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; + } + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js index bc51028c025d..edd833823e73 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js @@ -22,11 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); +var randu = require( '@stdlib/random/base/randu' ); 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; @@ -41,19 +40,6 @@ var opts = { // FUNCTIONS // -/** -* Returns a random value or `NaN`. -* -* @private -* @returns {number} random number or `NaN` -*/ -function rand() { - if ( bernoulli( 0.8 ) < 1 ) { - return NaN; - } - return uniform( -10.0, 10.0 ); -} - /** * Creates a benchmark function. * @@ -62,7 +48,17 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + 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; + } + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/c/benchmark.length.c index 351f8629ebcc..fa2512e14203 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/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 benchmark1( int iterations, int len ) { +static double benchmark( int iterations, int len ) { double elapsed; double x[ len ]; double v; @@ -102,16 +102,11 @@ static double benchmark1( int iterations, int len ) { 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; - } + 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_dnanvariance( len, 1.0, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -125,44 +120,6 @@ static double benchmark1( 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_dnanvariance_ndarray( len, 1.0, 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. */ @@ -185,18 +142,7 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, 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 ); + elapsed = benchmark( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt index 72ea56e1862e..ab3ad6e335d2 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, correction, x, strideX ) +{{alias}}( N, correction, x, stride ) Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -34,8 +34,8 @@ x: Float64Array Input array. - strideX: integer - Stride length. + stride: integer + Index increment. Returns ------- @@ -49,19 +49,22 @@ > {{alias}}( x.length, 1, x, 1 ) ~4.3333 - // Using `N` and stride parameters: - > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] ); - > {{alias}}( 4, 1, x, 2 ) + // Using `N` and `stride` parameters: + > x = new {{alias:@stdlib/array/float64}}( [ -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, 1, x, stride ) ~4.3333 // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 4, 1, x1, 2 ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > stride = 2; + > {{alias}}( N, 1, x1, stride ) ~4.3333 - -{{alias}}.ndarray( N, correction, x, strideX, offsetX ) +{{alias}}.ndarray( N, correction, x, stride, offset ) Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. @@ -90,10 +93,10 @@ x: Float64Array Input array. - strideX: integer - Stride length. + stride: integer + Index increment. - offsetX: integer + offset: integer Starting index. Returns @@ -109,8 +112,9 @@ ~4.3333 // Using offset parameter: - > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); - > {{alias}}.ndarray( 4, 1, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float64}}( [ 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, 1, x, 2, 1 ) ~4.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts index 8ba39bcd9070..7bb2784d86fb 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts @@ -28,7 +28,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param strideX - stride length + * @param stride - stride length * @returns variance * * @example @@ -39,7 +39,7 @@ interface Routine { * var v = dnanvariance( x.length, 1, x, 1 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: Float64Array, strideX: number ): number; + ( N: number, correction: number, x: Float64Array, stride: number ): number; /** * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. @@ -47,8 +47,8 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index + * @param stride - stride length + * @param offset - starting index * @returns variance * * @example @@ -59,7 +59,7 @@ interface Routine { * var v = dnanvariance.ndarray( x.length, 1, x, 1, 0 ); * // returns ~4.3333 */ - ndarray( N: number, correction: number, x: Float64Array, strideX: number, offsetX: number ): number; + ndarray( N: number, correction: number, x: Float64Array, stride: number, offset: number ): number; } /** @@ -68,7 +68,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array -* @param strideX - stride length +* @param stride - stride length * @returns variance * * @example diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c index 823b22cacffb..0ad819ac00f1 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c @@ -17,20 +17,21 @@ */ #include "stdlib/stats/base/dnanvariance.h" +#include #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 }; + 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; + int64_t N = 6; // Specify the stride length: - const int strideX = 2; + int64_t stride = 2; // Compute the variance: - double v = stdlib_strided_dnanvariance( N, 1.0, x, strideX ); + double v = stdlib_strided_dnanvariance( N, 1, x, stride ); // Print the result: printf( "sample variance: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js index 83a8e5dc2385..83755ce2d7fd 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js @@ -18,19 +18,22 @@ 'use strict'; -var uniform = require( '@stdlib/random/base/uniform' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var randu = require( '@stdlib/random/base/randu' ); +var round = require( '@stdlib/math/base/special/round' ); +var Float64Array = require( '@stdlib/array/float64' ); var dnanvariance = require( './../lib' ); -function rand() { - if ( bernoulli( 0.8 ) < 1 ) { - return NaN; +var x; +var i; + +x = new Float64Array( 10 ); +for ( i = 0; i < x.length; i++ ) { + if ( randu() < 0.2 ) { + x[ i ] = NaN; + } else { + x[ i ] = round( (randu()*100.0) - 50.0 ); } - return uniform( -50.0, 50.0 ); } - -var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = dnanvariance( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h index 4663f0444a12..b78e0d61d149 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DNANVARIANCE_H #define STDLIB_STATS_BASE_DNANVARIANCE_H -#include "stdlib/blas/base/shared.h" +#include /* * 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,12 +31,7 @@ extern "C" { /** * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. */ -double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); - -/** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and alternative indexing semantics. -*/ -double API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +double stdlib_strided_dnanvariance( const int64_t N, const double correction, const double *X, const int64_t stride ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js index c9c3c5227fd4..dc433d62c2ef 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js @@ -20,8 +20,7 @@ // MODULES // -var stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); +var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); // MAIN // @@ -32,19 +31,20 @@ var ndarray = require( './ndarray.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} strideX - stride length +* @param {integer} stride - stride length * @returns {number} variance * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* var N = x.length; * -* var v = dnanvariance( x.length, 1, x, 1 ); +* var v = dnanvariance( N, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariance( N, correction, x, strideX ) { - return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +function dnanvariance( N, correction, x, stride ) { + return dnanvariancepn( N, correction, x, stride ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js index ad3d7b4ddf9c..1e89d602c53e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js @@ -31,19 +31,20 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} strideX - stride length +* @param {integer} stride - stride length * @returns {number} variance * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* var N = x.length; * -* var v = dnanvariance( x.length, 1, x, 1 ); +* var v = dnanvariance( N, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariance( N, correction, x, strideX ) { - return addon( N, correction, x, strideX ); +function dnanvariance( N, correction, x, stride ) { + return addon( N, correction, x, stride ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js index 285b59e96e18..47949c9cc894 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js @@ -28,17 +28,20 @@ * var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* var N = x.length; * -* var v = dnanvariance( x.length, 1, x, 1 ); +* var v = dnanvariance( N, 1, x, 1 ); * // returns ~4.3333 * * @example * var Float64Array = require( '@stdlib/array/float64' ); +* var floor = require( '@stdlib/math/base/special/floor' ); * var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); +* var N = floor( x.length / 2 ); * -* var v = dnanvariance.ndarray( 5, 1, x, 2, 1 ); +* var v = dnanvariance.ndarray( N, 1, x, 2, 1 ); * // returns 6.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js index e2433522e480..78e383cc31b1 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js @@ -31,20 +31,22 @@ var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ).ndarray; * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - starting index * @returns {number} variance * * @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, NaN ] ); +* var N = floor( x.length / 2 ); * -* var v = dnanvariance( 5, 1, x, 2, 1 ); +* var v = dnanvariance( N, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariance( N, correction, x, strideX, offsetX ) { - return dnanvariancepn( N, correction, x, strideX, offsetX ); +function dnanvariance( N, correction, x, stride, offset ) { + return dnanvariancepn( N, correction, x, stride, offset ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js index da5963fbc607..6eb4a0ba435f 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js @@ -20,7 +20,8 @@ // MODULES // -var addon = require( './../src/addon.node' ); +var Float64Array = require( '@stdlib/array/float64' ); +var addon = require( './dnanvariance.native.js' ); // MAIN // @@ -31,20 +32,27 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - starting index * @returns {number} variance * * @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, NaN ] ); +* var N = floor( x.length / 2 ); * -* var v = dnanvariance( 5, 1, x, 2, 1 ); +* var v = dnanvariance( N, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariance( N, correction, x, strideX, offsetX ) { - return addon.ndarray( N, correction, x, strideX, offsetX ); +function dnanvariance( N, correction, 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, correction, view, stride ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json index 4aca007424b6..ca135dfb5608 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json @@ -1,7 +1,6 @@ { "options": { - "task": "build", - "wasm": false + "task": "build" }, "fields": [ { @@ -28,18 +27,17 @@ "confs": [ { "task": "build", - "wasm" : false, "src": [ - "./src/main.c" + "./src/dnanvariance.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", - "@stdlib/strided/base/stride2offset", "@stdlib/stats/base/dnanvariancepn", "@stdlib/napi/export", "@stdlib/napi/argv", @@ -51,52 +49,33 @@ }, { "task": "benchmark", - "wasm" : false, "src": [ - "./src/main.c" + "./src/dnanvariance.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", - "@stdlib/strided/base/stride2offset", "@stdlib/stats/base/dnanvariancepn" ] }, { "task": "examples", - "wasm" : false, "src": [ - "./src/main.c" + "./src/dnanvariance.c" ], "include": [ "./include" ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/blas/base/shared", - "@stdlib/strided/base/stride2offset", - "@stdlib/stats/base/dnanvariancepn" - ] - }, - { - "task": "", - "wasm": true, - "src": [ - "./src/main.c" - ], - "include": [ - "./include" + "libraries": [ + "-lm" ], - "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", - "@stdlib/strided/base/stride2offset", "@stdlib/stats/base/dnanvariancepn" ] } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c index b00fd7060521..ed817df01bed 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c @@ -17,7 +17,6 @@ */ #include "stdlib/stats/base/dnanvariance.h" -#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -36,29 +35,11 @@ static napi_value addon( 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, stride, argv, 3 ); STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ) - STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanvariance)( N, correction, X, strideX ), v ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanvariance( N, correction, X, stride ), 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, 5 ); - STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); - STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); - STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( N, correction, X, strideX, offsetX ), v ); - return v; -} - -STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c new file mode 100644 index 000000000000..13375cf0580d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c @@ -0,0 +1,34 @@ +/** +* @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/dnanvariance.h" +#include "stdlib/stats/base/dnanvariancepn.h" +#include + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param stride stride length +* @return output value +*/ +double stdlib_strided_dnanvariance( const int64_t N, const double correction, const double *X, const int64_t stride ) { + return stdlib_strided_dnanvariancepn( N, correction, X, stride ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c deleted file mode 100644 index 24693e756881..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c +++ /dev/null @@ -1,51 +0,0 @@ -/** -* @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/dnanvariance.h" -#include "stdlib/stats/base/dnanvariancepn.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/strided/base/stride2offset.h" -#include - -/** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param strideX stride length -* @return output value -*/ -double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ) { - const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); - return API_SUFFIX(stdlib_strided_dnanvariancepn_ndarray)( N, correction, X, strideX, ox ); -} - -/** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and alternative indexing semantics. -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param strideX stride length -* @param offsetX starting index for X -* @return output value -*/ -double API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - return stdlib_strided_dnanvariancepn_ndarray( N, correction, X, strideX, offsetX ); -} diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js index ba861d5e0773..2ca3f359486f 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js @@ -21,6 +21,7 @@ // 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 dnanvariance = require( './../lib/dnanvariance.js' ); @@ -212,6 +213,7 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -228,13 +230,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - v = dnanvariance( 5, 1, x, 2 ); + N = floor( x.length / 2 ); + v = dnanvariance( N, 1, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -251,8 +255,9 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 4.0, // 0 2.0 ]); + N = floor( x.length / 2 ); - v = dnanvariance( 5, 1, x, -2 ); + v = dnanvariance( N, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -290,6 +295,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p tape( 'the function supports view offsets', function test( t ) { var x0; var x1; + var N; var v; x0 = new Float64Array([ @@ -307,8 +313,9 @@ 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 = dnanvariance( 5, 1, x1, 2 ); + v = dnanvariance( N, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js index 1c24bf5141b2..5e485cb85641 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js @@ -22,6 +22,7 @@ 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' ); @@ -221,6 +222,7 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -237,13 +239,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - v = dnanvariance( 5, 1, x, 2 ); + N = floor( x.length / 2 ); + v = dnanvariance( N, 1, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -260,8 +264,9 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 4.0, // 0 2.0 ]); + N = floor( x.length / 2 ); - v = dnanvariance( 5, 1, x, -2 ); + v = dnanvariance( N, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -299,6 +304,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; + var N; var v; x0 = new Float64Array([ @@ -316,8 +322,9 @@ 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 = dnanvariance( 5, 1, x1, 2 ); + v = dnanvariance( N, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js index fdfbdb552e91..3e8dffe868f7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js @@ -21,6 +21,7 @@ // 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 dnanvariance = require( './../lib/ndarray.js' ); @@ -212,6 +213,7 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -228,13 +230,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - v = dnanvariance( 5, 1, x, 2, 0 ); + N = floor( x.length / 2 ); + v = dnanvariance( N, 1, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; var i; @@ -251,8 +255,9 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 4.0, // 0 2.0 ]); + N = floor( x.length / 2 ); - v = dnanvariance( 5, 1, x, -2, 8 ); + v = dnanvariance( N, 1, x, -2, 8 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -288,6 +293,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p }); tape( 'the function supports an `offset` parameter', function test( t ) { + var N; var x; var v; @@ -303,8 +309,9 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]); + N = floor( x.length / 2 ); - v = dnanvariance( 5, 1, x, 2, 1 ); + v = dnanvariance( N, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js index 6a525ab58914..3c6dc17258f4 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js @@ -22,6 +22,7 @@ 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' ); @@ -221,6 +222,7 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { + var N; var x; var v; @@ -237,13 +239,15 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - v = dnanvariance( 5, 1, x, 2, 0 ); + N = floor( x.length / 2 ); + v = dnanvariance( N, 1, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var N; var x; var v; var i; @@ -260,8 +264,9 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 4.0, // 0 2.0 ]); + N = floor( x.length / 2 ); - v = dnanvariance( 5, 1, x, -2, 8 ); + v = dnanvariance( N, 1, x, -2, 8 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -297,6 +302,7 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { + var N; var x; var v; @@ -312,8 +318,9 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { NaN, NaN // 4 ]); + N = floor( x.length / 2 ); - v = dnanvariance( 5, 1, x, 2, 1 ); + v = dnanvariance( N, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From bc98d55eb08444eab91c09298794450d22eff5de Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 23 Feb 2025 19:27:57 +0530 Subject: [PATCH 3/8] feat: add C ndarray interface and refactor implementation --- 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: passed - 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/dnanvariance/README.md | 177 +++++++++++++++--- .../base/dnanvariance/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 | 60 +++++- .../stats/base/dnanvariance/docs/repl.txt | 38 ++-- .../base/dnanvariance/docs/types/index.d.ts | 12 +- .../base/dnanvariance/examples/c/example.c | 9 +- .../stats/base/dnanvariance/examples/index.js | 21 +-- .../include/stdlib/stats/base/dnanvariance.h | 9 +- .../base/dnanvariance/lib/dnanvariance.js | 12 +- .../dnanvariance/lib/dnanvariance.native.js | 9 +- .../stats/base/dnanvariance/lib/index.js | 7 +- .../stats/base/dnanvariance/lib/ndarray.js | 12 +- .../base/dnanvariance/lib/ndarray.native.js | 20 +- .../stats/base/dnanvariance/manifest.json | 45 +++-- .../stats/base/dnanvariance/src/addon.c | 27 ++- .../base/dnanvariance/src/dnanvariance.c | 34 ---- .../stats/base/dnanvariance/src/main.c | 51 +++++ .../dnanvariance/test/test.dnanvariance.js | 13 +- .../test/test.dnanvariance.native.js | 13 +- .../base/dnanvariance/test/test.ndarray.js | 13 +- .../dnanvariance/test/test.ndarray.native.js | 13 +- 24 files changed, 457 insertions(+), 258 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c create mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md index 9b125e03d9c2..a287d25e129a 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md @@ -98,9 +98,9 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); ``` -#### dnanvariance( N, correction, x, stride ) +#### dnanvariance( N, correction, x, strideX ) -Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values. +Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -116,41 +116,38 @@ The function has the following parameters: - **N**: number of indexed elements. - **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: stride length for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] 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 [variance][variance] 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 x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN, NaN ] ); -var v = dnanvariance( N, 1, x, 2 ); +var v = dnanvariance( 5, 1, x, 2 ); // returns 6.25 ``` Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. - + ```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 x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dnanvariance( N, 1, x1, 2 ); +var v = dnanvariance( 5, 1, x1, 2 ); // returns 6.25 ``` -#### dnanvariance.ndarray( N, correction, x, stride, offset ) +#### dnanvariance.ndarray( N, correction, x, strideX, offsetX ) -Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. +Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -163,18 +160,18 @@ var v = dnanvariance.ndarray( x.length, 1, x, 1, 0 ); The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other value in `x` starting from the second value + + ```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 ] ); -var N = floor( x.length / 2 ); +var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); -var v = dnanvariance.ndarray( N, 1, x, 2, 1 ); +var v = dnanvariance.ndarray( 5, 1, x, 2, 1 ); // returns 6.25 ``` @@ -200,18 +197,19 @@ var v = dnanvariance.ndarray( N, 1, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -50.0, 50.0 ); } + +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = dnanvariance( x.length, 1, x, 1 ); @@ -222,6 +220,125 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dnanvariance.h" +``` + +#### stdlib_strided_dnanvariance( N, correction, \*X, strideX ) + +Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values. + +```c +const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; + +double v = stdlib_strided_dnanvariance( 4, 1.0, x, 1 ); +// returns ~4.3333 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +double stdlib_strided_dnanvariance( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnanvariance_ndarray( N, correction, \*X, strideX, offsetX ) + +Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values and alternative indexing semantics. + +```c +const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; + +double v = stdlib_strided_dnanvariance_ndarray( 4, 1.0, x, 1, 0 ); +// returns ~4.3333 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `n-c` where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **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_dnanvariance_ndarray( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dnanvariance.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 variance: + double v = stdlib_strided_dnanvariance( N, 1.0, x, strideX ); + + // Print the result: + printf( "sample variance: %lf\n", v ); +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js index d9a4d9e76d07..ac5a46043f47 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.js @@ -21,16 +21,30 @@ // MODULES // var bench = require( '@stdlib/bench' ); -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 dnanvariance = require( './../lib/dnanvariance.js' ); // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -39,17 +53,7 @@ var dnanvariance = require( './../lib/dnanvariance.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/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js index bf78c30f9d31..36b4add230c7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -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.8 ) < 1 ) { + 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/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js index 94926c91a30f..9edb4ab1122d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.js @@ -21,16 +21,30 @@ // MODULES // var bench = require( '@stdlib/bench' ); -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 dnanvariance = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @private +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -39,17 +53,7 @@ var dnanvariance = 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/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js index edd833823e73..bc51028c025d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -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.8 ) < 1 ) { + 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/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/c/benchmark.length.c index fa2512e14203..351f8629ebcc 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/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; @@ -102,11 +102,16 @@ static double benchmark( int iterations, int len ) { int i; for ( i = 0; i < len; i++ ) { - x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + 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_dnanvariance( len, 1.0, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -120,6 +125,44 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + if ( rand_double() < 0.2 ) { + x[ i ] = 0.0 / 0.0; // NaN + } else { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_dnanvariance_ndarray( len, 1.0, 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 +185,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt index ab3ad6e335d2..72ea56e1862e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, correction, x, stride ) +{{alias}}( N, correction, x, strideX ) Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. - 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. @@ -34,8 +34,8 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -49,22 +49,19 @@ > {{alias}}( x.length, 1, x, 1 ) ~4.3333 - // Using `N` and `stride` parameters: - > x = new {{alias:@stdlib/array/float64}}( [ -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, 1, x, stride ) + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] ); + > {{alias}}( 4, 1, x, 2 ) ~4.3333 // Using view offsets: - > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, 1, x1, stride ) + > {{alias}}( 4, 1, x1, 2 ) ~4.3333 -{{alias}}.ndarray( N, correction, x, stride, offset ) + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. @@ -93,10 +90,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -112,9 +109,8 @@ ~4.3333 // Using offset parameter: - > var x = new {{alias:@stdlib/array/float64}}( [ 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, 1, x, 2, 1 ) + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); + > {{alias}}.ndarray( 4, 1, x, 2, 1 ) ~4.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts index 7bb2784d86fb..8ba39bcd9070 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/docs/types/index.d.ts @@ -28,7 +28,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns variance * * @example @@ -39,7 +39,7 @@ interface Routine { * var v = dnanvariance( x.length, 1, x, 1 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: Float64Array, stride: number ): number; + ( N: number, correction: number, x: Float64Array, strideX: number ): number; /** * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. @@ -47,8 +47,8 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns variance * * @example @@ -59,7 +59,7 @@ interface Routine { * var v = dnanvariance.ndarray( x.length, 1, x, 1, 0 ); * // returns ~4.3333 */ - ndarray( N: number, correction: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, correction: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** @@ -68,7 +68,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns variance * * @example diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c index 0ad819ac00f1..823b22cacffb 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dnanvariance.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 variance: - double v = stdlib_strided_dnanvariance( N, 1, x, stride ); + double v = stdlib_strided_dnanvariance( N, 1.0, x, strideX ); // Print the result: printf( "sample variance: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js index 83755ce2d7fd..83a8e5dc2385 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/examples/index.js @@ -18,22 +18,19 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); var dnanvariance = require( './../lib' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( (randu()*100.0) - 50.0 ); +function rand() { + if ( bernoulli( 0.8 ) < 1 ) { + return NaN; } + return uniform( -50.0, 50.0 ); } + +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = dnanvariance( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h index b78e0d61d149..4663f0444a12 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DNANVARIANCE_H #define STDLIB_STATS_BASE_DNANVARIANCE_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 variance of a double-precision floating-point strided array ignoring `NaN` values. */ -double stdlib_strided_dnanvariance( const int64_t N, const double correction, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js index dc433d62c2ef..c9c3c5227fd4 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.js @@ -20,7 +20,8 @@ // MODULES // -var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -31,20 +32,19 @@ var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} variance * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanvariance( N, 1, x, 1 ); +* var v = dnanvariance( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariance( N, correction, x, stride ) { - return dnanvariancepn( N, correction, x, stride ); +function dnanvariance( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js index 1e89d602c53e..ad3d7b4ddf9c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/dnanvariance.native.js @@ -31,20 +31,19 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} variance * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanvariance( N, 1, x, 1 ); +* var v = dnanvariance( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariance( N, correction, x, stride ) { - return addon( N, correction, x, stride ); +function dnanvariance( N, correction, x, strideX ) { + return addon( N, correction, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js index 47949c9cc894..285b59e96e18 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/index.js @@ -28,20 +28,17 @@ * var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanvariance( N, 1, x, 1 ); +* var v = dnanvariance( x.length, 1, x, 1 ); * // returns ~4.3333 * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanvariance.ndarray( N, 1, x, 2, 1 ); +* var v = dnanvariance.ndarray( 5, 1, x, 2, 1 ); * // returns 6.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js index 78e383cc31b1..e2433522e480 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.js @@ -31,22 +31,20 @@ var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ).ndarray; * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @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} variance * * @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, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanvariance( N, 1, x, 2, 1 ); +* var v = dnanvariance( 5, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariance( N, correction, x, stride, offset ) { - return dnanvariancepn( N, correction, x, stride, offset ); +function dnanvariance( N, correction, x, strideX, offsetX ) { + return dnanvariancepn( N, correction, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js index 6eb4a0ba435f..da5963fbc607 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float64Array = require( '@stdlib/array/float64' ); -var addon = require( './dnanvariance.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,27 +31,20 @@ var addon = require( './dnanvariance.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @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} variance * * @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, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanvariance( N, 1, x, 2, 1 ); +* var v = dnanvariance( 5, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariance( N, correction, 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, correction, view, stride ); +function dnanvariance( N, correction, x, strideX, offsetX ) { + return addon.ndarray( N, correction, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json index ca135dfb5608..4aca007424b6 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/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/dnanvariance.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/stats/base/dnanvariancepn", "@stdlib/napi/export", "@stdlib/napi/argv", @@ -49,33 +51,52 @@ }, { "task": "benchmark", + "wasm" : false, "src": [ - "./src/dnanvariance.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/stats/base/dnanvariancepn" ] }, { "task": "examples", + "wasm" : false, "src": [ - "./src/dnanvariance.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/stats/base/dnanvariancepn" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/stats/base/dnanvariancepn" ] } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c index ed817df01bed..b00fd7060521 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/stats/base/dnanvariance.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -35,11 +36,29 @@ static napi_value addon( 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, stride, argv, 3 ); STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanvariance( N, correction, X, stride ), v ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ) + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanvariance)( N, correction, 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, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( N, correction, 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/dnanvariance/src/dnanvariance.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c deleted file mode 100644 index 13375cf0580d..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/dnanvariance.c +++ /dev/null @@ -1,34 +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/dnanvariance.h" -#include "stdlib/stats/base/dnanvariancepn.h" -#include - -/** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. -* -* @param N number of indexed elements -* @param correction degrees of freedom adjustment -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dnanvariance( const int64_t N, const double correction, const double *X, const int64_t stride ) { - return stdlib_strided_dnanvariancepn( N, correction, X, stride ); -} diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c new file mode 100644 index 000000000000..24693e756881 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c @@ -0,0 +1,51 @@ +/** +* @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/dnanvariance.h" +#include "stdlib/stats/base/dnanvariancepn.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dnanvariancepn_ndarray)( N, correction, X, strideX, ox ); +} + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and alternative indexing semantics. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @param offsetX starting index for X +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + return stdlib_strided_dnanvariancepn_ndarray( N, correction, X, strideX, offsetX ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js index 2ca3f359486f..ba861d5e0773 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.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 dnanvariance = require( './../lib/dnanvariance.js' ); @@ -213,7 +212,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -230,15 +228,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2 ); + v = dnanvariance( 5, 1, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -255,9 +251,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 4.0, // 0 2.0 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, -2 ); + v = dnanvariance( 5, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -295,7 +290,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -313,9 +307,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 = dnanvariance( N, 1, x1, 2 ); + v = dnanvariance( 5, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js index 5e485cb85641..1c24bf5141b2 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.dnanvariance.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' ); @@ -222,7 +221,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -239,15 +237,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2 ); + v = dnanvariance( 5, 1, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; var i; @@ -264,9 +260,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 4.0, // 0 2.0 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, -2 ); + v = dnanvariance( 5, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -304,7 +299,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -322,9 +316,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 = dnanvariance( N, 1, x1, 2 ); + v = dnanvariance( 5, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js index 3e8dffe868f7..fdfbdb552e91 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/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 dnanvariance = require( './../lib/ndarray.js' ); @@ -213,7 +212,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -230,15 +228,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2, 0 ); + v = dnanvariance( 5, 1, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; var i; @@ -255,9 +251,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 4.0, // 0 2.0 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, -2, 8 ); + v = dnanvariance( 5, 1, x, -2, 8 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -293,7 +288,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -309,9 +303,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2, 1 ); + v = dnanvariance( 5, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js index 3c6dc17258f4..6a525ab58914 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/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' ); @@ -222,7 +221,6 @@ tape( 'if provided a `correction` parameter yielding a correction term less than }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -239,15 +237,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2, 0 ); + v = dnanvariance( 5, 1, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; var i; @@ -264,9 +260,8 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 4.0, // 0 2.0 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, -2, 8 ); + v = dnanvariance( 5, 1, x, -2, 8 ); t.strictEqual( v, 6.25, 'returns expected value' ); x = new Float64Array( 1e3 ); @@ -302,7 +297,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` p }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -318,9 +312,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanvariance( N, 1, x, 2, 1 ); + v = dnanvariance( 5, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From e03088e6cd9ae3dc6550bfc7375c0a82659fee0a Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 23 Feb 2025 19:38:49 +0530 Subject: [PATCH 4/8] chore: update according to code review --- 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: 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 --- --- 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: passed - 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/dnanvariance/README.md | 4 ++-- .../dnanvariance/include/stdlib/stats/base/dnanvariance.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md index a287d25e129a..47e670a3519d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md @@ -100,7 +100,7 @@ var dnanvariance = require( '@stdlib/stats/base/dnanvariance' ); #### dnanvariance( N, correction, x, strideX ) -Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values. +Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values. ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -162,7 +162,7 @@ The function has the following additional parameters: - **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 [variance][variance] 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 [variance][variance] for every other element in `x` starting from the second element diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h index 4663f0444a12..3aefd43698da 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h @@ -29,12 +29,12 @@ extern "C" { #endif /** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. +* Computes the variance of a double-precision floating-point strided array, ignoring `NaN` values. */ double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); /** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and alternative indexing semantics. +* Computes the variance of a double-precision floating-point strided array, ignoring `NaN` values and alternative indexing semantics. */ double API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); From 6da38d242f3478bff99000451001adf26446bcd0 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 11 Mar 2025 22:00:26 +0530 Subject: [PATCH 5/8] fix: removed unwanted header files. Signed-off-by: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c index 24693e756881..1064db371c18 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c @@ -20,7 +20,6 @@ #include "stdlib/stats/base/dnanvariancepn.h" #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" -#include /** * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values. @@ -47,5 +46,5 @@ double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double * @return output value */ double API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - return stdlib_strided_dnanvariancepn_ndarray( N, correction, X, strideX, offsetX ); + return API_SUFFIX(stdlib_strided_dnanvariancepn_ndarray)( N, correction, X, strideX, offsetX ); } From 4310155e39c3888923480d1cd7f8b805e46c2024 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Fri, 14 Mar 2025 17:33:24 +0530 Subject: [PATCH 6/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/dnanvariance/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json index 4aca007424b6..b30178050e39 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/manifest.json @@ -84,7 +84,7 @@ ] }, { - "task": "", + "task": "build", "wasm": true, "src": [ "./src/main.c" From 7751a929dcae9562316eee10ed19280cd8de08a0 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 14 Mar 2025 18:46:17 -0700 Subject: [PATCH 7/8] docs: fix description Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/dnanvariance/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md index 47e670a3519d..6bac8378bd9c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/README.md @@ -270,7 +270,7 @@ double stdlib_strided_dnanvariance( const CBLAS_INT N, const double correction, #### stdlib_strided_dnanvariance_ndarray( N, correction, \*X, strideX, offsetX ) -Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values and alternative indexing semantics. +Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. ```c const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; From f9192a0c9ec8bcf73b0261cf985eb9ef11a15468 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 14 Mar 2025 18:49:38 -0700 Subject: [PATCH 8/8] Apply suggestions from code review Signed-off-by: Athan --- .../base/dnanvariance/include/stdlib/stats/base/dnanvariance.h | 2 +- lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h index 3aefd43698da..61fa856fd812 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/include/stdlib/stats/base/dnanvariance.h @@ -34,7 +34,7 @@ extern "C" { double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); /** -* Computes the variance of a double-precision floating-point strided array, ignoring `NaN` values and alternative indexing semantics. +* Computes the variance of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. */ double API_SUFFIX(stdlib_strided_dnanvariance_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c index 1064db371c18..d0841a9111b4 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariance/src/main.c @@ -36,7 +36,7 @@ double API_SUFFIX(stdlib_strided_dnanvariance)( const CBLAS_INT N, const double } /** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and alternative indexing semantics. +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using alternative indexing semantics. * * @param N number of indexed elements * @param correction degrees of freedom adjustment