From 6d25872e55b1dc8641bd854aba0a36a4981a4f62 Mon Sep 17 00:00:00 2001 From: Harsh Mathur Date: Thu, 2 Oct 2025 18:29:35 +0530 Subject: [PATCH 1/4] feat: add stats/base/ndarray/meankbn --- .../stats/base/ndarray/meanbkn/README.md | 127 ++++++++++++++++++ .../ndarray/meanbkn/benchmark/benchmark.js | 94 +++++++++++++ .../meanbkn/benchmark/benchmark.ndarray.js | 94 +++++++++++++ .../docs/img/equation_arithmetic_mean.svg | 42 ++++++ .../stats/base/ndarray/meanbkn/docs/repl.txt | 30 +++++ .../ndarray/meanbkn/docs/types/index.d.ts | 45 +++++++ .../base/ndarray/meanbkn/docs/types/test.ts | 47 +++++++ .../base/ndarray/meanbkn/examples/index.js | 30 +++++ .../stats/base/ndarray/meanbkn/lib/index.js | 44 ++++++ .../stats/base/ndarray/meanbkn/lib/main.js | 49 +++++++ .../stats/base/ndarray/meanbkn/lib/meanbkn.js | 58 ++++++++ .../stats/base/ndarray/meanbkn/lib/ndarray.js | 61 +++++++++ .../stats/base/ndarray/meanbkn/package.json | 67 +++++++++ .../stats/base/ndarray/meanbkn/test/test.js | 38 ++++++ .../base/ndarray/meanbkn/test/test.meanbkn.js | 56 ++++++++ .../base/ndarray/meanbkn/test/test.ndarray.js | 56 ++++++++ 16 files changed, 938 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/img/equation_arithmetic_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/meanbkn.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.meanbkn.js create mode 100644 lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/README.md new file mode 100644 index 000000000000..6e67850d88b8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/README.md @@ -0,0 +1,127 @@ + + +# meankbn-ndarray + +> Compute the [arithmetic mean][arithmetic-mean] of a one-dimensional ndarray using an improved Kahan–Babuška algorithm. + +
+ +The [arithmetic mean][arithmetic-mean] is defined as + + + +```math +\mu = \frac{1}{n} \sum_{i=0}^{n-1} x_i +``` + + + + +
+ + + +
+ +## Usage + +```javascript +var meankbn = require( '@stdlib/stats/base/ndarray/meankbn' ); +``` + +#### meanbkn( arrays ) + +Computes the [arithmetic mean][arithmetic-mean] of a one-dimensional ndarray. + +```javascript +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = [ 1.0, -2.0, 2.0 ]; +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + +var v = meankbn( [ x ] ); +// returns ~0.3333 +``` + +The function has the following parameters: + +- **arrays**: array-like object containing a one-dimensional input ndarray. + +
+ + + +
+ +## Notes + +- If provided an empty one-dimensional ndarray, the function returns `NaN`. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var meankbn = require( '@stdlib/stats/base/ndarray/meankbn' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'generic' +}); +var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = meankbn( [ x ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.js new file mode 100644 index 000000000000..0cdae0b5acf4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +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; +var meanbkn = require( './../lib/main.js' ); + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ + +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = meanbkn( x.length, x, 1 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ + +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..44427952be1d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.ndarray.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +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; +var meanbkn = require( './../lib/ndarray.js' ); + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -10, 10, options ); + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = meanbkn( x.length, x, 1, 0 ); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/img/equation_arithmetic_mean.svg b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/img/equation_arithmetic_mean.svg new file mode 100644 index 000000000000..c31439606fb6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/img/equation_arithmetic_mean.svg @@ -0,0 +1,42 @@ + +mu equals StartFraction 1 Over n EndFraction sigma-summation Underscript i equals 0 Overscript n minus 1 Endscripts x Subscript i + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/repl.txt new file mode 100644 index 000000000000..37a1a5dc3e01 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/repl.txt @@ -0,0 +1,30 @@ +{{alias}}( arrays ) + Computes the arithmetic mean of a one-dimensional ndarray using an + improved Kahan–Babuška algorithm. + + If provided an empty ndarray, the function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + Returns + ------- + out: number + Arithmetic mean. + + Examples + -------- + > var xbuf = [ 1.0, -2.0, 2.0 ]; + > var dt = 'generic'; + > var sh = [ xbuf.length ]; + > var sx = [ 1 ]; + > var ox = 0; + > var ord = 'row-major'; + > var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord ); + > {{alias}}( [ x ] ) + ~0.3333 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/index.d.ts new file mode 100644 index 000000000000..cc5463499a00 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/index.d.ts @@ -0,0 +1,45 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* +* You may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the arithmetic mean of a one-dimensional ndarray using an improved Kahan–Babuška algorithm. +* +* @param arrays - array-like object containing an input ndarray +* @returns arithmetic mean +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, -2.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +* +* var v = meankbn( [ x ] ); +* // returns ~0.3333 +*/ +declare function meankbn( arrays: [ T ] ): number; + +// EXPORTS // + +export = meankbn; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/test.ts new file mode 100644 index 000000000000..b11071d40bc1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/test.ts @@ -0,0 +1,47 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +*/ + +import ndarray = require( '@stdlib/ndarray/base/ctor' ); +import meankbn = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const xbuf = [ 1.0, -2.0, 2.0 ]; + const x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + + meankbn( [ x ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + meankbn( '10' ); // $ExpectError + meankbn( 10 ); // $ExpectError + meankbn( true ); // $ExpectError + meankbn( false ); // $ExpectError + meankbn( null ); // $ExpectError + meankbn( undefined ); // $ExpectError + meankbn( [] ); // $ExpectError + meankbn( {} ); // $ExpectError + meankbn( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const xbuf = [ 1.0, -2.0, 2.0 ]; + const x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); + + meankbn(); // $ExpectError + meankbn( [ x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/examples/index.js new file mode 100644 index 000000000000..b5f9f49d8e2d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var meanbkn = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +var v = meanbkn( x.length, x, 1 ); +console.log( v ); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/index.js new file mode 100644 index 000000000000..36de3d2ba5ce --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Compute the arithmetic mean of a one-dimensional ndarray using the improved Kahan–Babuška algorithm. +* +* @module @stdlib/stats/base/ndarray/meankbn +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var meankbn = require( '@stdlib/stats/base/ndarray/meankbn' ); +* +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = meankbn( [ x ] ); +* // returns 2.5 +*/ + +// MODULES // + +var meankbn = require( './main.js' ); + + +// EXPORTS // + +module.exports = meankbn; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/main.js new file mode 100644 index 000000000000..9dc880944eee --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/main.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var meankbn = require( '@stdlib/stats/strided/meankbn' ); +var wrap = require( '@stdlib/ndarray/base/wrap-function' ); + + +// MAIN // + +/** +* Computes the arithmetic mean of a one-dimensional ndarray using the improved Kahan–Babuška algorithm. +* +* @param {Array} arrays - input ndarray +* @returns {number} arithmetic mean +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = meankbn( [ x ] ); +* // returns 2.5 +*/ +var fcn = wrap( meankbn.ndarray ); + + +// EXPORTS // + +module.exports = fcn; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/meanbkn.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/meanbkn.js new file mode 100644 index 000000000000..d7b17c104bae --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/meanbkn.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes the arithmetic mean of a strided array using the Kahan–Babuška–Neumaier algorithm. +* +* ## Method +* +* - This implementation uses the "Kahan–Babuška–Neumaier algorithm" for improved numerical stability. +* +* ## References +* +* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @returns {number} arithmetic mean +* +* @example +* var x = [ 1.0, -2.0, 2.0 ]; +* +* var v = meanbkn( x.length, x, 1 ); +* // returns ~0.3333 +*/ +function meanbkn( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); +} + + +// EXPORTS // + +module.exports = meanbkn; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js new file mode 100644 index 000000000000..3da892f77239 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js @@ -0,0 +1,61 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var gsumbcn = require( '@stdlib/blas/ext/base/gsumbcn' ).ndarray; + + +// MAIN // + +/** +* Computes the arithmetic mean of a strided array using the Kahan–Babuška–Neumaier algorithm. +* +* ## Method +* +* - This implementation uses the "Kahan–Babuška–Neumaier algorithm" for improved numerical stability. +* +* ## References +* +* - Neumaier, Arnold. 1974. "Rounding Error Analysis of Some Methods for Summing Finite Sums." _Zeitschrift Für Angewandte Mathematik Und Mechanik_ 54 (1): 39–51. doi:[10.1002/zamm.19740540106](https://doi.org/10.1002/zamm.19740540106). +* +* @param {PositiveInteger} N - number of indexed elements +* @param {NumericArray} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {number} arithmetic mean +* +* @example +* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; +* +* var v = meanbkn( 4, x, 2, 1 ); +* // returns 1.25 +*/ +function meanbkn( N, x, strideX, offsetX ) { + if ( N <= 0 ) { + return NaN; + } + return gsumbcn( N, x, strideX, offsetX ) / N; +} + + +// EXPORTS // + +module.exports = meanbkn; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/package.json new file mode 100644 index 000000000000..466a23311fcc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/stats/base/ndarray/meankbn", + "version": "0.0.0", + "description": "Compute the arithmetic mean of a one-dimensional ndarray using an improved Kahan–Babuška algorithm.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "mathematics", + "math", + "average", + "avg", + "mean", + "arithmetic mean", + "central tendency", + "ndarray", + "kahan-babuska" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.js new file mode 100644 index 000000000000..57f945afba2a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var main = require( './../lib/main.js' ); +var ndarray = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.equal( typeof main, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'ndarray export is a function', function test( t ) { + t.equal( typeof ndarray, 'function', 'ndarray export is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.meanbkn.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.meanbkn.js new file mode 100644 index 000000000000..e2498069a3a0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.meanbkn.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var meanbkn = require( './../lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.equal( typeof meanbkn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns NaN if provided a value less than or equal to 0 for `N`', function test( t ) { + var v; + + v = meanbkn( 0, [ 1.0, 2.0, 3.0 ], 1 ); + t.equal( v !== v, true, 'returns NaN' ); + + v = meanbkn( -1, [ 1.0, 2.0, 3.0 ], 1 ); + t.equal( v !== v, true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function calculates the arithmetic mean of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, 2.0 ]; + + v = meanbkn( x.length, x, 1 ); + t.equal( v, 1/3, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.ndarray.js new file mode 100644 index 000000000000..4fdbeca2fbfb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.ndarray.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var meanbkn = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.equal( typeof meanbkn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns NaN if provided a value less than or equal to 0 for `N`', function test( t ) { + var v; + + v = meanbkn( 0, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.equal( v !== v, true, 'returns NaN' ); + + v = meanbkn( -1, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.equal( v !== v, true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function calculates the arithmetic mean of a strided array (ndarray)', function test( t ) { + var x; + var v; + + x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; + + v = meanbkn( 4, x, 2, 1 ); + t.equal( v, 1.25, 'returns expected value' ); + + t.end(); +}); From c8e8f02a915b7e6634ecaae5f121126e1aba6be9 Mon Sep 17 00:00:00 2001 From: Harsh Mathur Date: Thu, 2 Oct 2025 22:54:14 +0530 Subject: [PATCH 2/4] fixed a small bug --- .../@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js index 3da892f77239..52432f650caf 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js @@ -20,7 +20,7 @@ // MODULES // -var gsumbcn = require( '@stdlib/blas/ext/base/gsumbcn' ).ndarray; +var gsumkbn = require( '@stdlib/blas/ext/base/gsumkbn' ).ndarray; // MAIN // @@ -52,7 +52,7 @@ function meanbkn( N, x, strideX, offsetX ) { if ( N <= 0 ) { return NaN; } - return gsumbcn( N, x, strideX, offsetX ) / N; + return gsumkbn( N, x, strideX, offsetX ) / N; } From 8eaafff171bf0b0920deea114db964497b002263 Mon Sep 17 00:00:00 2001 From: Harsh Mathur Date: Thu, 2 Oct 2025 23:04:54 +0530 Subject: [PATCH 3/4] fixed the error for js-tests --- .../stats/base/ndarray/{meanbkn => meankbn}/README.md | 2 +- .../{meanbkn => meankbn}/benchmark/benchmark.js | 4 ++-- .../benchmark/benchmark.ndarray.js | 4 ++-- .../docs/img/equation_arithmetic_mean.svg | 0 .../base/ndarray/{meanbkn => meankbn}/docs/repl.txt | 0 .../ndarray/{meanbkn => meankbn}/docs/types/index.d.ts | 0 .../ndarray/{meanbkn => meankbn}/docs/types/test.ts | 0 .../ndarray/{meanbkn => meankbn}/examples/index.js | 4 ++-- .../base/ndarray/{meanbkn => meankbn}/lib/index.js | 0 .../base/ndarray/{meanbkn => meankbn}/lib/main.js | 0 .../{meanbkn/lib/meanbkn.js => meankbn/lib/meankbn.js} | 2 +- .../base/ndarray/{meanbkn => meankbn}/lib/ndarray.js | 6 +++--- .../base/ndarray/{meanbkn => meankbn}/package.json | 0 .../base/ndarray/{meanbkn => meankbn}/test/test.js | 0 .../test.meanbkn.js => meankbn/test/test.meankbn.js} | 10 +++++----- .../ndarray/{meanbkn => meankbn}/test/test.ndarray.js | 10 +++++----- 16 files changed, 21 insertions(+), 21 deletions(-) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/README.md (99%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/benchmark/benchmark.js (95%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/benchmark/benchmark.ndarray.js (95%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/docs/img/equation_arithmetic_mean.svg (100%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/docs/repl.txt (100%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/docs/types/index.d.ts (100%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/docs/types/test.ts (100%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/examples/index.js (91%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/lib/index.js (100%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/lib/main.js (100%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn/lib/meanbkn.js => meankbn/lib/meankbn.js} (95%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/lib/ndarray.js (94%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/package.json (100%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/test/test.js (100%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn/test/test.meanbkn.js => meankbn/test/test.meankbn.js} (82%) rename lib/node_modules/@stdlib/stats/base/ndarray/{meanbkn => meankbn}/test/test.ndarray.js (84%) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/README.md similarity index 99% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/README.md rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/README.md index 6e67850d88b8..3a80d36d9913 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/README.md +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/README.md @@ -50,7 +50,7 @@ The [arithmetic mean][arithmetic-mean] is defined as var meankbn = require( '@stdlib/stats/base/ndarray/meankbn' ); ``` -#### meanbkn( arrays ) +#### meankbn( arrays ) Computes the [arithmetic mean][arithmetic-mean] of a one-dimensional ndarray. diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/benchmark/benchmark.js similarity index 95% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/benchmark/benchmark.js index 0cdae0b5acf4..611a45d7e811 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/benchmark/benchmark.js @@ -25,7 +25,7 @@ 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; -var meanbkn = require( './../lib/main.js' ); +var meankbn = require( './../lib/main.js' ); // VARIABLES // @@ -51,7 +51,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = meanbkn( x.length, x, 1 ); + v = meankbn( x.length, x, 1 ); if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/benchmark/benchmark.ndarray.js similarity index 95% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.ndarray.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/benchmark/benchmark.ndarray.js index 44427952be1d..5b0a08aae2e4 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/benchmark/benchmark.ndarray.js @@ -25,7 +25,7 @@ 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; -var meanbkn = require( './../lib/ndarray.js' ); +var meankbn = require( './../lib/ndarray.js' ); // VARIABLES // @@ -52,7 +52,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = meanbkn( x.length, x, 1, 0 ); + v = meankbn( x.length, x, 1, 0 ); if ( isnan( v ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/img/equation_arithmetic_mean.svg b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/img/equation_arithmetic_mean.svg similarity index 100% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/img/equation_arithmetic_mean.svg rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/img/equation_arithmetic_mean.svg diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/repl.txt similarity index 100% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/repl.txt rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/repl.txt diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/types/index.d.ts similarity index 100% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/index.d.ts rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/types/index.d.ts diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/types/test.ts similarity index 100% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/docs/types/test.ts rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/examples/index.js similarity index 91% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/examples/index.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/examples/index.js index b5f9f49d8e2d..1f69de0c5336 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/examples/index.js @@ -19,12 +19,12 @@ 'use strict'; var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); -var meanbkn = require( './../lib' ); +var meankbn = require( './../lib' ); var x = discreteUniform( 10, -50, 50, { 'dtype': 'float64' }); console.log( x ); -var v = meanbkn( x.length, x, 1 ); +var v = meankbn( x.length, x, 1 ); console.log( v ); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/index.js similarity index 100% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/index.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/index.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/main.js similarity index 100% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/main.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/main.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/meanbkn.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/meankbn.js similarity index 95% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/meanbkn.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/meankbn.js index d7b17c104bae..cce6820142fb 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/meanbkn.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/meankbn.js @@ -21,7 +21,7 @@ // MODULES // var stride2offset = require( '@stdlib/strided/base/stride2offset' ); -var ndarray = require( './ndarray.js' ); +var ndarray = require( '@stdlib/stats/base/ndarray/meankbn/lib/ndarray.js' ); // MAIN // diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/ndarray.js similarity index 94% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/ndarray.js index 52432f650caf..03589d6a33e5 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/ndarray.js @@ -45,10 +45,10 @@ var gsumkbn = require( '@stdlib/blas/ext/base/gsumkbn' ).ndarray; * @example * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; * -* var v = meanbkn( 4, x, 2, 1 ); +* var v = meankbn( 4, x, 2, 1 ); * // returns 1.25 */ -function meanbkn( N, x, strideX, offsetX ) { +function meankbn( N, x, strideX, offsetX ) { if ( N <= 0 ) { return NaN; } @@ -58,4 +58,4 @@ function meanbkn( N, x, strideX, offsetX ) { // EXPORTS // -module.exports = meanbkn; +module.exports = meankbn; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/package.json similarity index 100% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/package.json rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/package.json diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.js similarity index 100% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.js diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.meanbkn.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.meankbn.js similarity index 82% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.meanbkn.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.meankbn.js index e2498069a3a0..92aded449a2f 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.meanbkn.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.meankbn.js @@ -21,23 +21,23 @@ // MODULES // var tape = require( 'tape' ); -var meanbkn = require( './../lib/main.js' ); +var meankbn = require( '@stdlib/stats/base/ndarray/meankbn/lib/main.js' ); // TESTS // tape( 'main export is a function', function test( t ) { - t.equal( typeof meanbkn, 'function', 'main export is a function' ); + t.equal( typeof meankbn, 'function', 'main export is a function' ); t.end(); }); tape( 'the function returns NaN if provided a value less than or equal to 0 for `N`', function test( t ) { var v; - v = meanbkn( 0, [ 1.0, 2.0, 3.0 ], 1 ); + v = meankbn( 0, [ 1.0, 2.0, 3.0 ], 1 ); t.equal( v !== v, true, 'returns NaN' ); - v = meanbkn( -1, [ 1.0, 2.0, 3.0 ], 1 ); + v = meankbn( -1, [ 1.0, 2.0, 3.0 ], 1 ); t.equal( v !== v, true, 'returns NaN' ); t.end(); @@ -49,7 +49,7 @@ tape( 'the function calculates the arithmetic mean of a strided array', function x = [ 1.0, -2.0, 2.0 ]; - v = meanbkn( x.length, x, 1 ); + v = meankbn( x.length, x, 1 ); t.equal( v, 1/3, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.ndarray.js similarity index 84% rename from lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.ndarray.js rename to lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.ndarray.js index 4fdbeca2fbfb..554b64fd409c 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meanbkn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.ndarray.js @@ -21,23 +21,23 @@ // MODULES // var tape = require( 'tape' ); -var meanbkn = require( './../lib/ndarray.js' ); +var meankbn = require( './../lib/ndarray.js' ); // TESTS // tape( 'main export is a function', function test( t ) { - t.equal( typeof meanbkn, 'function', 'main export is a function' ); + t.equal( typeof meankbn, 'function', 'main export is a function' ); t.end(); }); tape( 'the function returns NaN if provided a value less than or equal to 0 for `N`', function test( t ) { var v; - v = meanbkn( 0, [ 1.0, 2.0, 3.0 ], 1, 0 ); + v = meankbn( 0, [ 1.0, 2.0, 3.0 ], 1, 0 ); t.equal( v !== v, true, 'returns NaN' ); - v = meanbkn( -1, [ 1.0, 2.0, 3.0 ], 1, 0 ); + v = meankbn( -1, [ 1.0, 2.0, 3.0 ], 1, 0 ); t.equal( v !== v, true, 'returns NaN' ); t.end(); @@ -49,7 +49,7 @@ tape( 'the function calculates the arithmetic mean of a strided array (ndarray)' x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; - v = meanbkn( 4, x, 2, 1 ); + v = meankbn( 4, x, 2, 1 ); t.equal( v, 1.25, 'returns expected value' ); t.end(); From dd28bbea441e12dfbb5ad52405731d9d24e16f06 Mon Sep 17 00:00:00 2001 From: Harsh Mathur Date: Thu, 2 Oct 2025 23:24:44 +0530 Subject: [PATCH 4/4] fixed the error for reassigning ndarray --- .../stats/base/ndarray/meankbn/lib/main.js | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/main.js index 9dc880944eee..d35ecffd6e82 100644 --- a/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/main.js @@ -21,29 +21,8 @@ // MODULES // var meankbn = require( '@stdlib/stats/strided/meankbn' ); -var wrap = require( '@stdlib/ndarray/base/wrap-function' ); - - -// MAIN // - -/** -* Computes the arithmetic mean of a one-dimensional ndarray using the improved Kahan–Babuška algorithm. -* -* @param {Array} arrays - input ndarray -* @returns {number} arithmetic mean -* -* @example -* var ndarray = require( '@stdlib/ndarray/base/ctor' ); -* -* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; -* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); -* -* var v = meankbn( [ x ] ); -* // returns 2.5 -*/ -var fcn = wrap( meankbn.ndarray ); // EXPORTS // -module.exports = fcn; +module.exports = meankbn; \ No newline at end of file