From 3cb0dd01bfc5fac6b64d991736bd79bf5f91a08a Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 21 Jan 2025 23:18:18 +0530 Subject: [PATCH 01/24] 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 --- --- .../stats/base/dnanvariancepn/README.md | 164 ++++++++++-- .../dnanvariancepn/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/dnanvariancepn/docs/repl.txt | 38 ++- .../base/dnanvariancepn/docs/types/index.d.ts | 12 +- .../base/dnanvariancepn/examples/c/example.c | 9 +- .../base/dnanvariancepn/examples/index.js | 22 +- .../stdlib/stats/base/dnanvariancepn.h | 9 +- .../base/dnanvariancepn/lib/dnansumpw.js | 34 ++- .../base/dnanvariancepn/lib/dnanvariancepn.js | 65 +---- .../lib/dnanvariancepn.native.js | 9 +- .../stats/base/dnanvariancepn/lib/index.js | 7 +- .../stats/base/dnanvariancepn/lib/ndarray.js | 20 +- .../base/dnanvariancepn/lib/ndarray.native.js | 20 +- .../stats/base/dnanvariancepn/manifest.json | 52 ++-- .../stats/base/dnanvariancepn/src/addon.c | 29 ++- .../stats/base/dnanvariancepn/src/main.c | 238 ++++++++++++++++++ .../test/test.dnanvariancepn.js | 13 +- .../test/test.dnanvariancepn.native.js | 13 +- .../base/dnanvariancepn/test/test.ndarray.js | 13 +- .../test/test.ndarray.native.js | 13 +- 24 files changed, 661 insertions(+), 299 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md index a096d2bcc40d..2c2392dd5c06 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md @@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); ``` -#### dnanvariancepn( N, correction, x, stride ) +#### dnanvariancepn( N, correction, x, strideX ) Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values and using a two-pass algorithm. @@ -116,18 +116,16 @@ 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 v = dnanvariancepn( N, 1, x, 2 ); +var v = dnanvariancepn( 5, 1, x, 2 ); // returns 6.25 ``` @@ -137,18 +135,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dnanvariancepn( N, 1, x1, 2 ); +var v = dnanvariancepn( 4, 1, x1, 2 ); // returns 6.25 ``` -#### dnanvariancepn.ndarray( N, correction, x, stride, offset ) +#### dnanvariancepn.ndarray( N, correction, x, strideX, offsetX ) Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm and alternative indexing semantics. @@ -163,18 +158,16 @@ var v = dnanvariancepn.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 +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 ```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 v = dnanvariancepn.ndarray( N, 1, x, 2, 1 ); +var v = dnanvariancepn.ndarray( 4, 1, x, 2, 1 ); // returns 6.25 ``` @@ -200,19 +193,19 @@ var v = dnanvariancepn.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 dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); -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 ); } -console.log( x ); + +var x = filledarrayBy( 10, 'float64', rand ); var v = dnanvariancepn( x.length, 1, x, 1 ); console.log( v ); @@ -222,6 +215,125 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dnanvariancepn.h" +``` + +#### stdlib_strided_dnanvariancepn( N, correction, \*X, strideX ) + +Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values and using a two-pass algorithm. + +```c +const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; + +double v = stdlib_strided_dnanvariancepn( 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_dnanvariancepn( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnanvariancepn_ndarray( N, correction, \*X, strideX, offsetX ) + +Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm and alternative indexing semantics. + +```c +const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; + +double v = stdlib_strided_dnanvariancepn_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_dnanvariancepn_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/dnanvariancepn.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_dnanvariancepn( N, 1.0, x, strideX ); + + // Print the result: + printf( "sample variance: %lf\n", v ); +} +``` + +
+ + + +
+ + + * * *
diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.js index 938fb06d261c..7693bcc04538 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 dnanvariancepn = require( './../lib/dnanvariancepn.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 dnanvariancepn = require( './../lib/dnanvariancepn.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/dnanvariancepn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.native.js index 8f55e745acf0..b40859f8428d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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/dnanvariancepn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.ndarray.js index f643f79be93c..ae3f65a66ad1 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 dnanvariancepn = 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 dnanvariancepn = 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/dnanvariancepn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.ndarray.native.js index 22820da65b55..400968b5ae70 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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/dnanvariancepn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/c/benchmark.length.c index 2b1e4f8fc994..13c9d9e7fc35 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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_dnanvariancepn( 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_dnanvariancepn_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/dnanvariancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt index ec5c6b14c7f3..f16ec33e9f38 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 and using a two-pass algorithm. - 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 ------- @@ -45,29 +45,26 @@ Examples -------- // Standard Usage: - > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, NaN, 2.0 ] ); + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); > {{alias}}( x.length, 1, x, 1 ) ~4.3333 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, 1, x, stride ) + > {{alias}}( 3, 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 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}}( 3, 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 a two-pass algorithm and alternative - indexing semantics. + ignoring `NaN` values and using a one-pass trial mean algorithm and + alternative indexing semantics. While typed array views mandate a view offset based on the underlying buffer, the `offset` parameter supports indexing semantics based on a @@ -94,10 +91,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -114,8 +111,7 @@ // 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 ) + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) ~4.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/types/index.d.ts index 7a095f9ad539..abfb3a863547 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 = dnanvariancepn( 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 a two-pass algorithm and 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 = dnanvariancepn.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/dnanvariancepn/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/c/example.c index d557e4a16994..bdcfe68be923 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dnanvariancepn.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_dnanvariancepn( N, 1, x, stride ); + double v = stdlib_strided_dnanvariancepn( N, 1.0, x, strideX ); // Print the result: printf( "sample variance: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js index 9487e47461ee..be811562b964 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js @@ -18,23 +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 dnanvariancepn = 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 ); } -console.log( x ); + +var x = filledarrayBy( 10, 'float64', rand ); var v = dnanvariancepn( x.length, 1, x, 1 ); console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/include/stdlib/stats/base/dnanvariancepn.h b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/include/stdlib/stats/base/dnanvariancepn.h index 852e2dfe777e..8ad23b4ebb2a 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/include/stdlib/stats/base/dnanvariancepn.h +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/include/stdlib/stats/base/dnanvariancepn.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DNANVARIANCEPN_H #define STDLIB_STATS_BASE_DNANVARIANCEPN_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 and using a two-pass algorithm. */ -double stdlib_strided_dnanvariancepn( const int64_t N, const double correction, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnanvariancepn)( 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 using a two-pass algorithm and alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dnanvariancepn_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/dnanvariancepn/lib/dnansumpw.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js index 46988a3c2679..cd66a8d7dd8c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js @@ -46,22 +46,20 @@ var BLOCKSIZE = 128; * @param {PositiveInteger} N - number of indexed elements * @param {NumericArray} out - two-element output array whose first element is the accumulated sum and whose second element is the accumulated number of summed values * @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 {NumericArray} output array * * @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 out = [ 0.0, 0 ]; -* var v = dnansumpw( N, out, x, 2, 1 ); +* var v = dnansumpw( 5, out, x, 2, 1 ); * // returns [ 5.0, 4 ] */ -function dnansumpw( N, out, x, stride, offset ) { +function dnansumpw( N, out, x, strideX, offsetX ) { var ix; var s0; var s1; @@ -77,7 +75,7 @@ function dnansumpw( N, out, x, stride, offset ) { var v; var i; - ix = offset; + ix = offsetX; if ( N < 8 ) { // Use simple summation... s = 0.0; @@ -88,7 +86,7 @@ function dnansumpw( N, out, x, stride, offset ) { s += v; n += 1; } - ix += stride; + ix += strideX; } out[ 0 ] += s; out[ 1 ] += n; @@ -113,49 +111,49 @@ function dnansumpw( N, out, x, stride, offset ) { s0 += v; n += 1; } - ix += stride; + ix += strideX; v = x[ ix ]; if ( v === v ) { s1 += v; n += 1; } - ix += stride; + ix += strideX; v = x[ ix ]; if ( v === v ) { s2 += v; n += 1; } - ix += stride; + ix += strideX; v = x[ ix ]; if ( v === v ) { s3 += v; n += 1; } - ix += stride; + ix += strideX; v = x[ ix ]; if ( v === v ) { s4 += v; n += 1; } - ix += stride; + ix += strideX; v = x[ ix ]; if ( v === v ) { s5 += v; n += 1; } - ix += stride; + ix += strideX; v = x[ ix ]; if ( v === v ) { s6 += v; n += 1; } - ix += stride; + ix += strideX; v = x[ ix ]; if ( v === v ) { s7 += v; n += 1; } - ix += stride; + ix += strideX; } // Pairwise sum the accumulators: s = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); @@ -167,7 +165,7 @@ function dnansumpw( N, out, x, stride, offset ) { s += v; n += 1; } - ix += stride; + ix += strideX; } out[ 0 ] += s; out[ 1 ] += n; @@ -176,7 +174,7 @@ function dnansumpw( N, out, x, stride, offset ) { // Recurse by dividing by two, but avoiding non-multiples of unroll factor... n = floor( N/2 ); n -= n % 8; - return dnansumpw( n, out, x, stride, ix ) + dnansumpw( N-n, out, x, stride, ix+(n*stride) ); // eslint-disable-line max-len + return dnansumpw( n, out, x, strideX, ix ) + dnansumpw( N-n, out, x, strideX, ix+(n*strideX) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.js index 903162954441..73a686d31ff0 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.js @@ -20,12 +20,8 @@ // MODULES // -var dnansumpw = require( './dnansumpw.js' ); - - -// VARIABLES // - -var WORKSPACE = [ 0.0, 0 ]; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -45,68 +41,19 @@ var WORKSPACE = [ 0.0, 0 ]; * @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 = dnanvariancepn( N, 1, x, 1 ); +* var v = dnanvariancepn( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariancepn( N, correction, x, stride ) { - var mu; - var ix; - var M2; - var nc; - var M; - var d; - var v; - var n; - var i; - - if ( N <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - v = x[ 0 ]; - if ( v === v && N-correction > 0.0 ) { - return 0.0; - } - return NaN; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - // Compute an estimate for the mean... - WORKSPACE[ 0 ] = 0.0; - WORKSPACE[ 1 ] = 0; - dnansumpw( N, WORKSPACE, x, stride, ix ); - n = WORKSPACE[ 1 ]; - nc = n - correction; - if ( nc <= 0.0 ) { - return NaN; - } - mu = WORKSPACE[ 0 ] / n; - - // Compute the variance... - M2 = 0.0; - M = 0.0; - for ( i = 0; i < N; i++ ) { - v = x[ ix ]; - if ( v === v ) { - d = v - mu; - M2 += d * d; - M += d; - } - ix += stride; - } - return (M2/nc) - ((M/n)*(M/nc)); +function dnanvariancepn( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.native.js index 2c5bdb7a5bcb..004c519526ff 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.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 = dnanvariancepn( N, 1, x, 1 ); +* var v = dnanvariancepn( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariancepn( N, correction, x, stride ) { - return addon( N, correction, x, stride ); +function dnanvariancepn( N, correction, x, strideX ) { + return addon( N, correction, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/index.js index 9573909ea075..2d2bb09d5364 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/index.js @@ -28,20 +28,17 @@ * var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanvariancepn( N, 1, x, 1 ); +* var v = dnanvariancepn( x.length, 1, x, 1 ); * // returns ~4.3333 * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); * * 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 = dnanvariancepn.ndarray( N, 1, x, 2, 1 ); +* var v = dnanvariancepn.ndarray( 5, 1, x, 2, 1 ); * // returns 6.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js index 8f191ce6329f..0944045ffd28 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js @@ -45,21 +45,19 @@ var WORKSPACE = [ 0.0, 0 ]; * @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 = dnanvariancepn( N, 1, x, 2, 1 ); +* var v = dnanvariancepn( 5, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariancepn( N, correction, x, stride, offset ) { +function dnanvariancepn( N, correction, x, strideX, offsetX ) { var mu; var ix; var M2; @@ -73,8 +71,8 @@ function dnanvariancepn( N, correction, x, stride, offset ) { if ( N <= 0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { - v = x[ offset ]; + if ( N === 1 || strideX === 0 ) { + v = x[ offsetX ]; if ( v === v && N-correction > 0.0 ) { return 0.0; } @@ -83,7 +81,7 @@ function dnanvariancepn( N, correction, x, stride, offset ) { // Compute an estimate for the mean... WORKSPACE[ 0 ] = 0.0; WORKSPACE[ 1 ] = 0; - dnansumpw( N, WORKSPACE, x, stride, offset ); + dnansumpw( N, WORKSPACE, x, strideX, offsetX ); n = WORKSPACE[ 1 ]; nc = n - correction; if ( nc <= 0.0 ) { @@ -92,7 +90,7 @@ function dnanvariancepn( N, correction, x, stride, offset ) { mu = WORKSPACE[ 0 ] / n; // Compute the variance... - ix = offset; + ix = offsetX; M2 = 0.0; M = 0.0; for ( i = 0; i < N; i++ ) { @@ -102,7 +100,7 @@ function dnanvariancepn( N, correction, x, stride, offset ) { M2 += d * d; M += d; } - ix += stride; + ix += strideX; } return (M2/nc) - ((M/n)*(M/nc)); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.native.js index d9c7b94fa746..41228aad6f93 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float64Array = require( '@stdlib/array/float64' ); -var addon = require( './dnanvariancepn.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,27 +31,20 @@ var addon = require( './dnanvariancepn.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 = dnanvariancepn( N, 1, x, 2, 1 ); +* var v = dnanvariancepn( 5, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariancepn( 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 dnanvariancepn( N, correction, x, strideX, offsetX ) { + return addon.ndarray( N, correction, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json index 078ba0d29817..86308d31795d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json @@ -1,5 +1,8 @@ { - "options": {}, + "options": { + "task": "build", + "wasm": false + }, "fields": [ { "field": "src", @@ -25,17 +28,18 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ - "./src/dnanvariancepn.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -46,31 +50,51 @@ }, { "task": "benchmark", + "wasm": false, "src": [ - "./src/dnanvariancepn.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { "task": "examples", + "wasm": false, "src": [ - "./src/dnanvariancepn.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" ], + "include": [ + "./include" + ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] } ] } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c index 8c95a6675498..489ed0e96699 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ */ #include "stdlib/stats/base/dnanvariancepn.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_dnanvariancepn( 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_dnanvariancepn)( 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_dnanvariancepn_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/dnanvariancepn/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c new file mode 100644 index 000000000000..1d14b10a13e7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c @@ -0,0 +1,238 @@ +/** +* @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/dnanvariancepn.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. +* +* ## Method +* +* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`. +* +* ## References +* +* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050). +* +* @param N number of indexed elements +* @param W two-element output array +* @param X input array +* @param stride stride length +* @return output value +*/ +static void API_SUFFIX(dnansumpw)( const CBLAS_INT N, double *W, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + double sum; + CBLAS_INT ix; + CBLAS_INT M; + CBLAS_INT n; + CBLAS_INT i; + double s0; + double s1; + double s2; + double s3; + double s4; + double s5; + double s6; + double s7; + double v; + + ix = offsetX; + if ( N < 8 ) { + // Use simple summation... + sum = 0.0; + n = 0; + for ( i = 0; i < N; i++ ) { + v = X[ ix ]; + if ( v == v ) { + sum += X[ ix ]; + n += 1; + } + ix += strideX; + } + W[ 0 ] += sum; + W[ 1 ] += n; + return; + } + // Blocksize for pairwise summation: 128 (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.) + if ( N <= 128 ) { + // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... + s0 = 0.0; + s1 = 0.0; + s2 = 0.0; + s3 = 0.0; + s4 = 0.0; + s5 = 0.0; + s6 = 0.0; + s7 = 0.0; + n = 0; + + M = N % 8; + for ( i = 0; i < N-M; i += 8 ) { + v = X[ ix ]; + if ( v == v ) { + s0 += v; + n += 1; + } + ix += strideX; + v = X[ ix ]; + if ( v == v ) { + s1 += v; + n += 1; + } + ix += strideX; + v = X[ ix ]; + if ( v == v ) { + s2 += v; + n += 1; + } + ix += strideX; + v = X[ ix ]; + if ( v == v ) { + s3 += v; + n += 1; + } + ix += strideX; + v = X[ ix ]; + if ( v == v ) { + s4 += v; + n += 1; + } + ix += strideX; + v = X[ ix ]; + if ( v == v ) { + s5 += v; + n += 1; + } + ix += strideX; + v = X[ ix ]; + if ( v == v ) { + s6 += v; + n += 1; + } + ix += strideX; + v = X[ ix ]; + if ( v == v ) { + s7 += v; + n += 1; + } + ix += strideX; + } + // Pairwise sum the accumulators: + sum = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); + + // Clean-up loop... + for (; i < N; i++ ) { + v = X[ ix ]; + if ( v == v ) { + sum += X[ ix ]; + n += 1; + } + ix += strideX; + } + W[ 0 ] += sum; + W[ 1 ] += n; + return; + } + // Recurse by dividing by two, but avoiding non-multiples of unroll factor... + n = N / 2; + n -= n % 8; + API_SUFFIX(dnansumpw)( n, W, X, strideX, ix ); + API_SUFFIX(dnansumpw)( N-n, W, X, strideX, ix+(n*strideX) ); +} + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm. +* +* ## Method +* +* - This implementation uses a two-pass approach, as suggested by Neely (1966). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param stride stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanvariancepn)( 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 using a two-pass algorithm 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_dnanvariancepn_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + double W[] = { 0.0, 0.0 }; + CBLAS_INT ix; + CBLAS_INT i; + double mu; + double M2; + double nc; + double M; + double n; + double d; + double v; + + if ( N <= 0 ) { + return 0.0 / 0.0; // NaN + } + if ( N == 1 || strideX == 0 ) { + v = X[ 0 ]; + if ( v == v && (double)N-correction > 0.0 ) { + return 0.0; + } + return 0.0 / 0.0; // NaN + } + // Compute an estimate for the mean... + API_SUFFIX(dnansumpw)( N, W, X, strideX, offsetX ); + n = W[ 1 ]; + nc = n - correction; + if ( nc <= 0.0 ) { + return 0.0 / 0.0; // NaN + } + ix = offsetX; + mu = W[ 0 ] / n; + + // Compute the variance... + M2 = 0.0; + M = 0.0; + for ( i = 0; i < N; i++ ) { + v = X[ ix ]; + if ( v == v ) { + d = v - mu; + M2 += d * d; + M += d; + } + ix += strideX; + } + return (M2/nc) - ((M/n)*(M/nc)); +} diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.js index edd5606a6beb..809bfe9e6702 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.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 dnanvariancepn = require( './../lib/dnanvariancepn.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 = dnanvariancepn( N, 1, x, 2 ); + v = dnanvariancepn( 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 = dnanvariancepn( N, 1, x, -2 ); + v = dnanvariancepn( 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 = dnanvariancepn( N, 1, x1, 2 ); + v = dnanvariancepn( 5, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.native.js index 0e25d2f49446..21c9f75a9a85 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.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 = dnanvariancepn( N, 1, x, 2 ); + v = dnanvariancepn( 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 = dnanvariancepn( N, 1, x, -2 ); + v = dnanvariancepn( 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 = dnanvariancepn( N, 1, x1, 2 ); + v = dnanvariancepn( 5, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.js index ead3999c04a1..94ec373a067f 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 dnanvariancepn = 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 = dnanvariancepn( N, 1, x, 2, 0 ); + v = dnanvariancepn( 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 = dnanvariancepn( N, 1, x, -2, 8 ); + v = dnanvariancepn( 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 = dnanvariancepn( N, 1, x, 2, 1 ); + v = dnanvariancepn( 5, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.native.js index 93d05f14a494..5a80601b2f3d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 = dnanvariancepn( N, 1, x, 2, 0 ); + v = dnanvariancepn( 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 = dnanvariancepn( N, 1, x, -2, 8 ); + v = dnanvariancepn( 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 = dnanvariancepn( N, 1, x, 2, 1 ); + v = dnanvariancepn( 5, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From 9cfa46a73c5c48171883929eadb46b38d50f60df Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 21 Jan 2025 23:20:13 +0530 Subject: [PATCH 02/24] chore: removed unwanted files --- 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 --- --- 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 --- --- .../base/dnanvariancepn/src/dnanvariancepn.c | 239 ------------------ 1 file changed, 239 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/dnanvariancepn.c diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/dnanvariancepn.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/dnanvariancepn.c deleted file mode 100644 index f2ee669c48f7..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/dnanvariancepn.c +++ /dev/null @@ -1,239 +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/dnanvariancepn.h" -#include - -/** -* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. -* -* ## Method -* -* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`. -* -* ## References -* -* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050). -* -* @param N number of indexed elements -* @param W two-element output array -* @param X input array -* @param stride stride length -* @return output value -*/ -static void dnansumpw( const int64_t N, double *W, const double *X, const int64_t stride ) { - double *xp1; - double *xp2; - double sum; - int64_t ix; - int64_t M; - int64_t n; - int64_t i; - double s0; - double s1; - double s2; - double s3; - double s4; - double s5; - double s6; - double s7; - double v; - - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - if ( N < 8 ) { - // Use simple summation... - sum = 0.0; - n = 0; - for ( i = 0; i < N; i++ ) { - v = X[ ix ]; - if ( v == v ) { - sum += X[ ix ]; - n += 1; - } - ix += stride; - } - W[ 0 ] += sum; - W[ 1 ] += n; - return; - } - // Blocksize for pairwise summation: 128 (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.) - if ( N <= 128 ) { - // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... - s0 = 0.0; - s1 = 0.0; - s2 = 0.0; - s3 = 0.0; - s4 = 0.0; - s5 = 0.0; - s6 = 0.0; - s7 = 0.0; - n = 0; - - M = N % 8; - for ( i = 0; i < N-M; i += 8 ) { - v = X[ ix ]; - if ( v == v ) { - s0 += v; - n += 1; - } - ix += stride; - v = X[ ix ]; - if ( v == v ) { - s1 += v; - n += 1; - } - ix += stride; - v = X[ ix ]; - if ( v == v ) { - s2 += v; - n += 1; - } - ix += stride; - v = X[ ix ]; - if ( v == v ) { - s3 += v; - n += 1; - } - ix += stride; - v = X[ ix ]; - if ( v == v ) { - s4 += v; - n += 1; - } - ix += stride; - v = X[ ix ]; - if ( v == v ) { - s5 += v; - n += 1; - } - ix += stride; - v = X[ ix ]; - if ( v == v ) { - s6 += v; - n += 1; - } - ix += stride; - v = X[ ix ]; - if ( v == v ) { - s7 += v; - n += 1; - } - ix += stride; - } - // Pairwise sum the accumulators: - sum = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); - - // Clean-up loop... - for (; i < N; i++ ) { - v = X[ ix ]; - if ( v == v ) { - sum += X[ ix ]; - n += 1; - } - ix += stride; - } - W[ 0 ] += sum; - W[ 1 ] += n; - return; - } - // Recurse by dividing by two, but avoiding non-multiples of unroll factor... - n = N / 2; - n -= n % 8; - if ( stride < 0 ) { - xp1 = (double *)X + ( (n-N)*stride ); - xp2 = (double *)X; - } else { - xp1 = (double *)X; - xp2 = (double *)X + ( n*stride ); - } - dnansumpw( n, W, xp1, stride ); - dnansumpw( N-n, W, xp2, stride ); -} - -/** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm. -* -* ## Method -* -* - This implementation uses a two-pass approach, as suggested by Neely (1966). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @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_dnanvariancepn( const int64_t N, const double correction, const double *X, const int64_t stride ) { - double W[] = { 0.0, 0.0 }; - int64_t ix; - int64_t i; - double mu; - double M2; - double nc; - double M; - double n; - double d; - double v; - - if ( N <= 0 ) { - return 0.0 / 0.0; // NaN - } - if ( N == 1 || stride == 0 ) { - v = X[ 0 ]; - if ( v == v && (double)N-correction > 0.0 ) { - return 0.0; - } - return 0.0 / 0.0; // NaN - } - // Compute an estimate for the mean... - dnansumpw( N, W, X, stride ); - n = W[ 1 ]; - nc = n - correction; - if ( nc <= 0.0 ) { - return 0.0 / 0.0; // NaN - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - mu = W[ 0 ] / n; - - // Compute the variance... - M2 = 0.0; - M = 0.0; - for ( i = 0; i < N; i++ ) { - v = X[ ix ]; - if ( v == v ) { - d = v - mu; - M2 += d * d; - M += d; - } - ix += stride; - } - return (M2/nc) - ((M/n)*(M/nc)); -} From 8dfaa481cae66acb4abd56bcc771bdb799395fd2 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:17:17 +0530 Subject: [PATCH 03/24] chore: updated 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: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - 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: passed - 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/dnanvariancepn/README.md | 1 + .../@stdlib/stats/base/dnanvariancepn/docs/repl.txt | 4 ++-- .../@stdlib/stats/base/dnanvariancepn/examples/index.js | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md index 2c2392dd5c06..9d9dba6c13bb 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md @@ -206,6 +206,7 @@ function rand() { } var x = filledarrayBy( 10, 'float64', rand ); +console.log( x ); var v = dnanvariancepn( x.length, 1, x, 1 ); console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt index f16ec33e9f38..942132dbdc94 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt @@ -63,8 +63,8 @@ {{alias}}.ndarray( N, correction, x, strideX, offsetX ) Computes the variance of a double-precision floating-point strided array - ignoring `NaN` values and using a one-pass trial mean algorithm and - alternative indexing semantics. + ignoring `NaN` values and using a two-pass algorithm and alternative + indexing semantics. While typed array views mandate a view offset based on the underlying buffer, the `offset` parameter supports indexing semantics based on a diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js index be811562b964..e48ab79ce477 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js @@ -31,6 +31,7 @@ function rand() { } var x = filledarrayBy( 10, 'float64', rand ); +console.log( x ); var v = dnanvariancepn( x.length, 1, x, 1 ); console.log( v ); From c75eeb312dac925231dbd3377dbf6a6d7a5087be Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:24:07 +0530 Subject: [PATCH 04/24] chore: formated the params --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/stats/base/dnanvariancepn/src/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c index 1d14b10a13e7..938c10731db6 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c @@ -34,15 +34,15 @@ * @param N number of indexed elements * @param W two-element output array * @param X input array -* @param stride stride length +* @param stridex stride length * @return output value */ static void API_SUFFIX(dnansumpw)( const CBLAS_INT N, double *W, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - double sum; CBLAS_INT ix; CBLAS_INT M; CBLAS_INT n; CBLAS_INT i; + double sum; double s0; double s1; double s2; @@ -172,7 +172,7 @@ static void API_SUFFIX(dnansumpw)( const CBLAS_INT N, double *W, const double *X * @param N number of indexed elements * @param correction degrees of freedom adjustment * @param X input array -* @param stride stride length +* @param stridex stride length * @return output value */ double API_SUFFIX(stdlib_strided_dnanvariancepn)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ) { From 3e57d575f41da2f573ffe08e8de8b935ef42bbda Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Fri, 31 Jan 2025 18:04:30 +0530 Subject: [PATCH 05/24] fix: add external dependencies and remove internal dependencies --- 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: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../stats/base/dnanvariancepn/lib/ndarray.js | 4 +- .../stats/base/dnanvariancepn/manifest.json | 4 + .../stats/base/dnanvariancepn/src/main.c | 151 +----------------- 3 files changed, 13 insertions(+), 146 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js index 0944045ffd28..18cb4c72b2a1 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var dnansumpw = require( './dnansumpw.js' ); +var dnannsumpw = require( '@stdlib/blas/ext/base/dnannsumpw' ).ndarray; // VARIABLES // @@ -81,7 +81,7 @@ function dnanvariancepn( N, correction, x, strideX, offsetX ) { // Compute an estimate for the mean... WORKSPACE[ 0 ] = 0.0; WORKSPACE[ 1 ] = 0; - dnansumpw( N, WORKSPACE, x, strideX, offsetX ); + dnannsumpw( N, x, strideX, offsetX, WORKSPACE, 1, 0 ); n = WORKSPACE[ 1 ]; nc = n - correction; if ( nc <= 0.0 ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json index 86308d31795d..ddb23a2b34e7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json @@ -44,6 +44,7 @@ "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-double", + "@stdlib/blas/ext/base/dnannsumpw", "@stdlib/napi/argv-strided-float64array", "@stdlib/napi/create-double" ] @@ -61,6 +62,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dnannsumpw", "@stdlib/strided/base/stride2offset" ] }, @@ -77,6 +79,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dnannsumpw", "@stdlib/strided/base/stride2offset" ] }, @@ -93,6 +96,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/ext/base/dnannsumpw", "@stdlib/strided/base/stride2offset" ] } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c index 938c10731db6..277dd4140d34 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c @@ -17,146 +17,10 @@ */ #include "stdlib/stats/base/dnanvariancepn.h" +#include "stdlib/blas/ext/base/dnannsumpw.h" #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" -/** -* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. -* -* ## Method -* -* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`. -* -* ## References -* -* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050). -* -* @param N number of indexed elements -* @param W two-element output array -* @param X input array -* @param stridex stride length -* @return output value -*/ -static void API_SUFFIX(dnansumpw)( const CBLAS_INT N, double *W, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - CBLAS_INT ix; - CBLAS_INT M; - CBLAS_INT n; - CBLAS_INT i; - double sum; - double s0; - double s1; - double s2; - double s3; - double s4; - double s5; - double s6; - double s7; - double v; - - ix = offsetX; - if ( N < 8 ) { - // Use simple summation... - sum = 0.0; - n = 0; - for ( i = 0; i < N; i++ ) { - v = X[ ix ]; - if ( v == v ) { - sum += X[ ix ]; - n += 1; - } - ix += strideX; - } - W[ 0 ] += sum; - W[ 1 ] += n; - return; - } - // Blocksize for pairwise summation: 128 (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.) - if ( N <= 128 ) { - // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... - s0 = 0.0; - s1 = 0.0; - s2 = 0.0; - s3 = 0.0; - s4 = 0.0; - s5 = 0.0; - s6 = 0.0; - s7 = 0.0; - n = 0; - - M = N % 8; - for ( i = 0; i < N-M; i += 8 ) { - v = X[ ix ]; - if ( v == v ) { - s0 += v; - n += 1; - } - ix += strideX; - v = X[ ix ]; - if ( v == v ) { - s1 += v; - n += 1; - } - ix += strideX; - v = X[ ix ]; - if ( v == v ) { - s2 += v; - n += 1; - } - ix += strideX; - v = X[ ix ]; - if ( v == v ) { - s3 += v; - n += 1; - } - ix += strideX; - v = X[ ix ]; - if ( v == v ) { - s4 += v; - n += 1; - } - ix += strideX; - v = X[ ix ]; - if ( v == v ) { - s5 += v; - n += 1; - } - ix += strideX; - v = X[ ix ]; - if ( v == v ) { - s6 += v; - n += 1; - } - ix += strideX; - v = X[ ix ]; - if ( v == v ) { - s7 += v; - n += 1; - } - ix += strideX; - } - // Pairwise sum the accumulators: - sum = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); - - // Clean-up loop... - for (; i < N; i++ ) { - v = X[ ix ]; - if ( v == v ) { - sum += X[ ix ]; - n += 1; - } - ix += strideX; - } - W[ 0 ] += sum; - W[ 1 ] += n; - return; - } - // Recurse by dividing by two, but avoiding non-multiples of unroll factor... - n = N / 2; - n -= n % 8; - API_SUFFIX(dnansumpw)( n, W, X, strideX, ix ); - API_SUFFIX(dnansumpw)( N-n, W, X, strideX, ix+(n*strideX) ); -} - /** * Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm. * @@ -191,14 +55,14 @@ double API_SUFFIX(stdlib_strided_dnanvariancepn)( const CBLAS_INT N, const doubl * @return output value */ double API_SUFFIX(stdlib_strided_dnanvariancepn_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - double W[] = { 0.0, 0.0 }; CBLAS_INT ix; CBLAS_INT i; + CBLAS_INT n; + double sum; double mu; double M2; double nc; double M; - double n; double d; double v; @@ -213,14 +77,13 @@ double API_SUFFIX(stdlib_strided_dnanvariancepn_ndarray)( const CBLAS_INT N, con return 0.0 / 0.0; // NaN } // Compute an estimate for the mean... - API_SUFFIX(dnansumpw)( N, W, X, strideX, offsetX ); - n = W[ 1 ]; - nc = n - correction; + sum = API_SUFFIX(stdlib_strided_dnannsumpw_ndarray)( N, X, strideX, offsetX, &n ); + nc =(double)n - correction; if ( nc <= 0.0 ) { return 0.0 / 0.0; // NaN } ix = offsetX; - mu = W[ 0 ] / n; + mu = sum / (double)n; // Compute the variance... M2 = 0.0; @@ -234,5 +97,5 @@ double API_SUFFIX(stdlib_strided_dnanvariancepn_ndarray)( const CBLAS_INT N, con } ix += strideX; } - return (M2/nc) - ((M/n)*(M/nc)); + return (M2/nc) - ((M/(double)n)*(M/nc)); } From 6bcd510b9c42170e5953e3738bd8dfff0701c328 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Fri, 31 Jan 2025 18:13:22 +0530 Subject: [PATCH 06/24] chore: updated copyright years --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c index 277dd4140d34..26c2beaa2958 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From fbaead40082df3e672743e2facc92f491689cabb Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 2 Feb 2025 23:08:12 +0530 Subject: [PATCH 07/24] chore: added NaN value in array --- 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: failed --- --- .../@stdlib/stats/base/dnanvariancepn/README.md | 10 +++++----- .../stats/base/dnanvariancepn/docs/repl.txt | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md index 9d9dba6c13bb..647f8bf193b7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md @@ -123,7 +123,7 @@ The `N` and stride parameters determine which elements in the strided array are ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ] ); +var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN, NaN ] ); var v = dnanvariancepn( 5, 1, x, 2 ); // returns 6.25 @@ -136,10 +136,10 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -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 v = dnanvariancepn( 4, 1, x1, 2 ); +var v = dnanvariancepn( 5, 1, x1, 2 ); // returns 6.25 ``` @@ -165,9 +165,9 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); +var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); -var v = dnanvariancepn.ndarray( 4, 1, x, 2, 1 ); +var v = dnanvariancepn.ndarray( 5, 1, x, 2, 1 ); // returns 6.25 ``` diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt index 942132dbdc94..5e018c05de8c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt @@ -45,19 +45,19 @@ Examples -------- // Standard Usage: - > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, NaN, 2.0 ] ); > {{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 ] ); - > {{alias}}( 3, 1, x, 2 ) + > 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 ); - > {{alias}}( 3, 1, x1, 2 ) + > {{alias}}( 4, 1, x1, 2 ) ~4.3333 @@ -110,8 +110,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 ] ); - > {{alias}}.ndarray( 3, 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 From 617c7208d52c37e39ac2799aa8fa4c5f176495e2 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 2 Feb 2025 23:09:17 +0530 Subject: [PATCH 08/24] fix: lint fixes --- 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 --- --- .../@stdlib/stats/base/dnanvariancepn/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md index 647f8bf193b7..127c394bf946 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md @@ -123,7 +123,7 @@ The `N` and stride parameters determine which elements in the strided array are ```javascript var Float64Array = require( '@stdlib/array/float64' ); -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, NaN]); var v = dnanvariancepn( 5, 1, x, 2 ); // returns 6.25 @@ -136,7 +136,7 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -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, NaN]); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var v = dnanvariancepn( 5, 1, x1, 2 ); @@ -165,7 +165,7 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float64Array = require( '@stdlib/array/float64' ); -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, NaN, NaN]); var v = dnanvariancepn.ndarray( 5, 1, x, 2, 1 ); // returns 6.25 From ae082a23f2f282716c8d92bb0bd02e86228c84c6 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sat, 8 Feb 2025 12:06:48 +0530 Subject: [PATCH 09/24] fix: updated docs and remove unwanted files --- 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 --- --- .../stats/base/dnanvariancepn/README.md | 4 +- .../base/dnanvariancepn/lib/dnansumpw.js | 183 ------------------ 2 files changed, 2 insertions(+), 185 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md index 127c394bf946..94f85eef944a 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md @@ -123,7 +123,7 @@ The `N` and stride parameters determine which elements in the strided array are ```javascript var Float64Array = require( '@stdlib/array/float64' ); -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, NaN ] ); // eslint-disable-line max-len var v = dnanvariancepn( 5, 1, x, 2 ); // returns 6.25 @@ -165,7 +165,7 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float64Array = require( '@stdlib/array/float64' ); -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, NaN, NaN ] ); // eslint-disable-line max-len var v = dnanvariancepn.ndarray( 5, 1, x, 2, 1 ); // returns 6.25 diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js deleted file mode 100644 index cd66a8d7dd8c..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js +++ /dev/null @@ -1,183 +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. -*/ - -'use strict'; - -// MODULES // - -var floor = require( '@stdlib/math/base/special/floor' ); - - -// VARIABLES // - -// Blocksize for pairwise summation (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.): -var BLOCKSIZE = 128; - - -// MAIN // - -/** -* Computes the sum of a double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. -* -* ## Method -* -* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`. -* -* ## References -* -* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050). -* -* @private -* @param {PositiveInteger} N - number of indexed elements -* @param {NumericArray} out - two-element output array whose first element is the accumulated sum and whose second element is the accumulated number of summed values -* @param {Float64Array} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {NumericArray} output array -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* -* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); -* -* var out = [ 0.0, 0 ]; -* var v = dnansumpw( 5, out, x, 2, 1 ); -* // returns [ 5.0, 4 ] -*/ -function dnansumpw( N, out, x, strideX, offsetX ) { - var ix; - var s0; - var s1; - var s2; - var s3; - var s4; - var s5; - var s6; - var s7; - var M; - var s; - var n; - var v; - var i; - - ix = offsetX; - if ( N < 8 ) { - // Use simple summation... - s = 0.0; - n = 0; - for ( i = 0; i < N; i++ ) { - v = x[ ix ]; - if ( v === v ) { - s += v; - n += 1; - } - ix += strideX; - } - out[ 0 ] += s; - out[ 1 ] += n; - return out; - } - if ( N <= BLOCKSIZE ) { - // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... - s0 = 0.0; - s1 = 0.0; - s2 = 0.0; - s3 = 0.0; - s4 = 0.0; - s5 = 0.0; - s6 = 0.0; - s7 = 0.0; - n = 0; - - M = N % 8; - for ( i = 0; i < N-M; i += 8 ) { - v = x[ ix ]; - if ( v === v ) { - s0 += v; - n += 1; - } - ix += strideX; - v = x[ ix ]; - if ( v === v ) { - s1 += v; - n += 1; - } - ix += strideX; - v = x[ ix ]; - if ( v === v ) { - s2 += v; - n += 1; - } - ix += strideX; - v = x[ ix ]; - if ( v === v ) { - s3 += v; - n += 1; - } - ix += strideX; - v = x[ ix ]; - if ( v === v ) { - s4 += v; - n += 1; - } - ix += strideX; - v = x[ ix ]; - if ( v === v ) { - s5 += v; - n += 1; - } - ix += strideX; - v = x[ ix ]; - if ( v === v ) { - s6 += v; - n += 1; - } - ix += strideX; - v = x[ ix ]; - if ( v === v ) { - s7 += v; - n += 1; - } - ix += strideX; - } - // Pairwise sum the accumulators: - s = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); - - // Clean-up loop... - for ( i; i < N; i++ ) { - v = x[ ix ]; - if ( v === v ) { - s += v; - n += 1; - } - ix += strideX; - } - out[ 0 ] += s; - out[ 1 ] += n; - return out; - } - // Recurse by dividing by two, but avoiding non-multiples of unroll factor... - n = floor( N/2 ); - n -= n % 8; - return dnansumpw( n, out, x, strideX, ix ) + dnansumpw( N-n, out, x, strideX, ix+(n*strideX) ); // eslint-disable-line max-len -} - - -// EXPORTS // - -module.exports = dnansumpw; From b33108b31e621934e84dbe875892392210574c49 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sat, 8 Feb 2025 12:08:50 +0530 Subject: [PATCH 10/24] fix: updated copyright year --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c index 489ed0e96699..85ad079b6e30 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From f48cd365de0cc300a68c3f34b2a992c2151a453e Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 09:25:58 +0530 Subject: [PATCH 11/24] chore: lint 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: 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/dnanvariancepn/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md index 94f85eef944a..7b0bf24d6267 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md @@ -136,7 +136,7 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -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, NaN ] ); // eslint-disable-line max-len var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var v = dnanvariancepn( 5, 1, x1, 2 ); From cc8ee1d1d08622d6536b627c1dd17ec3ff763f27 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:02:30 +0530 Subject: [PATCH 12/24] feat: added did_d function --- 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: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/math/base/napi/ternary/README.md | 40 ++++++++++ .../include/stdlib/math/base/napi/ternary.h | 42 ++++++++++ .../@stdlib/math/base/napi/ternary/src/main.c | 76 +++++++++++++++++++ 3 files changed, 158 insertions(+) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index 889c4a4160d5..359cbfe867a4 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -222,6 +222,46 @@ The function accepts the following arguments: void stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ); ``` +#### stdlib_math_base_napi_did_d( env, info, fcn ) + +Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. + +```c +#include +#include + +// ... + +static double fcn( const double x, const int32_t y, const double z ) { + // ... +} + +// ... + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +napi_value addon( napi_env env, napi_callback_info info ) { + return stdlib_math_base_napi_did_d( env, info, fcn ); +} + +// ... +``` + +The function accepts the following arguments: + +- **env**: `[in] napi_env` environment under which the function is invoked. +- **info**: `[in] napi_callback_info` callback data. +- **fcn**: `[in] double (*fcn)( double, int32_t, double )` ternary function. + +```c +void stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ); +``` + #### stdlib_math_base_napi_iid_d( env, info, fcn ) Invokes a ternary function accepting two signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h index 68a1ff9a0351..6661c30e0066 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h @@ -144,6 +144,48 @@ }; \ NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_dii_d_init ) +/** +* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +* +* @param fcn ternary function +* +* @example +* #include +* +* static double fcn( const double x, const int_32 y, const double z ) { +* // ... +* } +* +* // ... +* +* // Register a Node-API module: +* STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ); +*/ +#define STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ) \ + static napi_value stdlib_math_base_napi_did_d_wrapper( \ + napi_env env, \ + napi_callback_info info \ + ) { \ + return stdlib_math_base_napi_did_d( env, info, fcn ); \ + }; \ + static napi_value stdlib_math_base_napi_did_d_init( \ + napi_env env, \ + napi_value exports \ + ) { \ + napi_value fcn; \ + napi_status status = napi_create_function( \ + env, \ + "exports", \ + NAPI_AUTO_LENGTH, \ + stdlib_math_base_napi_did_d_wrapper, \ + NULL, \ + &fcn \ + ); \ + assert( status == napi_ok ); \ + return fcn; \ + }; \ + NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_did_d_init ) + /** * Macro for registering a Node-API module exporting an interface invoking a ternary function accepting two signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. * diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c index e780fdb2679d..1a391916a02f 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c @@ -249,6 +249,82 @@ napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, d return v; } +/** +* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +* +* ## Notes +* +* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: +* +* - `x`: input value. +* - `y`: input value. +* - `z`: input value. +* +* @param env environment under which the function is invoked +* @param info callback data +* @param fcn ternary function +* @return function return value as a Node-API double-precision floating-point number +*/ +napi_value stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ) { + napi_status status; + + size_t argc = 3; + napi_value argv[ 3 ]; + status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); + assert( status == napi_ok ); + + if ( argc < 3 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype2; + status = napi_typeof( env, argv[ 2 ], &vtype2 ); + assert( status == napi_ok ); + if ( vtype2 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + double x; + status = napi_get_value_double( env, argv[ 0 ], &x ); + assert( status == napi_ok ); + + int32_t y; + status = napi_get_value_int32( env, argv[ 1 ], &y ); + assert( status == napi_ok ); + + double z; + status = napi_get_value_double( env, argv[ 2 ], &z ); + assert( status == napi_ok ); + + napi_value v; + status = napi_create_double( env, fcn( x, y, z ), &v ); + assert( status == napi_ok ); + + return v; +} + /** * Invokes a ternary function accepting two signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. * From 113884d961eeafcfa7951be071e7fc6053695bd7 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:02:30 +0530 Subject: [PATCH 13/24] feat: added did_d function --- 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: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: failed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: failed --- --- .../stats/base/dnanvariancepn/README.md | 169 ++----------- .../dnanvariancepn/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/dnanvariancepn/docs/repl.txt | 38 +-- .../base/dnanvariancepn/docs/types/index.d.ts | 12 +- .../base/dnanvariancepn/examples/c/example.c | 9 +- .../base/dnanvariancepn/examples/index.js | 21 +- .../stdlib/stats/base/dnanvariancepn.h | 9 +- .../base/dnanvariancepn/lib/dnansumpw.js | 185 ++++++++++++++ .../base/dnanvariancepn/lib/dnanvariancepn.js | 65 ++++- .../lib/dnanvariancepn.native.js | 9 +- .../stats/base/dnanvariancepn/lib/index.js | 7 +- .../stats/base/dnanvariancepn/lib/ndarray.js | 22 +- .../base/dnanvariancepn/lib/ndarray.native.js | 20 +- .../stats/base/dnanvariancepn/manifest.json | 56 +--- .../stats/base/dnanvariancepn/src/addon.c | 27 +- .../base/dnanvariancepn/src/dnanvariancepn.c | 239 ++++++++++++++++++ .../stats/base/dnanvariancepn/src/main.c | 101 -------- .../test/test.dnanvariancepn.js | 13 +- .../test/test.dnanvariancepn.native.js | 13 +- .../base/dnanvariancepn/test/test.ndarray.js | 13 +- .../test/test.ndarray.native.js | 13 +- 25 files changed, 706 insertions(+), 515 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js create mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/dnanvariancepn.c delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md index 7b0bf24d6267..a096d2bcc40d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/README.md @@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); ``` -#### dnanvariancepn( N, correction, x, strideX ) +#### dnanvariancepn( N, correction, x, stride ) Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values and using a two-pass algorithm. @@ -116,16 +116,18 @@ 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 ] ); // eslint-disable-line max-len +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 = dnanvariancepn( 5, 1, x, 2 ); +var v = dnanvariancepn( N, 1, x, 2 ); // returns 6.25 ``` @@ -135,15 +137,18 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); -var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); // eslint-disable-line max-len +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 = dnanvariancepn( 5, 1, x1, 2 ); +var N = floor( x0.length / 2 ); + +var v = dnanvariancepn( N, 1, x1, 2 ); // returns 6.25 ``` -#### dnanvariancepn.ndarray( N, correction, x, strideX, offsetX ) +#### dnanvariancepn.ndarray( N, correction, x, stride, offset ) Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm and alternative indexing semantics. @@ -158,16 +163,18 @@ var v = dnanvariancepn.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 element in `x` starting from the second element +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 ] ); // eslint-disable-line max-len +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 = dnanvariancepn.ndarray( 5, 1, x, 2, 1 ); +var v = dnanvariancepn.ndarray( N, 1, x, 2, 1 ); // returns 6.25 ``` @@ -193,19 +200,18 @@ var v = dnanvariancepn.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 dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); -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 = dnanvariancepn( x.length, 1, x, 1 ); @@ -216,125 +222,6 @@ console.log( v ); - - -* * * - -
- -## C APIs - - - -
- -
- - - - - -
- -### Usage - -```c -#include "stdlib/stats/base/dnanvariancepn.h" -``` - -#### stdlib_strided_dnanvariancepn( N, correction, \*X, strideX ) - -Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values and using a two-pass algorithm. - -```c -const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; - -double v = stdlib_strided_dnanvariancepn( 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_dnanvariancepn( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); -``` - -#### stdlib_strided_dnanvariancepn_ndarray( N, correction, \*X, strideX, offsetX ) - -Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm and alternative indexing semantics. - -```c -const double x[] = { 1.0, -2.0, 0.0/0.0, 2.0 }; - -double v = stdlib_strided_dnanvariancepn_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_dnanvariancepn_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/dnanvariancepn.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_dnanvariancepn( N, 1.0, x, strideX ); - - // Print the result: - printf( "sample variance: %lf\n", v ); -} -``` - -
- - - -
- - - * * *
diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.js index 7693bcc04538..938fb06d261c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 dnanvariancepn = require( './../lib/dnanvariancepn.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/dnanvariancepn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.native.js index b40859f8428d..8f55e745acf0 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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/dnanvariancepn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.ndarray.js index ae3f65a66ad1..f643f79be93c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 dnanvariancepn = 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/dnanvariancepn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.ndarray.native.js index 400968b5ae70..22820da65b55 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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/dnanvariancepn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/c/benchmark.length.c index 13c9d9e7fc35..2b1e4f8fc994 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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_dnanvariancepn( 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_dnanvariancepn_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/dnanvariancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt index 5e018c05de8c..ec5c6b14c7f3 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 and using a two-pass algorithm. - 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 a two-pass algorithm and alternative indexing semantics. @@ -91,10 +94,10 @@ x: Float64Array Input array. - strideX: integer - Stride length. + stride: integer + Index increment. - offsetX: integer + offset: integer Starting index. Returns @@ -110,8 +113,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/dnanvariancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/types/index.d.ts index abfb3a863547..7a095f9ad539 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 = dnanvariancepn( 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 a two-pass algorithm and 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 = dnanvariancepn.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/dnanvariancepn/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/c/example.c index bdcfe68be923..d557e4a16994 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/c/example.c @@ -17,20 +17,21 @@ */ #include "stdlib/stats/base/dnanvariancepn.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_dnanvariancepn( N, 1.0, x, strideX ); + double v = stdlib_strided_dnanvariancepn( N, 1, x, stride ); // Print the result: printf( "sample variance: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js index e48ab79ce477..9487e47461ee 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 dnanvariancepn = 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 = dnanvariancepn( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/include/stdlib/stats/base/dnanvariancepn.h b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/include/stdlib/stats/base/dnanvariancepn.h index 8ad23b4ebb2a..852e2dfe777e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/include/stdlib/stats/base/dnanvariancepn.h +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/include/stdlib/stats/base/dnanvariancepn.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DNANVARIANCEPN_H #define STDLIB_STATS_BASE_DNANVARIANCEPN_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 and using a two-pass algorithm. */ -double API_SUFFIX(stdlib_strided_dnanvariancepn)( 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 using a two-pass algorithm and alternative indexing semantics. -*/ -double API_SUFFIX(stdlib_strided_dnanvariancepn_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +double stdlib_strided_dnanvariancepn( 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/dnanvariancepn/lib/dnansumpw.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js new file mode 100644 index 000000000000..46988a3c2679 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnansumpw.js @@ -0,0 +1,185 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var floor = require( '@stdlib/math/base/special/floor' ); + + +// VARIABLES // + +// Blocksize for pairwise summation (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.): +var BLOCKSIZE = 128; + + +// MAIN // + +/** +* Computes the sum of a double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. +* +* ## Method +* +* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`. +* +* ## References +* +* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050). +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} out - two-element output array whose first element is the accumulated sum and whose second element is the accumulated number of summed values +* @param {Float64Array} x - input array +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - starting index +* @returns {NumericArray} output array +* +* @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 out = [ 0.0, 0 ]; +* var v = dnansumpw( N, out, x, 2, 1 ); +* // returns [ 5.0, 4 ] +*/ +function dnansumpw( N, out, x, stride, offset ) { + var ix; + var s0; + var s1; + var s2; + var s3; + var s4; + var s5; + var s6; + var s7; + var M; + var s; + var n; + var v; + var i; + + ix = offset; + if ( N < 8 ) { + // Use simple summation... + s = 0.0; + n = 0; + for ( i = 0; i < N; i++ ) { + v = x[ ix ]; + if ( v === v ) { + s += v; + n += 1; + } + ix += stride; + } + out[ 0 ] += s; + out[ 1 ] += n; + return out; + } + if ( N <= BLOCKSIZE ) { + // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... + s0 = 0.0; + s1 = 0.0; + s2 = 0.0; + s3 = 0.0; + s4 = 0.0; + s5 = 0.0; + s6 = 0.0; + s7 = 0.0; + n = 0; + + M = N % 8; + for ( i = 0; i < N-M; i += 8 ) { + v = x[ ix ]; + if ( v === v ) { + s0 += v; + n += 1; + } + ix += stride; + v = x[ ix ]; + if ( v === v ) { + s1 += v; + n += 1; + } + ix += stride; + v = x[ ix ]; + if ( v === v ) { + s2 += v; + n += 1; + } + ix += stride; + v = x[ ix ]; + if ( v === v ) { + s3 += v; + n += 1; + } + ix += stride; + v = x[ ix ]; + if ( v === v ) { + s4 += v; + n += 1; + } + ix += stride; + v = x[ ix ]; + if ( v === v ) { + s5 += v; + n += 1; + } + ix += stride; + v = x[ ix ]; + if ( v === v ) { + s6 += v; + n += 1; + } + ix += stride; + v = x[ ix ]; + if ( v === v ) { + s7 += v; + n += 1; + } + ix += stride; + } + // Pairwise sum the accumulators: + s = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); + + // Clean-up loop... + for ( i; i < N; i++ ) { + v = x[ ix ]; + if ( v === v ) { + s += v; + n += 1; + } + ix += stride; + } + out[ 0 ] += s; + out[ 1 ] += n; + return out; + } + // Recurse by dividing by two, but avoiding non-multiples of unroll factor... + n = floor( N/2 ); + n -= n % 8; + return dnansumpw( n, out, x, stride, ix ) + dnansumpw( N-n, out, x, stride, ix+(n*stride) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = dnansumpw; diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.js index 73a686d31ff0..903162954441 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.js @@ -20,8 +20,12 @@ // MODULES // -var stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); +var dnansumpw = require( './dnansumpw.js' ); + + +// VARIABLES // + +var WORKSPACE = [ 0.0, 0 ]; // MAIN // @@ -41,19 +45,68 @@ 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 = dnanvariancepn( x.length, 1, x, 1 ); +* var v = dnanvariancepn( N, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariancepn( N, correction, x, strideX ) { - return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); +function dnanvariancepn( N, correction, x, stride ) { + var mu; + var ix; + var M2; + var nc; + var M; + var d; + var v; + var n; + var i; + + if ( N <= 0 ) { + return NaN; + } + if ( N === 1 || stride === 0 ) { + v = x[ 0 ]; + if ( v === v && N-correction > 0.0 ) { + return 0.0; + } + return NaN; + } + if ( stride < 0 ) { + ix = (1-N) * stride; + } else { + ix = 0; + } + // Compute an estimate for the mean... + WORKSPACE[ 0 ] = 0.0; + WORKSPACE[ 1 ] = 0; + dnansumpw( N, WORKSPACE, x, stride, ix ); + n = WORKSPACE[ 1 ]; + nc = n - correction; + if ( nc <= 0.0 ) { + return NaN; + } + mu = WORKSPACE[ 0 ] / n; + + // Compute the variance... + M2 = 0.0; + M = 0.0; + for ( i = 0; i < N; i++ ) { + v = x[ ix ]; + if ( v === v ) { + d = v - mu; + M2 += d * d; + M += d; + } + ix += stride; + } + return (M2/nc) - ((M/n)*(M/nc)); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.native.js index 004c519526ff..2c5bdb7a5bcb 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/dnanvariancepn.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 = dnanvariancepn( x.length, 1, x, 1 ); +* var v = dnanvariancepn( N, 1, x, 1 ); * // returns ~4.3333 */ -function dnanvariancepn( N, correction, x, strideX ) { - return addon( N, correction, x, strideX ); +function dnanvariancepn( N, correction, x, stride ) { + return addon( N, correction, x, stride ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/index.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/index.js index 2d2bb09d5364..9573909ea075 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/index.js @@ -28,17 +28,20 @@ * var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); +* var N = x.length; * -* var v = dnanvariancepn( x.length, 1, x, 1 ); +* var v = dnanvariancepn( N, 1, x, 1 ); * // returns ~4.3333 * * @example * var Float64Array = require( '@stdlib/array/float64' ); +* var floor = require( '@stdlib/math/base/special/floor' ); * var dnanvariancepn = require( '@stdlib/stats/base/dnanvariancepn' ); * * 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 = dnanvariancepn.ndarray( 5, 1, x, 2, 1 ); +* var v = dnanvariancepn.ndarray( N, 1, x, 2, 1 ); * // returns 6.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js index 18cb4c72b2a1..8f191ce6329f 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var dnannsumpw = require( '@stdlib/blas/ext/base/dnannsumpw' ).ndarray; +var dnansumpw = require( './dnansumpw.js' ); // VARIABLES // @@ -45,19 +45,21 @@ var WORKSPACE = [ 0.0, 0 ]; * @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 = dnanvariancepn( 5, 1, x, 2, 1 ); +* var v = dnanvariancepn( N, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariancepn( N, correction, x, strideX, offsetX ) { +function dnanvariancepn( N, correction, x, stride, offset ) { var mu; var ix; var M2; @@ -71,8 +73,8 @@ function dnanvariancepn( N, correction, x, strideX, offsetX ) { if ( N <= 0 ) { return NaN; } - if ( N === 1 || strideX === 0 ) { - v = x[ offsetX ]; + if ( N === 1 || stride === 0 ) { + v = x[ offset ]; if ( v === v && N-correction > 0.0 ) { return 0.0; } @@ -81,7 +83,7 @@ function dnanvariancepn( N, correction, x, strideX, offsetX ) { // Compute an estimate for the mean... WORKSPACE[ 0 ] = 0.0; WORKSPACE[ 1 ] = 0; - dnannsumpw( N, x, strideX, offsetX, WORKSPACE, 1, 0 ); + dnansumpw( N, WORKSPACE, x, stride, offset ); n = WORKSPACE[ 1 ]; nc = n - correction; if ( nc <= 0.0 ) { @@ -90,7 +92,7 @@ function dnanvariancepn( N, correction, x, strideX, offsetX ) { mu = WORKSPACE[ 0 ] / n; // Compute the variance... - ix = offsetX; + ix = offset; M2 = 0.0; M = 0.0; for ( i = 0; i < N; i++ ) { @@ -100,7 +102,7 @@ function dnanvariancepn( N, correction, x, strideX, offsetX ) { M2 += d * d; M += d; } - ix += strideX; + ix += stride; } return (M2/nc) - ((M/n)*(M/nc)); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.native.js index 41228aad6f93..d9c7b94fa746 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/lib/ndarray.native.js @@ -20,7 +20,8 @@ // MODULES // -var addon = require( './../src/addon.node' ); +var Float64Array = require( '@stdlib/array/float64' ); +var addon = require( './dnanvariancepn.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 = dnanvariancepn( 5, 1, x, 2, 1 ); +* var v = dnanvariancepn( N, 1, x, 2, 1 ); * // returns 6.25 */ -function dnanvariancepn( N, correction, x, strideX, offsetX ) { - return addon.ndarray( N, correction, x, strideX, offsetX ); +function dnanvariancepn( 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/dnanvariancepn/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json index ddb23a2b34e7..078ba0d29817 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/manifest.json @@ -1,8 +1,5 @@ { - "options": { - "task": "build", - "wasm": false - }, + "options": {}, "fields": [ { "field": "src", @@ -28,77 +25,52 @@ "confs": [ { "task": "build", - "wasm": false, "src": [ - "./src/main.c" + "./src/dnanvariancepn.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared", - "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-double", - "@stdlib/blas/ext/base/dnannsumpw", "@stdlib/napi/argv-strided-float64array", "@stdlib/napi/create-double" ] }, { "task": "benchmark", - "wasm": false, "src": [ - "./src/main.c" + "./src/dnanvariancepn.c" ], "include": [ "./include" ], - "libraries": [], + "libraries": [ + "-lm" + ], "libpath": [], - "dependencies": [ - "@stdlib/blas/base/shared", - "@stdlib/blas/ext/base/dnannsumpw", - "@stdlib/strided/base/stride2offset" - ] + "dependencies": [] }, { "task": "examples", - "wasm": false, "src": [ - "./src/main.c" + "./src/dnanvariancepn.c" ], "include": [ "./include" ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/blas/base/shared", - "@stdlib/blas/ext/base/dnannsumpw", - "@stdlib/strided/base/stride2offset" - ] - }, - { - "task": "", - "wasm": true, - "src": [ - "./src/main.c" + "libraries": [ + "-lm" ], - "include": [ - "./include" - ], - "libraries": [], "libpath": [], - "dependencies": [ - "@stdlib/blas/base/shared", - "@stdlib/blas/ext/base/dnannsumpw", - "@stdlib/strided/base/stride2offset" - ] + "dependencies": [] } ] } diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c index 85ad079b6e30..8c95a6675498 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/addon.c @@ -17,7 +17,6 @@ */ #include "stdlib/stats/base/dnanvariancepn.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_dnanvariancepn)( N, correction, X, strideX ), v ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 2 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanvariancepn( 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_dnanvariancepn_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/dnanvariancepn/src/dnanvariancepn.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/dnanvariancepn.c new file mode 100644 index 000000000000..f2ee669c48f7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/dnanvariancepn.c @@ -0,0 +1,239 @@ +/** +* @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/dnanvariancepn.h" +#include + +/** +* Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation. +* +* ## Method +* +* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`. +* +* ## References +* +* - Higham, Nicholas J. 1993. "The Accuracy of Floating Point Summation." _SIAM Journal on Scientific Computing_ 14 (4): 783–99. doi:[10.1137/0914050](https://doi.org/10.1137/0914050). +* +* @param N number of indexed elements +* @param W two-element output array +* @param X input array +* @param stride stride length +* @return output value +*/ +static void dnansumpw( const int64_t N, double *W, const double *X, const int64_t stride ) { + double *xp1; + double *xp2; + double sum; + int64_t ix; + int64_t M; + int64_t n; + int64_t i; + double s0; + double s1; + double s2; + double s3; + double s4; + double s5; + double s6; + double s7; + double v; + + if ( stride < 0 ) { + ix = (1-N) * stride; + } else { + ix = 0; + } + if ( N < 8 ) { + // Use simple summation... + sum = 0.0; + n = 0; + for ( i = 0; i < N; i++ ) { + v = X[ ix ]; + if ( v == v ) { + sum += X[ ix ]; + n += 1; + } + ix += stride; + } + W[ 0 ] += sum; + W[ 1 ] += n; + return; + } + // Blocksize for pairwise summation: 128 (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.) + if ( N <= 128 ) { + // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... + s0 = 0.0; + s1 = 0.0; + s2 = 0.0; + s3 = 0.0; + s4 = 0.0; + s5 = 0.0; + s6 = 0.0; + s7 = 0.0; + n = 0; + + M = N % 8; + for ( i = 0; i < N-M; i += 8 ) { + v = X[ ix ]; + if ( v == v ) { + s0 += v; + n += 1; + } + ix += stride; + v = X[ ix ]; + if ( v == v ) { + s1 += v; + n += 1; + } + ix += stride; + v = X[ ix ]; + if ( v == v ) { + s2 += v; + n += 1; + } + ix += stride; + v = X[ ix ]; + if ( v == v ) { + s3 += v; + n += 1; + } + ix += stride; + v = X[ ix ]; + if ( v == v ) { + s4 += v; + n += 1; + } + ix += stride; + v = X[ ix ]; + if ( v == v ) { + s5 += v; + n += 1; + } + ix += stride; + v = X[ ix ]; + if ( v == v ) { + s6 += v; + n += 1; + } + ix += stride; + v = X[ ix ]; + if ( v == v ) { + s7 += v; + n += 1; + } + ix += stride; + } + // Pairwise sum the accumulators: + sum = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); + + // Clean-up loop... + for (; i < N; i++ ) { + v = X[ ix ]; + if ( v == v ) { + sum += X[ ix ]; + n += 1; + } + ix += stride; + } + W[ 0 ] += sum; + W[ 1 ] += n; + return; + } + // Recurse by dividing by two, but avoiding non-multiples of unroll factor... + n = N / 2; + n -= n % 8; + if ( stride < 0 ) { + xp1 = (double *)X + ( (n-N)*stride ); + xp2 = (double *)X; + } else { + xp1 = (double *)X; + xp2 = (double *)X + ( n*stride ); + } + dnansumpw( n, W, xp1, stride ); + dnansumpw( N-n, W, xp2, stride ); +} + +/** +* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm. +* +* ## Method +* +* - This implementation uses a two-pass approach, as suggested by Neely (1966). +* +* ## References +* +* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). +* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). +* +* @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_dnanvariancepn( const int64_t N, const double correction, const double *X, const int64_t stride ) { + double W[] = { 0.0, 0.0 }; + int64_t ix; + int64_t i; + double mu; + double M2; + double nc; + double M; + double n; + double d; + double v; + + if ( N <= 0 ) { + return 0.0 / 0.0; // NaN + } + if ( N == 1 || stride == 0 ) { + v = X[ 0 ]; + if ( v == v && (double)N-correction > 0.0 ) { + return 0.0; + } + return 0.0 / 0.0; // NaN + } + // Compute an estimate for the mean... + dnansumpw( N, W, X, stride ); + n = W[ 1 ]; + nc = n - correction; + if ( nc <= 0.0 ) { + return 0.0 / 0.0; // NaN + } + if ( stride < 0 ) { + ix = (1-N) * stride; + } else { + ix = 0; + } + mu = W[ 0 ] / n; + + // Compute the variance... + M2 = 0.0; + M = 0.0; + for ( i = 0; i < N; i++ ) { + v = X[ ix ]; + if ( v == v ) { + d = v - mu; + M2 += d * d; + M += d; + } + ix += stride; + } + return (M2/nc) - ((M/n)*(M/nc)); +} diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c deleted file mode 100644 index 26c2beaa2958..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/src/main.c +++ /dev/null @@ -1,101 +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/dnanvariancepn.h" -#include "stdlib/blas/ext/base/dnannsumpw.h" -#include "stdlib/blas/base/shared.h" -#include "stdlib/strided/base/stride2offset.h" - -/** -* Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm. -* -* ## Method -* -* - This implementation uses a two-pass approach, as suggested by Neely (1966). -* -* ## References -* -* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958). -* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036). -* -* @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_dnanvariancepn)( 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 using a two-pass algorithm 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_dnanvariancepn_ndarray)( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { - CBLAS_INT ix; - CBLAS_INT i; - CBLAS_INT n; - double sum; - double mu; - double M2; - double nc; - double M; - double d; - double v; - - if ( N <= 0 ) { - return 0.0 / 0.0; // NaN - } - if ( N == 1 || strideX == 0 ) { - v = X[ 0 ]; - if ( v == v && (double)N-correction > 0.0 ) { - return 0.0; - } - return 0.0 / 0.0; // NaN - } - // Compute an estimate for the mean... - sum = API_SUFFIX(stdlib_strided_dnannsumpw_ndarray)( N, X, strideX, offsetX, &n ); - nc =(double)n - correction; - if ( nc <= 0.0 ) { - return 0.0 / 0.0; // NaN - } - ix = offsetX; - mu = sum / (double)n; - - // Compute the variance... - M2 = 0.0; - M = 0.0; - for ( i = 0; i < N; i++ ) { - v = X[ ix ]; - if ( v == v ) { - d = v - mu; - M2 += d * d; - M += d; - } - ix += strideX; - } - return (M2/nc) - ((M/(double)n)*(M/nc)); -} diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.js index 809bfe9e6702..edd5606a6beb 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.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 dnanvariancepn = require( './../lib/dnanvariancepn.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 = dnanvariancepn( 5, 1, x, 2 ); + N = floor( x.length / 2 ); + v = dnanvariancepn( 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 = dnanvariancepn( 5, 1, x, -2 ); + v = dnanvariancepn( 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 = dnanvariancepn( 5, 1, x1, 2 ); + v = dnanvariancepn( N, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.native.js index 21c9f75a9a85..0e25d2f49446 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.dnanvariancepn.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 = dnanvariancepn( 5, 1, x, 2 ); + N = floor( x.length / 2 ); + v = dnanvariancepn( 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 = dnanvariancepn( 5, 1, x, -2 ); + v = dnanvariancepn( 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 = dnanvariancepn( 5, 1, x1, 2 ); + v = dnanvariancepn( N, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.js index 94ec373a067f..ead3999c04a1 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 dnanvariancepn = 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 = dnanvariancepn( 5, 1, x, 2, 0 ); + N = floor( x.length / 2 ); + v = dnanvariancepn( 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 = dnanvariancepn( 5, 1, x, -2, 8 ); + v = dnanvariancepn( 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 = dnanvariancepn( 5, 1, x, 2, 1 ); + v = dnanvariancepn( N, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.native.js index 5a80601b2f3d..93d05f14a494 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanvariancepn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanvariancepn/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 = dnanvariancepn( 5, 1, x, 2, 0 ); + N = floor( x.length / 2 ); + v = dnanvariancepn( 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 = dnanvariancepn( 5, 1, x, -2, 8 ); + v = dnanvariancepn( 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 = dnanvariancepn( 5, 1, x, 2, 1 ); + v = dnanvariancepn( N, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From f392242205e292d94f75079c0352ae4d73b525f8 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:27:19 +0530 Subject: [PATCH 14/24] chore: revert 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 --- --- .../include/stdlib/math/base/napi/ternary.h | 242 ----------- .../@stdlib/math/base/napi/ternary/src/main.c | 402 ------------------ 2 files changed, 644 deletions(-) delete mode 100644 lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h index d8a5f5d6a008..52a0383bcc35 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h @@ -19,247 +19,6 @@ #ifndef STDLIB_MATH_BASE_NAPI_TERNARY_H #define STDLIB_MATH_BASE_NAPI_TERNARY_H -<<<<<<< HEAD -#include -#include - -/** -* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting and returning double-precision floating-point numbers. -* -* @param fcn ternary function -* -* @example -* static double add( const double x, const double y, const double z ) { -* return x + y + z; -* } -* -* // ... -* -* // Register a Node-API module: -* STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( add ); -*/ -#define STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( fcn ) \ - static napi_value stdlib_math_base_napi_ddd_d_wrapper( \ - napi_env env, \ - napi_callback_info info \ - ) { \ - return stdlib_math_base_napi_ddd_d( env, info, fcn ); \ - }; \ - static napi_value stdlib_math_base_napi_ddd_d_init( \ - napi_env env, \ - napi_value exports \ - ) { \ - napi_value fcn; \ - napi_status status = napi_create_function( \ - env, \ - "exports", \ - NAPI_AUTO_LENGTH, \ - stdlib_math_base_napi_ddd_d_wrapper, \ - NULL, \ - &fcn \ - ); \ - assert( status == napi_ok ); \ - return fcn; \ - }; \ - NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_ddd_d_init ) - -/** -* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting and returning single-precision floating-point numbers. -* -* @param fcn ternary function -* -* @example -* static float addf( const float x, const float y, const float z ) { -* return x + y + z; -* } -* -* // ... -* -* // Register a Node-API module: -* STDLIB_MATH_BASE_NAPI_MODULE_FFF_F( addf ); -*/ -#define STDLIB_MATH_BASE_NAPI_MODULE_FFF_F( fcn ) \ - static napi_value stdlib_math_base_napi_fff_f_wrapper( \ - napi_env env, \ - napi_callback_info info \ - ) { \ - return stdlib_math_base_napi_fff_f( env, info, fcn ); \ - }; \ - static napi_value stdlib_math_base_napi_fff_f_init( \ - napi_env env, \ - napi_value exports \ - ) { \ - napi_value fcn; \ - napi_status status = napi_create_function( \ - env, \ - "exports", \ - NAPI_AUTO_LENGTH, \ - stdlib_math_base_napi_fff_f_wrapper, \ - NULL, \ - &fcn \ - ); \ - assert( status == napi_ok ); \ - return fcn; \ - }; \ - NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_fff_f_init ) - -/** -* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. -* -* @param fcn ternary function -* -* @example -* #include -* -* static double fcn( const double x, const int_32 y, const int_32 z ) { -* // ... -* } -* -* // ... -* -* // Register a Node-API module: -* STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ); -*/ -#define STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ) \ - static napi_value stdlib_math_base_napi_dii_d_wrapper( \ - napi_env env, \ - napi_callback_info info \ - ) { \ - return stdlib_math_base_napi_dii_d( env, info, fcn ); \ - }; \ - static napi_value stdlib_math_base_napi_dii_d_init( \ - napi_env env, \ - napi_value exports \ - ) { \ - napi_value fcn; \ - napi_status status = napi_create_function( \ - env, \ - "exports", \ - NAPI_AUTO_LENGTH, \ - stdlib_math_base_napi_dii_d_wrapper, \ - NULL, \ - &fcn \ - ); \ - assert( status == napi_ok ); \ - return fcn; \ - }; \ - NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_dii_d_init ) - -/** -* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. -* -* @param fcn ternary function -* -* @example -* #include -* -* static double fcn( const double x, const int_32 y, const double z ) { -* // ... -* } -* -* // ... -* -* // Register a Node-API module: -* STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ); -*/ -#define STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ) \ - static napi_value stdlib_math_base_napi_did_d_wrapper( \ - napi_env env, \ - napi_callback_info info \ - ) { \ - return stdlib_math_base_napi_did_d( env, info, fcn ); \ - }; \ - static napi_value stdlib_math_base_napi_did_d_init( \ - napi_env env, \ - napi_value exports \ - ) { \ - napi_value fcn; \ - napi_status status = napi_create_function( \ - env, \ - "exports", \ - NAPI_AUTO_LENGTH, \ - stdlib_math_base_napi_did_d_wrapper, \ - NULL, \ - &fcn \ - ); \ - assert( status == napi_ok ); \ - return fcn; \ - }; \ - NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_did_d_init ) - -/** -* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting two signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. -* -* @param fcn ternary function -* -* @example -* #include -* -* static double fcn( const int_32 x, const int_32 y, const double z ) { -* // ... -* } -* -* // ... -* -* // Register a Node-API module: -* STDLIB_MATH_BASE_NAPI_MODULE_IID_D( fcn ); -*/ -#define STDLIB_MATH_BASE_NAPI_MODULE_IID_D( fcn ) \ - static napi_value stdlib_math_base_napi_iid_d_wrapper( \ - napi_env env, \ - napi_callback_info info \ - ) { \ - return stdlib_math_base_napi_iid_d( env, info, fcn ); \ - }; \ - static napi_value stdlib_math_base_napi_iid_d_init( \ - napi_env env, \ - napi_value exports \ - ) { \ - napi_value fcn; \ - napi_status status = napi_create_function( \ - env, \ - "exports", \ - NAPI_AUTO_LENGTH, \ - stdlib_math_base_napi_iid_d_wrapper, \ - NULL, \ - &fcn \ - ); \ - assert( status == napi_ok ); \ - return fcn; \ - }; \ - NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_iid_d_init ) - -/* -* If C++, prevent name mangling so that the compiler emits a ternary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -/** -* Invokes a ternary function accepting and returning double-precision floating-point numbers. -*/ -napi_value stdlib_math_base_napi_ddd_d( napi_env env, napi_callback_info info, double (*fcn)( double, double, double ) ); - -/** -* Invokes a ternary function accepting and returning single-precision floating-point numbers. -*/ -napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float ) ); - -/** -* Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. -*/ -napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ); - -/** -* Invokes a ternary function accepting two signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. -*/ -napi_value stdlib_math_base_napi_iid_d( napi_env env, napi_callback_info info, double (*fcn)( int32_t, int32_t, double ) ); - -#ifdef __cplusplus -} -#endif -======= // NOTE: keep in alphabetical order... #include "stdlib/math/base/napi/ternary/ccc_c.h" #include "stdlib/math/base/napi/ternary/ddd_d.h" @@ -268,6 +27,5 @@ napi_value stdlib_math_base_napi_iid_d( napi_env env, napi_callback_info info, d #include "stdlib/math/base/napi/ternary/iid_d.h" #include "stdlib/math/base/napi/ternary/iii_d.h" #include "stdlib/math/base/napi/ternary/zzz_z.h" ->>>>>>> develop #endif // !STDLIB_MATH_BASE_NAPI_TERNARY_H diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c b/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c deleted file mode 100644 index 1a391916a02f..000000000000 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/src/main.c +++ /dev/null @@ -1,402 +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/math/base/napi/ternary.h" -#include -#include -#include - -/** -* Invokes a ternary function accepting and returning double-precision floating-point numbers. -* -* ## Notes -* -* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: -* -* - `x`: input value. -* - `y`: input value. -* - `z`: input value. -* -* @param env environment under which the function is invoked -* @param info callback data -* @param fcn ternary function -* @return function return value as a Node-API double-precision floating-point number -*/ -napi_value stdlib_math_base_napi_ddd_d( napi_env env, napi_callback_info info, double (*fcn)( double, double, double ) ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype1; - status = napi_typeof( env, argv[ 1 ], &vtype1 ); - assert( status == napi_ok ); - if ( vtype1 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - double x; - status = napi_get_value_double( env, argv[ 0 ], &x ); - assert( status == napi_ok ); - - double y; - status = napi_get_value_double( env, argv[ 1 ], &y ); - assert( status == napi_ok ); - - double z; - status = napi_get_value_double( env, argv[ 2 ], &z ); - assert( status == napi_ok ); - - napi_value v; - status = napi_create_double( env, fcn( x, y, z ), &v ); - assert( status == napi_ok ); - - return v; -} - -/** -* Invokes a ternary function accepting and returning single-precision floating-point numbers. -* -* ## Notes -* -* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: -* -* - `x`: input value. -* - `y`: input value. -* - `z`: input value. -* -* @param env environment under which the function is invoked -* @param info callback data -* @param fcn ternary function -* @return function return value as a Node-API double-precision floating-point number -*/ -napi_value stdlib_math_base_napi_fff_f( napi_env env, napi_callback_info info, float (*fcn)( float, float, float ) ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype1; - status = napi_typeof( env, argv[ 1 ], &vtype1 ); - assert( status == napi_ok ); - if ( vtype1 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - double x; - status = napi_get_value_double( env, argv[ 0 ], &x ); - assert( status == napi_ok ); - - double y; - status = napi_get_value_double( env, argv[ 1 ], &y ); - assert( status == napi_ok ); - - double z; - status = napi_get_value_double( env, argv[ 2 ], &z ); - assert( status == napi_ok ); - - napi_value v; - status = napi_create_double( env, (double)fcn( (float)x, (float)y, (float)z ), &v ); - assert( status == napi_ok ); - - return v; -} - -/** -* Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. -* -* ## Notes -* -* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: -* -* - `x`: input value. -* - `y`: input value. -* - `z`: input value. -* -* @param env environment under which the function is invoked -* @param info callback data -* @param fcn ternary function -* @return function return value as a Node-API double-precision floating-point number -*/ -napi_value stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype1; - status = napi_typeof( env, argv[ 1 ], &vtype1 ); - assert( status == napi_ok ); - if ( vtype1 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - double x; - status = napi_get_value_double( env, argv[ 0 ], &x ); - assert( status == napi_ok ); - - int32_t y; - status = napi_get_value_int32( env, argv[ 1 ], &y ); - assert( status == napi_ok ); - - int32_t z; - status = napi_get_value_int32( env, argv[ 2 ], &z ); - assert( status == napi_ok ); - - napi_value v; - status = napi_create_double( env, fcn( x, y, z ), &v ); - assert( status == napi_ok ); - - return v; -} - -/** -* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. -* -* ## Notes -* -* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: -* -* - `x`: input value. -* - `y`: input value. -* - `z`: input value. -* -* @param env environment under which the function is invoked -* @param info callback data -* @param fcn ternary function -* @return function return value as a Node-API double-precision floating-point number -*/ -napi_value stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype1; - status = napi_typeof( env, argv[ 1 ], &vtype1 ); - assert( status == napi_ok ); - if ( vtype1 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - double x; - status = napi_get_value_double( env, argv[ 0 ], &x ); - assert( status == napi_ok ); - - int32_t y; - status = napi_get_value_int32( env, argv[ 1 ], &y ); - assert( status == napi_ok ); - - double z; - status = napi_get_value_double( env, argv[ 2 ], &z ); - assert( status == napi_ok ); - - napi_value v; - status = napi_create_double( env, fcn( x, y, z ), &v ); - assert( status == napi_ok ); - - return v; -} - -/** -* Invokes a ternary function accepting two signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. -* -* ## Notes -* -* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: -* -* - `x`: input value. -* - `y`: input value. -* - `z`: input value. -* -* @param env environment under which the function is invoked -* @param info callback data -* @param fcn ternary function -* @return function return value as a Node-API double-precision floating-point number -*/ -napi_value stdlib_math_base_napi_iid_d( napi_env env, napi_callback_info info, double (*fcn)( int32_t, int32_t, double ) ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype1; - status = napi_typeof( env, argv[ 1 ], &vtype1 ); - assert( status == napi_ok ); - if ( vtype1 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); - assert( status == napi_ok ); - return NULL; - } - - int32_t x; - status = napi_get_value_int32( env, argv[ 1 ], &x ); - assert( status == napi_ok ); - - int32_t y; - status = napi_get_value_int32( env, argv[ 2 ], &y ); - assert( status == napi_ok ); - - double z; - status = napi_get_value_double( env, argv[ 0 ], &z ); - assert( status == napi_ok ); - - napi_value v; - status = napi_create_double( env, fcn( x, y, z ), &v ); - assert( status == napi_ok ); - - return v; -} From 6fc7920798cf28a34a346b24fd4b46c9284db5c9 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:36:00 +0530 Subject: [PATCH 15/24] feat: added did_d function --- 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 --- --- .../@stdlib/math/base/napi/ternary/README.md | 63 ++++++++++++ .../stdlib/math/base/napi/ternary/did_d.h | 84 ++++++++++++++++ .../math/base/napi/ternary/src/did_d.h | 98 +++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h create mode 100644 lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index cd51ef459186..2b6a8f69d748 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -326,6 +326,69 @@ The function accepts the following arguments: void stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ); ``` +#### STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ) + +Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. + +```c +#include + +static double fcn( const double x, const int32_t y, const double z ) { + // ... +} + +// ... + +// Register a Node-API module: +STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ); +``` + +The macro expects the following arguments: + +- **fcn**: `double (*fcn)( double, int32_t, double )` ternary function. + +When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration. + +#### stdlib_math_base_napi_did_d( env, info, fcn ) + +Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. + +```c +#include +#include + +// ... + +static double fcn( const double x, const int32_t y, const double z ) { + // ... +} + +// ... + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +napi_value addon( napi_env env, napi_callback_info info ) { + return stdlib_math_base_napi_did_d( env, info, fcn ); +} + +// ... +``` + +The function accepts the following arguments: + +- **env**: `[in] napi_env` environment under which the function is invoked. +- **info**: `[in] napi_callback_info` callback data. +- **fcn**: `[in] double (*fcn)( double, int32_t, double )` ternary function. + +```c +void stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ); +``` + #### STDLIB_MATH_BASE_NAPI_MODULE_FFF_F( fcn ) Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting and returning single-precision floating-point numbers. diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h new file mode 100644 index 000000000000..41bdcdeda5f4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h @@ -0,0 +1,84 @@ +/** +* @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. +*/ + +#ifndef STDLIB_MATH_BASE_NAPI_TERNARY_DID_D_H +#define STDLIB_MATH_BASE_NAPI_TERNARY_DID_D_H + +#include +#include +#include + +/** +* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +* +* @param fcn ternary function +* +* @example +* #include +* +* static double fcn( const double x, const int_32 y, const double z ) { +* // ... +* } +* +* // ... +* +* // Register a Node-API module: +* STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ); +*/ +#define STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ) \ + static napi_value stdlib_math_base_napi_did_d_wrapper( \ + napi_env env, \ + napi_callback_info info \ + ) { \ + return stdlib_math_base_napi_did_d( env, info, fcn ); \ + }; \ + static napi_value stdlib_math_base_napi_did_d_init( \ + napi_env env, \ + napi_value exports \ + ) { \ + napi_value fcn; \ + napi_status status = napi_create_function( \ + env, \ + "exports", \ + NAPI_AUTO_LENGTH, \ + stdlib_math_base_napi_did_d_wrapper, \ + NULL, \ + &fcn \ + ); \ + assert( status == napi_ok ); \ + return fcn; \ + }; \ + NAPI_MODULE( NODE_GYP_MODULE_NAME, stdlib_math_base_napi_did_d_init ) + +/* +* If C++, prevent name mangling so that the compiler emits a ternary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +*/ +napi_value stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_MATH_BASE_NAPI_TERNARY_DID_D_H diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h b/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h new file mode 100644 index 000000000000..5c3bea96eaec --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h @@ -0,0 +1,98 @@ +/** +* @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/math/base/napi/ternary/did_d.h" +#include +#include +#include + +/** +* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +* +* ## Notes +* +* - This function expects that the callback `info` argument provides access to the following JavaScript arguments: +* +* - `x`: input value. +* - `y`: input value. +* - `z`: input value. +* +* @param env environment under which the function is invoked +* @param info callback data +* @param fcn ternary function +* @return function return value as a Node-API double-precision floating-point number +*/ +napi_value stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ) { + napi_status status; + + size_t argc = 3; + napi_value argv[ 3 ]; + status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL ); + assert( status == napi_ok ); + + if ( argc < 3 ) { + status = napi_throw_error( env, NULL, "invalid invocation. Must provide three numbers." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype0; + status = napi_typeof( env, argv[ 0 ], &vtype0 ); + assert( status == napi_ok ); + if ( vtype0 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype1; + status = napi_typeof( env, argv[ 1 ], &vtype1 ); + assert( status == napi_ok ); + if ( vtype1 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + napi_valuetype vtype2; + status = napi_typeof( env, argv[ 2 ], &vtype2 ); + assert( status == napi_ok ); + if ( vtype2 != napi_number ) { + status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." ); + assert( status == napi_ok ); + return NULL; + } + + double x; + status = napi_get_value_double( env, argv[ 0 ], &x ); + assert( status == napi_ok ); + + int32_t y; + status = napi_get_value_int32( env, argv[ 1 ], &y ); + assert( status == napi_ok ); + + double z; + status = napi_get_value_double( env, argv[ 2 ], &z ); + assert( status == napi_ok ); + + napi_value v; + status = napi_create_double( env, fcn( x, y, z ), &v ); + assert( status == napi_ok ); + + return v; +} From 9d97048b1e235270f7dd9f61e966310f03da1157 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:40:22 +0530 Subject: [PATCH 16/24] chore: updated copyright year --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: 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: 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 --- --- .../napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h | 2 +- lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h index 41bdcdeda5f4..909a24e3d635 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h b/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h index 5c3bea96eaec..18ea20dc39c8 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 818b47957cf04fcaa3c47a990fc84fc1e43c9f80 Mon Sep 17 00:00:00 2001 From: Karan Anand <119553199+anandkaranubc@users.noreply.github.com> Date: Tue, 21 Jan 2025 12:26:41 -0800 Subject: [PATCH 17/24] bench: refactor random number generation in `stats/base/dists/beta` PR-URL: https://github.com/stdlib-js/stdlib/pull/4837 Reviewed-by: Athan Reines --- .../dists/beta/entropy/benchmark/benchmark.js | 5 +++++ .../beta/kurtosis/benchmark/benchmark.js | 5 +++++ .../dists/beta/logpdf/benchmark/benchmark.js | 20 +++++++++++++++++++ .../dists/beta/pdf/benchmark/benchmark.js | 20 +++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/dists/beta/entropy/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/beta/entropy/benchmark/benchmark.js index e6546d02fb66..2302eb98d8fc 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/beta/entropy/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/beta/entropy/benchmark/benchmark.js @@ -21,8 +21,13 @@ // MODULES // var bench = require( '@stdlib/bench' ); +<<<<<<< HEAD var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); +======= +var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +>>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; diff --git a/lib/node_modules/@stdlib/stats/base/dists/beta/kurtosis/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/beta/kurtosis/benchmark/benchmark.js index 76c359e09cb3..ecdbdb36745b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/beta/kurtosis/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/beta/kurtosis/benchmark/benchmark.js @@ -21,8 +21,13 @@ // MODULES // var bench = require( '@stdlib/bench' ); +<<<<<<< HEAD var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); +======= +var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +>>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; diff --git a/lib/node_modules/@stdlib/stats/base/dists/beta/logpdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/beta/logpdf/benchmark/benchmark.js index fdef1fcd06d5..5fea4b2761b6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/beta/logpdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/beta/logpdf/benchmark/benchmark.js @@ -21,8 +21,13 @@ // MODULES // var bench = require( '@stdlib/bench' ); +<<<<<<< HEAD var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); +======= +var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +>>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -40,6 +45,7 @@ bench( pkg, function benchmark( b ) { var i; len = 100; +<<<<<<< HEAD alpha = new Float64Array( len ); beta = new Float64Array( len ); x = new Float64Array( len ); @@ -47,6 +53,15 @@ bench( pkg, function benchmark( b ) { alpha[ i ] = uniform( EPS, 100.0 ); beta[ i ] = uniform( EPS, 100.0 ); x[ i ] = uniform( EPS, 2.0 ); +======= + x = new Float64Array( len ); + alpha = new Float64Array( len ); + beta = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = uniform( EPS, 2.0 ); + alpha[ i ] = uniform( EPS, 100.0 ); + beta[ i ] = uniform( EPS, 100.0 ); +>>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) } b.tic(); @@ -76,6 +91,11 @@ bench( pkg+':factory', function benchmark( b ) { alpha = 100.56789; beta = 55.54321; mylogpdf = logpdf.factory( alpha, beta ); + len = 100; + x = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = uniform( EPS, 2.0 ); + } len = 100; x = new Float64Array( len ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/beta/pdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/beta/pdf/benchmark/benchmark.js index 69cc5f4f6b58..67d4f658137b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/beta/pdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/beta/pdf/benchmark/benchmark.js @@ -21,8 +21,13 @@ // MODULES // var bench = require( '@stdlib/bench' ); +<<<<<<< HEAD var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); +======= +var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +>>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -40,6 +45,7 @@ bench( pkg, function benchmark( b ) { var i; len = 100; +<<<<<<< HEAD alpha = new Float64Array( len ); beta = new Float64Array( len ); x = new Float64Array( len ); @@ -47,6 +53,15 @@ bench( pkg, function benchmark( b ) { alpha[ i ] = uniform( EPS, 100.0 ); beta[ i ] = uniform( EPS, 100.0 ); x[ i ] = uniform( EPS, 2.0 ); +======= + x = new Float64Array( len ); + alpha = new Float64Array( len ); + beta = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = uniform( EPS, 2.0 ); + alpha[ i ] = uniform( EPS, 100.0 ); + beta[ i ] = uniform( EPS, 100.0 ); +>>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) } b.tic(); @@ -76,6 +91,11 @@ bench( pkg+':factory', function benchmark( b ) { alpha = 100.56789; beta = 55.54321; mypdf = pdf.factory( alpha, beta ); + len = 100; + x = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = uniform( EPS, 2.0 ); + } len = 100; x = new Float64Array( len ); From 07107204c3939cd5696fdaf1ab17c68dff61b152 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:54:11 +0530 Subject: [PATCH 18/24] chore: squash commits --- .../base/dists/binomial/skewness/benchmark/benchmark.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/skewness/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/skewness/benchmark/benchmark.js index 738012adaa31..7fc41e4a0a5b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/skewness/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/skewness/benchmark/benchmark.js @@ -21,7 +21,6 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var Int32Array = require( '@stdlib/array/int32' ); var Float64Array = require( '@stdlib/array/float64' ); var uniform = require( '@stdlib/random/base/uniform' ); var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); @@ -40,7 +39,11 @@ bench( pkg, function benchmark( b ) { var i; len = 100; +<<<<<<< HEAD n = new Int32Array( len ); +======= + n = new Float64Array( len ); +>>>>>>> af55f0d6d6b (bench: refactor random number generation in `stats/base/dists/binomial`) p = new Float64Array( len ); for ( i = 0; i < len; i++ ) { n[ i ] = discreteUniform( 1, 100 ); From 8d2bcf2409fa8ece7894f7b84b1becb0b12b51f4 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Tue, 18 Feb 2025 13:55:04 +0530 Subject: [PATCH 19/24] chore: squash commits --- .../stats/base/dists/betaprime/mean/benchmark/benchmark.js | 6 +++++- .../stats/base/dists/betaprime/mode/benchmark/benchmark.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/betaprime/mean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/betaprime/mean/benchmark/benchmark.js index 6fd59473daa0..cab10f813617 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/betaprime/mean/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/betaprime/mean/benchmark/benchmark.js @@ -21,8 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -43,7 +43,11 @@ bench( pkg, function benchmark( b ) { beta = new Float64Array( len ); for ( i = 0; i < len; i++ ) { alpha[ i ] = uniform( EPS, 10.0 ); +<<<<<<< HEAD beta[ i ] = uniform( 1.0 + EPS, 11.0 ); +======= + beta[ i ] = uniform( 1.0 + EPS, 10.0 ); +>>>>>>> 68894a16cc9 (bench: refactor random number generation in `stats/base/dists/betaprime`) } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/betaprime/mode/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/betaprime/mode/benchmark/benchmark.js index 1b881edbcf5d..90529269da26 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/betaprime/mode/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/betaprime/mode/benchmark/benchmark.js @@ -21,8 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; From 36f7e23dede9a8b1dd9bb10cdc60097777529f88 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Wed, 19 Feb 2025 13:57:24 +0530 Subject: [PATCH 20/24] chore: updated 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: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: failed --- --- .../@stdlib/math/base/napi/ternary/README.md | 44 +++++++++---------- .../include/stdlib/math/base/napi/ternary.h | 1 + .../stdlib/math/base/napi/ternary/did_d.h | 4 +- .../math/base/napi/ternary/manifest.json | 1 + .../napi/ternary/src/{did_d.h => did_d.c} | 2 +- 5 files changed, 27 insertions(+), 25 deletions(-) rename lib/node_modules/@stdlib/math/base/napi/ternary/src/{did_d.h => did_d.c} (95%) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index 2b6a8f69d748..9c26711252a5 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -263,32 +263,32 @@ The function accepts the following arguments: void stdlib_math_base_napi_ddd_d( napi_env env, napi_callback_info info, double (*fcn)( double, double, double ) ); ``` -#### STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ) +#### STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ) -Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. +Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. ```c #include -static double fcn( const double x, const int32_t y, const int32_t z ) { +static double fcn( const double x, const int32_t y, const double z ) { // ... } // ... // Register a Node-API module: -STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ); +STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ); ``` The macro expects the following arguments: -- **fcn**: `double (*fcn)( double, int32_t, int32_t )` ternary function. +- **fcn**: `double (*fcn)( double, int32_t, double )` ternary function. When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration. -#### stdlib_math_base_napi_dii_d( env, info, fcn ) +#### stdlib_math_base_napi_did_d( env, info, fcn ) -Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. +Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. ```c #include @@ -296,7 +296,7 @@ Invokes a ternary function accepting a double-precision floating-point number an // ... -static double fcn( const double x, const int32_t y, const int32_t z ) { +static double fcn( const double x, const int32_t y, const double z ) { // ... } @@ -310,7 +310,7 @@ static double fcn( const double x, const int32_t y, const int32_t z ) { * @return Node-API value */ napi_value addon( napi_env env, napi_callback_info info ) { - return stdlib_math_base_napi_dii_d( env, info, fcn ); + return stdlib_math_base_napi_did_d( env, info, fcn ); } // ... @@ -320,38 +320,38 @@ The function accepts the following arguments: - **env**: `[in] napi_env` environment under which the function is invoked. - **info**: `[in] napi_callback_info` callback data. -- **fcn**: `[in] double (*fcn)( double, int32_t, int32_t )` ternary function. +- **fcn**: `[in] double (*fcn)( double, int32_t, double )` ternary function. ```c -void stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ); +void stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ); ``` -#### STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ) +#### STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ) -Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. ```c #include -static double fcn( const double x, const int32_t y, const double z ) { +static double fcn( const double x, const int32_t y, const int32_t z ) { // ... } // ... // Register a Node-API module: -STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ); +STDLIB_MATH_BASE_NAPI_MODULE_DII_D( fcn ); ``` The macro expects the following arguments: -- **fcn**: `double (*fcn)( double, int32_t, double )` ternary function. +- **fcn**: `double (*fcn)( double, int32_t, int32_t )` ternary function. When used, this macro should be used **instead of** `NAPI_MODULE`. The macro includes `NAPI_MODULE`, thus ensuring Node-API module registration. -#### stdlib_math_base_napi_did_d( env, info, fcn ) +#### stdlib_math_base_napi_dii_d( env, info, fcn ) -Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +Invokes a ternary function accepting a double-precision floating-point number and two signed 32-bit integers and returning a double-precision floating-point number. ```c #include @@ -359,7 +359,7 @@ Invokes a ternary function accepting a double-precision floating-point number, a // ... -static double fcn( const double x, const int32_t y, const double z ) { +static double fcn( const double x, const int32_t y, const int32_t z ) { // ... } @@ -373,7 +373,7 @@ static double fcn( const double x, const int32_t y, const double z ) { * @return Node-API value */ napi_value addon( napi_env env, napi_callback_info info ) { - return stdlib_math_base_napi_did_d( env, info, fcn ); + return stdlib_math_base_napi_dii_d( env, info, fcn ); } // ... @@ -383,10 +383,10 @@ The function accepts the following arguments: - **env**: `[in] napi_env` environment under which the function is invoked. - **info**: `[in] napi_callback_info` callback data. -- **fcn**: `[in] double (*fcn)( double, int32_t, double )` ternary function. +- **fcn**: `[in] double (*fcn)( double, int32_t, int32_t )` ternary function. ```c -void stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ); +void stdlib_math_base_napi_dii_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, int32_t ) ); ``` #### STDLIB_MATH_BASE_NAPI_MODULE_FFF_F( fcn ) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h index 52a0383bcc35..a077b8238776 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary.h @@ -22,6 +22,7 @@ // NOTE: keep in alphabetical order... #include "stdlib/math/base/napi/ternary/ccc_c.h" #include "stdlib/math/base/napi/ternary/ddd_d.h" +#include "stdlib/math/base/napi/ternary/did_d.h" #include "stdlib/math/base/napi/ternary/dii_d.h" #include "stdlib/math/base/napi/ternary/fff_f.h" #include "stdlib/math/base/napi/ternary/iid_d.h" diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h index 909a24e3d635..c892a6dc1657 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h @@ -24,7 +24,7 @@ #include /** -* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. * * @param fcn ternary function * @@ -73,7 +73,7 @@ extern "C" { #endif /** -* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. */ napi_value stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ); diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/manifest.json b/lib/node_modules/@stdlib/math/base/napi/ternary/manifest.json index 1d49b6d90248..234f29f223c3 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/manifest.json +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/manifest.json @@ -27,6 +27,7 @@ "src": [ "./src/ccc_c.c", "./src/ddd_d.c", + "./src/did_d.c", "./src/dii_d.c", "./src/fff_f.c", "./src/iid_d.c", diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h b/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.c similarity index 95% rename from lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h rename to lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.c index 18ea20dc39c8..c71529252e6c 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.c @@ -22,7 +22,7 @@ #include /** -* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integers and a double-precision floating-point number and returning a double-precision floating-point number. +* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. * * ## Notes * From d6cfbf7da43946090b3546af17bbf9703d1bd623 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Wed, 19 Feb 2025 15:57:51 +0530 Subject: [PATCH 21/24] chore: merge develop --- 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: failed --- --- .../dists/beta/entropy/benchmark/benchmark.js | 5 ----- .../beta/kurtosis/benchmark/benchmark.js | 5 ----- .../dists/beta/logpdf/benchmark/benchmark.js | 20 ------------------- .../dists/beta/pdf/benchmark/benchmark.js | 20 ------------------- .../betaprime/mean/benchmark/benchmark.js | 6 +----- .../betaprime/mode/benchmark/benchmark.js | 2 +- .../binomial/skewness/benchmark/benchmark.js | 5 +---- .../dists/planck/stdev/benchmark/benchmark.js | 4 ++++ .../base/dists/planck/stdev/lib/native.js | 4 ++++ .../stats/base/dists/uniform/logcdf/README.md | 3 +++ .../stats/base/dists/uniform/logpdf/README.md | 3 +++ .../base/dists/uniform/logpdf/src/main.c | 4 ++++ .../stats/base/dists/uniform/stdev/README.md | 3 +++ 13 files changed, 24 insertions(+), 60 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/beta/entropy/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/beta/entropy/benchmark/benchmark.js index 2302eb98d8fc..e6546d02fb66 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/beta/entropy/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/beta/entropy/benchmark/benchmark.js @@ -21,13 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -<<<<<<< HEAD var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); -======= -var Float64Array = require( '@stdlib/array/float64' ); -var uniform = require( '@stdlib/random/base/uniform' ); ->>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; diff --git a/lib/node_modules/@stdlib/stats/base/dists/beta/kurtosis/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/beta/kurtosis/benchmark/benchmark.js index ecdbdb36745b..76c359e09cb3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/beta/kurtosis/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/beta/kurtosis/benchmark/benchmark.js @@ -21,13 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -<<<<<<< HEAD var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); -======= -var Float64Array = require( '@stdlib/array/float64' ); -var uniform = require( '@stdlib/random/base/uniform' ); ->>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; diff --git a/lib/node_modules/@stdlib/stats/base/dists/beta/logpdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/beta/logpdf/benchmark/benchmark.js index 5fea4b2761b6..fdef1fcd06d5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/beta/logpdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/beta/logpdf/benchmark/benchmark.js @@ -21,13 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -<<<<<<< HEAD var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); -======= -var Float64Array = require( '@stdlib/array/float64' ); -var uniform = require( '@stdlib/random/base/uniform' ); ->>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -45,7 +40,6 @@ bench( pkg, function benchmark( b ) { var i; len = 100; -<<<<<<< HEAD alpha = new Float64Array( len ); beta = new Float64Array( len ); x = new Float64Array( len ); @@ -53,15 +47,6 @@ bench( pkg, function benchmark( b ) { alpha[ i ] = uniform( EPS, 100.0 ); beta[ i ] = uniform( EPS, 100.0 ); x[ i ] = uniform( EPS, 2.0 ); -======= - x = new Float64Array( len ); - alpha = new Float64Array( len ); - beta = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = uniform( EPS, 2.0 ); - alpha[ i ] = uniform( EPS, 100.0 ); - beta[ i ] = uniform( EPS, 100.0 ); ->>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) } b.tic(); @@ -91,11 +76,6 @@ bench( pkg+':factory', function benchmark( b ) { alpha = 100.56789; beta = 55.54321; mylogpdf = logpdf.factory( alpha, beta ); - len = 100; - x = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = uniform( EPS, 2.0 ); - } len = 100; x = new Float64Array( len ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/beta/pdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/beta/pdf/benchmark/benchmark.js index 67d4f658137b..69cc5f4f6b58 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/beta/pdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/beta/pdf/benchmark/benchmark.js @@ -21,13 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -<<<<<<< HEAD var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); -======= -var Float64Array = require( '@stdlib/array/float64' ); -var uniform = require( '@stdlib/random/base/uniform' ); ->>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -45,7 +40,6 @@ bench( pkg, function benchmark( b ) { var i; len = 100; -<<<<<<< HEAD alpha = new Float64Array( len ); beta = new Float64Array( len ); x = new Float64Array( len ); @@ -53,15 +47,6 @@ bench( pkg, function benchmark( b ) { alpha[ i ] = uniform( EPS, 100.0 ); beta[ i ] = uniform( EPS, 100.0 ); x[ i ] = uniform( EPS, 2.0 ); -======= - x = new Float64Array( len ); - alpha = new Float64Array( len ); - beta = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = uniform( EPS, 2.0 ); - alpha[ i ] = uniform( EPS, 100.0 ); - beta[ i ] = uniform( EPS, 100.0 ); ->>>>>>> 939454926b7 (bench: refactor random number generation in `stats/base/dists/beta`) } b.tic(); @@ -91,11 +76,6 @@ bench( pkg+':factory', function benchmark( b ) { alpha = 100.56789; beta = 55.54321; mypdf = pdf.factory( alpha, beta ); - len = 100; - x = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = uniform( EPS, 2.0 ); - } len = 100; x = new Float64Array( len ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/betaprime/mean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/betaprime/mean/benchmark/benchmark.js index cab10f813617..6fd59473daa0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/betaprime/mean/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/betaprime/mean/benchmark/benchmark.js @@ -21,8 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var Float64Array = require( '@stdlib/array/float64' ); var uniform = require( '@stdlib/random/base/uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -43,11 +43,7 @@ bench( pkg, function benchmark( b ) { beta = new Float64Array( len ); for ( i = 0; i < len; i++ ) { alpha[ i ] = uniform( EPS, 10.0 ); -<<<<<<< HEAD beta[ i ] = uniform( 1.0 + EPS, 11.0 ); -======= - beta[ i ] = uniform( 1.0 + EPS, 10.0 ); ->>>>>>> 68894a16cc9 (bench: refactor random number generation in `stats/base/dists/betaprime`) } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/betaprime/mode/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/betaprime/mode/benchmark/benchmark.js index 90529269da26..1b881edbcf5d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/betaprime/mode/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/betaprime/mode/benchmark/benchmark.js @@ -21,8 +21,8 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/base/uniform' ); var Float64Array = require( '@stdlib/array/float64' ); -var uniform = require( '@stdlib/random/base/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; diff --git a/lib/node_modules/@stdlib/stats/base/dists/binomial/skewness/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/binomial/skewness/benchmark/benchmark.js index 7fc41e4a0a5b..738012adaa31 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/binomial/skewness/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/binomial/skewness/benchmark/benchmark.js @@ -21,6 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); +var Int32Array = require( '@stdlib/array/int32' ); var Float64Array = require( '@stdlib/array/float64' ); var uniform = require( '@stdlib/random/base/uniform' ); var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); @@ -39,11 +40,7 @@ bench( pkg, function benchmark( b ) { var i; len = 100; -<<<<<<< HEAD n = new Int32Array( len ); -======= - n = new Float64Array( len ); ->>>>>>> af55f0d6d6b (bench: refactor random number generation in `stats/base/dists/binomial`) p = new Float64Array( len ); for ( i = 0; i < len; i++ ) { n[ i ] = discreteUniform( 1, 100 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js index ea32995e84b0..67ccb9bf88d3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js @@ -39,7 +39,11 @@ bench( pkg, function benchmark( b ) { len = 100; lambda = new Float64Array( len ); for ( i = 0; i < len; i++ ) { +<<<<<<< HEAD lambda[ i ] = uniform( 0.1, 11.0 ); +======= + lambda[ i ] = uniform( 1.0, 11.0 ); +>>>>>>> c9a203d92ef (chore: merge develop) } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js index cb86f0131b13..4d71ee6cad22 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js @@ -30,8 +30,12 @@ var addon = require( './../src/addon.node' ); * * @private * @param {number} lambda - shape parameter +<<<<<<< HEAD * @returns {PositiveNumber} standard deviation +======= +* @returns {Probability} evaluated standard deviation +>>>>>>> c9a203d92ef (chore: merge develop) * * @example * var v = stdev( 0.1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md index d5eebad9161e..5ea030df0d4b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md @@ -241,10 +241,13 @@ int main( void ) { +<<<<<<< HEAD
+======= +>>>>>>> c9a203d92ef (chore: merge develop) +======= +>>>>>>> c9a203d92ef (chore: merge develop) +======= +>>>>>>> c9a203d92ef (chore: merge develop)
From 26d5ed3c0885ab5ed425946eb2ba2e83dcb46395 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Wed, 19 Feb 2025 16:00:35 +0530 Subject: [PATCH 22/24] chore: revert changes --- .../stats/base/dists/planck/stdev/README.md | 3 +-- .../dists/planck/stdev/benchmark/benchmark.js | 4 ---- .../stats/base/dists/planck/stdev/lib/native.js | 5 ----- .../base/dists/triangular/entropy/README.md | 4 ---- .../base/dists/triangular/kurtosis/README.md | 4 ---- .../stats/base/dists/triangular/logcdf/README.md | 4 ---- .../stats/base/dists/triangular/logpdf/README.md | 16 ++++------------ .../stats/base/dists/triangular/mean/README.md | 4 ---- .../stats/base/dists/triangular/median/README.md | 4 ---- .../stats/base/dists/triangular/mgf/README.md | 16 ++++------------ .../stats/base/dists/triangular/mode/README.md | 4 ---- .../stats/base/dists/triangular/pdf/README.md | 16 ++++------------ .../base/dists/triangular/skewness/README.md | 4 ---- .../stats/base/dists/triangular/stdev/README.md | 4 ---- .../stats/base/dists/uniform/logcdf/README.md | 7 ------- .../stats/base/dists/uniform/logpdf/README.md | 7 ------- .../stats/base/dists/uniform/logpdf/src/main.c | 4 ---- .../stats/base/dists/uniform/pdf/README.md | 6 +----- .../stats/base/dists/uniform/stdev/README.md | 7 ------- 19 files changed, 14 insertions(+), 109 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/README.md b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/README.md index 4d5983495930..2bd3ab9b0e23 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/README.md @@ -64,8 +64,7 @@ v = stdev( 1.5 ); // returns ~0.6080 ``` -If provided a shape parameter `λ` which is nonpositive, the function returns `NaN`. - +If provided a success probability `λ` which is nonpositive, the function returns `NaN`. ```javascript var v = stdev( NaN ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js index 67ccb9bf88d3..fe1ea89ff2e0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js @@ -39,11 +39,7 @@ bench( pkg, function benchmark( b ) { len = 100; lambda = new Float64Array( len ); for ( i = 0; i < len; i++ ) { -<<<<<<< HEAD - lambda[ i ] = uniform( 0.1, 11.0 ); -======= lambda[ i ] = uniform( 1.0, 11.0 ); ->>>>>>> c9a203d92ef (chore: merge develop) } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js index 4d71ee6cad22..4e9760920ce8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js @@ -30,12 +30,7 @@ var addon = require( './../src/addon.node' ); * * @private * @param {number} lambda - shape parameter -<<<<<<< HEAD -* @returns {PositiveNumber} standard deviation - -======= * @returns {Probability} evaluated standard deviation ->>>>>>> c9a203d92ef (chore: merge develop) * * @example * var v = stdev( 0.1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/entropy/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/entropy/README.md index 6a4b8a340aa0..8f698d9e1ca9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/entropy/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/entropy/README.md @@ -233,10 +233,6 @@ int main( void ) { -
- - -
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/kurtosis/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/kurtosis/README.md index 86e942fc1aa3..f8ab658d635d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/kurtosis/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/kurtosis/README.md @@ -233,10 +233,6 @@ int main( void ) { -
- - -
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/logcdf/README.md index 908bb4d19c58..2712eaf1d427 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/logcdf/README.md @@ -158,10 +158,6 @@ for ( i = 0; i < 25; i++ ) { -
- - - - - - - - -
- -
- diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/mean/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/mean/README.md index f648ff1cbd14..e294590d2a2c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/mean/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/mean/README.md @@ -235,10 +235,6 @@ int main( void ) { -
- - -
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/median/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/median/README.md index e62e34663ff5..f33f6243d6d5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/median/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/median/README.md @@ -235,10 +235,6 @@ int main( void ) { -
- - -
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/README.md index 6283c6605905..b536ae5bf161 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/README.md @@ -163,6 +163,10 @@ for ( i = 0; i < 10; i++ ) { + + +
+ * * * @@ -259,18 +263,6 @@ int main( void ) {
- - -
- - - - - -
- -
- diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/mode/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/mode/README.md index a7f9baec5f27..f6d6af98c5a7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/mode/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/mode/README.md @@ -233,10 +233,6 @@ int main( void ) { - - - -
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/pdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/pdf/README.md index 3e9de2ca3506..9edd4427b3a6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/pdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/pdf/README.md @@ -148,6 +148,10 @@ for ( i = 0; i < 25; i++ ) { + + +
+ * * * @@ -244,18 +248,6 @@ int main( void ) {
- - -
- - - - - -
- -
- diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/README.md index d98a25e9fa6d..e5b36504b2c2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/README.md @@ -235,10 +235,6 @@ int main( void ) { - - - -
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/README.md index 203c58ee9ef0..002e602588d7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/README.md @@ -235,10 +235,6 @@ int main( void ) { -
- - -
diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md index 5ea030df0d4b..7586f2e3f76b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md @@ -241,13 +241,6 @@ int main( void ) { -<<<<<<< HEAD -
- - - -======= ->>>>>>> c9a203d92ef (chore: merge develop) - - - -======= ->>>>>>> c9a203d92ef (chore: merge develop) - - - - - - -======= ->>>>>>> c9a203d92ef (chore: merge develop)
From 8e387344c6bbeb6eb89d266fcf0378fec375b807 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Wed, 19 Feb 2025 16:03:20 +0530 Subject: [PATCH 23/24] chore: revert changes --- .../stats/base/dists/planck/stdev/README.md | 3 ++- .../dists/planck/stdev/benchmark/benchmark.js | 2 +- .../stats/base/dists/planck/stdev/lib/native.js | 3 ++- .../base/dists/triangular/entropy/README.md | 4 ++++ .../base/dists/triangular/kurtosis/README.md | 4 ++++ .../stats/base/dists/triangular/logcdf/README.md | 4 ++++ .../stats/base/dists/triangular/logpdf/README.md | 16 ++++++++++++---- .../stats/base/dists/triangular/mean/README.md | 4 ++++ .../stats/base/dists/triangular/median/README.md | 4 ++++ .../stats/base/dists/triangular/mgf/README.md | 16 ++++++++++++---- .../stats/base/dists/triangular/mode/README.md | 4 ++++ .../stats/base/dists/triangular/pdf/README.md | 16 ++++++++++++---- .../base/dists/triangular/skewness/README.md | 4 ++++ .../stats/base/dists/triangular/stdev/README.md | 4 ++++ .../stats/base/dists/uniform/logcdf/README.md | 4 ++++ .../stats/base/dists/uniform/logpdf/README.md | 4 ++++ .../stats/base/dists/uniform/logpdf/src/main.c | 2 +- .../stats/base/dists/uniform/pdf/README.md | 6 +++++- .../stats/base/dists/uniform/stdev/README.md | 4 ++++ 19 files changed, 91 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/README.md b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/README.md index 2bd3ab9b0e23..4d5983495930 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/README.md @@ -64,7 +64,8 @@ v = stdev( 1.5 ); // returns ~0.6080 ``` -If provided a success probability `λ` which is nonpositive, the function returns `NaN`. +If provided a shape parameter `λ` which is nonpositive, the function returns `NaN`. + ```javascript var v = stdev( NaN ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js index fe1ea89ff2e0..ea32995e84b0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/benchmark/benchmark.js @@ -39,7 +39,7 @@ bench( pkg, function benchmark( b ) { len = 100; lambda = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - lambda[ i ] = uniform( 1.0, 11.0 ); + lambda[ i ] = uniform( 0.1, 11.0 ); } b.tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js index 4e9760920ce8..cb86f0131b13 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/stdev/lib/native.js @@ -30,7 +30,8 @@ var addon = require( './../src/addon.node' ); * * @private * @param {number} lambda - shape parameter -* @returns {Probability} evaluated standard deviation +* @returns {PositiveNumber} standard deviation + * * @example * var v = stdev( 0.1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/entropy/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/entropy/README.md index 8f698d9e1ca9..6a4b8a340aa0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/entropy/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/entropy/README.md @@ -233,6 +233,10 @@ int main( void ) { +
+ + +
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/kurtosis/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/kurtosis/README.md index f8ab658d635d..86e942fc1aa3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/kurtosis/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/kurtosis/README.md @@ -233,6 +233,10 @@ int main( void ) { +
+ + +
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/logcdf/README.md index 2712eaf1d427..908bb4d19c58 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/logcdf/README.md @@ -158,6 +158,10 @@ for ( i = 0; i < 25; i++ ) { +
+ + + + + + + + +
+ +
+ diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/mean/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/mean/README.md index e294590d2a2c..f648ff1cbd14 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/mean/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/mean/README.md @@ -235,6 +235,10 @@ int main( void ) { + + + +
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/median/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/median/README.md index f33f6243d6d5..e62e34663ff5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/median/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/median/README.md @@ -235,6 +235,10 @@ int main( void ) { +
+ + +
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/README.md index b536ae5bf161..6283c6605905 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/mgf/README.md @@ -163,10 +163,6 @@ for ( i = 0; i < 10; i++ ) { - - -
- * * * @@ -263,6 +259,18 @@ int main( void ) {
+ + +
+ + + + + +
+ +
+ diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/mode/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/mode/README.md index f6d6af98c5a7..a7f9baec5f27 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/mode/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/mode/README.md @@ -233,6 +233,10 @@ int main( void ) { + + + +
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/pdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/pdf/README.md index 9edd4427b3a6..3e9de2ca3506 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/pdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/pdf/README.md @@ -148,10 +148,6 @@ for ( i = 0; i < 25; i++ ) { - - -
- * * * @@ -248,6 +244,18 @@ int main( void ) {
+ + +
+ + + + + +
+ +
+ diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/README.md index e5b36504b2c2..d98a25e9fa6d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/skewness/README.md @@ -235,6 +235,10 @@ int main( void ) { + + + +
diff --git a/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/README.md b/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/README.md index 002e602588d7..203c58ee9ef0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/triangular/stdev/README.md @@ -235,6 +235,10 @@ int main( void ) { +
+ + +
diff --git a/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md index 7586f2e3f76b..d5eebad9161e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/uniform/logcdf/README.md @@ -241,6 +241,10 @@ int main( void ) { +
+ + + + + + + + + + + +
From 1f1e29d6a143ef4b40384dc6ed9377a392c4044f Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 19 Feb 2025 16:26:14 -0800 Subject: [PATCH 24/24] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/math/base/napi/ternary/README.md | 4 ++-- .../ternary/include/stdlib/math/base/napi/ternary/did_d.h | 4 ++-- lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md index 9c26711252a5..94a06e5afa4c 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/README.md +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/README.md @@ -265,7 +265,7 @@ void stdlib_math_base_napi_ddd_d( napi_env env, napi_callback_info info, double #### STDLIB_MATH_BASE_NAPI_MODULE_DID_D( fcn ) -Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. +Macro for registering a Node-API module exporting an interface for invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integer, and a double-precision floating-point number and returning a double-precision floating-point number. ```c #include @@ -288,7 +288,7 @@ When used, this macro should be used **instead of** `NAPI_MODULE`. The macro inc #### stdlib_math_base_napi_did_d( env, info, fcn ) -Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. +Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integer, and a double-precision floating-point number and returning a double-precision floating-point number. ```c #include diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h index c892a6dc1657..a4cd08aa31bb 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/include/stdlib/math/base/napi/ternary/did_d.h @@ -24,7 +24,7 @@ #include /** -* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. +* Macro for registering a Node-API module exporting an interface invoking a ternary function accepting a double-precision floating-point number, a signed 32-bit integer, and a double-precision floating-point number and returning a double-precision floating-point number. * * @param fcn ternary function * @@ -73,7 +73,7 @@ extern "C" { #endif /** -* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. +* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integer, and a double-precision floating-point number and returning a double-precision floating-point number. */ napi_value stdlib_math_base_napi_did_d( napi_env env, napi_callback_info info, double (*fcn)( double, int32_t, double ) ); diff --git a/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.c b/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.c index c71529252e6c..624038ca8700 100644 --- a/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.c +++ b/lib/node_modules/@stdlib/math/base/napi/ternary/src/did_d.c @@ -22,7 +22,7 @@ #include /** -* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integer and a double-precision floating-point number and returning a double-precision floating-point number. +* Invokes a ternary function accepting a double-precision floating-point number, a signed 32-bit integer, and a double-precision floating-point number and returning a double-precision floating-point number. * * ## Notes *