From 87a38be53fb6170710f02eb07dc4c7963498a9ab Mon Sep 17 00:00:00 2001 From: DhruvArvindSingh Date: Sat, 4 Jan 2025 21:11:50 +0000 Subject: [PATCH 1/8] feat: added ndarray implementation for @stats/base/dvarmpn --- 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 --- --- .../include/stdlib/stats/base/dvarmpn.h | 8 +++- .../@stdlib/stats/base/dvarmpn/lib/dvarmpn.js | 40 +++++------------ .../stats/base/dvarmpn/lib/dvarmpn.native.js | 6 +-- .../@stdlib/stats/base/dvarmpn/lib/ndarray.js | 16 +++---- .../stats/base/dvarmpn/lib/ndarray.native.js | 20 +++------ .../@stdlib/stats/base/dvarmpn/manifest.json | 40 ++++++++++++++--- .../@stdlib/stats/base/dvarmpn/src/addon.c | 27 ++++++++++-- .../base/dvarmpn/src/{dvarmpn.c => main.c} | 43 +++++++++++++------ 8 files changed, 120 insertions(+), 80 deletions(-) rename lib/node_modules/@stdlib/stats/base/dvarmpn/src/{dvarmpn.c => main.c} (52%) diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/include/stdlib/stats/base/dvarmpn.h b/lib/node_modules/@stdlib/stats/base/dvarmpn/include/stdlib/stats/base/dvarmpn.h index faa2f0cf310e..71357a9720bb 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/include/stdlib/stats/base/dvarmpn.h +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/include/stdlib/stats/base/dvarmpn.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DVARMPN_H #define STDLIB_STATS_BASE_DVARMPN_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,11 @@ extern "C" { /** * Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm. */ -double stdlib_strided_dvarmpn( const int64_t N, const double mean, const double correction, const double *X, const int64_t stride ); +double API_SUFFIX( stdlib_strided_dvarmpn )( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX ); +/** +* Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm using alternative indexing semantics. +*/ +double API_SUFFIX( stdlib_strided_dvarmpn_ndarray )( const CBLAS_INT N, const double mean, 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/dvarmpn/lib/dvarmpn.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.js index 06ffd38b877a..6648bf90cd11 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + // MAIN // /** @@ -32,7 +38,7 @@ * @param {number} mean - mean * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - strideX length * @returns {number} variance * * @example @@ -43,35 +49,9 @@ * var v = dvarmpn( x.length, 1.0/3.0, 1, x, 1 ); * // returns ~4.3333 */ -function dvarmpn( N, mean, correction, x, stride ) { - 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; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - M2 = 0.0; - M = 0.0; - for ( i = 0; i < N; i++ ) { - d = x[ ix ] - mean; - M2 += d * d; - M += d; - ix += stride; - } - return (M2/n) - ((M/N)*(M/n)); +function dvarmpn( N, mean, correction, x, strideX ) { + var ox = stride2offset( N, strideX); + return ndarray( N, mean, correction, x, strideX, ox ); } diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js index acadade5dfd6..fe7f3a7d5b0b 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js @@ -32,7 +32,7 @@ var addon = require( './../src/addon.node' ); * @param {number} mean - mean * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - strideX length * @returns {number} variance * * @example @@ -43,8 +43,8 @@ var addon = require( './../src/addon.node' ); * var v = dvarmpn( x.length, 1.0/3.0, 1, x, 1 ); * // returns ~4.3333 */ -function dvarmpn( N, mean, correction, x, stride ) { - return addon( N, mean, correction, x, stride ); +function dvarmpn( N, mean, correction, x, strideX ) { + return addon( N, mean, correction, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.js index 9c90106996c7..61c77cbacdf9 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.js @@ -32,21 +32,19 @@ * @param {number} mean - mean * @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 - strideX 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 = dvarmpn( N, 1.25, 1, x, 2, 1 ); +* var v = dvarmpn( 4, 1.25, 1, x, 2, 1 ); * // returns 6.25 */ -function dvarmpn( N, mean, correction, x, stride, offset ) { +function dvarmpn( N, mean, correction, x, strideX, offsetX ) { var ix; var M2; var M; @@ -58,17 +56,17 @@ function dvarmpn( N, mean, 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; } - ix = offset; + ix = offsetX; M2 = 0.0; M = 0.0; for ( i = 0; i < N; i++ ) { d = x[ ix ] - mean; 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/dvarmpn/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.native.js index b6da08fa1994..54e1dff61d5b 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float64Array = require( '@stdlib/array/float64' ); -var addon = require( './dvarmpn.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -33,27 +32,20 @@ var addon = require( './dvarmpn.native.js' ); * @param {number} mean - mean * @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 - strideX 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 = dvarmpn( N, 1.25, 1, x, 2, 1 ); +* var v = dvarmpn( 4, 1.25, 1, x, 2, 1 ); * // returns 6.25 */ -function dvarmpn( N, mean, 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, mean, correction, view, stride ); +function dvarmpn( N, mean, correction, x, strideX, offsetX ) { + return addon.ndarray( N, mean, correction, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/manifest.json b/lib/node_modules/@stdlib/stats/base/dvarmpn/manifest.json index ad4bf3c4d7d3..a41fde9bf052 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/manifest.json @@ -1,6 +1,7 @@ { "options": { - "task": "build" + "task": "build", + "wasm": false }, "fields": [ { @@ -27,8 +28,9 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ - "./src/dvarmpn.c" + "./src/main.c" ], "include": [ "./include" @@ -38,6 +40,8 @@ ], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -48,8 +52,9 @@ }, { "task": "benchmark", + "wasm": false, "src": [ - "./src/dvarmpn.c" + "./src/main.c" ], "include": [ "./include" @@ -58,12 +63,16 @@ "-lm" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] }, { "task": "examples", + "wasm": false, "src": [ - "./src/dvarmpn.c" + "./src/main.c" ], "include": [ "./include" @@ -72,7 +81,26 @@ "-lm" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] } ] } diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/src/addon.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/src/addon.c index f2eb4d860dd8..19084c1a64f6 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/src/addon.c @@ -35,12 +35,31 @@ static napi_value addon( 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_INT64( env, stride, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 4 ); STDLIB_NAPI_ARGV_DOUBLE( env, mean, argv, 1 ); STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 3 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dvarmpn( N, mean, correction, X, stride ), v ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 3 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dvarmpn( N, mean, 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, 6 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 4 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 5 ); + STDLIB_NAPI_ARGV_DOUBLE( env, mean, argv, 1 ); + STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 3 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dvarmpn_ndarray( N, mean, 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/dvarmpn/src/dvarmpn.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/src/main.c similarity index 52% rename from lib/node_modules/@stdlib/stats/base/dvarmpn/src/dvarmpn.c rename to lib/node_modules/@stdlib/stats/base/dvarmpn/src/main.c index 47755558d75a..273fea26f9af 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/src/dvarmpn.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/src/main.c @@ -17,7 +17,8 @@ */ #include "stdlib/stats/base/dvarmpn.h" -#include +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/shared.h" /** * Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm. @@ -31,12 +32,34 @@ * @param mean mean * @param correction degrees of freedom adjustment * @param X input array -* @param stride stride length +* @param strideX strideX length * @return output value */ -double stdlib_strided_dvarmpn( const int64_t N, const double mean, const double correction, const double *X, const int64_t stride ) { - int64_t ix; - int64_t i; +double API_SUFFIX( stdlib_strided_dvarmpn )( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dvarmpn_ndarray)( N, mean, correction, X, strideX, ox ); +} + +/** +* Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm. +* +* ## 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 mean mean +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX strideX length +* @param offsetX starting index +* @return output value +*/ + +double API_SUFFIX( stdlib_strided_dvarmpn_ndarray )( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT i; double dN; double M2; double M; @@ -48,21 +71,17 @@ double stdlib_strided_dvarmpn( const int64_t N, const double mean, const double 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; } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } + ix = offsetX; M2 = 0.0; M = 0.0; for ( i = 0; i < N; i++ ) { d = X[ ix ] - mean; M2 += d * d; M += d; - ix += stride; + ix += strideX; } return (M2/n) - ((M/dN)*(M/n)); } From fa22cd0e49b4e52468eef3e468f4ccf30d346314 Mon Sep 17 00:00:00 2001 From: DhruvArvindSingh Date: Sat, 4 Jan 2025 22:08:34 +0000 Subject: [PATCH 2/8] refactor: refactored benchmarks in @stdlib/stats/base/dvarmpn --- 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: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - 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: failed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: failed --- --- .../stats/base/dvarmpn/benchmark/benchmark.js | 18 +++---- .../dvarmpn/benchmark/benchmark.native.js | 14 ++---- .../dvarmpn/benchmark/benchmark.ndarray.js | 18 +++---- .../benchmark/benchmark.ndarray.native.js | 14 ++---- .../dvarmpn/benchmark/c/benchmark.length.c | 50 ++++++++++++++++++- .../stats/base/dvarmpn/docs/types/index.d.ts | 12 ++--- .../stats/base/dvarmpn/examples/c/example.c | 11 ++-- .../stats/base/dvarmpn/examples/index.js | 15 ++---- 8 files changed, 92 insertions(+), 60 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js index 629b3891f9aa..63dfdbace9f3 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var linspace = require( '@stdlib/array/linspace' ); 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 dvarmpn = require( './../lib/dvarmpn.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dvarmpn = require( './../lib/dvarmpn.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 = linspace( -len/2, len/2, len, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js index cf8da139dace..cf47feb21e08 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/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 linspace = require( '@stdlib/array/linspace' ); 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 dvarmpn = tryRequire( resolve( __dirname, './../lib/dvarmpn.native.js' ) ); var opts = { 'skip': ( dvarmpn instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -48,13 +50,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = linspace( -len/2, len/2, len, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js index 8fa3ba35a4ae..1c90be62b6c3 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var linspace = require( '@stdlib/array/linspace' ); 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 dvarmpn = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,13 +45,7 @@ var dvarmpn = 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 = linspace( -len/2, len/2, len, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js index 070c702dff6b..1afa6d090460 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/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 linspace = require( '@stdlib/array/linspace' ); 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 dvarmpn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( dvarmpn instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -48,13 +50,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = linspace( -len/2, len/2, len, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c index 56cfbeedb9f3..4c299448d903 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/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_dvarmpn( len, 0.0, 1, 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; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = i; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_dvarmpn( len, 0.0, 1, x, 1, 1 ); + 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; + 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/dvarmpn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/types/index.d.ts index f3bba910cdba..50ce324d936b 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/types/index.d.ts @@ -29,7 +29,7 @@ interface Routine { * @param mean - mean * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length + * @param strideX - strideX length * @returns variance * * @example @@ -40,7 +40,7 @@ interface Routine { * var v = dvarmpn( x.length, 1.0/3.0, 1, x, 1 ); * // returns ~4.3333 */ - ( N: number, mean: number, correction: number, x: Float64Array, stride: number ): number; + ( N: number, mean: number, correction: number, x: Float64Array, strideX: number ): number; /** * Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm and alternative indexing semantics. @@ -49,8 +49,8 @@ interface Routine { * @param mean - mean * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - strideX length + * @param offsetX - starting index * @returns variance * * @example @@ -61,7 +61,7 @@ interface Routine { * var v = dvarmpn.ndarray( x.length, 1.0/3.0, 1, x, 1, 0 ); * // returns ~4.3333 */ - ndarray( N: number, mean: number, correction: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, mean: number, correction: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** @@ -71,7 +71,7 @@ interface Routine { * @param mean - mean * @param correction - degrees of freedom adjustment * @param x - input array -* @param stride - stride length +* @param strideX - strideX length * @returns variance * * @example diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/c/example.c index a1a1c0711ebd..1e436b0d809f 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dvarmpn.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.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; // Specify the number of elements: - int64_t N = 4; + const int N = 4; - // Specify the stride length: - int64_t stride = 2; + // Specify the strideX length: + const int strideX = 2; // Compute the variance: - double v = stdlib_strided_dvarmpn( N, 4.5, 1, x, stride ); + double v = stdlib_strided_dvarmpn( N, 4.5, 1, x, strideX ); // Print the result: printf( "sample variance: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js index 5cd2c4729b61..1070d9c2eaf9 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js @@ -18,18 +18,13 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var linspace = require( '@stdlib/array/linspace' ); var dvarmpn = 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 options = { + 'dtype': 'float32' +}; +var x = linspace( -5.0, 5.0, 10, options ); console.log( x ); var v = dvarmpn( x.length, 0.0, 1, x, 1 ); From dddbaa23a9390755ad2769d79a596fec3dca9491 Mon Sep 17 00:00:00 2001 From: DhruvArvindSingh Date: Sat, 4 Jan 2025 22:19:55 +0000 Subject: [PATCH 3/8] fix: benchmarks --- 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: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - 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: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: failed --- --- .../@stdlib/stats/base/dvarmpn/benchmark/benchmark.js | 2 +- .../@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js | 2 +- .../stats/base/dvarmpn/benchmark/benchmark.ndarray.js | 2 +- .../stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js | 2 +- .../@stdlib/stats/base/dvarmpn/examples/index.js | 2 +- .../@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js | 5 +++++ 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js index 63dfdbace9f3..be4ee9df7bb4 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js @@ -31,7 +31,7 @@ var dvarmpn = require( './../lib/dvarmpn.js' ); // VARIABLES // var options = { - 'dtype': 'float32' + 'dtype': 'float64' }; diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js index cf47feb21e08..acc91ae778ac 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js @@ -36,7 +36,7 @@ var opts = { 'skip': ( dvarmpn instanceof Error ) }; var options = { - 'dtype': 'float32' + 'dtype': 'float64' }; diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js index 1c90be62b6c3..6508592c1aec 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js @@ -31,7 +31,7 @@ var dvarmpn = require( './../lib/ndarray.js' ); // VARIABLES // var options = { - 'dtype': 'float32' + 'dtype': 'float64' }; diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js index 1afa6d090460..4f27b9fc560e 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js @@ -36,7 +36,7 @@ var opts = { 'skip': ( dvarmpn instanceof Error ) }; var options = { - 'dtype': 'float32' + 'dtype': 'float64' }; diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js index 1070d9c2eaf9..075aaa5b8781 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js @@ -22,7 +22,7 @@ var linspace = require( '@stdlib/array/linspace' ); var dvarmpn = require( './../lib' ); var options = { - 'dtype': 'float32' + 'dtype': 'float64' }; var x = linspace( -5.0, 5.0, 10, options ); console.log( x ); diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js index fe7f3a7d5b0b..32ca89554f3c 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js @@ -28,6 +28,11 @@ var addon = require( './../src/addon.node' ); /** * Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm. * +* ## 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 {PositiveInteger} N - number of indexed elements * @param {number} mean - mean * @param {number} correction - degrees of freedom adjustment From 521f17ca69e0dedf11a702117d9926cef62f52ad Mon Sep 17 00:00:00 2001 From: DhruvArvindSingh Date: Sun, 5 Jan 2025 10:29:10 +0000 Subject: [PATCH 4/8] fix: benchmark.c --- 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: passed - 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 --- --- .../@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c index 4c299448d903..f259bc7121fc 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c @@ -130,7 +130,7 @@ static double benchmark1( int iterations, int len ) { */ static double benchmark2( int iterations, int len ) { double elapsed; - float x[ len ]; + double x[ len ]; float v; double t; int i; @@ -142,7 +142,7 @@ static double benchmark2( int iterations, int len ) { t = tic(); for ( i = 0; i < iterations; i++ ) { // cppcheck-suppress uninitvar - v = stdlib_strided_dvarmpn( len, 0.0, 1, x, 1, 1 ); + v = stdlib_strided_dvarmpn_ndarray( len, 0.0, 1, x, 1, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); break; From 61d65110639910c70bf5e4c1828b473fd3d74f73 Mon Sep 17 00:00:00 2001 From: DhruvArvindSingh Date: Sun, 5 Jan 2025 11:18:44 +0000 Subject: [PATCH 5/8] refactor: test and repl --- 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: passed - 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: passed - 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: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- .../dvarmpn/benchmark/c/benchmark.length.c | 2 +- .../@stdlib/stats/base/dvarmpn/docs/repl.txt | 30 +++++++++---------- .../stats/base/dvarmpn/test/test.dvarmpn.js | 13 ++------ .../base/dvarmpn/test/test.dvarmpn.native.js | 13 ++------ .../stats/base/dvarmpn/test/test.ndarray.js | 13 ++------ .../base/dvarmpn/test/test.ndarray.native.js | 13 ++------ 6 files changed, 27 insertions(+), 57 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c index f259bc7121fc..21535d7e8499 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c @@ -182,7 +182,7 @@ int main( void ) { printf( "ok %d benchmark finished\n", count ); } } - for ( i = MIN; i <= MAX; i++ ) { + for ( i = MIN; i <= MAX - 3; i++ ) { len = pow( 10, i ); iter = ITERATIONS; for ( j = 0; j < REPEATS; j++ ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/repl.txt index 051500d27e9f..8c5de8c540a4 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, mean, correction, x, stride ) +{{alias}}( N, mean, correction, x, strideX ) Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction 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 ------- @@ -49,20 +49,19 @@ > {{alias}}( x.length, 1.0/3.0, 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 ); - > {{alias}}( N, 1.0/3.0, 1, x, 2 ) + > {{alias}}( 3, 1.0/3.0, 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 ); - > {{alias}}( N, 1.0/3.0, 1, x1, 2 ) + > {{alias}}( 3, 1.0/3.0, 1, x1, 2 ) ~4.3333 -{{alias}}.ndarray( N, mean, correction, x, stride, offset ) + +{{alias}}.ndarray( N, mean, correction, x, strideX, offsetX ) Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm and alternative indexing semantics. @@ -94,10 +93,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. - offset: integer + offsetX: integer Starting index. Returns @@ -114,8 +113,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.0/3.0, 1, x, 2, 1 ) + > {{alias}}.ndarray( 3, 1.0/3.0, 1, x, 2, 1 ) ~4.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.dvarmpn.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.dvarmpn.js index c39ebcc5c373..55f9f58e2b58 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.dvarmpn.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.dvarmpn.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 dvarmpn = require( './../lib/dvarmpn.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 = dvarmpn( N, 1.25, 1, x, 2 ); + v = dvarmpn( 4, 1.25, 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 = dvarmpn( N, 1.25, 1, x, -2 ); + v = dvarmpn( 4, 1.25, 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 = dvarmpn( N, 1.25, 1, x1, 2 ); + v = dvarmpn( 4, 1.25, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.dvarmpn.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.dvarmpn.native.js index 350ba90aa36a..0459dcc77617 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.dvarmpn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.dvarmpn.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 = dvarmpn( N, 1.25, 1, x, 2 ); + v = dvarmpn( 4, 1.25, 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 = dvarmpn( N, 1.25, 1, x, -2 ); + v = dvarmpn( 4, 1.25, 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 = dvarmpn( N, 1.25, 1, x1, 2 ); + v = dvarmpn( 4, 1.25, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.ndarray.js index e924282277b3..680b7078df02 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/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 dvarmpn = 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 = dvarmpn( N, 1.25, 1, x, 2, 0 ); + v = dvarmpn( 4, 1.25, 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 = dvarmpn( N, 1.25, 1, x, -2, 6 ); + v = dvarmpn( 4, 1.25, 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 = dvarmpn( N, 1.25, 1, x, 2, 1 ); + v = dvarmpn( 4, 1.25, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.ndarray.native.js index dcecc2f42cd4..2d9b315be9e2 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/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 = dvarmpn( N, 1.25, 1, x, 2, 0 ); + v = dvarmpn( 4, 1.25, 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 = dvarmpn( N, 1.25, 1, x, -2, 6 ); + v = dvarmpn( 4, 1.25, 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 = dvarmpn( N, 1.25, 1, x, 2, 1 ); + v = dvarmpn( 4, 1.25, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From 15b7142575de342832c53acedd1fb2db3e960ec4 Mon Sep 17 00:00:00 2001 From: DhruvArvindSingh Date: Sat, 18 Jan 2025 20:18:08 +0000 Subject: [PATCH 6/8] chore: resolved issues in stats/base/dvarmpn --- 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: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - 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: passed - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - 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/dvarmpn/benchmark/benchmark.js | 4 ++-- .../dvarmpn/benchmark/benchmark.native.js | 4 ++-- .../dvarmpn/benchmark/benchmark.ndarray.js | 4 ++-- .../benchmark/benchmark.ndarray.native.js | 4 ++-- .../dvarmpn/benchmark/c/benchmark.length.c | 2 +- .../@stdlib/stats/base/dvarmpn/docs/repl.txt | 4 ++-- .../stats/base/dvarmpn/docs/types/index.d.ts | 6 +++--- .../stats/base/dvarmpn/examples/c/example.c | 2 +- .../stats/base/dvarmpn/examples/index.js | 4 ++-- .../include/stdlib/stats/base/dvarmpn.h | 6 +++--- .../@stdlib/stats/base/dvarmpn/lib/dvarmpn.js | 5 ++--- .../stats/base/dvarmpn/lib/dvarmpn.native.js | 9 ++------- .../@stdlib/stats/base/dvarmpn/lib/ndarray.js | 4 ++-- .../stats/base/dvarmpn/lib/ndarray.native.js | 4 ++-- .../@stdlib/stats/base/dvarmpn/src/addon.c | 4 ++-- .../@stdlib/stats/base/dvarmpn/src/main.c | 20 +++++++------------ 16 files changed, 37 insertions(+), 49 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js index be4ee9df7bb4..1eba9844c5bb 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var linspace = require( '@stdlib/array/linspace' ); +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 pkg = require( './../package.json' ).name; @@ -45,7 +45,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = linspace( -len/2, len/2, len, options ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js index acc91ae778ac..6a4163da2419 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var linspace = require( '@stdlib/array/linspace' ); +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 tryRequire = require( '@stdlib/utils/try-require' ); @@ -50,7 +50,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = linspace( -len/2, len/2, len, options ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js index 6508592c1aec..e562d3d6a9c3 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var linspace = require( '@stdlib/array/linspace' ); +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 pkg = require( './../package.json' ).name; @@ -45,7 +45,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = linspace( -len/2, len/2, len, options ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js index 4f27b9fc560e..27e60d6828a8 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/benchmark.ndarray.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var linspace = require( '@stdlib/array/linspace' ); +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 tryRequire = require( '@stdlib/utils/try-require' ); @@ -50,7 +50,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = linspace( -len/2, len/2, len, options ); + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c index 21535d7e8499..18b00720190b 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/benchmark/c/benchmark.length.c @@ -136,7 +136,7 @@ static double benchmark2( int iterations, int len ) { int i; for ( i = 0; i < len; i++ ) { - x[ i ] = i; + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; } v = 0.0f; t = tic(); diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/repl.txt index 8c5de8c540a4..2b2e73a96b25 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/repl.txt @@ -35,7 +35,7 @@ Input array. strideX: integer - Stride Length. + Stride length. Returns ------- @@ -94,7 +94,7 @@ Input array. strideX: integer - Stride Length. + Stride length. offsetX: integer Starting index. diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/types/index.d.ts index 50ce324d936b..253f5b6b3daa 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/docs/types/index.d.ts @@ -29,7 +29,7 @@ interface Routine { * @param mean - mean * @param correction - degrees of freedom adjustment * @param x - input array - * @param strideX - strideX length + * @param strideX - stride length * @returns variance * * @example @@ -49,7 +49,7 @@ interface Routine { * @param mean - mean * @param correction - degrees of freedom adjustment * @param x - input array - * @param strideX - strideX length + * @param strideX - stride length * @param offsetX - starting index * @returns variance * @@ -71,7 +71,7 @@ interface Routine { * @param mean - mean * @param correction - degrees of freedom adjustment * @param x - input array -* @param strideX - strideX length +* @param strideX - stride length * @returns variance * * @example diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/c/example.c index 1e436b0d809f..6dcdfb5311cc 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/c/example.c @@ -26,7 +26,7 @@ int main( void ) { // Specify the number of elements: const int N = 4; - // Specify the strideX length: + // Specify the stride length: const int strideX = 2; // Compute the variance: diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js index 075aaa5b8781..f84fec7440aa 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js @@ -18,13 +18,13 @@ 'use strict'; -var linspace = require( '@stdlib/array/linspace' ); +var uniform = require( '@stdlib/random/array/uniform' ); var dvarmpn = require( './../lib' ); var options = { 'dtype': 'float64' }; -var x = linspace( -5.0, 5.0, 10, options ); +var x = uniform( 10, -100, 100, options ); console.log( x ); var v = dvarmpn( x.length, 0.0, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/include/stdlib/stats/base/dvarmpn.h b/lib/node_modules/@stdlib/stats/base/dvarmpn/include/stdlib/stats/base/dvarmpn.h index 71357a9720bb..f1eb54b46ed3 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/include/stdlib/stats/base/dvarmpn.h +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/include/stdlib/stats/base/dvarmpn.h @@ -31,11 +31,11 @@ extern "C" { /** * Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm. */ -double API_SUFFIX( stdlib_strided_dvarmpn )( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX ); +double API_SUFFIX(stdlib_strided_dvarmpn)( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX ); /** -* Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm using alternative indexing semantics. +* Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm with alternative indexing semantics. */ -double API_SUFFIX( stdlib_strided_dvarmpn_ndarray )( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +double API_SUFFIX(stdlib_strided_dvarmpn_ndarray)( const CBLAS_INT N, const double mean, 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/dvarmpn/lib/dvarmpn.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.js index 6648bf90cd11..600039fe1685 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.js @@ -38,7 +38,7 @@ var ndarray = require( './ndarray.js' ); * @param {number} mean - mean * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} strideX - strideX length +* @param {integer} strideX - stride length * @returns {number} variance * * @example @@ -50,8 +50,7 @@ var ndarray = require( './ndarray.js' ); * // returns ~4.3333 */ function dvarmpn( N, mean, correction, x, strideX ) { - var ox = stride2offset( N, strideX); - return ndarray( N, mean, correction, x, strideX, ox ); + return ndarray( N, mean, correction, x, strideX, stride2offset( N, strideX) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js index 32ca89554f3c..d279504d69c7 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/dvarmpn.native.js @@ -28,16 +28,11 @@ var addon = require( './../src/addon.node' ); /** * Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm. * -* ## 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 {PositiveInteger} N - number of indexed elements * @param {number} mean - mean * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} strideX - strideX length +* @param {integer} strideX - stride length * @returns {number} variance * * @example @@ -46,7 +41,7 @@ var addon = require( './../src/addon.node' ); * var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); * * var v = dvarmpn( x.length, 1.0/3.0, 1, x, 1 ); -* // returns ~4.3333 +* //returns ~4.3333 */ function dvarmpn( N, mean, correction, x, strideX ) { return addon( N, mean, correction, x, strideX ); diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.js index 61c77cbacdf9..38d0601be223 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.js @@ -32,7 +32,7 @@ * @param {number} mean - mean * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} strideX - strideX length +* @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * @@ -42,7 +42,7 @@ * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * * var v = dvarmpn( 4, 1.25, 1, x, 2, 1 ); -* // returns 6.25 +* //returns 6.25 */ function dvarmpn( N, mean, correction, x, strideX, offsetX ) { var ix; diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.native.js index 54e1dff61d5b..0e6414dc1344 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/lib/ndarray.native.js @@ -32,7 +32,7 @@ var addon = require( './../src/addon.node' ); * @param {number} mean - mean * @param {number} correction - degrees of freedom adjustment * @param {Float64Array} x - input array -* @param {integer} strideX - strideX length +* @param {integer} strideX - stride length * @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * @@ -42,7 +42,7 @@ var addon = require( './../src/addon.node' ); * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * * var v = dvarmpn( 4, 1.25, 1, x, 2, 1 ); -* // returns 6.25 +* //returns 6.25 */ function dvarmpn( N, mean, correction, x, strideX, offsetX ) { return addon.ndarray( N, mean, correction, x, strideX, offsetX ); diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/src/addon.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/src/addon.c index 19084c1a64f6..e1fb00b3161e 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/src/addon.c @@ -39,7 +39,7 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_DOUBLE( env, mean, argv, 1 ); STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 3 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dvarmpn( N, mean, correction, X, strideX ), v ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dvarmpn)( N, mean, correction, X, strideX ), v ); return v; } @@ -58,7 +58,7 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_DOUBLE( env, mean, argv, 1 ); STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 3 ); - STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dvarmpn_ndarray( N, mean, correction, X, strideX, offsetX ), v ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dvarmpn_ndarray)( N, mean, correction, X, strideX, offsetX ), v ); return v; } diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/src/main.c b/lib/node_modules/@stdlib/stats/base/dvarmpn/src/main.c index 273fea26f9af..a7ea9b6ea70e 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/src/main.c @@ -32,32 +32,26 @@ * @param mean mean * @param correction degrees of freedom adjustment * @param X input array -* @param strideX strideX length +* @param strideX stride length * @return output value */ -double API_SUFFIX( stdlib_strided_dvarmpn )( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX ) { - const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); - return API_SUFFIX(stdlib_strided_dvarmpn_ndarray)( N, mean, correction, X, strideX, ox ); +double API_SUFFIX(stdlib_strided_dvarmpn)( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX ) { + return API_SUFFIX(stdlib_strided_dvarmpn_ndarray)( N, mean, correction, X, strideX, stdlib_strided_stride2offset( N, strideX ) ); } /** -* Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm. -* -* ## 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). +* Computes the variance of a double-precision floating-point strided array provided a known mean and using Neely's correction algorithm and alternative indexing semantics. * * @param N number of indexed elements * @param mean mean * @param correction degrees of freedom adjustment * @param X input array -* @param strideX strideX length -* @param offsetX starting index +* @param strideX stride length +* @param offsetX starting index * @return output value */ -double API_SUFFIX( stdlib_strided_dvarmpn_ndarray )( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { +double API_SUFFIX(stdlib_strided_dvarmpn_ndarray)( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { CBLAS_INT ix; CBLAS_INT i; double dN; From 718f26d9011b90d613e46b85e9d908fa0dbb4818 Mon Sep 17 00:00:00 2001 From: DhruvArvindSingh Date: Sat, 18 Jan 2025 20:26:48 +0000 Subject: [PATCH 7/8] chore: updated examples js --- 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: 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: 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/dvarmpn/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js index f84fec7440aa..2cdc0ff1b798 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/examples/index.js @@ -18,7 +18,7 @@ 'use strict'; -var uniform = require( '@stdlib/random/array/uniform' ); +var uniform = require( '@stdlib/random/array/discrete-uniform' ); var dvarmpn = require( './../lib' ); var options = { From 06cdd25ece150fea86b9c50fc34d0d746cee03a7 Mon Sep 17 00:00:00 2001 From: DhruvArvindSingh Date: Sat, 18 Jan 2025 20:54:55 +0000 Subject: [PATCH 8/8] chore: updated readme --- 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/dvarmpn/README.md | 131 +++++++++++++++++- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dvarmpn/README.md b/lib/node_modules/@stdlib/stats/base/dvarmpn/README.md index 0095e5a671d0..ff7ad78fce13 100644 --- a/lib/node_modules/@stdlib/stats/base/dvarmpn/README.md +++ b/lib/node_modules/@stdlib/stats/base/dvarmpn/README.md @@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var dvarmpn = require( '@stdlib/stats/base/dvarmpn' ); ``` -#### dvarmpn( N, mean, correction, x, stride ) +#### dvarmpn( N, mean, correction, x, strideX ) Computes the [variance][variance] of a double-precision floating-point strided array `x` provided a known `mean` and using Neely's correction algorithm. @@ -117,9 +117,9 @@ The function has the following parameters: - **mean**: mean. - **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**: index increment 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 `strideX` 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' ); @@ -149,7 +149,7 @@ var v = dvarmpn( N, 1.25, 1, x1, 2 ); // returns 6.25 ``` -#### dvarmpn.ndarray( N, mean, correction, x, stride, offset ) +#### dvarmpn.ndarray( N, mean, correction, x, strideX, offsetX ) Computes the [variance][variance] of a double-precision floating-point strided array provided a known `mean` and using Neely's correction algorithm and alternative indexing semantics. @@ -164,7 +164,7 @@ var v = dvarmpn.ndarray( x.length, 1.0/3.0, 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 @@ -223,6 +223,127 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dvarmpn.h" +``` + +#### stdlib_strided_dvarmpn( N, mean, correction, \*X, strideX ) + +Computes the [variance][variance] of a double-precision floating-point strided array `x` provided a known `mean` and using Neely's correction algorithm. + +```c +const double x[] = { 1.0, -2.0, 2.0 }; + +double v = stdlib_strided_dvarmpn( x.length, 1.0/3.0, 1, x, 1 ); +// returns ~4.3333 +``` + +The function accepts the following arguments: + +- **N**: number of indexed elements. +- **mean**: mean. +- **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]. +- **strideX**: index increment for `x`. + +```c +double stdlib_strided_dvarmpn( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dvarmpn_ndarray( N, mean, correction, \*X, strideX, offsetX ) + +Computes the [variance][variance] of a double-precision floating-point strided array provided a known `mean` and using Neely's correction algorithm and alternative indexing semantics. + +```c +const double x[] = { 1.0, -2.0, 2.0 }; + +double v = stdlib_strided_dvarmpn_ndarray( x.length, 1.0/3.0, 1, x, 1, 0 ); +// returns ~4.3333 +``` + +The function accepts the following arguments: + +- **N**: number of indexed elements. +- **mean**: mean. +- **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]. +- **strideX**: index increment for `x`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dvarmpn_ndarray( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dvarmpn.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the variance: + double v = stdlib_strided_dvarmpn( N, 4.5, 1, x, strideX ); + + // Print the result: + printf( "sample variance: %lf\n", v ); +} +``` + +
+ + + +
+ + + * * *