diff --git a/lib/node_modules/@stdlib/blas/base/zaxpy/README.md b/lib/node_modules/@stdlib/blas/base/zaxpy/README.md index 12e11b4a6dd3..b5529e5e1007 100644 --- a/lib/node_modules/@stdlib/blas/base/zaxpy/README.md +++ b/lib/node_modules/@stdlib/blas/base/zaxpy/README.md @@ -51,9 +51,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **alpha**: scalar [`Complex128`][@stdlib/complex/float64/ctor] constant. - **x**: first input [`Complex128Array`][@stdlib/array/complex128]. -- **strideX**: index increment for `x`. +- **strideX**: stride length for `x`. - **y**: second input [`Complex128Array`][@stdlib/array/complex128]. -- **strideY**: index increment for `y`. +- **strideY**: stride length for `y`. The `N` and stride parameters determine how values from `x` are scaled by `alpha` and added to `y`. For example, to scale every other value in `x` by `alpha` and add the result to every other value of `y`, @@ -137,6 +137,7 @@ zaxpy.ndarray( 3, alpha, x, 1, 1, y, 1, 1 ); ## Notes - If `N <= 0`, both functions return `y` unchanged. +- If `alpha === 0`, both functions return `y` unchanged. - `zaxpy()` corresponds to the [BLAS][blas] level 1 function [`zaxpy`][zaxpy]. @@ -171,6 +172,14 @@ var alpha = new Complex128( 2.0, 2.0 ); // Scale values from `x` by `alpha` and add the result to `y`: zaxpy( x.length, alpha, x, 1, y, 1 ); +// Print the results: +logEach( '(%s)*(%s) + (%s) = %s', alpha, x, yc, y ); + +yc = zcopy( y.length, y, 1, zeros( y.length, 'complex128' ), 1 ); + +// Scale values from `x` by `alpha` and add the result to `y` using alternative indexing semantics: +zaxpy.ndarray( x.length, alpha, x, 1, 0, y, 1, 0 ); + // Print the results: logEach( '(%s)*(%s) + (%s) = %s', alpha, x, yc, y ); ``` @@ -179,6 +188,152 @@ logEach( '(%s)*(%s) + (%s) = %s', alpha, x, yc, y ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/base/caxpy.h" +``` + +#### c_caxpy( N, alpha, \*X, strideX, \*Y, strideY ) + +Scales values from `X` by `alpha` and adds the result to `Y`. + +```c +#include "stdlib/complex/float32/ctor.h" + +float x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; +float y[] = { -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 }; +const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 ); + +c_caxpy( 4, alpha, (void *)x, 1, (void *)y, 1 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] stdlib_complex128_t` scalar constant. +- **X**: `[in] void*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **Y**: `[inout] void*` output array. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. + +```c +void c_caxpy( const CBLAS_INT N, const stdlib_complex128_t alpha, const void *x, const CBLAS_INT strideX, void *y, const CBLAS_INT strideY ); +``` + +#### c_caxpy_ndarray( N, alpha, \*X, strideX, offsetX, \*Y, strideY, offsetY ) + +Scales values from `X` by `alpha` and adds the result to `Y` using alternative indexing semantics. + +```c +#include "stdlib/complex/float32/ctor.h" + +float x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; +float y[] = { -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0 }; +const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 ); + +c_caxpy_ndarray( 4, alpha, (void *)x, 1, 0, (void *)y, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] stdlib_complex128_t` scalar constant. +- **X**: `[in] void*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[inout] void*` output array. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. + +```c +void c_caxpy_ndarray( const CBLAS_INT N, const stdlib_complex128_t alpha, const void *x, const CBLAS_INT strideX, const CBLAS_INT offsetX, void *y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/base/caxpy.h" +#include "stdlib/complex/float32/ctor.h" +#include + +int main( void ) { + // Create strided arrays: + double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + double y[] = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; + + // Create a complex scalar: + const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 ); + + // Specify the number of elements: + const int N = 4; + + // Specify stride lengths: + const int strideX = 1; + const int strideY = 1; + + // Scale values from `x` by `alpha` and add the result to `y`: + c_zaxpy( N, alpha, (void *)x, strideX, (void *)y, strideY ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "zaxpy[ %i ] = %lf + %lfj\n", i, y[ i * 2 ], y[ ( i * 2 ) + 1 ] ); + } + + // Scale values from `x` by `alpha` and add the result to `y` using alternative indexing semantics: + c_zaxpy_ndarray( N, alpha, (void *)x, strideX, 0, (void *)y, strideY, 0 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "zaxpy[ %i ] = %lf + %lfj\n", i, y[ i * 2 ], y[ ( i * 2 ) + 1 ] ); + } +} +``` + +
+ + + +
+ + + @@ -191,7 +183,7 @@ for ( i = 0; i < p.length; i++ ) { #### stdlib_base_dists_kumaraswamy_quantile( p, a, b ) -Evaluates the quantile function of a Kumaraswamy's double bounded distribution. +Evaluates the quantile function of a [Kumaraswamy's double bounded][kumaraswamy-distribution] distribution with parameters `a` (first shape parameter) and `b` (second shape parameter). ```c double out = stdlib_base_dists_kumaraswamy_quantile( 0.5, 1.0, 1.0 ); @@ -205,8 +197,7 @@ The function accepts the following arguments: - **b**: `[in] double` second shape parameter. ```c -double stdlib_base_dists_kumaraswamy_quantile( const double p, const -double a, const double b ); +double stdlib_base_dists_kumaraswamy_quantile( const double p, const double a, const double b ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/quantile/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/quantile/examples/index.js index af11e2caa9af..667a70687650 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/quantile/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/quantile/examples/index.js @@ -20,19 +20,11 @@ var uniform = require( '@stdlib/random/array/uniform' ); var EPS = require( '@stdlib/constants/float64/eps' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); var quantile = require( './../lib' ); -var a; -var b; -var p; -var y; -var i; +var p = uniform( 10, 0.0, 1.0 ); +var a = uniform( 10, EPS, 5.0 ); +var b = uniform( 10, EPS, 5.0 ); -p = uniform( 10, 0.0, 1.0 ); -a = uniform( 10, EPS, 5.0 ); -b = uniform( 10, EPS, 5.0 ); - -for ( i = 0; i < p.length; i++ ) { - y = quantile( p[ i ], a[ i ], b[ i ] ); - console.log( 'p: %d, a: %d, b: %d, Q(p;a,b): %d', p[ i ].toFixed( 4 ), a[ i ].toFixed( 4 ), b[ i ].toFixed( 4 ), y.toFixed( 4 ) ); -} +logEachMap( 'p: %0.4f, a: %0.4f, b: %0.4f, Q(p;a,b): %0.4f', p, a, b, quantile ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/laplace/mean/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/laplace/mean/test/test.native.js index 2c3ad550ecfb..9437df79e258 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/laplace/mean/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/laplace/mean/test/test.native.js @@ -86,7 +86,7 @@ tape( 'if provided a nonpositive `b`, the function returns `NaN`', opts, functio t.end(); }); -tape( 'the function returns the mean of a Laplace distribution', opts, function test( t ) { +tape( 'the function returns the expected value of a Laplace distribution', opts, function test( t ) { var expected; var mu; var b; diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/kurtosis/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/kurtosis/test/test.native.js index e6fe71419d21..9c9b786e649d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/kurtosis/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/kurtosis/test/test.native.js @@ -92,7 +92,7 @@ tape( 'if provided a success probability `p` outside of `[0,1]`, the function re t.end(); }); -tape( 'the function returns the kurtosis of a negative binomial distribution', opts, function test( t ) { +tape( 'the function returns the excess kurtosis of a negative binomial distribution', opts, function test( t ) { var expected; var r; var p; diff --git a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/test/test.native.js index 24dd0753faca..dbc3fef031e7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/negative-binomial/variance/test/test.native.js @@ -75,7 +75,7 @@ tape( 'if provided `r <= 0` or `p <= 0` or `p > 1`, the function returns `NaN`', t.end(); }); -tape( 'the function evaluates the variance for a negative binomial distribution', opts, function test( t ) { +tape( 'the function returns the variance of a negative binomial distribution', opts, function test( t ) { var expected; var delta; var tol; diff --git a/lib/node_modules/@stdlib/stats/base/dists/planck/entropy/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/planck/entropy/test/test.native.js index b68e051730a8..1c04a206c328 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/planck/entropy/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/planck/entropy/test/test.native.js @@ -67,7 +67,7 @@ tape( 'if provided a shape parameter `lambda` which is nonpositive, the function t.end(); }); -tape( 'the function returns the entropy of a Planck distribution', opts, function test( t ) { +tape( 'the function returns the differential entropy of a Planck distribution', opts, function test( t ) { var expected; var lambda; var delta; diff --git a/lib/node_modules/@stdlib/stats/base/dists/poisson/cdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/poisson/cdf/README.md index 36847244b0af..6c9974e44cfb 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/poisson/cdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/poisson/cdf/README.md @@ -115,6 +115,30 @@ y = mycdf( 8.0 ); +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var cdf = require( '@stdlib/stats/base/dists/poisson/cdf' ); + +var opts = { + 'dtype': 'float64' +}; +var lambda = uniform( 10, 0.0, 10.0, opts ); +var x = uniform( 10, 0.0, 10.0, opts ); + +logEachMap( 'x: %0.4f, λ: %0.4f, F(x;λ): %0.4f', x, lambda, cdf ); +``` + +
+ + + * * *
@@ -175,8 +199,8 @@ static double random_uniform( double min, double max ) { } int main( void ) { - double x; double lambda; + double x; double y; int i; @@ -197,35 +221,6 @@ int main( void ) { -* * * - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var cdf = require( '@stdlib/stats/base/dists/poisson/cdf' ); - -var lambda; -var x; -var y; -var i; - -for ( i = 0; i < 10; i++ ) { - x = randu() * 10.0; - lambda = randu() * 10.0; - y = cdf( x, lambda ); - console.log( 'x: %d, λ: %d, F(x;λ): %d', x.toFixed( 4 ), lambda.toFixed( 4 ), y.toFixed( 4 ) ); -} -``` - -
- - - @@ -180,23 +184,23 @@ var v = nanrangeBy.ndarray( 3, x, 1, x.length-3, accessor ); ```javascript -var uniform = require( '@stdlib/random/base/uniform' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var randu = require( '@stdlib/random/base/randu' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); var nanrangeBy = require( '@stdlib/stats/base/nanrange-by' ); -function rand() { - if ( bernoulli( 0.8 ) < 0.2 ) { +function fill() { + if ( randu() < 0.2 ) { return NaN; } - return uniform( -50.0, 50.0 ); + return discreteUniform( -50, 50 ); } function accessor( v ) { return v * 2.0; } -var x = filledarrayBy( 10, 'float64', rand ); +var x = filledarrayBy( 10, 'float64', fill ); console.log( x ); var v = nanrangeBy( x.length, x, 1, accessor ); @@ -236,8 +240,6 @@ console.log( v ); [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray -[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor - [@stdlib/stats/strided/dnanrange]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dnanrange diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/nanrange-by/benchmark/benchmark.js index 3931e4e384cf..497323944104 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/benchmark/benchmark.js @@ -21,13 +21,11 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; -var nanrangeBy = require( './../lib/main.js' ); +var nanrangeBy = require( './../lib/nanrange_by.js' ); // FUNCTIONS // @@ -43,19 +41,6 @@ function accessor( value ) { return value * 2.0; } -/** -* Returns a random number. -* -* @private -* @returns {number} random number -*/ -function rand() { - if ( bernoulli( 0.8 ) < 1 ) { - return NaN; - } - return uniform( -50.0, 50.0 ); -} - /** * Create a benchmark function. * @@ -64,7 +49,17 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'generic', rand ); + var x; + var i; + + x = []; + for ( i = 0; i < len; i++ ) { + if ( randu() < 0.2 ) { + x.push( NaN ); + } else { + x.push( ( randu()*20.0 ) - 10.0 ); + } + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanrange-by/benchmark/benchmark.ndarray.js index cec2b32c4fa0..8b8c84d3bdb2 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/benchmark/benchmark.ndarray.js @@ -21,9 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); -var filledarrayBy = require( '@stdlib/array/filled-by' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -43,19 +41,6 @@ function accessor( value ) { return value * 2.0; } -/** -* Returns a random number. -* -* @private -* @returns {number} random number -*/ -function rand() { - if ( bernoulli( 0.8 ) < 1 ) { - return NaN; - } - return uniform( -50.0, 50.0 ); -} - /** * Create a benchmark function. * @@ -64,7 +49,17 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'generic', rand ); + var x; + var i; + + x = []; + for ( i = 0; i < len; i++ ) { + if ( randu() < 0.2 ) { + x.push( NaN ); + } else { + x.push( ( randu()*20.0 ) - 10.0 ); + } + } return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/repl.txt index 3425fd2e6bcf..306a3a977dd2 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, x, strideX, clbk[, thisArg] ) - Computes the range of a strided array via a callback function, ignoring +{{alias}}( N, x, stride, clbk[, thisArg] ) + Calculates the range of a strided array via a callback function, ignoring `NaN` values. - The `N` and stride parameters determine which elements in the strided array - are accessed at runtime. + The `N` and `stride` parameters determine which elements in `x` are accessed + at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. @@ -34,8 +34,8 @@ Input array/collection. If provided an object, the object must be array- like (excluding strings and functions). - strideX: integer - Stride length. + stride: integer + Index increment for `x`. clbk: Function Callback function. @@ -56,24 +56,25 @@ > {{alias}}( x.length, x, 1, accessor ) 18.0 - // Using `N` and stride parameters: + // Using `N` and `stride` parameters: > x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0, 1.0 ]; - > {{alias}}( 4, x, 2, accessor ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}( N, x, 2, accessor ) 14.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, x1, 2, accessor ) + > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); + > {{alias}}( N, x1, 2, accessor ) 8.0 - -{{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] ) +{{alias}}.ndarray( N, x, stride, offset, clbk[, thisArg] ) Calculates the range of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the offset parameter supports indexing semantics based on a + buffer, the `offset` parameter supports indexing semantics based on a starting index. Parameters @@ -85,11 +86,11 @@ Input array/collection. If provided an object, the object must be array- like (excluding strings and functions). - strideX: integer - Stride length. + stride: integer + Index increment for `x`. - offsetX: integer - Starting index. + offset: integer + Starting index of `x`. clbk: Function Callback function. @@ -112,7 +113,8 @@ // Using an index offset: > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; - > {{alias}}.ndarray( 3, x, 2, 1, accessor ) + > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); + > {{alias}}.ndarray( N, x, 2, 1, accessor ) 8.0 See Also diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/types/index.d.ts index caa6d2312b59..502636524eb1 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/types/index.d.ts @@ -20,12 +20,7 @@ /// -import { Collection, AccessorArrayLike } from '@stdlib/types/array'; - -/** -* Input array. -*/ -type InputArray = Collection | AccessorArrayLike; +import { Collection } from '@stdlib/types/array'; /** * Returns an accessed value. @@ -88,7 +83,7 @@ type Callback = Nullary | Unary | Binary | Ternary | */ interface Routine { /** - * Computes the range of a strided array via a callback function, ignoring `NaN` values. + * Calculates the range of a strided array via a callback function, ignoring `NaN` values. * * ## Notes * @@ -107,7 +102,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param strideX - stride length + * @param stride - stride length * @param clbk - callback * @param thisArg - execution context * @returns range @@ -122,10 +117,10 @@ interface Routine { * var v = nanrangeBy( x.length, x, 1, accessor ); * // returns 18.0 */ - ( N: number, x: InputArray, strideX: number, clbk: Callback, thisArg?: ThisParameterType> ): number; + ( N: number, x: Collection, stride: number, clbk: Callback, thisArg?: ThisParameterType> ): number; /** - * Computes the range of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. + * Calculates the range of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics. * * ## Notes * @@ -144,8 +139,8 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param strideX - stride length - * @param offsetX - starting index + * @param stride - stride length + * @param offset - starting index * @param clbk - callback * @param thisArg - execution context * @returns range @@ -160,11 +155,11 @@ interface Routine { * var v = nanrangeBy.ndarray( x.length, x, 1, 0, accessor ); * // returns 18.0 */ - ndarray( N: number, x: InputArray, strideX: number, offsetX: number, clbk: Callback, thisArg?: ThisParameterType> ): number; + ndarray( N: number, x: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): number; } /** -* Computes the range of a strided array via a callback function, ignoring `NaN` values. +* Calculates the range of a strided array via a callback function, ignoring `NaN` values. * * ## Notes * @@ -183,7 +178,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param strideX - stride length +* @param stride - stride length * @param clbk - callback * @param thisArg - execution context * @returns range diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/types/test.ts index 309fa8677c85..076af8773ea2 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/docs/types/test.ts @@ -16,7 +16,6 @@ * limitations under the License. */ -import AccessorArray = require( '@stdlib/array/base/accessor' ); import nanrangeBy = require( './index' ); const accessor = (): number => { @@ -31,10 +30,7 @@ const accessor = (): number => { const x = new Float64Array( 10 ); nanrangeBy( x.length, x, 1, accessor ); // $ExpectType number - nanrangeBy( x.length, new AccessorArray( x ), 1, accessor ); // $ExpectType number - nanrangeBy( x.length, x, 1, accessor, {} ); // $ExpectType number - nanrangeBy( x.length, new AccessorArray( x ), 1, accessor, {} ); // $ExpectType number } // The compiler throws an error if the function is provided a first argument which is not a number... @@ -74,7 +70,7 @@ const accessor = (): number => { nanrangeBy( x.length, x, undefined, accessor ); // $ExpectError nanrangeBy( x.length, x, [], accessor ); // $ExpectError nanrangeBy( x.length, x, {}, accessor ); // $ExpectError - nanrangeBy( x.length, x, ( x: number ): number => x, accessor ); // $ExpectError + nanrangeBy( x.length, x, ( x: number, accessor ): number => x, accessor ); // $ExpectError } // The compiler throws an error if the function is provided a fourth argument which is not a function... @@ -106,10 +102,7 @@ const accessor = (): number => { const x = new Float64Array( 10 ); nanrangeBy.ndarray( x.length, x, 1, 0, accessor ); // $ExpectType number - nanrangeBy.ndarray( x.length, new AccessorArray( x ), 1, 0, accessor ); // $ExpectType number - nanrangeBy.ndarray( x.length, x, 1, 0, accessor, {} ); // $ExpectType number - nanrangeBy.ndarray( x.length, new AccessorArray( x ), 1, 0, accessor, {} ); // $ExpectType number } // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/nanrange-by/examples/index.js index 6f2b6c34b546..8aaaf469c7a4 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/examples/index.js @@ -18,23 +18,23 @@ 'use strict'; -var uniform = require( '@stdlib/random/base/uniform' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var randu = require( '@stdlib/random/base/randu' ); var filledarrayBy = require( '@stdlib/array/filled-by' ); -var bernoulli = require( '@stdlib/random/base/bernoulli' ); var nanrangeBy = require( './../lib' ); -function rand() { - if ( bernoulli( 0.8 ) < 0.2 ) { +function fill() { + if ( randu() < 0.2 ) { return NaN; } - return uniform( -50.0, 50.0 ); + return discreteUniform( -50, 50 ); } function accessor( v ) { return v * 2.0; } -var x = filledarrayBy( 10, 'float64', rand ); +var x = filledarrayBy( 10, 'float64', fill ); console.log( x ); var v = nanrangeBy( x.length, x, 1, accessor ); diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/index.js b/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/index.js index 3ae440117e2e..dfc81b840c2f 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Compute the range of a strided array via a callback function and ignoring `NaN` values. +* Calculate the range of a strided array via a callback function and ignoring `NaN` values. * * @module @stdlib/stats/base/nanrange-by * @@ -50,14 +50,7 @@ // MODULES // -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var main = require( './main.js' ); -var ndarray = require( './ndarray.js' ); - - -// MAIN // - -setReadOnly( main, 'ndarray', ndarray ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/main.js index e25596b0f392..806353376607 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/main.js @@ -20,35 +20,14 @@ // MODULES // -var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var nanrangeBy = require( './nanrange_by.js' ); var ndarray = require( './ndarray.js' ); // MAIN // -/** -* Computes the range of a strided array via a callback function, ignoring `NaN` values. -* -* @param {PositiveInteger} N - number of indexed elements -* @param {Collection} x - input array -* @param {integer} strideX - index increment -* @param {Callback} clbk - callback -* @param {*} [thisArg] - execution context -* @returns {number} range -* -* @example -* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; -* -* function accessor( v ) { -* return v * 2.0; -* } -* -* var v = nanrangeBy( x.length, x, 1, accessor ); -* // returns 18.0 -*/ -function nanrangeBy( N, x, strideX, clbk, thisArg ) { - return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg ); -} +setReadOnly( nanrangeBy, 'ndarray', ndarray ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/nanrange_by.js b/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/nanrange_by.js new file mode 100644 index 000000000000..b7b9dd146f9f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/nanrange_by.js @@ -0,0 +1,100 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Calculates the range of a strided array via a callback function, ignoring `NaN` values. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {Collection} x - input array/collection +* @param {integer} stride - index increment +* @param {Callback} clbk - callback +* @param {*} [thisArg] - execution context +* @returns {number} range +* +* @example +* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ]; +* +* function accessor( v ) { +* return v * 2.0; +* } +* +* var v = nanrangeBy( x.length, x, 1, accessor ); +* // returns 18.0 +*/ +function nanrangeBy( N, x, stride, clbk, thisArg ) { + var max; + var min; + var ix; + var v; + var i; + + if ( N <= 0 ) { + return NaN; + } + if ( N === 1 || stride === 0 ) { + v = clbk.call( thisArg, x[ 0 ], 0, 0, x ); + if ( v === void 0 || isnan( v ) ) { + return NaN; + } + return 0.0; + } + if ( stride < 0 ) { + ix = (1-N) * stride; + } else { + ix = 0; + } + for ( i = 0; i < N; i++ ) { + min = clbk.call( thisArg, x[ ix ], i, ix, x ); + if ( min === min && min !== void 0 ) { + break; + } + ix += stride; + } + if ( i === N ) { + return NaN; + } + max = min; + i += 1; + for ( i; i < N; i++ ) { + ix += stride; + v = clbk.call( thisArg, x[ ix ], i, ix, x ); + if ( v === void 0 || isnan( v ) ) { + continue; + } + if ( v < min ) { + min = v; + } else if ( v > max ) { + max = v; + } + } + return max - min; +} + + +// EXPORTS // + +module.exports = nanrangeBy; diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/ndarray.js index 1d517958bcd8..8d7bcbae67df 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/lib/ndarray.js @@ -21,19 +21,17 @@ // MODULES // var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var accessors = require( './accessors.js' ); // MAIN // /** -* Computes the range of a strided array via a callback function, ignoring `NaN` values. +* Calculates the range of a strided array via a callback function, ignoring `NaN` values. * * @param {PositiveInteger} N - number of indexed elements -* @param {Collection} x - input array -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index +* @param {Collection} x - input array/collection +* @param {integer} stride - index increment +* @param {NonNegativeInteger} offset - starting index * @param {Callback} clbk - callback * @param {*} [thisArg] - execution context * @returns {number} range @@ -48,35 +46,30 @@ var accessors = require( './accessors.js' ); * var v = nanrangeBy( x.length, x, 1, 0, accessor ); * // returns 18.0 */ -function nanrangeBy( N, x, strideX, offsetX, clbk, thisArg ) { +function nanrangeBy( N, x, stride, offset, clbk, thisArg ) { var max; var min; var ix; - var o; var v; var i; if ( N <= 0 ) { return NaN; } - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - return accessors( N, o, strideX, offsetX, clbk, thisArg ); - } - if ( N === 1 || strideX === 0 ) { - v = clbk.call( thisArg, x[ offsetX ], 0, offsetX, x ); + if ( N === 1 || stride === 0 ) { + v = clbk.call( thisArg, x[ 0 ], 0, 0, x ); if ( v === void 0 || isnan( v ) ) { return NaN; } return 0.0; } - ix = offsetX; + ix = offset; for ( i = 0; i < N; i++ ) { min = clbk.call( thisArg, x[ ix ], i, ix, x ); if ( min === min && min !== void 0 ) { break; } - ix += strideX; + ix += stride; } if ( i === N ) { return NaN; @@ -84,7 +77,7 @@ function nanrangeBy( N, x, strideX, offsetX, clbk, thisArg ) { max = min; i += 1; for ( i; i < N; i++ ) { - ix += strideX; + ix += stride; v = clbk.call( thisArg, x[ ix ], i, ix, x ); if ( v === void 0 || isnan( v ) ) { continue; diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/test/test.nanrange_by.js b/lib/node_modules/@stdlib/stats/base/nanrange-by/test/test.nanrange_by.js new file mode 100644 index 000000000000..ce1e4d8fe3ed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/test/test.nanrange_by.js @@ -0,0 +1,233 @@ +/** +* @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 floor = require( '@stdlib/math/base/special/floor' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var Float64Array = require( '@stdlib/array/float64' ); +var nanrangeBy = require( './../lib/nanrange_by.js' ); + + +// FUNCTIONS // + +function accessor( v ) { + if ( v === void 0 ) { + return; + } + return v * 2.0; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nanrangeBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 5', function test( t ) { + t.strictEqual( nanrangeBy.length, 5, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the range of a strided array via a callback function, ignoring NaN values', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, NaN, 3.0 ]; + v = nanrangeBy( x.length, x, 1, accessor ); + t.strictEqual( v, 18.0, 'returns expected value' ); + + x = [ -4.0, NaN, -5.0 ]; + v = nanrangeBy( x.length, x, 1, accessor ); + t.strictEqual( v, 2.0, 'returns expected value' ); + + x = [ -0.0, 0.0, NaN, -0.0 ]; + v = nanrangeBy( x.length, x, 1, accessor ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = nanrangeBy( x.length, x, 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = nanrangeBy( x.length, x, 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Array( 5 ); // sparse array + v = nanrangeBy( x.length, x, 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Array( 5 ); // sparse array + x[ 2 ] = 1.0; + v = nanrangeBy( x.length, x, 1, accessor ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanrangeBy( 0, x, 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = nanrangeBy( -1, x, 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanrangeBy( 1, x, 1, accessor ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Array( 1 ); // sparse array + v = nanrangeBy( 1, x, 1, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var N; + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0, + NaN, // 4 + NaN + ]; + + N = floor( x.length / 2 ); + v = nanrangeBy( N, x, 2, accessor ); + + t.strictEqual( v, 12.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; + var x; + var v; + + x = [ + NaN, // 4 + NaN, + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + N = floor( x.length / 2 ); + v = nanrangeBy( N, x, -2, accessor ); + + t.strictEqual( v, 12.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = nanrangeBy( x.length, x, 0, accessor ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = new Array( 1 ); // sparse array + v = nanrangeBy( 1, x, 0, accessor ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var N; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0, + NaN, // 4 + NaN + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); + + v = nanrangeBy( N, x1, 2, accessor ); + t.strictEqual( v, 12.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a callback execution context', function test( t ) { + var ctx; + var x; + + x = [ 1.0, 2.0, 3.0, NaN, 4.0, 5.0 ]; + ctx = { + 'count': 0 + }; + nanrangeBy( x.length, x, 1, accessor, ctx ); + + t.strictEqual( ctx.count, x.length, 'returns expected value' ); + t.end(); + + function accessor( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return v * 2.0; + } +}); diff --git a/lib/node_modules/@stdlib/stats/base/nanrange-by/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanrange-by/test/test.ndarray.js index e56dff487a70..33f6c629025d 100644 --- a/lib/node_modules/@stdlib/stats/base/nanrange-by/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/nanrange-by/test/test.ndarray.js @@ -21,7 +21,7 @@ // MODULES // var tape = require( 'tape' ); -var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var nanrangeBy = require( './../lib/ndarray.js' ); @@ -74,11 +74,11 @@ tape( 'the function calculates the range of a strided array via a callback funct v = nanrangeBy( x.length, x, 1, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 5 ); // sparse array v = nanrangeBy( x.length, x, 1, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); - x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 5 ); // sparse array x[ 2 ] = 1.0; v = nanrangeBy( x.length, x, 1, 0, accessor ); t.strictEqual( v, 0.0, 'returns expected value' ); @@ -86,42 +86,6 @@ tape( 'the function calculates the range of a strided array via a callback funct t.end(); }); -tape( 'the function calculates the range of a strided array via a callback function, ignoring NaN values (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, NaN, 3.0 ]; - v = nanrangeBy( x.length, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( v, 18.0, 'returns expected value' ); - - x = [ -4.0, NaN, -5.0 ]; - v = nanrangeBy( x.length, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( v, 2.0, 'returns expected value' ); - - x = [ -0.0, 0.0, NaN, -0.0 ]; - v = nanrangeBy( x.length, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); - - x = [ NaN ]; - v = nanrangeBy( x.length, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - x = [ NaN, NaN ]; - v = nanrangeBy( x.length, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array - v = nanrangeBy( x.length, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array - x[ 2 ] = 1.0; - v = nanrangeBy( x.length, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - t.end(); -}); - tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { var x; var v; @@ -137,21 +101,6 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = nanrangeBy( 0, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = nanrangeBy( -1, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - tape( 'if provided an `N` parameter equal to `1`, the function returns `0`', function test( t ) { var x; var v; @@ -161,30 +110,15 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns `0`', fun v = nanrangeBy( 1, x, 1, 0, accessor ); t.strictEqual( v, 0.0, 'returns expected value' ); - x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 1 ); // sparse array v = nanrangeBy( 1, x, 1, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); -tape( 'if provided an `N` parameter equal to `1`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = nanrangeBy( 1, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array - v = nanrangeBy( 1, toAccessorArray( x ), 1, 0, accessor ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - tape( 'the function supports a `stride` parameter', function test( t ) { + var N; var x; var v; @@ -201,36 +135,15 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]; - v = nanrangeBy( 5, x, 2, 0, accessor ); - - t.strictEqual( v, 12.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, // 0 - 2.0, - 2.0, // 1 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 3 - 2.0, - NaN, // 4 - NaN - ]; - - v = nanrangeBy( 5, toAccessorArray( x ), 2, 0, accessor ); + N = floor( x.length / 2 ); + v = nanrangeBy( N, x, 2, 0, accessor ); t.strictEqual( v, 12.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; var x; var v; @@ -247,30 +160,8 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - v = nanrangeBy( 5, x, -2, 8, accessor ); - - t.strictEqual( v, 12.0, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - NaN, // 4 - NaN, - 1.0, // 3 - 2.0, - 2.0, // 2 - -7.0, - -2.0, // 1 - 3.0, - 4.0, // 0 - 2.0 - ]; - - v = nanrangeBy( 5, toAccessorArray( x ), -2, 8, accessor ); + N = floor( x.length / 2 ); + v = nanrangeBy( N, x, -2, 8, accessor ); t.strictEqual( v, 12.0, 'returns expected value' ); t.end(); @@ -285,29 +176,13 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', v = nanrangeBy( x.length, x, 0, 0, accessor ); t.strictEqual( v, 0.0, 'returns expected value' ); - x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array + x = new Array( 1 ); // sparse array v = nanrangeBy( 1, x, 0, 0, accessor ); t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns `0` (accessors)', function test( t ) { - var x; - var v; - - x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; - - v = nanrangeBy( x.length, toAccessorArray( x ), 0, 0, accessor ); - t.strictEqual( v, 0.0, 'returns expected value' ); - - x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array - v = nanrangeBy( 1, toAccessorArray( x ), 0, 0, accessor ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - tape( 'the function supports an offset parameter', function test( t ) { var x; var v; @@ -329,27 +204,6 @@ tape( 'the function supports an offset parameter', function test( t ) { t.end(); }); -tape( 'the function supports an offset parameter (accessors)', function test( t ) { - var x; - var v; - - x = [ - 1.0, - -2.0, // 0 - 3.0, - 4.0, // 1 - 5.0, - -6.0, // 2 - NaN, - NaN // 3 - ]; - - v = nanrangeBy( 4, toAccessorArray( x ), 2, 1, accessor ); - t.strictEqual( v, 20.0, 'returns expected value' ); - - t.end(); -}); - tape( 'the function supports providing a callback execution context', function test( t ) { var ctx; var x; @@ -368,22 +222,3 @@ tape( 'the function supports providing a callback execution context', function t return v * 2.0; } }); - -tape( 'the function supports providing a callback execution context (accessors)', function test( t ) { - var ctx; - var x; - - x = [ 1.0, 2.0, 3.0, NaN, 4.0, 5.0 ]; - ctx = { - 'count': 0 - }; - nanrangeBy( x.length, toAccessorArray( x ), 1, 0, accessor, ctx ); - - t.strictEqual( ctx.count, x.length, 'returns expected value' ); - t.end(); - - function accessor( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return v * 2.0; - } -}); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/drange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/drange/README.md new file mode 100644 index 000000000000..b113d5e594d7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/README.md @@ -0,0 +1,116 @@ + + +# drange + +> Compute the [range][range] of a one-dimensional double-precision floating-point ndarray. + +
+ +The [**range**][range] is defined as the difference between the maximum and minimum values. + +
+ + + +
+ +## Usage + +```javascript +var drange = require( '@stdlib/stats/base/ndarray/drange' ); +``` + +#### drange( arrays ) + +Computes the [range][range] of a one-dimensional double-precision floating-point ndarray. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var v = drange( [ x ] ); +// returns 3.0 +``` + +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 drange = require( '@stdlib/stats/base/ndarray/drange' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = drange( [ x ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/drange/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/drange/benchmark/benchmark.js new file mode 100644 index 000000000000..88b2461a05e3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/benchmark/benchmark.js @@ -0,0 +1,102 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var drange = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = drange( [ x ] ); + 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/drange/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/drange/docs/repl.txt new file mode 100644 index 000000000000..f6d7e68428bc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( arrays ) + Computes the range of a one-dimensional double-precision floating-point + ndarray. + + If provided an empty ndarray, the function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + Returns + ------- + out: number + Range. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var dt = 'float64'; + > 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 ] ) + 4.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/drange/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/drange/docs/types/index.d.ts new file mode 100644 index 000000000000..5f15df5f50af --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/docs/types/index.d.ts @@ -0,0 +1,46 @@ +/* +* @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 { float64ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the range of a one-dimensional double-precision floating-point ndarray. +* +* @param arrays - array-like object containing an input ndarray +* @returns range +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = drange( [ x ] ); +* // returns 3.0 +*/ +declare function drange( arrays: [ float64ndarray ] ): number; + + +// EXPORTS // + +export = drange; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/drange/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/drange/docs/types/test.ts new file mode 100644 index 000000000000..db79162f0f5c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/docs/types/test.ts @@ -0,0 +1,57 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import drange = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + drange( [ x ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + drange( '10' ); // $ExpectError + drange( 10 ); // $ExpectError + drange( true ); // $ExpectError + drange( false ); // $ExpectError + drange( null ); // $ExpectError + drange( undefined ); // $ExpectError + drange( [] ); // $ExpectError + drange( {} ); // $ExpectError + drange( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float64' + }); + + drange(); // $ExpectError + drange( [ x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/drange/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/drange/examples/index.js new file mode 100644 index 000000000000..4e0c668da739 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var drange = require( './../lib' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); +var x = new ndarray( 'float64', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = drange( [ x ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/drange/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/drange/lib/index.js new file mode 100644 index 000000000000..0d877e359044 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* Compute the range of a one-dimensional double-precision floating-point ndarray. +* +* @module @stdlib/stats/base/ndarray/drange +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var drange = require( '@stdlib/stats/base/ndarray/drange' ); +* +* var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = drange( [ x ] ); +* // returns 3.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/drange/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/drange/lib/main.js new file mode 100644 index 000000000000..1993542ffbb7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/lib/main.js @@ -0,0 +1,56 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/stats/strided/drange' ).ndarray; + + +// MAIN // + +/** +* Computes the range of a one-dimensional double-precision floating-point ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray +* @returns {number} range +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float64Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = drange( [ x ] ); +* // returns 3.0 +*/ +function drange( arrays ) { + var x = arrays[ 0 ]; + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = drange; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/drange/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/drange/package.json new file mode 100644 index 000000000000..31dc5ef1ff72 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/stats/base/ndarray/drange", + "version": "0.0.0", + "description": "Compute the range of a one-dimensional double-precision floating-point ndarray.", + "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", + "maximum", + "max", + "minimum", + "min", + "range", + "extremes", + "domain", + "extent", + "float64", + "double", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/drange/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/drange/test/test.js new file mode 100644 index 000000000000..9fafb4c440d3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/drange/test/test.js @@ -0,0 +1,173 @@ +/** +* @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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var drange = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float64', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof drange, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( drange.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the range of a one-dimensional ndarray', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = drange( [ vector( x, 6, 1, 0 ) ] ); + t.strictEqual( v, 9.0, 'returns expected value' ); + + x = new Float64Array( [ -4.0, -5.0 ] ); + v = drange( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = new Float64Array( [ -0.0, 0.0, -0.0 ] ); + v = drange( [ vector( x, 3, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN ] ); + v = drange( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = new Float64Array( [ NaN, NaN ] ); + v = drange( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty vector, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float64Array( [] ); + + v = drange( [ vector( x, 0, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a vector containing a single element, the function returns `0`', function test( t ) { + var x; + var v; + + x = new Float64Array( [ 1.0 ] ); + + v = drange( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var x; + var v; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = drange( [ vector( x, 4, 2, 0 ) ] ); + + t.strictEqual( v, 6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var x; + var v; + + x = new Float64Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = drange( [ vector( x, 4, -2, 6 ) ] ); + + t.strictEqual( v, 6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var x; + var v; + + x = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = drange( [ vector( x, 4, 2, 1 ) ] ); + t.strictEqual( v, 6.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/range/README.md new file mode 100644 index 000000000000..b63491b39ef0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/README.md @@ -0,0 +1,115 @@ + + +# range + +> Compute the [range][range] of a one-dimensional ndarray. + +
+ +The [**range**][range] is defined as the difference between the maximum and minimum values. + +
+ + + +
+ +## Usage + +```javascript +var range = require( '@stdlib/stats/base/ndarray/range' ); +``` + +#### range( arrays ) + +Computes the [range][range] of a one-dimensional ndarray. + +```javascript +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 = range( [ x ] ); +// returns 3.0 +``` + +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 range = require( '@stdlib/stats/base/ndarray/range' ); + +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 = range( [ x ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/range/benchmark/benchmark.js new file mode 100644 index 000000000000..7c7285d38d4e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/benchmark/benchmark.js @@ -0,0 +1,102 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var range = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = range( [ x ] ); + 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/range/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/range/docs/repl.txt new file mode 100644 index 000000000000..28a63c29add9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/docs/repl.txt @@ -0,0 +1,31 @@ + +{{alias}}( arrays ) + Computes the range of a one-dimensional ndarray. + + If provided an empty ndarray, the function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + Returns + ------- + out: number + Range. + + 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 ] ) + 4.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/range/docs/types/index.d.ts new file mode 100644 index 000000000000..8edb2d9ad8e9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/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 range of a one-dimensional ndarray. +* +* @param arrays - array-like object containing an input ndarray +* @returns range +* +* @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 = range( [ x ] ); +* // returns 3.0 +*/ +declare function range( arrays: [ T ] ): number; + + +// EXPORTS // + +export = range; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/range/docs/types/test.ts new file mode 100644 index 000000000000..9aa0fa4489e5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/docs/types/test.ts @@ -0,0 +1,57 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import range = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + + range( [ x ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + range( '10' ); // $ExpectError + range( 10 ); // $ExpectError + range( true ); // $ExpectError + range( false ); // $ExpectError + range( null ); // $ExpectError + range( undefined ); // $ExpectError + range( [] ); // $ExpectError + range( {} ); // $ExpectError + range( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'generic' + }); + + range(); // $ExpectError + range( [ x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range/examples/index.js new file mode 100644 index 000000000000..f9fcfcd3c7cf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var range = require( './../lib' ); + +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 = range( [ x ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/range/lib/index.js new file mode 100644 index 000000000000..039dbde30fe9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/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 range of a one-dimensional ndarray. +* +* @module @stdlib/stats/base/ndarray/range +* +* @example +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var range = require( '@stdlib/stats/base/ndarray/range' ); +* +* var xbuf = [ 1.0, 3.0, 4.0, 2.0 ]; +* var x = new ndarray( 'generic', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = range( [ x ] ); +* // returns 3.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/range/lib/main.js new file mode 100644 index 000000000000..0e731d8cd874 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/lib/main.js @@ -0,0 +1,55 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/stats/strided/range' ).ndarray; + + +// MAIN // + +/** +* Computes the range of a one-dimensional ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray +* @returns {number} range +* +* @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 = range( [ x ] ); +* // returns 3.0 +*/ +function range( arrays ) { + var x = arrays[ 0 ]; + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = range; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/range/package.json new file mode 100644 index 000000000000..6d855003a391 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/stats/base/ndarray/range", + "version": "0.0.0", + "description": "Compute the range of a one-dimensional ndarray.", + "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", + "maximum", + "max", + "minimum", + "min", + "range", + "extremes", + "domain", + "extent", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/range/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/range/test/test.js new file mode 100644 index 000000000000..1d6761d3c867 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/range/test/test.js @@ -0,0 +1,172 @@ +/** +* @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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var range = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'generic', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof range, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( range.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the range of a one-dimensional ndarray', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = range( [ vector( x, 6, 1, 0 ) ] ); + t.strictEqual( v, 9.0, 'returns expected value' ); + + x = [ -4.0, -5.0 ]; + v = range( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = [ -0.0, 0.0, -0.0 ]; + v = range( [ vector( x, 3, 1, 0 ) ] ); + t.strictEqual( isPositiveZero( v ), true, 'returns expected value' ); + + x = [ NaN ]; + v = range( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + x = [ NaN, NaN ]; + v = range( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty vector, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = []; + + v = range( [ vector( x, 0, 1, 0 ) ] ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a vector containing a single element, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0 ]; + + v = range( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + v = range( [ vector( x, 4, 2, 0 ) ] ); + + t.strictEqual( v, 6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + v = range( [ vector( x, 4, -2, 6 ) ] ); + + t.strictEqual( v, 6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var x; + var v; + + x = [ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]; + + v = range( [ vector( x, 4, 2, 1 ) ] ); + t.strictEqual( v, 6.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/srange/README.md b/lib/node_modules/@stdlib/stats/base/ndarray/srange/README.md new file mode 100644 index 000000000000..2a781e522fec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/README.md @@ -0,0 +1,116 @@ + + +# srange + +> Compute the [range][range] of a one-dimensional single-precision floating-point ndarray. + +
+ +The [**range**][range] is defined as the difference between the maximum and minimum values. + +
+ + + +
+ +## Usage + +```javascript +var srange = require( '@stdlib/stats/base/ndarray/srange' ); +``` + +#### srange( arrays ) + +Computes the [range][range] of a one-dimensional single-precision floating-point ndarray. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); + +var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); + +var v = srange( [ x ] ); +// returns 3.0 +``` + +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 srange = require( '@stdlib/stats/base/ndarray/srange' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = srange( [ x ] ); +console.log( v ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/srange/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/ndarray/srange/benchmark/benchmark.js new file mode 100644 index 000000000000..db5d035e9ab4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/benchmark/benchmark.js @@ -0,0 +1,102 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var srange = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var xbuf; + var x; + + xbuf = uniform( len, -10.0, 10.0, options ); + x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); + + return benchmark; + + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = srange( [ x ] ); + 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/srange/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/ndarray/srange/docs/repl.txt new file mode 100644 index 000000000000..6254ed4c2aa3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( arrays ) + Computes the range of a one-dimensional single-precision floating-point + ndarray. + + If provided an empty ndarray, the function returns `NaN`. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing a one-dimensional input ndarray. + + Returns + ------- + out: number + Range. + + Examples + -------- + > var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] ); + > var dt = 'float32'; + > 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 ] ) + 4.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/srange/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/ndarray/srange/docs/types/index.d.ts new file mode 100644 index 000000000000..bc7e62d6ad2b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/docs/types/index.d.ts @@ -0,0 +1,46 @@ +/* +* @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 { float32ndarray } from '@stdlib/types/ndarray'; + +/** +* Computes the range of a one-dimensional single-precision floating-point ndarray. +* +* @param arrays - array-like object containing an input ndarray +* @returns range +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = srange( [ x ] ); +* // returns 3.0 +*/ +declare function srange( arrays: [ float32ndarray ] ): number; + + +// EXPORTS // + +export = srange; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/srange/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/ndarray/srange/docs/types/test.ts new file mode 100644 index 000000000000..66e4ed7a30d3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/docs/types/test.ts @@ -0,0 +1,57 @@ +/* +* @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. +*/ + +/* eslint-disable space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import srange = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + + srange( [ x ] ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not an array of ndarrays... +{ + srange( '10' ); // $ExpectError + srange( 10 ); // $ExpectError + srange( true ); // $ExpectError + srange( false ); // $ExpectError + srange( null ); // $ExpectError + srange( undefined ); // $ExpectError + srange( [] ); // $ExpectError + srange( {} ); // $ExpectError + srange( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = zeros( [ 10 ], { + 'dtype': 'float32' + }); + + srange(); // $ExpectError + srange( [ x ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/srange/examples/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/srange/examples/index.js new file mode 100644 index 000000000000..cf2beb86a819 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var srange = require( './../lib' ); + +var xbuf = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +var x = new ndarray( 'float32', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' ); +console.log( ndarray2array( x ) ); + +var v = srange( [ x ] ); +console.log( v ); diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/srange/lib/index.js b/lib/node_modules/@stdlib/stats/base/ndarray/srange/lib/index.js new file mode 100644 index 000000000000..e31bef09ffeb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/lib/index.js @@ -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. +*/ + +'use strict'; + +/** +* Compute the range of a one-dimensional single-precision floating-point ndarray. +* +* @module @stdlib/stats/base/ndarray/srange +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* var srange = require( '@stdlib/stats/base/ndarray/srange' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = srange( [ x ] ); +* // returns 3.0 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/srange/lib/main.js b/lib/node_modules/@stdlib/stats/base/ndarray/srange/lib/main.js new file mode 100644 index 000000000000..f14fd0379842 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/lib/main.js @@ -0,0 +1,56 @@ +/** +* @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 numelDimension = require( '@stdlib/ndarray/base/numel-dimension' ); +var getStride = require( '@stdlib/ndarray/base/stride' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); +var strided = require( '@stdlib/stats/strided/srange' ).ndarray; + + +// MAIN // + +/** +* Computes the range of a one-dimensional single-precision floating-point ndarray. +* +* @param {ArrayLikeObject} arrays - array-like object containing an input ndarray +* @returns {number} range +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/base/ctor' ); +* +* var xbuf = new Float32Array( [ 1.0, 3.0, 4.0, 2.0 ] ); +* var x = new ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); +* +* var v = srange( [ x ] ); +* // returns 3.0 +*/ +function srange( arrays ) { + var x = arrays[ 0 ]; + return strided( numelDimension( x, 0 ), getData( x ), getStride( x, 0 ), getOffset( x ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = srange; diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/srange/package.json b/lib/node_modules/@stdlib/stats/base/ndarray/srange/package.json new file mode 100644 index 000000000000..ce73218d30fc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/stats/base/ndarray/srange", + "version": "0.0.0", + "description": "Compute the range of a one-dimensional single-precision floating-point ndarray.", + "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", + "maximum", + "max", + "minimum", + "min", + "range", + "extremes", + "domain", + "extent", + "float32", + "float", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/base/ndarray/srange/test/test.js b/lib/node_modules/@stdlib/stats/base/ndarray/srange/test/test.js new file mode 100644 index 000000000000..2460b742f955 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/ndarray/srange/test/test.js @@ -0,0 +1,173 @@ +/** +* @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 tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var Float32Array = require( '@stdlib/array/float32' ); +var ndarray = require( '@stdlib/ndarray/base/ctor' ); +var srange = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a one-dimensional ndarray. +* +* @private +* @param {Collection} buffer - underlying data buffer +* @param {NonNegativeInteger} length - number of indexed elements +* @param {integer} stride - stride length +* @param {NonNegativeInteger} offset - index offset +* @returns {ndarray} one-dimensional ndarray +*/ +function vector( buffer, length, stride, offset ) { + return new ndarray( 'float32', buffer, [ length ], [ stride ], offset, 'row-major' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof srange, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 1', function test( t ) { + t.strictEqual( srange.length, 1, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the range of a one-dimensional ndarray', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + v = srange( [ vector( x, 6, 1, 0 ) ] ); + t.strictEqual( v, 9.0, 'returns expected value' ); + + x = new Float32Array( [ -4.0, -5.0 ] ); + v = srange( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( v, 1.0, 'returns expected value' ); + + x = new Float32Array( [ -0.0, 0.0, -0.0 ] ); + v = srange( [ vector( x, 3, 1, 0 ) ] ); + t.strictEqual( isPositiveZerof( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN ] ); + v = srange( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + x = new Float32Array( [ NaN, NaN ] ); + v = srange( [ vector( x, 2, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an empty vector, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = new Float32Array( [] ); + + v = srange( [ vector( x, 0, 1, 0 ) ] ); + t.strictEqual( isnanf( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a vector containing a single element, the function returns `0`', function test( t ) { + var x; + var v; + + x = new Float32Array( [ 1.0 ] ); + + v = srange( [ vector( x, 1, 1, 0 ) ] ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-unit strides', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + v = srange( [ vector( x, 4, 2, 0 ) ] ); + + t.strictEqual( v, 6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having negative strides', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + v = srange( [ vector( x, 4, -2, 6 ) ] ); + + t.strictEqual( v, 6.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports one-dimensional ndarrays having non-zero offsets', function test( t ) { + var x; + var v; + + x = new Float32Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + v = srange( [ vector( x, 4, 2, 1 ) ] ); + t.strictEqual( v, 6.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/range-by/lib/accessors.js b/lib/node_modules/@stdlib/stats/base/range-by/lib/accessors.js index 85bfabd0bb72..d9f95e3aa0d6 100644 --- a/lib/node_modules/@stdlib/stats/base/range-by/lib/accessors.js +++ b/lib/node_modules/@stdlib/stats/base/range-by/lib/accessors.js @@ -67,7 +67,7 @@ function rangeBy( N, x, strideX, offsetX, clbk, thisArg) { get = x.accessors[ 0 ]; if ( N === 1 || strideX === 0 ) { - v = clbk.call( thisArg, get( xbuf, offsetX ), 0, offsetX, xbuf ); + v = clbk.call( thisArg, get( xbuf, offsetX ), 0, offsetX, x ); if ( v === void 0 || isnan( v ) ) { return NaN; } @@ -75,7 +75,7 @@ function rangeBy( N, x, strideX, offsetX, clbk, thisArg) { } ix = offsetX; for ( i = 0; i < N; i++ ) { - min = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf ); + min = clbk.call( thisArg, get( xbuf, ix ), i, ix, x ); if ( min !== void 0 ) { break; } @@ -88,7 +88,7 @@ function rangeBy( N, x, strideX, offsetX, clbk, thisArg) { i += 1; for ( i; i < N; i++ ) { ix += strideX; - v = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf ); + v = clbk.call( thisArg, get( xbuf, ix ), i, ix, x ); if ( v === void 0 ) { continue; } diff --git a/lib/node_modules/@stdlib/stats/base/stdevwd/test/test.stdevwd.js b/lib/node_modules/@stdlib/stats/base/stdevwd/test/test.stdevwd.js new file mode 100644 index 000000000000..dcf840ce4032 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/stdevwd/test/test.stdevwd.js @@ -0,0 +1,207 @@ +/** +* @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 floor = require( '@stdlib/math/base/special/floor' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var stdevwd = require( './../lib/stdevwd.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof stdevwd, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( stdevwd.length, 4, 'has expected arity' ); + t.end(); +}); + +tape( 'the function calculates the population standard deviation of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = stdevwd( x.length, 0, x, 1 ); + t.strictEqual( v, sqrt( 53.5/x.length ), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = stdevwd( x.length, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = stdevwd( x.length, 0, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function calculates the sample standard deviation of a strided array', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ]; + v = stdevwd( x.length, 1, x, 1 ); + t.strictEqual( v, sqrt( 53.5/(x.length-1) ), 'returns expected value' ); + + x = [ -4.0, -4.0 ]; + v = stdevwd( x.length, 1, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + x = [ NaN, 4.0 ]; + v = stdevwd( x.length, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = stdevwd( 0, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = stdevwd( -1, 1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the function returns a population standard deviation of `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = stdevwd( 1, 0, x, 1 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `correction` parameter yielding `N-correction` less than or equal to `0`, the function returns `NaN`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = stdevwd( x.length, x.length, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = stdevwd( x.length, x.length+1, x, 1 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `stride` parameter', function test( t ) { + var N; + var x; + var v; + + x = [ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]; + + N = floor( x.length / 2 ); + v = stdevwd( N, 1, x, 2 ); + + t.strictEqual( v, 2.5, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var N; + var x; + var v; + + x = [ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]; + + N = floor( x.length / 2 ); + v = stdevwd( N, 1, x, -2 ); + + t.strictEqual( v, 2.5, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', function test( t ) { + var x; + var v; + + x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; + + v = stdevwd( x.length, 1, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports view offsets', function test( t ) { + var x0; + var x1; + var N; + var v; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + N = floor(x1.length / 2); + + v = stdevwd( N, 1, x1, 2 ); + t.strictEqual( v, 2.5, 'returns expected value' ); + + t.end(); +});