diff --git a/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c index c6da372d28b0..26bde725dfa1 100644 --- a/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/math/strided/special/strunc/benchmark/c/benchmark.length.c @@ -114,11 +114,25 @@ float rand_uniformf( float a, float b ) { */ static double benchmark( int iterations, int len ) { double elapsed; - float x[ len ]; - float y[ len ]; + float *x; + float *y; double t; int i; + x = (float *)malloc( len * sizeof( float ) ); + y = (float *)malloc( len * sizeof( float ) ); + + if (x == NULL || y == NULL ) { + if ( x != NULL ) { + free( x ); + } + if ( y != NULL ) { + free( y ); + } + printf("Error: unable to allocate memory.\n"); + exit( 1 ); + } + for ( i = 0; i < len; i++ ) { x[ i ] = rand_uniformf( -10.0f, 10.0f ); y[ i ] = 0.0f; @@ -135,6 +149,10 @@ static double benchmark( int iterations, int len ) { if ( y[ 0 ] != y[ 0 ] ) { printf( "should not return NaN\n" ); } + + free( x ); + free( y ); + return elapsed; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/index.js new file mode 100644 index 000000000000..2ac7dd5a6ff2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/index.js @@ -0,0 +1,25 @@ +'use strict'; + +/** +* Half-normal distribution expected value. +* +* @module @stdlib/stats/base/dists/halfnormal/mean +* +* @example +* var mean = require( '@stdlib/stats/base/dists/halfnormal/mean' ); +* +* var v = mean( 1.0 ); +* // returns ~0.798 +* +* var v = mean( 2.0 ); +* // returns ~1.596 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/main.js new file mode 100644 index 000000000000..f963b4ef3f7f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/main.js @@ -0,0 +1,45 @@ +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var PI = require( '@stdlib/constants/float64/pi' ); + + +// CONSTANTS // + +var SQRT_TWO_OVER_PI = sqrt( 2.0 / PI ); + + +// MAIN // + +/** +* Returns the expected value of a half-normal distribution. +* +* @param {number} sigma - scale parameter +* @returns {number} expected value +* +* @example +* var v = mean( 1.0 ); +* // returns ~0.798 +* +* @example +* var v = mean( 2.0 ); +* // returns ~1.596 +* +* @example +* var v = mean( -1.0 ); +* // returns NaN +*/ +function mean( sigma ) { + if ( isnan( sigma ) || sigma <= 0.0 ) { + return NaN; + } + return sigma * SQRT_TWO_OVER_PI; +} + + +// EXPORTS // + +module.exports = mean; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/package.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/package.json new file mode 100644 index 000000000000..eb273822e197 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/stats/base/dists/halfnormal/mean", + "version": "0.0.0", + "description": "Half-normal distribution expected value.", + "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": { + "lib": "./lib", + "doc": "./docs", + "test": "./test", + "benchmark": "./benchmark" + }, + "types": "./docs/types", + "scripts": { + "test": "make test", + "test-cov": "make test-cov", + "test-browsers": "make test-browsers" + }, + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": { + "@stdlib/constants/float64/pi": "^0.2.2", + "@stdlib/math/base/assert/is-nan": "^0.2.2", + "@stdlib/math/base/special/sqrt": "^0.2.2" + }, + "devDependencies": { + "@stdlib/math/base/special/abs": "^0.2.2", + "tape": "git+https://github.com/kgryte/tape.git#fix/globby", + "istanbul": "^0.4.1", + "tap-min": "git+https://github.com/Planeshifter/tap-min.git", + "@stdlib/bench/harness": "^0.2.2" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "half-normal", + "halfnormal", + "mean", + "expected value", + "expectation" + ] +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/test/test.js new file mode 100644 index 000000000000..fd091852c3ba --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/test/test.js @@ -0,0 +1,68 @@ +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var mean = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.equal( typeof mean, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for `sigma`, the function returns `NaN`', function test( t ) { + var v = mean( NaN ); + t.equal( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'if provided a value less than or equal to 0 for `sigma`, the function returns `NaN`', function test( t ) { + var v; + + v = mean( 0.0 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = mean( -1.0 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = mean( NINF ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns the expected value', function test( t ) { + var expected; + var sigma; + var v; + var i; + + // Test cases (sigma, expected) + // Mean = sigma * sqrt(2/pi) -> sigma * ~0.79788456 + sigma = [ 1.0, 2.0, 5.0, 0.5 ]; + expected = [ + 0.79788456, + 1.59576912, + 3.98942280, + 0.39894228 + ]; + + for ( i = 0; i < sigma.length; i++ ) { + v = mean( sigma[ i ] ); + // We check if the difference is very small (epsilon) + if ( abs( v - expected[ i ] ) > 1e-7 ) { + t.fail( 'returns ' + v + ' when expected ' + expected[ i ] ); + } else { + t.pass( 'returns ' + v + ' when expected ' + expected[ i ] ); + } + } + t.end(); +}); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/index.js new file mode 100644 index 000000000000..3292e3a438d1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/index.js @@ -0,0 +1,25 @@ +'use strict'; + +/** +* Half-normal distribution variance. +* +* @module @stdlib/stats/base/dists/halfnormal/variance +* +* @example +* var variance = require( '@stdlib/stats/base/dists/halfnormal/variance' ); +* +* var v = variance( 1.0 ); +* // returns ~0.363 +* +* var v = variance( 2.0 ); +* // returns ~1.454 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/main.js new file mode 100644 index 000000000000..a899d215106b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/main.js @@ -0,0 +1,46 @@ +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var PI = require( '@stdlib/constants/float64/pi' ); + + +// CONSTANTS // + +// 1 - 2/pi +var FACTOR = 1.0 - ( 2.0 / PI ); + + +// MAIN // + +/** +* Returns the variance of a half-normal distribution. +* +* @param {number} sigma - scale parameter +* @returns {number} variance +* +* @example +* var v = variance( 1.0 ); +* // returns ~0.363 +* +* @example +* var v = variance( 2.0 ); +* // returns ~1.454 +* +* @example +* var v = variance( -1.0 ); +* // returns NaN +*/ +function variance( sigma ) { + if ( isnan( sigma ) || sigma <= 0.0 ) { + return NaN; + } + return pow( sigma, 2.0 ) * FACTOR; +} + + +// EXPORTS // + +module.exports = variance; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/package.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/package.json new file mode 100644 index 000000000000..f36defce757c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/stats/base/dists/halfnormal/variance", + "version": "0.0.0", + "description": "Half-normal distribution variance.", + "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": { + "doc": "./docs", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": { + "test": "make test", + "test-cov": "make test-cov", + "test-browsers": "make test-browsers" + }, + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": { + "@stdlib/constants/float64/pi": "^0.2.2", + "@stdlib/math/base/assert/is-nan": "^0.2.2", + "@stdlib/math/base/special/pow": "^0.2.2" + }, + "devDependencies": { + "@stdlib/math/base/special/abs": "^0.2.2", + "tape": "git+https://github.com/kgryte/tape.git#fix/globby", + "istanbul": "^0.4.1", + "tap-min": "git+https://github.com/Planeshifter/tap-min.git" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "half-normal", + "halfnormal", + "variance", + "var", + "dispersion" + ] +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/test/test.js new file mode 100644 index 000000000000..7df13869c64a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/test/test.js @@ -0,0 +1,67 @@ +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var variance = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.equal( typeof variance, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for `sigma`, the function returns `NaN`', function test( t ) { + var v = variance( NaN ); + t.equal( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'if provided a value less than or equal to 0 for `sigma`, the function returns `NaN`', function test( t ) { + var v; + + v = variance( 0.0 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( -1.0 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( NINF ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns the variance', function test( t ) { + var expected; + var sigma; + var v; + var i; + + // Test cases (sigma, expected) + // Variance = sigma^2 * (1 - 2/pi) + // 1 - 2/pi ≈ 0.3633802276 + sigma = [ 1.0, 2.0, 5.0 ]; + expected = [ + 0.36338023, + 1.45352091, + 9.08450569 + ]; + + for ( i = 0; i < sigma.length; i++ ) { + v = variance( sigma[ i ] ); + if ( abs( v - expected[ i ] ) > 1e-7 ) { + t.fail( 'returns ' + v + ' when expected ' + expected[ i ] ); + } else { + t.pass( 'returns ' + v + ' when expected ' + expected[ i ] ); + } + } + t.end(); +}); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/mean/package.json b/lib/node_modules/@stdlib/stats/base/dists/normal/mean/package.json index 4436790320f9..8f145ed2d6a6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/mean/package.json +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/mean/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/stats/base/dists/normal/mean", + "name": "@stdlib/stats/base/dists/halfnormal/mean", "version": "0.0.0", - "description": "Normal distribution expected value.", + "description": "Half-normal distribution expected value.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -14,19 +14,18 @@ } ], "main": "./lib", - "gypfile": true, "directories": { - "benchmark": "./benchmark", "doc": "./docs", - "example": "./examples", - "include": "./include", "lib": "./lib", - "src": "./src", "test": "./test" }, "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", + "scripts": { + "test": "make test", + "test-cov": "make test-cov", + "test-browsers": "make test-browsers" + }, + "homepage": "https://stdlib.io", "repository": { "type": "git", "url": "git://github.com/stdlib-js/stdlib.git" @@ -34,8 +33,17 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": {}, - "devDependencies": {}, + "dependencies": { + "@stdlib/constants/float64/pi": "^0.2.2", + "@stdlib/math/base/assert/is-nan": "^0.2.2", + "@stdlib/math/base/special/sqrt": "^0.2.2" + }, + "devDependencies": { + "@stdlib/math/base/special/abs": "^0.2.2", + "tape": "git+https://github.com/kgryte/tape.git#fix/globby", + "istanbul": "^0.4.1", + "tap-min": "git+https://github.com/Planeshifter/tap-min.git" + }, "engines": { "node": ">=0.10.0", "npm": ">2.7.0" @@ -57,15 +65,10 @@ "statistics", "stats", "distribution", - "dist", - "moments", - "gaussian", - "normal", - "continuous", + "half-normal", + "halfnormal", "mean", - "average", - "avg", - "expected", - "univariate" + "expected value", + "expectation" ] -} +} \ No newline at end of file