From 3bd5c1ecbe8e3b749c14a36cdce5ce7cab4f7740 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sat, 11 Jan 2025 00:10:39 +0530 Subject: [PATCH 01/11] feat: add C ndarray interface and refactor implementation --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/stats/base/dvariancepn/README.md | 164 ++++++++++++++---- .../base/dvariancepn/benchmark/benchmark.js | 18 +- .../dvariancepn/benchmark/benchmark.native.js | 14 +- .../benchmark/benchmark.ndarray.js | 18 +- .../benchmark/benchmark.ndarray.native.js | 14 +- .../benchmark/c/benchmark.length.c | 50 +++++- .../stats/base/dvariancepn/docs/repl.txt | 32 ++-- .../base/dvariancepn/docs/types/index.d.ts | 12 +- .../base/dvariancepn/examples/c/example.c | 9 +- .../stats/base/dvariancepn/examples/index.js | 14 +- .../include/stdlib/stats/base/dvariancepn.h | 9 +- .../stats/base/dvariancepn/lib/dvariancepn.js | 44 +---- .../dvariancepn/lib/dvariancepn.native.js | 9 +- .../stats/base/dvariancepn/lib/index.js | 7 +- .../stats/base/dvariancepn/lib/ndarray.js | 18 +- .../base/dvariancepn/lib/ndarray.native.js | 20 +-- .../stats/base/dvariancepn/manifest.json | 49 ++++-- .../stats/base/dvariancepn/src/addon.c | 27 ++- .../dvariancepn/src/{dvariancepn.c => main.c} | 45 +++-- .../base/dvariancepn/test/test.dvariancepn.js | 13 +- .../test/test.dvariancepn.native.js | 13 +- .../base/dvariancepn/test/test.ndarray.js | 13 +- .../dvariancepn/test/test.ndarray.native.js | 13 +- 23 files changed, 371 insertions(+), 254 deletions(-) rename lib/node_modules/@stdlib/stats/base/dvariancepn/src/{dvariancepn.c => main.c} (59%) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md index a2c83064d151..9dd4624dced2 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md @@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var dvariancepn = require( '@stdlib/stats/base/dvariancepn' ); ``` -#### dvariancepn( N, correction, x, stride ) +#### dvariancepn( N, correction, x, strideX ) Computes the [variance][variance] of a double-precision floating-point strided array `x` using a two-pass algorithm. @@ -106,9 +106,8 @@ Computes the [variance][variance] of a double-precision floating-point strided a var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dvariancepn( N, 1, x, 1 ); +var v = dvariancepn( x.length, 1, x, 1 ); // returns ~4.3333 ``` @@ -117,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. 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 ] ); -var N = floor( x.length / 2 ); -var v = dvariancepn( N, 1, x, 2 ); +var v = dvariancepn( 4, 1, x, 2 ); // returns 6.25 ``` @@ -138,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 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dvariancepn( N, 1, x1, 2 ); +var v = dvariancepn( 4, 1, x1, 2 ); // returns 6.25 ``` -#### dvariancepn.ndarray( N, correction, x, stride, offset ) +#### dvariancepn.ndarray( N, correction, x, strideX, offsetX ) Computes the [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. @@ -157,26 +151,23 @@ Computes the [variance][variance] of a double-precision floating-point strided a var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dvariancepn.ndarray( N, 1, x, 1, 0 ); +var v = dvariancepn.ndarray( x.length, 1, x, 1, 0 ); // returns ~4.33333 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [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 = dvariancepn.ndarray( N, 1, x, 2, 1 ); +var v = dvariancepn.ndarray( 4, 1, x, 2, 1 ); // returns 6.25 ``` @@ -202,18 +193,12 @@ var v = dvariancepn.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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dvariancepn = require( '@stdlib/stats/base/dvariancepn' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); console.log( x ); var v = dvariancepn( x.length, 1, x, 1 ); @@ -224,6 +209,125 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dvariancepn.h" +``` + +#### stdlib_strided_dvariancepn( N, correction, \*X, strideX ) + +Computes the [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm. + +```c +const double x[] = { 1.0, -2.0, 2.0 }; + +double v = stdlib_strided_dvariancepn( 3, 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. 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_dvariancepn( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dvariancepn_ndarray( N, correction, \*X, strideX, offsetX ) + +Computes the [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. + +```c +const double x[] = { 1.0, -2.0, 2.0 }; + +double v = stdlib_strided_dvariancepn_ndarray( 3, 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. 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_dvariancepn_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/dvariancepn.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the variance: + double v = stdlib_strided_dvariancepn( N, 1, x, strideX ); + + // Print the result: + printf( "sample variance: %lf\n", v ); +} +``` + +
+ + + +
+ + + * * *
diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.js index 9356ac09867b..6d5e1483f487 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dvariancepn = require( './../lib/dvariancepn.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dvariancepn = require( './../lib/dvariancepn.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.native.js index 9af58732f864..e25ff0b14c76 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.native.js @@ -22,10 +22,9 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +35,9 @@ var dvariancepn = tryRequire( resolve( __dirname, './../lib/dvariancepn.native.j var opts = { 'skip': ( dvariancepn instanceof Error ) }; +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -48,13 +50,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++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.ndarray.js index be5c5eb0f585..b61af4b1cdf0 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.ndarray.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dvariancepn = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dvariancepn = 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++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.ndarray.native.js index 041e67bd1432..8b436b1afdb8 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,9 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +35,9 @@ var dvariancepn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( dvariancepn instanceof Error ) }; +var options = { + 'dtype': 'float64' +}; // FUNCTIONS // @@ -48,13 +50,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++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/c/benchmark.length.c index bec6fffe6253..2139344126c7 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double v; @@ -107,6 +107,7 @@ static double benchmark( int iterations, int len ) { v = 0.0; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_dvariancepn( len, 1.0, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -120,6 +121,40 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + 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_dvariancepn_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 +177,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dvariancepn/docs/repl.txt index a970883a0e1f..b8df14ab9101 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/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 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. @@ -31,8 +31,8 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. Returns ------- @@ -46,22 +46,19 @@ > {{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 using a two-pass algorithm and alternative indexing semantics. @@ -89,10 +86,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. - offset: integer + offsetX: integer Starting index. Returns @@ -109,8 +106,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/dvariancepn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dvariancepn/docs/types/index.d.ts index f6cf81de4464..a8969411fafb 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/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 = dvariancepn( 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 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 = dvariancepn.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/dvariancepn/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dvariancepn/examples/c/example.c index 0f337f017fd5..2b9b1bbfca8d 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dvariancepn.h" -#include #include int main( void ) { // Create a strided array: - double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; // Specify the number of elements: - int64_t N = 4; + const int N = 4; // Specify the stride length: - int64_t stride = 2; + const int strideX = 2; // Compute the variance: - double v = stdlib_strided_dvariancepn( N, 1, x, stride ); + double v = stdlib_strided_dvariancepn( N, 1, x, strideX ); // Print the result: printf( "sample variance: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/examples/index.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/examples/index.js index 2a3db31a834e..dff4e48464b6 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/examples/index.js @@ -18,18 +18,12 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dvariancepn = require( './../lib' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); console.log( x ); var v = dvariancepn( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/include/stdlib/stats/base/dvariancepn.h b/lib/node_modules/@stdlib/stats/base/dvariancepn/include/stdlib/stats/base/dvariancepn.h index 00284d0e74b4..48cee71d8bfe 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/include/stdlib/stats/base/dvariancepn.h +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/include/stdlib/stats/base/dvariancepn.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DVARIANCEPN_H #define STDLIB_STATS_BASE_DVARIANCEPN_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 using a two-pass algorithm. */ -double stdlib_strided_dvariancepn( const int64_t N, const double correction, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dvariancepn)( 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 using a two-pass algorithm and alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dvariancepn_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/dvariancepn/lib/dvariancepn.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/dvariancepn.js index 83fadb4b6519..e5c33e6e76b5 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/dvariancepn.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/dvariancepn.js @@ -20,7 +20,8 @@ // MODULES // -var dsumpw = require( '@stdlib/blas/ext/base/dsumpw' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -40,52 +41,19 @@ var dsumpw = require( '@stdlib/blas/ext/base/dsumpw' ); * @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, 2.0 ] ); -* var N = x.length; * -* var v = dvariancepn( N, 1, x, 1 ); +* var v = dvariancepn( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function dvariancepn( N, correction, x, stride ) { - var mu; - var ix; - var M2; - var M; - var d; - var n; - var i; - - n = N - correction; - if ( N <= 0 || n <= 0.0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - return 0.0; - } - // Compute an estimate for the mean: - mu = dsumpw( N, x, stride ) / N; - - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - // Compute the variance... - M2 = 0.0; - M = 0.0; - for ( i = 0; i < N; i++ ) { - d = x[ ix ] - mu; - M2 += d * d; - M += d; - ix += stride; - } - return (M2/n) - ((M/N)*(M/n)); +function dvariancepn( N, correction, x, strideX ) { + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/dvariancepn.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/dvariancepn.native.js index e64dd7544302..88678f7eb409 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/dvariancepn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/dvariancepn.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, 2.0 ] ); -* var N = x.length; * -* var v = dvariancepn( N, 1, x, 1 ); +* var v = dvariancepn( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function dvariancepn( N, correction, x, stride ) { - return addon( N, correction, x, stride ); +function dvariancepn( N, correction, x, strideX ) { + return addon( N, correction, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/index.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/index.js index 602b42f409ab..be5471299fd3 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/index.js @@ -28,20 +28,17 @@ * var dvariancepn = require( '@stdlib/stats/base/dvariancepn' ); * * var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = dvariancepn( N, 1, x, 1 ); +* var v = dvariancepn( x.length, 1, x, 1 ); * // returns ~4.3333 * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var dvariancepn = require( '@stdlib/stats/base/dvariancepn' ); * * 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 = dvariancepn.ndarray( N, 1, x, 2, 1 ); +* var v = dvariancepn.ndarray( 4, 1, x, 2, 1 ); * // returns 6.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.js index 7f2b436be50d..e09686339a38 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.js @@ -40,21 +40,19 @@ var dsumpw = require( '@stdlib/blas/ext/base/dsumpw' ).ndarray; * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = dvariancepn( N, 1, x, 2, 1 ); +* var v = dvariancepn( 4, 1, x, 2, 1 ); * // returns 6.25 */ -function dvariancepn( N, correction, x, stride, offset ) { +function dvariancepn( N, correction, x, strideX, offsetX ) { var mu; var ix; var M2; @@ -67,21 +65,21 @@ function dvariancepn( N, correction, x, stride, offset ) { if ( N <= 0 || n <= 0.0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { + if ( N === 1 || strideX === 0 ) { return 0.0; } // Compute an estimate for the mean: - mu = dsumpw( N, x, stride, offset ) / N; + mu = dsumpw( N, x, strideX, offsetX ) / N; // Compute the variance... - ix = offset; + ix = offsetX; M2 = 0.0; M = 0.0; for ( i = 0; i < N; i++ ) { d = x[ ix ] - mu; M2 += d * d; M += d; - ix += stride; + ix += strideX; } return (M2/n) - ((M/N)*(M/n)); } diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js index bea2992f28a6..d363f4601601 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float64Array = require( '@stdlib/array/float64' ); -var addon = require( './dvariancepn.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,27 +31,20 @@ var addon = require( './dvariancepn.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 ] ); -* var N = floor( x.length / 2 ); * -* var v = dvariancepn( N, 1, x, 2, 1 ); +* var v = dvariancepn( 4, 1, x, 2, 1 ); * // returns 6.25 */ -function dvariancepn( 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 dvariancepn( N, correction, x, strideX, offsetX ) { + return addon.ndarray( N, correction, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/manifest.json b/lib/node_modules/@stdlib/stats/base/dvariancepn/manifest.json index e91a6c7339b1..eee543e2c17a 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/manifest.json @@ -1,6 +1,7 @@ { "options": { - "task": "build" + "task": "build", + "wasm": false }, "fields": [ { @@ -27,18 +28,19 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ - "./src/dvariancepn.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/blas/ext/base/dsumpw", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -49,34 +51,53 @@ }, { "task": "benchmark", + "wasm": false, "src": [ - "./src/dvariancepn.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dsumpw" + "@stdlib/blas/ext/base/dsumpw", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { "task": "examples", + "wasm": false, "src": [ - "./src/dvariancepn.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/ext/base/dsumpw", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dsumpw" + "@stdlib/blas/ext/base/dsumpw", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/src/addon.c b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/addon.c index f43890ff4aae..c91dffd425aa 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/addon.c @@ -17,6 +17,7 @@ */ #include "stdlib/stats/base/dvariancepn.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_dvariancepn( 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_dvariancepn)( 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_dvariancepn_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/dvariancepn/src/dvariancepn.c b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c similarity index 59% rename from lib/node_modules/@stdlib/stats/base/dvariancepn/src/dvariancepn.c rename to lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c index 6c71778c9261..4c2a2182f5c2 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/src/dvariancepn.c +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c @@ -17,8 +17,8 @@ */ #include "stdlib/stats/base/dvariancepn.h" -#include "stdlib/blas/ext/base/dsumpw.h" -#include +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Computes the variance of a double-precision floating-point strided array using a two-pass algorithm. @@ -32,15 +32,30 @@ * - 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 +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @return output value */ -double stdlib_strided_dvariancepn( const int64_t N, const double correction, const double *X, const int64_t stride ) { - int64_t ix; - int64_t i; +double API_SUFFIX(stdlib_strided_dvariancepn)( 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_dvariancepn_ndarray)( N, correction, X, strideX, ox ); +} + +/** +* Computes the variance of a double-precision floating-point strided array 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_dvariancepn_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; double dN; double mu; double M2; @@ -53,14 +68,14 @@ double stdlib_strided_dvariancepn( const int64_t N, const double correction, con if ( N <= 0 || n <= 0.0 ) { return 0.0 / 0.0; // NaN } - if ( N == 1 || stride == 0 ) { + if ( N == 1 || strideX == 0 ) { return 0.0; } // Compute an estimate for the mean: - mu = stdlib_strided_dsumpw( N, X, stride ) / dN; + mu = stdlib_strided_dsumpw( N, X, strideX ) / dN; - if ( stride < 0 ) { - ix = (1-N) * stride; + if ( strideX < 0 ) { + ix = (1-N) * strideX; } else { ix = 0; } @@ -71,7 +86,7 @@ double stdlib_strided_dvariancepn( const int64_t N, const double correction, con d = X[ ix ] - mu; M2 += d * d; M += d; - ix += stride; + ix += strideX; } return (M2/n) - ((M/dN)*(M/n)); } diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.dvariancepn.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.dvariancepn.js index 4774c7f3a55f..a128ed25d85b 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.dvariancepn.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.dvariancepn.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 dvariancepn = require( './../lib/dvariancepn.js' ); @@ -121,7 +120,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -136,15 +134,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, 2 ); + v = dvariancepn( 4, 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; @@ -159,8 +155,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, -2 ); + v = dvariancepn( 4, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -181,7 +176,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -197,9 +191,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 = dvariancepn( N, 1, x1, 2 ); + v = dvariancepn( 4, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.dvariancepn.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.dvariancepn.native.js index bd639543ca5c..c3d179a4b119 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.dvariancepn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.dvariancepn.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' ); @@ -130,7 +129,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -145,15 +143,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, 2 ); + v = dvariancepn( 4, 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; @@ -168,8 +164,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, -2 ); + v = dvariancepn( 4, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -190,7 +185,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -206,9 +200,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 = dvariancepn( N, 1, x1, 2 ); + v = dvariancepn( 4, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js index 401a11e321f5..56c4fa5ee9d7 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/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 dvariancepn = require( './../lib/ndarray.js' ); @@ -121,7 +120,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -136,15 +134,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, 2, 0 ); + v = dvariancepn( 4, 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; @@ -159,8 +155,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, -2, 6 ); + v = dvariancepn( 4, 1, x, -2, 6 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -179,7 +174,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -193,9 +187,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, 2, 1 ); + v = dvariancepn( 4, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js index d85915b27707..2f25ddd43e9f 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/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' ); @@ -130,7 +129,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -145,15 +143,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, 2, 0 ); + v = dvariancepn( 4, 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; @@ -168,8 +164,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, -2, 6 ); + v = dvariancepn( 4, 1, x, -2, 6 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -188,7 +183,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -202,9 +196,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = dvariancepn( N, 1, x, 2, 1 ); + v = dvariancepn( 4, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From b8eeb0802c77beb16e914a28f7ecb9103becc931 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sat, 11 Jan 2025 12:22:00 +0530 Subject: [PATCH 02/11] fix: updated test values --- 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: passed - 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: passed --- --- .../@stdlib/stats/base/dvariancepn/src/main.c | 1 + .../base/dvariancepn/test/test.ndarray.native.js | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c index 4c2a2182f5c2..905e11ffa804 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c @@ -17,6 +17,7 @@ */ #include "stdlib/stats/base/dvariancepn.h" +#include "stdlib/blas/ext/base/dsumpw.h" #include "stdlib/blas/base/shared.h" #include "stdlib/strided/base/stride2offset.h" diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js index 2f25ddd43e9f..1a70c493aa74 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js @@ -187,14 +187,14 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { var v; x = new Float64Array([ + 1.0, + 2.0, // 0 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 + -7.0, // 1 -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 + 3.0, // 2 + 4.0, + 2.0 // 3 ]); v = dvariancepn( 4, 1, x, 2, 1 ); From 7537799b83728a53e05794d2dd6ac6ca9a998382 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sat, 11 Jan 2025 12:27:01 +0530 Subject: [PATCH 03/11] fix: updated test values --- 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: passed - 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: failed --- --- .../stats/base/dvariancepn/test/test.ndarray.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js index 56c4fa5ee9d7..3bf3e8174a11 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js @@ -178,14 +178,14 @@ tape( 'the function supports an `offset` parameter', function test( t ) { var v; x = new Float64Array([ + 1.0, + 2.0, // 0 2.0, - 1.0, // 0 - 2.0, - -2.0, // 1 + -7.0, // 1 -2.0, - 2.0, // 2 - 3.0, - 4.0 // 3 + 3.0, // 2 + 4.0, + 2.0 // 3 ]); v = dvariancepn( 4, 1, x, 2, 1 ); From b1a636703a7d43974a78838fdff874805000e1b1 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sat, 11 Jan 2025 12:30:07 +0530 Subject: [PATCH 04/11] fix: in test 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: passed - 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: passed --- --- .../stats/base/dvariancepn/test/test.ndarray.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js index 3bf3e8174a11..56c4fa5ee9d7 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.js @@ -178,14 +178,14 @@ tape( 'the function supports an `offset` parameter', function test( t ) { var v; x = new Float64Array([ - 1.0, - 2.0, // 0 2.0, - -7.0, // 1 + 1.0, // 0 + 2.0, + -2.0, // 1 -2.0, - 3.0, // 2 - 4.0, - 2.0 // 3 + 2.0, // 2 + 3.0, + 4.0 // 3 ]); v = dvariancepn( 4, 1, x, 2, 1 ); From 7b3cfe84573e926b77030a152cad937725266531 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sat, 11 Jan 2025 12:33:37 +0530 Subject: [PATCH 05/11] fix: updated input array value --- 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: 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 --- --- .../@stdlib/stats/base/dvariancepn/lib/ndarray.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js index d363f4601601..23d889bc2916 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js @@ -38,7 +38,7 @@ var addon = require( './../src/addon.node' ); * @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 ] ); +* var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); * * var v = dvariancepn( 4, 1, x, 2, 1 ); * // returns 6.25 From b281eb78aaa3470e7c7752bc2e9fa603891ed7e1 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 12 Jan 2025 18:10:35 +0530 Subject: [PATCH 06/11] fix: updated function to support ndarray --- 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: passed - 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: passed --- --- .../stats/base/dvariancepn/lib/ndarray.native.js | 2 +- .../@stdlib/stats/base/dvariancepn/src/main.c | 8 ++------ .../stats/base/dvariancepn/test/test.ndarray.native.js | 10 +++++----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js index 23d889bc2916..d363f4601601 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/lib/ndarray.native.js @@ -38,7 +38,7 @@ var addon = require( './../src/addon.node' ); * @example * 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 ] ); +* var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * * var v = dvariancepn( 4, 1, x, 2, 1 ); * // returns 6.25 diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c index 905e11ffa804..191a0f9ed54d 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c @@ -73,13 +73,9 @@ double API_SUFFIX(stdlib_strided_dvariancepn_ndarray)( const CBLAS_INT N, const return 0.0; } // Compute an estimate for the mean: - mu = stdlib_strided_dsumpw( N, X, strideX ) / dN; + mu = API_SUFFIX(stdlib_strided_dsumpw_ndarray)( N, X, strideX, offsetX ) / dN; - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } + ix = offsetX; // Compute the variance... M2 = 0.0; M = 0.0; diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js index 1a70c493aa74..437e464619b4 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js @@ -188,13 +188,13 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { x = new Float64Array([ 1.0, - 2.0, // 0 + 1.0, // 0 2.0, - -7.0, // 1 + -2.0, // 1 -2.0, - 3.0, // 2 - 4.0, - 2.0 // 3 + 2.0, // 2 + 3.0, + 4.0 // 3 ]); v = dvariancepn( 4, 1, x, 2, 1 ); From 2c1b61001c25c9b57033cf5b7204375398adce9b Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 12 Jan 2025 18:46:17 +0530 Subject: [PATCH 07/11] fix: revert changes in test inputs --- 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: passed - 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: passed --- --- .../@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js index 437e464619b4..2f25ddd43e9f 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/test/test.ndarray.native.js @@ -187,7 +187,7 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { var v; x = new Float64Array([ - 1.0, + 2.0, 1.0, // 0 2.0, -2.0, // 1 From 2a80103582cd16d5319334878297f6cd74296487 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Mon, 13 Jan 2025 20:10:15 +0530 Subject: [PATCH 08/11] chore: updated values as per given 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: 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/dvariancepn/README.md | 12 ++++++------ .../@stdlib/stats/base/dvariancepn/docs/repl.txt | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md index 9dd4624dced2..a1acfa4d199e 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md @@ -240,10 +240,10 @@ console.log( v ); Computes the [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm. ```c -const double x[] = { 1.0, -2.0, 2.0 }; +const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 } -double v = stdlib_strided_dvariancepn( 3, 1.0, x, 1 ); -// returns ~4.3333 +double v = stdlib_strided_dvariancepn( 4, 1.0, x, 1, 0 ); +// returns ~6.666667 ``` The function accepts the following arguments: @@ -262,10 +262,10 @@ double stdlib_strided_dvariancepn( const CBLAS_INT N, const double correction, c Computes the [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics. ```c -const double x[] = { 1.0, -2.0, 2.0 }; +const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 } -double v = stdlib_strided_dvariancepn_ndarray( 3, 1.0, x, 1, 0 ); -// returns ~4.3333 +double v = stdlib_strided_dvariancepn_ndarray( 4, 1.0, x, 1, 0 ); +// returns ~6.666667 ``` The function accepts the following arguments: diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dvariancepn/docs/repl.txt index b8df14ab9101..1113261afebb 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/docs/repl.txt @@ -32,7 +32,7 @@ Input array. strideX: integer - Stride Length. + Stride length. Returns ------- @@ -87,7 +87,7 @@ Input array. strideX: integer - Stride Length. + Stride length. offsetX: integer Starting index. From bf7544c5b099e0deb10f35c7c1afacc7db671793 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 19 Jan 2025 12:29:15 +0530 Subject: [PATCH 09/11] chore: updated inputs in docs --- 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/dvariancepn/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md index a1acfa4d199e..45334ad28b28 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md @@ -242,8 +242,8 @@ Computes the [variance][variance] of a double-precision floating-point strided a ```c const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 } -double v = stdlib_strided_dvariancepn( 4, 1.0, x, 1, 0 ); -// returns ~6.666667 +double v = stdlib_strided_dvariancepn( 8, 1.0, x, 1 ); +// returns 6 ``` The function accepts the following arguments: From 2eb9370349d5a5d51a6f4f26ca6ba47872dd2409 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 23:04:47 -0800 Subject: [PATCH 10/11] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/dvariancepn/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md b/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md index 45334ad28b28..e2470fcd9e0b 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/README.md @@ -243,7 +243,7 @@ Computes the [variance][variance] of a double-precision floating-point strided a const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 } double v = stdlib_strided_dvariancepn( 8, 1.0, x, 1 ); -// returns 6 +// returns 6.0 ``` The function accepts the following arguments: @@ -264,7 +264,7 @@ Computes the [variance][variance] of a double-precision floating-point strided a ```c const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 } -double v = stdlib_strided_dvariancepn_ndarray( 4, 1.0, x, 1, 0 ); +double v = stdlib_strided_dvariancepn_ndarray( 4, 1.0, x, 2, 0 ); // returns ~6.666667 ``` @@ -313,7 +313,7 @@ int main( void ) { const int strideX = 2; // Compute the variance: - double v = stdlib_strided_dvariancepn( N, 1, x, strideX ); + double v = stdlib_strided_dvariancepn( N, 1.0, x, strideX ); // Print the result: printf( "sample variance: %lf\n", v ); From 5a129291af94c9b4fcc106fe5f879121a6a0977f Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 2 Feb 2025 23:09:39 -0800 Subject: [PATCH 11/11] style: insert empty line before comment Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c index 191a0f9ed54d..48df188fc2cf 100644 --- a/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dvariancepn/src/main.c @@ -76,6 +76,7 @@ double API_SUFFIX(stdlib_strided_dvariancepn_ndarray)( const CBLAS_INT N, const mu = API_SUFFIX(stdlib_strided_dsumpw_ndarray)( N, X, strideX, offsetX ) / dN; ix = offsetX; + // Compute the variance... M2 = 0.0; M = 0.0;