diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/README.md new file mode 100644 index 000000000000..3a80d36d9913 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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' ); +``` + +#### meankbn( 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/meankbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/benchmark/benchmark.js new file mode 100644 index 000000000000..611a45d7e811 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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 meankbn = 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 = meankbn( 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/meankbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..5b0a08aae2e4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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 meankbn = 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 = meankbn( 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/meankbn/docs/img/equation_arithmetic_mean.svg b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/img/equation_arithmetic_mean.svg new file mode 100644 index 000000000000..c31439606fb6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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/meankbn/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/repl.txt new file mode 100644 index 000000000000..37a1a5dc3e01 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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/meankbn/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/types/index.d.ts new file mode 100644 index 000000000000..cc5463499a00 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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/meankbn/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/docs/types/test.ts new file mode 100644 index 000000000000..b11071d40bc1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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/meankbn/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/examples/index.js new file mode 100644 index 000000000000..1f69de0c5336 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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 meankbn = require( './../lib' ); + +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +console.log( x ); + +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/meankbn/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/index.js new file mode 100644 index 000000000000..36de3d2ba5ce --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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/meankbn/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/main.js new file mode 100644 index 000000000000..d35ecffd6e82 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/main.js @@ -0,0 +1,28 @@ +/** +* @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' ); + + +// EXPORTS // + +module.exports = meankbn; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/meankbn.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/meankbn.js new file mode 100644 index 000000000000..cce6820142fb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/meankbn.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( '@stdlib/stats/base/ndarray/meankbn/lib/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/meankbn/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/lib/ndarray.js new file mode 100644 index 000000000000..03589d6a33e5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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 gsumkbn = require( '@stdlib/blas/ext/base/gsumkbn' ).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 = meankbn( 4, x, 2, 1 ); +* // returns 1.25 +*/ +function meankbn( N, x, strideX, offsetX ) { + if ( N <= 0 ) { + return NaN; + } + return gsumkbn( N, x, strideX, offsetX ) / N; +} + + +// EXPORTS // + +module.exports = meankbn; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/package.json new file mode 100644 index 000000000000..466a23311fcc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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/meankbn/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.js new file mode 100644 index 000000000000..57f945afba2a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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/meankbn/test/test.meankbn.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.meankbn.js new file mode 100644 index 000000000000..92aded449a2f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.meankbn.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 meankbn = require( '@stdlib/stats/base/ndarray/meankbn/lib/main.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + 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 = meankbn( 0, [ 1.0, 2.0, 3.0 ], 1 ); + t.equal( v !== v, true, 'returns NaN' ); + + v = meankbn( -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 = 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/meankbn/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/test/test.ndarray.js new file mode 100644 index 000000000000..554b64fd409c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/meankbn/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 meankbn = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + 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 = meankbn( 0, [ 1.0, 2.0, 3.0 ], 1, 0 ); + t.equal( v !== v, true, 'returns NaN' ); + + v = meankbn( -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 = meankbn( 4, x, 2, 1 ); + t.equal( v, 1.25, 'returns expected value' ); + + t.end(); +});