diff --git a/lib/node_modules/@stdlib/blas/base/dsyr/README.md b/lib/node_modules/@stdlib/blas/base/dsyr/README.md index 5b275a1c26b0..2c37c5482c79 100644 --- a/lib/node_modules/@stdlib/blas/base/dsyr/README.md +++ b/lib/node_modules/@stdlib/blas/base/dsyr/README.md @@ -53,7 +53,7 @@ The function has the following parameters: - **x**: input [`Float64Array`][mdn-float64array]. - **sx**: stride length for `x`. - **A**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array]. -- **lda**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over the elements of `x` in reverse order, diff --git a/lib/node_modules/@stdlib/blas/base/dsyr/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/dsyr/docs/types/index.d.ts index 1e87b3720a3c..c4625b611044 100644 --- a/lib/node_modules/@stdlib/blas/base/dsyr/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/dsyr/docs/types/index.d.ts @@ -51,7 +51,7 @@ interface Routine { ( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, x: Float64Array, strideX: number, A: Float64Array, LDA: number ): Float64Array; /** - * Performs the matrix-vector operation `y = alpha*A*x + beta*y` using alternative indexing semantics and where `alpha` and `beta` are scalars, `x` and `y` are `N` element vectors, and `A` is an `N` by `N` symmetric matrix. + * Performs the symmetric rank 1 operation `A = α*x*x^T + A` using alternative indexing semantics and where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. * * @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced * @param N - number of elements along each dimension in the matrix `A` diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/README.md b/lib/node_modules/@stdlib/blas/base/ssyr/README.md index 46f70bb33083..d2c67b73039b 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/README.md +++ b/lib/node_modules/@stdlib/blas/base/ssyr/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +Copyright (c) 2024 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. @@ -20,7 +20,7 @@ limitations under the License. # ssyr -> Perform the symmetric rank 1 operation `A = α*x*x**T + A`. +> Perform the symmetric rank 1 operation `A = α*x*x^T + A`.
@@ -32,16 +32,16 @@ var ssyr = require( '@stdlib/blas/base/ssyr' ); #### ssyr( order, uplo, N, α, x, sx, A, LDA ) -Performs the symmetric rank 1 operation `A = α*x*x**T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. +Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); +var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); ssyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 ); -// A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] +// A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] ``` The function has the following parameters: @@ -51,20 +51,20 @@ The function has the following parameters: - **N**: number of elements along each dimension of `A`. - **α**: scalar constant. - **x**: input [`Float32Array`][mdn-float32array]. -- **sx**: index increment for `x`. +- **sx**: stride length for `x`. - **A**: input matrix stored in linear memory as a [`Float32Array`][mdn-float32array]. -- **lda**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). -The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over every other element of `x` in reverse order, +The stride parameters determine how elements in the input arrays are accessed at runtime. For example, to iterate over the elements of `x` in reverse order, ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); -var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); +var x = new Float32Array( [ 3.0, 2.0, 1.0 ] ); -ssyr( 'row-major', 'upper', 3, 1.0, x, -2, A, 3 ); -// A => [ 26.0, 17.0, 8.0, 0.0, 10.0, 5.0, 0.0, 0.0, 2.0 ] +ssyr( 'row-major', 'upper', 3, 1.0, x, -1, A, 3 ); +// A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] ``` Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. @@ -75,14 +75,14 @@ Note that indexing is relative to the first index. To introduce an offset, use [ var Float32Array = require( '@stdlib/array/float32' ); // Initial arrays... -var x0 = new Float32Array( [ 1.0, 1.0, 1.0, 1.0 ] ); -var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); +var x0 = new Float32Array( [ 0.0, 3.0, 2.0, 1.0 ] ); +var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); // Create offset views... var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element ssyr( 'row-major', 'upper', 3, 1.0, x1, -1, A, 3 ); -// A => [ 2.0, 3.0, 4.0, 0.0, 2.0, 3.0, 0.0, 0.0, 2.0 ] +// A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] ``` #### ssyr.ndarray( uplo, N, α, x, sx, ox, A, sa1, sa2, oa ) @@ -92,11 +92,11 @@ Performs the symmetric rank 1 operation `A = α*x*x^T + A`, using alternative in ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); +var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); ssyr.ndarray( 'upper', 3, 1.0, x, 1, 0, A, 3, 1, 0 ); -// A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] +// A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] ``` The function has the following additional parameters: @@ -111,11 +111,11 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); +var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); ssyr.ndarray( 'upper', 3, 1.0, x, -2, 4, A, 3, 1, 0 ); -// A => [ 26.0, 17.0, 8.0, 0.0, 10.0, 5.0, 0.0, 0.0, 2.0 ] +// A => [ 26.0, 17.0, 8.0, 2.0, 10.0, 5.0, 3.0, 2.0, 2.0 ] ```
@@ -149,11 +149,18 @@ var opts = { var N = 3; -var A = ones( N*N, opts.dtype ); +// Create N-by-N symmetric matrices: +var A1 = ones( N*N, opts.dtype ); +var A2 = ones( N*N, opts.dtype ); + +// Create a random vector: var x = discreteUniform( N, -10.0, 10.0, opts ); -ssyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 ); -console.log( A ); +ssyr( 'row-major', 'upper', 3, 1.0, x, 1, A1, 3 ); +console.log( A1 ); + +ssyr.ndarray( 'upper', 3, 1.0, x, 1, 0, A2, 3, 1, 0 ); +console.log( A2 ); ``` @@ -186,62 +193,62 @@ console.log( A ); #include "stdlib/blas/base/ssyr.h" ``` -#### c_ssyr( order, uplo, N, alpha, \*X, strideX, \*A, LDA ) +#### c_ssyr( layout, uplo, N, alpha, \*X, sx, \*A, LDA ) -Performs the symmetric rank 1 operation `A = α*x*x^T + A`. +Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. ```c #include "stdlib/blas/base/shared.h" -float A[] = { 1.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 3.0f, 2.0f, 1.0f }; -const float x[] = { 1.0f, 2.0f, 3.0f }; +float A[] = { 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 }; +const float x[] = { 1.0, 2.0, 3.0 }; -c_ssyr( CblasColMajor, CblasUpper, 3, 1.0f, x, 1, A, 3 ); +c_ssyr( CblasColMajor, CblasUpper, 3, 1.0, x, 1, A, 3 ); ``` The function accepts the following arguments: -- **order**: `[in] CBLAS_LAYOUT` storage layout. +- **layout**: `[in] CBLAS_LAYOUT` storage layout. - **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced. - **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`. -- **alpha**: `[in] float` scalar. +- **alpha**: `[in] float` scalar constant. - **X**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **sx**: `[in] CBLAS_INT` stride length for `X`. - **A**: `[inout] float*` input matrix. - **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). ```c -void c_ssyr( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ) +void c_ssyr( const CBLAS_LAYOUT layout, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ) ``` -#### c_ssyr_ndarray( uplo, N, alpha, \*X, strideX, offsetX, \*A, sa1, sa2, oa ) +#### c_ssyr_ndarray( uplo, N, alpha, \*X, sx, ox, \*A, sa1, sa2, oa ) -Performs the symmetric rank 1 operation `A = α*x*x^T + A` using alternative indexing semantics. +Performs the symmetric rank 1 operation `A = α*x*x^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. ```c #include "stdlib/blas/base/shared.h" -float A[] = { 1.0f, 2.0f, 3.0f, 0.0f, 1.0f, 2.0f, 0.0f, 0.0f, 1.0f }; -const float x[] = { 1.0f, 2.0f, 3.0f }; +float A[] = { 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 }; +const float x[] = { 1.0, 2.0, 3.0 }; -c_ssyr_ndarray( CblasUpper, 3, 1.0f, x, 1, 0, A, 3, 1, 0 ); +c_ssyr_ndarray( CblasUpper, 3, 1.0, x, 1, 0, A, 3, 1, 0 ); ``` The function accepts the following arguments: - **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced. - **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`. -- **alpha**: `[in] float` scalar. +- **alpha**: `[in] float` scalar constant. - **X**: `[in] float*` input array. -- **strideX**: `[in] CBLAS_INT` index increment for `X`. -- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **sx**: `[in] CBLAS_INT` stride length for `X`. +- **ox**: `[in] CBLAS_INT` starting index for `X`. - **A**: `[inout] float*` input matrix. - **sa1**: `[in] CBLAS_INT` stride of the first dimension of `A`. - **sa2**: `[in] CBLAS_INT` stride of the second dimension of `A`. - **oa**: `[in] CBLAS_INT` starting index for `A`. ```c -void c_ssyr_ndarray( const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *A, const CBLAS_INT sa1, const CBLAS_INT sa2, const CBLAS_INT oa ) +void c_ssyr_ndarray( const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA ) ``` @@ -268,27 +275,39 @@ void c_ssyr_ndarray( const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha #include int main( void ) { - // Create strided arrays: - float A[] = { 1.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 3.0f, 2.0f, 1.0f }; - const float x[] = { 1.0f, 2.0f, 3.0f }; - - // Specify the number of elements along each dimension of `A`: + // Define 3x3 symmetric matrices stored in row-major layout: + float A1[ 3*3 ] = { + 1.0f, 2.0f, 3.0f, + 2.0f, 1.0f, 2.0f, + 3.0f, 2.0f, 1.0f + }; + + float A2[ 3*3 ] = { + 1.0f, 2.0f, 3.0f, + 2.0f, 1.0f, 2.0f, + 3.0f, 2.0f, 1.0f + }; + + // Define a vector: + const float x[ 3 ] = { 1.0f, 2.0f, 3.0f }; + + // Specify the number of elements along each dimension of `A1` and `A2`: const int N = 3; // Perform the symmetric rank 1 operation `A = α*x*x^T + A`: - c_ssyr( CblasColMajor, CblasUpper, N, 1.0f, x, 1, A, N ); + c_ssyr( CblasColMajor, CblasUpper, N, 1.0f, x, 1, A1, N ); // Print the result: for ( int i = 0; i < N*N; i++ ) { - printf( "A[ %i ] = %f\n", i, A[ i ] ); + printf( "A1[ %i ] = %f\n", i, A1[ i ] ); } - // Perform the symmetric rank 1 operation `A = α*x*x^T + A`: - c_ssyr_ndarray( CblasUpper, N, 1.0f, x, 1, 0, A, N, 1, 0 ); + // Perform the symmetric rank 1 operation `A = α*x*x^T + A` using alternative indexing semantics: + c_ssyr_ndarray( CblasUpper, N, 1.0, x, 1, 0, A2, N, 1, 0 ); // Print the result: for ( int i = 0; i < N*N; i++ ) { - printf( "A[ %i ] = %f\n", i, A[ i ] ); + printf( "A2[ %i ] = %f\n", i, A[ i ] ); } } ``` @@ -315,7 +334,7 @@ int main( void ) { [blas]: http://www.netlib.org/blas -[blas-ssyr]: https://www.netlib.org/lapack/explore-html/dc/d82/group__her_gad7585662770cdd3001ed08c7a864cd21.html#gad7585662770cdd3001ed08c7a864cd21 +[blas-ssyr]: https://www.netlib.org/lapack/explore-html-3.6.1/d6/d30/group__single__blas__level2_ga7b8a99048765ed2bf7c1e770bff0b622.html [mdn-float32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/blas/base/ssyr/benchmark/c/benchmark.c index b011206956dd..08a08b53a12f 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/blas/base/ssyr/benchmark/c/benchmark.c @@ -83,7 +83,7 @@ static double tic( void ) { * Runs a benchmark. * * @param iterations number of iterations -* @param N number of elements along each dimension +* @param N array dimension size * @return elapsed time in seconds */ static double benchmark1( int iterations, int N ) { @@ -93,18 +93,18 @@ static double benchmark1( int iterations, int N ) { double t; int i; - stdlib_strided_sfill( N, 0.5f, x, 1 ); + stdlib_strided_sfill( N, 1.0f, x, 1 ); stdlib_strided_sfill( N*N, 1.0f, A, 1 ); t = tic(); for ( i = 0; i < iterations; i++ ) { - c_ssyr( CblasRowMajor, CblasUpper, N, 1.0, x, 1, A, N ); - if ( A[ 0 ] != A[ 0 ] ) { + c_ssyr( CblasRowMajor, CblasUpper, N, 1.0f, x, 1, A, N ); + if ( A[ i%(N*2) ] != A[ i%(N*2) ] ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( A[ 0 ] != A[ 0 ] ) { + if ( A[ i%(N*2) ] != A[ i%(N*2) ] ) { printf( "should not return NaN\n" ); } return elapsed; @@ -114,7 +114,7 @@ static double benchmark1( int iterations, int N ) { * Runs a benchmark. * * @param iterations number of iterations -* @param N number of elements along each dimension +* @param N array dimension size * @return elapsed time in seconds */ static double benchmark2( int iterations, int N ) { @@ -124,18 +124,18 @@ static double benchmark2( int iterations, int N ) { double t; int i; - stdlib_strided_sfill( N, 0.5f, x, 1 ); + stdlib_strided_sfill( N, 1.0f, x, 1 ); stdlib_strided_sfill( N*N, 1.0f, A, 1 ); t = tic(); for ( i = 0; i < iterations; i++ ) { - c_ssyr_ndarray( CblasUpper, N, 1.0, x, 1, 0, A, N, 1, 0 ); - if ( A[ 0 ] != A[ 0 ] ) { + c_ssyr_ndarray( CblasUpper, N, 1.0f, x, 1, 0, A, N, 1, 0 ); + if ( A[ i%(N*2) ] != A[ i%(N*2) ] ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( A[ 0 ] != A[ 0 ] ) { + if ( A[ i%(N*2) ] != A[ i%(N*2) ] ) { printf( "should not return NaN\n" ); } return elapsed; diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ssyr/docs/repl.txt index 2e2dd549e30b..20e6c104383f 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/ssyr/docs/repl.txt @@ -46,10 +46,24 @@ Examples -------- + // Standard usage: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] ); - > var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 0.0, 2.0 ] ); + > var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 2.0, 1.0 ] ); > {{alias}}( 'row-major', 'upper', 2, 1.0, x, 1, A, 2 ) - [ 2.0, 3.0, 0.0, 3.0 ] + [ 2.0, 3.0, 2.0, 2.0 ] + + // Advanced indexing: + > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] ); + > var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 2.0, 1.0 ] ); + > {{alias}}( 'row-major', 'upper', 2, 1.0, x, -1, A, 2 ) + [ 2.0, 3.0, 2.0, 2.0 ] + + // Using typed array views: + > var x0 = new {{alias:@stdlib/array/float32}}( [ 0.0, 1.0, 1.0 ] ); + > A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 2.0, 1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 'row-major', 'upper', 2, 1.0, x, 1, A, 2 ) + [ 2.0, 3.0, 2.0, 2.0 ] {{alias}}.ndarray( uplo, N, α, x, sx, ox, A, sa1, sa2, oa ) @@ -102,9 +116,9 @@ Examples -------- > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] ); - > var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 0.0, 2.0 ] ); + > var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 2.0, 1.0 ] ); > {{alias}}.ndarray( 'upper', 2, 1.0, x, 1, 0, A, 2, 1, 0 ) - [ 2.0, 3.0, 0.0, 3.0 ] + [ 2.0, 3.0, 2.0, 2.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ssyr/docs/types/index.d.ts index ecd8c9b1e93c..6606508d807f 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/ssyr/docs/types/index.d.ts @@ -42,16 +42,16 @@ interface Routine { * @example * var Float32Array = require( '@stdlib/array/float32' ); * - * var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] + * var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * * ssyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 ); - * // A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] + * // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] */ ( order: Layout, uplo: MatrixTriangle, N: number, alpha: number, x: Float32Array, strideX: number, A: Float32Array, LDA: number ): Float32Array; /** - * Performs the symmetric rank 1 operation `A = α*x*x^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. + * Performs the symmetric rank 1 operation `A = α*x*x^T + A` using alternative indexing semantics and where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. * * @param uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced * @param N - number of elements along each dimension in the matrix `A` @@ -68,11 +68,11 @@ interface Routine { * @example * var Float32Array = require( '@stdlib/array/float32' ); * - * var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] + * var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * * ssyr.ndarray( 'upper', 3, 1.0, x, 1, 0, A, 3, 1, 0 ); - * // A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] + * // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] */ ndarray( uplo: MatrixTriangle, N: number, alpha: number, x: Float32Array, strideX: number, offsetX: number, A: Float32Array, strideA1: number, strideA2: number, offsetA: number ): Float32Array; } @@ -93,20 +93,20 @@ interface Routine { * @example * var Float32Array = require( '@stdlib/array/float32' ); * -* var A = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 2.0, 2.0, 0.0, 0.0, 3.0 ] ); +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * -* ssyr( 'column-major', 'lower', 3, 2.0, x, 1, A, 3 ); -* // y => [ 3.0, 5.0, 7.0, 0.0, 10.0, 14.0, 0.0, 0.0, 21.0 ] +* ssyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 ); +* // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] * * @example * var Float32Array = require( '@stdlib/array/float32' ); * -* var A = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 2.0, 2.0, 0.0, 0.0, 3.0 ] ); +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * -* ssyr.ndarray( 'lower', 3, 2.0, x, 1, 0, A, 3, 1, 0 ); -* // y => [ 3.0, 5.0, 7.0, 0.0, 10.0, 14.0, 0.0, 0.0, 21.0 ] +* ssyr.ndarray( 'upper', 3, 1.0, x, 1, 0, A, 3, 1, 0 ); +* // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] */ declare var ssyr: Routine; diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/ssyr/examples/c/example.c index 79fd505af706..74b8e35f5b88 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/ssyr/examples/c/example.c @@ -21,26 +21,38 @@ #include int main( void ) { - // Create strided arrays: - float A[] = { 1.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f, 3.0f, 2.0f, 1.0f }; - const float x[] = { 1.0f, 2.0f, 3.0f }; + // Define 3x3 symmetric matrices stored in row-major layout: + float A1[ 3*3 ] = { + 1.0f, 2.0f, 3.0f, + 2.0f, 1.0f, 2.0f, + 3.0f, 2.0f, 1.0f + }; - // Specify the number of elements along each dimension of `A`: + float A2[ 3*3 ] = { + 1.0f, 2.0f, 3.0f, + 2.0f, 1.0f, 2.0f, + 3.0f, 2.0f, 1.0f + }; + + // Define a vector: + const float x[ 3 ] = { 1.0f, 2.0f, 3.0f }; + + // Specify the number of elements along each dimension of `A1` and `A2`: const int N = 3; // Perform the symmetric rank 1 operation `A = α*x*x^T + A`: - c_ssyr( CblasColMajor, CblasUpper, N, 1.0f, x, 1, A, N ); + c_ssyr( CblasColMajor, CblasUpper, N, 1.0f, x, 1, A1, N ); // Print the result: for ( int i = 0; i < N*N; i++ ) { - printf( "A[ %i ] = %f\n", i, A[ i ] ); + printf( "A1[ %i ] = %f\n", i, A1[ i ] ); } - // Perform the symmetric rank 1 operation `A = α*x*x^T + A`: - c_ssyr_ndarray( CblasUpper, N, 1.0f, x, 1, 0, A, N, 1, 0 ); + // Perform the symmetric rank 1 operation `A = α*x*x^T + A` using alternative indexing semantics: + c_ssyr_ndarray( CblasUpper, N, 1.0f, x, 1, 0, A2, N, 1, 0 ); // Print the result: for ( int i = 0; i < N*N; i++ ) { - printf( "A[ %i ] = %f\n", i, A[ i ] ); + printf( "A2[ %i ] = %f\n", i, A2[ i ] ); } } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/examples/index.js b/lib/node_modules/@stdlib/blas/base/ssyr/examples/index.js index adca419f4049..68923b310abc 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/examples/index.js @@ -28,8 +28,15 @@ var opts = { var N = 3; -var A = ones( N*N, opts.dtype ); +// Create N-by-N symmetric matrices: +var A1 = ones( N*N, opts.dtype ); +var A2 = ones( N*N, opts.dtype ); + +// Create a random vector: var x = discreteUniform( N, -10.0, 10.0, opts ); -ssyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 ); -console.log( A ); +ssyr( 'row-major', 'upper', 3, 1.0, x, 1, A1, 3 ); +console.log( A1 ); + +ssyr.ndarray( 'upper', 3, 1.0, x, 1, 0, A2, 3, 1, 0 ); +console.log( A2 ); diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/include/stdlib/blas/base/ssyr.h b/lib/node_modules/@stdlib/blas/base/ssyr/include/stdlib/blas/base/ssyr.h index 5bfd9ba29ddc..81aa3ad0237a 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/include/stdlib/blas/base/ssyr.h +++ b/lib/node_modules/@stdlib/blas/base/ssyr/include/stdlib/blas/base/ssyr.h @@ -32,12 +32,12 @@ extern "C" { #endif /** -* Performs the symmetric rank 1 operation `A = α*x*x^T + A`. +* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. */ -void API_SUFFIX(c_ssyr)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ); +void API_SUFFIX(c_ssyr)( const CBLAS_LAYOUT layout, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ); /** -* Performs the symmetric rank 1 operation `A = α*x*x^T + A` using alternative indexing semantics. +* Performs the symmetric rank 1 operation `A = α*x*x^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. */ void API_SUFFIX(c_ssyr_ndarray)( const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA ); diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/include/stdlib/blas/base/ssyr_cblas.h b/lib/node_modules/@stdlib/blas/base/ssyr/include/stdlib/blas/base/ssyr_cblas.h index 7a4cc560e204..cf984264e617 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/include/stdlib/blas/base/ssyr_cblas.h +++ b/lib/node_modules/@stdlib/blas/base/ssyr/include/stdlib/blas/base/ssyr_cblas.h @@ -32,9 +32,9 @@ extern "C" { #endif /** -* Performs the symmetric rank 1 operation `A = α*x*x^T + A`. +* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. */ -void API_SUFFIX(cblas_ssyr)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ); +void API_SUFFIX(cblas_ssyr)( const CBLAS_LAYOUT layout, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/lib/base.js b/lib/node_modules/@stdlib/blas/base/ssyr/lib/base.js index f485e02b04a2..b495c70b0014 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/lib/base.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/lib/base.js @@ -21,7 +21,6 @@ // MODULES // var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); -var f32 = require( '@stdlib/number/float64/base/to-float32' ); // MAIN // @@ -32,7 +31,7 @@ var f32 = require( '@stdlib/number/float64/base/to-float32' ); * @private * @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced * @param {NonNegativeInteger} N - number of elements along each dimension of `A` -* @param {number} alpha - scalar +* @param {number} alpha - scalar constant * @param {Float32Array} x - input vector * @param {integer} strideX - `x` stride length * @param {NonNegativeInteger} offsetX - starting index for `x` @@ -45,11 +44,11 @@ var f32 = require( '@stdlib/number/float64/base/to-float32' ); * @example * var Float32Array = require( '@stdlib/array/float32' ); * -* var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * * ssyr( 'upper', 3, 1.0, x, 1, 0, A, 3, 1, 0 ); -* // A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] +* // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] */ function ssyr( uplo, N, alpha, x, strideX, offsetX, A, strideA1, strideA2, offsetA ) { // eslint-disable-line max-len var isrm; @@ -60,7 +59,7 @@ function ssyr( uplo, N, alpha, x, strideX, offsetX, A, strideA1, strideA2, offse var sa1; var i0; var i1; - var oa; + var ia; var ox; isrm = isRowMajor( [ strideA1, strideA2 ] ); @@ -75,18 +74,19 @@ function ssyr( uplo, N, alpha, x, strideX, offsetX, A, strideA1, strideA2, offse } ox = offsetX; if ( - ( isrm && uplo === 'lower' ) || - ( !isrm && uplo === 'upper' ) + ( !isrm && uplo === 'upper' ) || + ( isrm && uplo === 'lower' ) ) { ix1 = ox; for ( i1 = 0; i1 < N; i1++ ) { if ( x[ ix1 ] !== 0.0 ) { - tmp = f32( alpha * x[ ix1 ] ); - oa = offsetA + (sa1*i1); + tmp = alpha * x[ ix1 ]; + ia = offsetA + (sa1*i1); ix0 = ox; for ( i0 = 0; i0 <= i1; i0++ ) { - A[ oa+(sa0*i0) ] += f32( x[ ix0 ] * tmp ); + A[ ia ] += x[ ix0 ] * tmp; ix0 += strideX; + ia += sa0; } } ix1 += strideX; @@ -97,12 +97,13 @@ function ssyr( uplo, N, alpha, x, strideX, offsetX, A, strideA1, strideA2, offse ix1 = ox; for ( i1 = 0; i1 < N; i1++ ) { if ( x[ ix1 ] !== 0.0 ) { - tmp = f32( alpha * x[ ix1 ] ); - oa = offsetA + (sa1*i1); + tmp = alpha * x[ ix1 ]; + ia = offsetA + (sa1*i1) + (sa0*i1); ix0 = ix1; for ( i0 = i1; i0 < N; i0++ ) { - A[ oa+(sa0*i0) ] += f32( x[ ix0 ] * tmp ); + A[ ia ] += x[ ix0 ] * tmp; ix0 += strideX; + ia += sa0; } } ix1 += strideX; diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/lib/index.js b/lib/node_modules/@stdlib/blas/base/ssyr/lib/index.js index 96880f9d49a6..96a36f1c3cae 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/lib/index.js @@ -37,11 +37,11 @@ * var Float32Array = require( '@stdlib/array/float32' ); * var ssyr = require( '@stdlib/blas/base/ssyr' ); * -* var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * * ssyr.ndarray( 'upper', 3, 1.0, x, 1, 0, A, 3, 1, 0 ); -* // A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] +* // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.js index 5fd020560ee8..80b84bc65b05 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.js @@ -32,7 +32,7 @@ var base = require( './base.js' ); * * @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced * @param {NonNegativeInteger} N - number of elements along each dimension of `A` -* @param {number} alpha - scalar +* @param {number} alpha - scalar constant * @param {Float32Array} x - input vector * @param {integer} strideX - `x` stride length * @param {NonNegativeInteger} offsetX - starting index for `x` @@ -43,16 +43,18 @@ var base = require( './base.js' ); * @throws {TypeError} first argument must specify whether to reference the lower or upper triangular matrix * @throws {RangeError} second argument must be a nonnegative integer * @throws {RangeError} fifth argument must be non-zero +* @throws {RangeError} eighth argument must be non-zero +* @throws {RangeError} ninth argument must be non-zero * @returns {Float32Array} `A` * * @example * var Float32Array = require( '@stdlib/array/float32' ); * -* var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * * ssyr( 'upper', 3, 1.0, x, 1, 0, A, 3, 1, 0 ); -* // A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] +* // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] */ function ssyr( uplo, N, alpha, x, strideX, offsetX, A, strideA1, strideA2, offsetA ) { // eslint-disable-line max-len if ( !isMatrixTriangle( uplo ) ) { @@ -70,6 +72,7 @@ function ssyr( uplo, N, alpha, x, strideX, offsetX, A, strideA1, strideA2, offse if ( strideA2 === 0 ) { throw new RangeError( format( 'invalid argument. Ninth argument must be non-zero. Value: `%d`.', strideA2 ) ); } + // Check if we can early return... if ( N === 0 || alpha === 0.0 ) { return A; } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.native.js index 9c27a57d15d3..1ebf5befe2d2 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ndarray.native.js @@ -20,7 +20,9 @@ // MODULES // +var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' ); var resolveUplo = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +var format = require( '@stdlib/string/format' ); var addon = require( './../src/addon.node' ); @@ -31,7 +33,7 @@ var addon = require( './../src/addon.node' ); * * @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced * @param {NonNegativeInteger} N - number of elements along each dimension of `A` -* @param {number} alpha - scalar +* @param {number} alpha - scalar constant * @param {Float32Array} x - input vector * @param {integer} strideX - `x` stride length * @param {NonNegativeInteger} offsetX - starting index for `x` @@ -39,18 +41,42 @@ var addon = require( './../src/addon.node' ); * @param {integer} strideA1 - stride of the first dimension of `A` * @param {integer} strideA2 - stride of the second dimension of `A` * @param {NonNegativeInteger} offsetA - starting index for `A` +* @throws {TypeError} first argument must specify whether to reference the lower or upper triangular matrix +* @throws {RangeError} second argument must be a nonnegative integer +* @throws {RangeError} fifth argument must be non-zero +* @throws {RangeError} eighth argument must be non-zero +* @throws {RangeError} ninth argument must be non-zero * @returns {Float32Array} `A` * * @example * var Float32Array = require( '@stdlib/array/float32' ); * -* var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * * ssyr( 'upper', 3, 1.0, x, 1, 0, A, 3, 1, 0 ); -* // A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] +* // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] */ function ssyr( uplo, N, alpha, x, strideX, offsetX, A, strideA1, strideA2, offsetA ) { // eslint-disable-line max-len + if ( !isMatrixTriangle( uplo ) ) { + throw new TypeError( format( 'invalid argument. First argument must specify whether to reference the lower or upper triangular matrix. Value: `%s`.', uplo ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Fifth argument must be non-zero. Value: `%d`.', strideX ) ); + } + if ( strideA1 === 0 ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be non-zero. Value: `%d`.', strideA1 ) ); + } + if ( strideA2 === 0 ) { + throw new RangeError( format( 'invalid argument. Ninth argument must be non-zero. Value: `%d`.', strideA2 ) ); + } + // Check if we can early return... + if ( N === 0 || alpha === 0.0 ) { + return A; + } addon.ndarray( resolveUplo( uplo ), N, alpha, x, strideX, offsetX, A, strideA1, strideA2, offsetA ); // eslint-disable-line max-len return A; } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ssyr.js b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ssyr.js index ec78aebbac2d..f10d3974de3d 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ssyr.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ssyr.js @@ -37,7 +37,7 @@ var base = require( './base.js' ); * @param {string} order - storage layout * @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced * @param {NonNegativeInteger} N - number of elements along each dimension of `A` -* @param {number} alpha - scalar +* @param {number} alpha - scalar constant * @param {Float32Array} x - input vector * @param {integer} strideX - `x` stride length * @param {Float32Array} A - input matrix @@ -52,11 +52,11 @@ var base = require( './base.js' ); * @example * var Float32Array = require( '@stdlib/array/float32' ); * -* var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * * ssyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 ); -* // A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] +* // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] */ function ssyr( order, uplo, N, alpha, x, strideX, A, LDA ) { var sa1; @@ -78,6 +78,7 @@ function ssyr( order, uplo, N, alpha, x, strideX, A, LDA ) { if ( LDA < max( 1, N ) ) { throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, LDA ) ); } + // Check if we can early return... if ( N === 0 || alpha === 0.0 ) { return A; } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ssyr.native.js b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ssyr.native.js index 48d68d82e4e2..79b0cd96aadb 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/lib/ssyr.native.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/lib/ssyr.native.js @@ -20,8 +20,12 @@ // MODULES // +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isMatrixTriangle = require( '@stdlib/blas/base/assert/is-matrix-triangle' ); +var max = require( '@stdlib/math/base/special/fast/max' ); var resolveOrder = require( '@stdlib/blas/base/layout-resolve-enum' ); var resolveUplo = require( '@stdlib/blas/base/matrix-triangle-resolve-enum' ); +var format = require( '@stdlib/string/format' ); var addon = require( './../src/addon.node' ); @@ -33,23 +37,47 @@ var addon = require( './../src/addon.node' ); * @param {string} order - storage layout * @param {string} uplo - specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced * @param {NonNegativeInteger} N - number of elements along each dimension of `A` -* @param {number} alpha - scalar +* @param {number} alpha - scalar constant * @param {Float32Array} x - input vector * @param {integer} strideX - `x` stride length * @param {Float32Array} A - input matrix * @param {integer} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @throws {TypeError} first argument must be a valid order +* @throws {TypeError} second argument must specify whether to reference the lower or upper triangular matrix +* @throws {RangeError} third argument must be a nonnegative integer +* @throws {RangeError} sixth argument must be non-zero +* @throws {RangeError} eighth argument must be greater than or equal to max(1,N) * @returns {Float32Array} `A` * * @example * var Float32Array = require( '@stdlib/array/float32' ); * -* var A = new Float32Array( [ 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 0.0, 1.0, 2.0 ], [ 0.0, 0.0, 1.0 ] ] +* var A = new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ); // => [ [ 1.0, 2.0, 3.0 ], [ 2.0, 1.0, 2.0 ], [ 3.0, 2.0, 1.0 ] ] * var x = new Float32Array( [ 1.0, 2.0, 3.0 ] ); * * ssyr( 'row-major', 'upper', 3, 1.0, x, 1, A, 3 ); -* // A => [ 2.0, 4.0, 6.0, 0.0, 5.0, 8.0, 0.0, 0.0, 10.0 ] +* // A => [ 2.0, 4.0, 6.0, 2.0, 5.0, 8.0, 3.0, 2.0, 10.0 ] */ function ssyr( order, uplo, N, alpha, x, strideX, A, LDA ) { + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( !isMatrixTriangle( uplo ) ) { + throw new TypeError( format( 'invalid argument. Second argument must specify whether to reference the lower or upper triangular matrix. Value: `%s`.', uplo ) ); + } + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + if ( strideX === 0 ) { + throw new RangeError( format( 'invalid argument. Sixth argument must be non-zero. Value: `%d`.', strideX ) ); + } + if ( LDA < max( 1, N ) ) { + throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.', N, LDA ) ); + } + // Check if we can early return... + if ( N === 0 || alpha === 0.0 ) { + return A; + } addon( resolveOrder( order ), resolveUplo( uplo ), N, alpha, x, strideX, A, LDA ); // eslint-disable-line max-len return A; } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/manifest.json b/lib/node_modules/@stdlib/blas/base/ssyr/manifest.json index 82ff44ce9dc7..637646eb1cec 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/ssyr/manifest.json @@ -30,11 +30,84 @@ "confs": [ { "task": "build", - "os": "win", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/ssyr.c", + "./src/ssyr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-float", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/argv-strided-float32array2d" + ] + }, + { + "task": "benchmark", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/ssyr.c", + "./src/ssyr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/blas/ext/base/sfill" + ] + }, + { + "task": "examples", + "os": "linux", + "blas": "", + "wasm": false, + "src": [ + "./src/ssyr.c", + "./src/ssyr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "linux", "blas": "openblas", "wasm": false, "src": [ - "./src/ssyr_cblas.c" + "./src/ssyr_cblas.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -46,22 +119,26 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-strided-float32array2d", - "@stdlib/napi/argv-float" + "@stdlib/napi/argv-strided-float32array2d" ] }, { "task": "benchmark", - "os": "win", + "os": "linux", "blas": "openblas", "wasm": false, "src": [ - "./src/ssyr_cblas.c" + "./src/ssyr_cblas.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -72,16 +149,21 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/blas/ext/base/sfill" ] }, { "task": "examples", - "os": "win", + "os": "linux", "blas": "openblas", "wasm": false, "src": [ - "./src/ssyr_cblas.c" + "./src/ssyr_cblas.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -92,7 +174,82 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" + ] + }, + + { + "task": "build", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/ssyr.c", + "./src/ssyr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-float", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/argv-strided-float32array2d" + ] + }, + { + "task": "benchmark", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/ssyr.c", + "./src/ssyr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/blas/ext/base/sfill" + ] + }, + { + "task": "examples", + "os": "mac", + "blas": "", + "wasm": false, + "src": [ + "./src/ssyr.c", + "./src/ssyr_ndarray.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" ] }, @@ -102,7 +259,8 @@ "blas": "apple_accelerate_framework", "wasm": false, "src": [ - "./src/ssyr_cblas.c" + "./src/ssyr_cblas.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -113,13 +271,16 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-strided-float32array2d", - "@stdlib/napi/argv-float" + "@stdlib/napi/argv-strided-float32array2d" ] }, { @@ -128,7 +289,8 @@ "blas": "apple_accelerate_framework", "wasm": false, "src": [ - "./src/ssyr_cblas.c" + "./src/ssyr_cblas.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -138,7 +300,11 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/blas/ext/base/sfill" ] }, { @@ -147,7 +313,8 @@ "blas": "apple_accelerate_framework", "wasm": false, "src": [ - "./src/ssyr_cblas.c" + "./src/ssyr_cblas.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -157,7 +324,10 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" ] }, @@ -167,7 +337,8 @@ "blas": "openblas", "wasm": false, "src": [ - "./src/ssyr_cblas.c" + "./src/ssyr_cblas.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -179,13 +350,16 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-strided-float32array2d", - "@stdlib/napi/argv-float" + "@stdlib/napi/argv-strided-float32array2d" ] }, { @@ -194,7 +368,8 @@ "blas": "openblas", "wasm": false, "src": [ - "./src/ssyr_cblas.c" + "./src/ssyr_cblas.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -205,7 +380,11 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/blas/ext/base/sfill" ] }, { @@ -214,7 +393,8 @@ "blas": "openblas", "wasm": false, "src": [ - "./src/ssyr_cblas.c" + "./src/ssyr_cblas.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -225,17 +405,21 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major" ] }, { "task": "build", - "os": "linux", + "os": "win", "blas": "", "wasm": false, "src": [ - "./src/ssyr.c" + "./src/ssyr.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -244,24 +428,26 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", + "@stdlib/strided/base/stride2offset", + "@stdlib/ndarray/base/assert/is-row-major", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-int32", - "@stdlib/napi/argv-strided-float32array", - "@stdlib/napi/argv-strided-float32array2d", "@stdlib/napi/argv-float", - "@stdlib/strided/base/stride2offset", - "@stdlib/ndarray/base/assert/is-row-major" + "@stdlib/napi/argv-strided-float32array", + "@stdlib/napi/argv-strided-float32array2d" ] }, { "task": "benchmark", - "os": "linux", + "os": "win", "blas": "", "wasm": false, "src": [ - "./src/ssyr.c" + "./src/ssyr.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -270,19 +456,20 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", - "@stdlib/blas/ext/base/sfill", - "@stdlib/math/base/special/floorf", + "@stdlib/blas/base/xerbla", "@stdlib/strided/base/stride2offset", - "@stdlib/ndarray/base/assert/is-row-major" + "@stdlib/ndarray/base/assert/is-row-major", + "@stdlib/blas/ext/base/sfill" ] }, { "task": "examples", - "os": "linux", + "os": "win", "blas": "", "wasm": false, "src": [ - "./src/ssyr.c" + "./src/ssyr.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -291,6 +478,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", "@stdlib/strided/base/stride2offset", "@stdlib/ndarray/base/assert/is-row-major" ] @@ -302,7 +490,8 @@ "blas": "", "wasm": true, "src": [ - "./src/ssyr.c" + "./src/ssyr.c", + "./src/ssyr_ndarray.c" ], "include": [ "./include" @@ -311,6 +500,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/blas/base/xerbla", "@stdlib/strided/base/stride2offset", "@stdlib/ndarray/base/assert/is-row-major" ] diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/src/addon.c b/lib/node_modules/@stdlib/blas/base/ssyr/src/addon.c index 558db6a0786e..d891de8b0a00 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/ssyr/src/addon.c @@ -35,9 +35,12 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { + CBLAS_INT sa1; + CBLAS_INT sa2; + STDLIB_NAPI_ARGV( env, info, argv, argc, 8 ); - STDLIB_NAPI_ARGV_INT32( env, order, argv, 0 ); + STDLIB_NAPI_ARGV_INT32( env, layout, argv, 0 ); STDLIB_NAPI_ARGV_INT32( env, uplo, argv, 1 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 2 ); @@ -46,10 +49,17 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 3 ); + if ( layout == CblasColMajor ) { + sa1 = 1; + sa2 = LDA; + } else { // layout == CblasRowMajor + sa1 = LDA; + sa2 = 1; + } STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 4 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, A, ((N-1)*LDA) + N, 1, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY2D( env, A, N, N, sa1, sa2, argv, 6 ); - API_SUFFIX(c_ssyr)( order, uplo, N, alpha, X, strideX, A, LDA ); + API_SUFFIX(c_ssyr)( layout, uplo, N, alpha, X, strideX, A, LDA ); return NULL; } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr.c b/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr.c index 74929aabfcfc..9c5a043f47e7 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr.c +++ b/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr.c @@ -18,114 +18,66 @@ #include "stdlib/blas/base/ssyr.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/blas/base/xerbla.h" #include "stdlib/strided/base/stride2offset.h" -#include "stdlib/ndarray/base/assert/is_row_major.h" /** -* Performs the symmetric rank 1 operation `A = α*x*x^T + A`. +* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. * -* @param order storage layout +* @param layout storage layout * @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced * @param N number of elements along each dimension of `A` -* @param alpha scalar +* @param alpha scalar constant * @param X input vector * @param strideX `X` stride length * @param A input matrix * @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) */ -void API_SUFFIX(c_ssyr)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ) { +void API_SUFFIX(c_ssyr)( const CBLAS_LAYOUT layout, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ) { + CBLAS_INT vala; CBLAS_INT sa1; CBLAS_INT sa2; CBLAS_INT ox; - if ( N == 0 || alpha == 0.0f ) { + // Perform input argument validation... + if ( layout != CblasRowMajor && layout != CblasColMajor ) { + c_xerbla( 1, "c_ssyr", "Error: invalid argument. First argument must be a valid layout. Value: `%d`.", layout ); return; } - if ( order == CblasColMajor ) { - sa1 = 1; - sa2 = LDA; - } else { // order == 'row-major' - sa1 = LDA; - sa2 = 1; + if ( uplo != CblasLower && uplo != CblasUpper ) { + c_xerbla( 2, "c_ssyr", "Error: invalid argument. Second argument must specify whether to reference the lower or upper triangular matrix. Value: `%d`.", uplo ); + return; } - ox = STDLIB_BLAS_BASE_STRIDE2OFFSET( N, strideX ); - API_SUFFIX(c_ssyr_ndarray)( uplo, N, alpha, X, strideX, ox, A, sa1, sa2, 0 ); - return; -} - -/** -* Performs the symmetric rank 1 operation `A = α*x*x^T + A` using alternative indexing semantics. -* -* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced -* @param N number of elements along each dimension of `A` -* @param alpha scalar -* @param X input vector -* @param strideX `X` stride length -* @param offsetX starting index of `X` -* @param A input matrix -* @param strideA1 stride of the first dimension of `A` -* @param strideA2 stride of the second dimension of `A` -* @param offsetA starting index of `A` -*/ -void API_SUFFIX(c_ssyr_ndarray)( const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA ) { - CBLAS_INT isrm; - CBLAS_INT ix0; - CBLAS_INT ix1; - CBLAS_INT sa0; - CBLAS_INT sa1; - CBLAS_INT i0; - CBLAS_INT i1; - CBLAS_INT oa; - CBLAS_INT ox; - float tmp; - - int64_t strides[] = { strideA1, strideA2 }; - if ( N == 0 || alpha == 0.0f ) { + if ( N < 0 ) { + c_xerbla( 3, "c_ssyr", "Error: invalid argument. Third argument must be a nonnegative integer. Value: `%d`.", N ); return; } - isrm = stdlib_ndarray_is_row_major( 2, strides ); - if ( isrm ) { - // For row-major matrices, the last dimension has the fastest changing index... - sa0 = strideA2; // stride for innermost loop - sa1 = strideA1; // stride for outermost loop - } else { // isColMajor - // For column-major matrices, the first dimension has the fastest changing index... - sa0 = strideA1; // stride for innermost loop - sa1 = strideA2; // stride for outermost loop + if ( strideX == 0 ) { + c_xerbla( 6, "c_ssyr", "Error: invalid argument. Sixth argument must be nonzero. Value: `%d`.", strideX ); + return; } - ox = offsetX; - if ( - ( isrm && uplo == CblasLower ) || - ( !isrm && uplo == CblasUpper ) - ) { - ix1 = ox; - for ( i1 = 0; i1 < N; i1++ ) { - if ( X[ ix1 ] != 0.0f ) { - tmp = alpha * X[ ix1 ]; - oa = offsetA + (sa1*i1); - ix0 = ox; - for ( i0 = 0; i0 <= i1; i0++ ) { - A[ oa+(sa0*i0) ] += X[ ix0 ] * tmp; - ix0 += strideX; - } - } - ix1 += strideX; - } + // max(1, N) + if ( N < 1 ) { + vala = 1; + } else { + vala = N; + } + if ( LDA < vala ) { + c_xerbla( 10, "c_ssyr", "Error: invalid argument. Eighth argument must be greater than or equal to max(1,%d). Value: `%d`.", vala, LDA ); return; } - // ( isrm && uplo == 'CblasUpper' ) || ( !isrm && uplo == 'CblasLower' ) - ix1 = ox; - for ( i1 = 0; i1 < N; i1++ ) { - if ( X[ ix1 ] != 0.0f ) { - tmp = alpha * X[ ix1 ]; - oa = offsetA + (sa1*i1); - ix0 = ix1; - for ( i0 = i1; i0 < N; i0++ ) { - A[ oa+(sa0*i0) ] += X[ ix0 ] * tmp; - ix0 += strideX; - } - } - ix1 += strideX; + // Check whether we can avoid computation altogether... + if ( N == 0 || alpha == 0.0f ) { + return; } + if ( layout == CblasColMajor ) { + sa1 = 1; + sa2 = LDA; + } else { // layout == CblasRowMajor + sa1 = LDA; + sa2 = 1; + } + ox = stdlib_strided_stride2offset( N, strideX ); + API_SUFFIX(c_ssyr_ndarray)( uplo, N, alpha, X, strideX, ox, A, sa1, sa2, 0 ); return; } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr_cblas.c b/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr_cblas.c index de11f791c556..ece591d7abcc 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr_cblas.c @@ -21,17 +21,17 @@ #include "stdlib/blas/base/shared.h" /** -* Performs the symmetric rank 1 operation `A = α*x*x^T + A`. +* Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. * -* @param order storage layout +* @param layout storage layout * @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced * @param N number of elements along each dimension of `A` -* @param alpha scalar -* @param x input vector +* @param alpha scalar constant +* @param X input vector * @param strideX `X` stride length * @param A input matrix * @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) */ -void API_SUFFIX(c_ssyr)( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ) { - API_SUFFIX(cblas_ssyr)( order, uplo, N, alpha, X, strideX, A, LDA ); +void API_SUFFIX(c_ssyr)( const CBLAS_LAYOUT layout, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *A, const CBLAS_INT LDA ) { + API_SUFFIX(cblas_ssyr)( layout, uplo, N, alpha, X, strideX, A, LDA ); } diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr_ndarray.c b/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr_ndarray.c new file mode 100644 index 000000000000..730c2d69d120 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ssyr/src/ssyr_ndarray.c @@ -0,0 +1,120 @@ +/** +* @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. +*/ + +#include "stdlib/blas/base/ssyr.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/blas/base/xerbla.h" +#include "stdlib/ndarray/base/assert/is_row_major.h" + +/** +* Performs the symmetric rank 1 operation `A = α*x*x^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix. +* +* @param uplo specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced +* @param N number of elements along each dimension of `A` +* @param alpha scalar constant +* @param X input vector +* @param strideX `X` stride length +* @param offsetX starting index of `X` +* @param A input matrix +* @param strideA1 stride of the first dimension of `A` +* @param strideA2 stride of the second dimension of `A` +* @param offsetA starting index of `A` +*/ +void API_SUFFIX(c_ssyr_ndarray)( const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA ) { + int64_t sa[ 2 ]; + CBLAS_INT isrm; + CBLAS_INT ix0; + CBLAS_INT ix1; + CBLAS_INT sa0; + CBLAS_INT sa1; + CBLAS_INT i0; + CBLAS_INT i1; + CBLAS_INT ia; + CBLAS_INT ox; + float tmp; + + // Note on variable naming convention: sa#, ix#, iy#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Perform input argument validation... + if ( uplo != CblasLower && uplo != CblasUpper ) { + c_xerbla( 1, "c_ssyr_ndarray", "Error: invalid argument. First argument must specify whether to reference the lower or upper triangular matrix. Value: `%d`.", uplo ); + return; + } + if ( N < 0 ) { + c_xerbla( 2, "c_ssyr_ndarray", "Error: invalid argument. Second argument must be a nonnegative integer. Value: `%d`.", N ); + return; + } + if ( strideX == 0 ) { + c_xerbla( 5, "c_ssyr_ndarray", "Error: invalid argument. Fifth argument must be a nonzero. Value: `%d`.", strideX ); + return; + } + // Check whether we can avoid computation altogether... + if ( N == 0 || alpha == 0.0f ) { + return; + } + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + sa[ 0 ] = strideA1; + sa[ 1 ] = strideA2; + isrm = stdlib_ndarray_is_row_major( 2, sa ); + if ( isrm ) { + // For row-major matrices, the last dimension has the fastest changing index... + sa0 = strideA2; // stride for innermost loop + sa1 = strideA1; // stride for outermost loop + } else { // isColMajor + // For column-major matrices, the first dimension has the fastest changing index... + sa0 = strideA1; // stride for innermost loop + sa1 = strideA2; // stride for outermost loop + } + ox = offsetX; + if ( + ( isrm && uplo == CblasLower ) || + ( !isrm && uplo == CblasUpper ) + ) { + ix1 = ox; + for ( i1 = 0; i1 < N; i1++ ) { + if ( X[ ix1 ] != 0.0f ) { + tmp = alpha * X[ ix1 ]; + ia = offsetA + (sa1*i1); + ix0 = ox; + for ( i0 = 0; i0 <= i1; i0++ ) { + A[ ia ] += X[ ix0 ] * tmp; + ix0 += strideX; + ia += sa0; + } + } + ix1 += strideX; + } + return; + } + // ( isrm && uplo == CblasUpper ) || ( !isrm && uplo == CblasLower ) + ix1 = ox; + for ( i1 = 0; i1 < N; i1++ ) { + if ( X[ ix1 ] != 0.0f ) { + tmp = alpha * X[ ix1 ]; + ia = offsetA + (sa1*i1) + (sa0*i1); + ix0 = ix1; + for ( i0 = i1; i0 < N; i0++ ) { + A[ ia ] += X[ ix0 ] * tmp; + ix0 += strideX; + ia += sa0; + } + } + ix1 += strideX; + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ndarray.native.js index 30c45558c698..6343aca76b09 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ndarray.native.js @@ -25,7 +25,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); -var str2enumMatrixTriangle = require( '@stdlib/blas/base/matrix-triangle-str2enum' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -77,6 +76,126 @@ tape( 'the function has an arity of 10', opts, function test( t ) { t.end(); }); +tape( 'the function throws an error if provided an invalid first argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( value, data.N, data.alpha, new Float32Array( data.x ), data.strideX, data.offsetX, new Float32Array( data.A ), data.strideA1, data.strideA2, data.offsetA ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.uplo, value, data.alpha, new Float32Array( data.x ), data.strideX, data.offsetX, new Float32Array( data.A ), data.strideA1, data.strideA2, data.offsetA ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid fifth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.uplo, data.N, data.alpha, new Float32Array( data.x ), value, data.offsetX, new Float32Array( data.A ), data.strideA1, data.strideA2, data.offsetA ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.uplo, data.N, data.alpha, new Float32Array( data.x ), data.strideX, data.offsetX, new Float32Array( data.A ), value, data.strideA2, data.offsetA ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid ninth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.uplo, data.N, data.alpha, new Float32Array( data.x ), data.strideX, data.offsetX, new Float32Array( data.A ), data.strideA1, value, data.offsetA ); + }; + } +}); + tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` (row-major, upper)', opts, function test( t ) { var expected; var data; @@ -91,7 +210,7 @@ tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -112,7 +231,7 @@ tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -133,7 +252,7 @@ tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -154,7 +273,7 @@ tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -172,7 +291,7 @@ tape( 'the function returns a reference to the input matrix `A`', opts, function a = new Float32Array( data.A ); x = new Float32Array( data.x ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.end(); @@ -192,11 +311,11 @@ tape( 'if `N` is zero or the scalar constant is zero, the function returns the i expected = new Float32Array( data.A ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), 0, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, 0, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( a, expected, 'returns expected value' ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, 0.0, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, 0.0, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( a, expected, 'returns expected value' ); @@ -217,11 +336,11 @@ tape( 'if `N` is zero or the scalar constant is zero, the function returns the i expected = new Float32Array( data.A ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), 0, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, 0, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( a, expected, 'returns expected value' ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, 0.0, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, 0.0, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( a, expected, 'returns expected value' ); @@ -242,7 +361,7 @@ tape( 'the function supports specifying the strides of the first and second dime expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -263,7 +382,7 @@ tape( 'the function supports specifying the strides of the first and second dime expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -284,7 +403,7 @@ tape( 'the function supports a negative stride for the first dimension of `A` (r expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -305,7 +424,7 @@ tape( 'the function supports a negative stride for the first dimension of `A` (c expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -326,7 +445,7 @@ tape( 'the function supports a negative stride for the second dimension of `A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -347,7 +466,7 @@ tape( 'the function supports a negative stride for the second dimension of `A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -368,7 +487,7 @@ tape( 'the function supports negative strides for both dimensions of `A` (row-ma expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -389,7 +508,7 @@ tape( 'the function supports negative strides for both dimensions of `A` (column expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -410,7 +529,7 @@ tape( 'the function supports specifying an `A` offset (row-major)', opts, functi expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -431,7 +550,7 @@ tape( 'the function supports specifying an `A` offset (column-major)', opts, fun expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -452,7 +571,7 @@ tape( 'the function supports specifying an `x` stride (row-major)', opts, functi expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -473,7 +592,7 @@ tape( 'the function supports specifying an `x` stride (column-major)', opts, fun expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -494,7 +613,7 @@ tape( 'the function supports specifying a negative `x` stride (row-major)', opts expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -515,7 +634,7 @@ tape( 'the function supports specifying a negative `x` stride (column-major)', o expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -578,7 +697,7 @@ tape( 'the function supports complex access patterns (row-major)', opts, functio expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -599,7 +718,7 @@ tape( 'the function supports complex access patterns (column-major)', opts, func expected = new Float32Array( data.A_out ); - out = ssyr( str2enumMatrixTriangle( data.uplo ), data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); + out = ssyr( data.uplo, data.N, data.alpha, x, data.strideX, data.offsetX, a, data.strideA1, data.strideA2, data.offsetA ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ssyr.native.js b/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ssyr.native.js index 96e34b00e9f5..3337635e8801 100644 --- a/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ssyr.native.js +++ b/lib/node_modules/@stdlib/blas/base/ssyr/test/test.ssyr.native.js @@ -25,8 +25,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); var Float32Array = require( '@stdlib/array/float32' ); -var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' ); -var str2enumLayout = require( '@stdlib/blas/base/layout-str2enum' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -64,6 +62,134 @@ tape( 'the function has an arity of 8', opts, function test( t ) { t.end(); }); +tape( 'the function throws an error if provided an invalid first argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( value, data.uplo, data.N, data.alpha, new Float32Array( data.x ), data.strideX, new Float32Array( data.A ), data.lda ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid second argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.order, value, data.N, data.alpha, new Float32Array( data.x ), data.strideX, new Float32Array( data.A ), data.lda ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid third argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.order, data.uplo, value, data.alpha, new Float32Array( data.x ), data.strideX, new Float32Array( data.A ), data.lda ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid sixth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.order, data.uplo, data.N, data.alpha, new Float32Array( data.x ), value, new Float32Array( data.A ), data.lda ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid eighth argument', opts, function test( t ) { + var values; + var data; + var i; + + data = ru; + + values = [ + 2, + 1, + 0, + -1, + -2, + -3 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + ssyr( data.order, data.uplo, data.N, data.alpha, new Float32Array( data.x ), data.strideX, new Float32Array( data.A ), value ); + }; + } +}); + tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` (row-major, upper)', opts, function test( t ) { var expected; var data; @@ -78,7 +204,7 @@ tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -99,7 +225,7 @@ tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -120,7 +246,7 @@ tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -141,7 +267,7 @@ tape( 'the function performs the symmetric rank 1 operation `A = α*x*x^T + A` ( expected = new Float32Array( data.A_out ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -159,7 +285,7 @@ tape( 'the function returns a reference to the input matrix `A`', opts, function a = new Float32Array( data.A ); x = new Float32Array( data.x ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.end(); @@ -179,11 +305,11 @@ tape( 'if `N` is zero or the scalar constant is zero, the function returns the i expected = new Float32Array( data.A ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), 0, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, 0, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( a, expected, 'returns expected value' ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, 0.0, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, 0.0, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( a, expected, 'returns expected value' ); @@ -204,11 +330,11 @@ tape( 'if `N` is zero or the scalar constant is zero, the function returns the i expected = new Float32Array( data.A ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), 0, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, 0, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( a, expected, 'returns expected value' ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, 0.0, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, 0.0, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( a, expected, 'returns expected value' ); @@ -229,7 +355,7 @@ tape( 'the function supports specifying an `x` stride (row-major)', opts, functi expected = new Float32Array( data.A_out ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -250,7 +376,7 @@ tape( 'the function supports specifying an `x` stride (column-major)', opts, fun expected = new Float32Array( data.A_out ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -271,7 +397,7 @@ tape( 'the function supports specifying a negative `x` stride (row-major)', opts expected = new Float32Array( data.A_out ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); @@ -292,7 +418,7 @@ tape( 'the function supports specifying a negative `x` stride (column-major)', o expected = new Float32Array( data.A_out ); - out = ssyr( str2enumLayout( data.order ), str2enum( data.uplo ), data.N, data.alpha, x, data.strideX, a, data.lda ); + out = ssyr( data.order, data.uplo, data.N, data.alpha, x, data.strideX, a, data.lda ); t.strictEqual( out, a, 'returns expected value' ); t.deepEqual( out, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/object/every-in-by/README.md b/lib/node_modules/@stdlib/object/every-in-by/README.md index e239e2548da0..78a51c36f397 100644 --- a/lib/node_modules/@stdlib/object/every-in-by/README.md +++ b/lib/node_modules/@stdlib/object/every-in-by/README.md @@ -122,6 +122,14 @@ bool = everyInBy( o, isPositive ); @@ -130,6 +138,16 @@ bool = everyInBy( o, isPositive ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/lognormal/pdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/lognormal/pdf/README.md index a2daf53d012c..5b04ba1f912e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/lognormal/pdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/lognormal/pdf/README.md @@ -167,7 +167,7 @@ for ( i = 0; i < 10; i++ ) { #### stdlib_base_dists_lognormal_pdf( x, mu, sigma ) -Evaluates the [probability density function][pdf] (PDF) of a [lognormal][lognormal-distribution] distribution with parameters input value `x`, location parameter `mu` and scale parameter `sigma`. +Evaluates the [probability density function][pdf] (PDF) of a [lognormal][lognormal-distribution] distribution with location parameter `mu` and scale parameter `sigma`. ```c double y = stdlib_base_dists_lognormal_pdf( 2.0, 0.0, 1.0 ); diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/README.md b/lib/node_modules/@stdlib/stats/strided/sztest2/README.md new file mode 100644 index 000000000000..997c4159ab1d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/README.md @@ -0,0 +1,420 @@ + + + + +# sztest2 + +> Compute a two-sample Z-test for two single-precision floating-point strided arrays. + +
+ +A Z-test commonly refers to a two-sample location test which compares the means of two independent sets of measurements `X` and `Y` when the population standard deviations are known. A Z-test supports testing three different null hypotheses `H0`: + +- `H0: μX - μY ≥ Δ` versus the alternative hypothesis `H1: μX - μY < Δ`. +- `H0: μX - μY ≤ Δ` versus the alternative hypothesis `H1: μX - μY > Δ`. +- `H0: μX - μY = Δ` versus the alternative hypothesis `H1: μX - μY ≠ Δ`. + +Here, `μX` and `μY` are the true population means of samples `X` and `Y`, respectively, and `Δ` is the hypothesized difference in means (typically `0` by default). + +
+ + + +
+ +## Usage + +```javascript +var sztest2 = require( '@stdlib/stats/strided/sztest2' ); +``` + +#### sztest2( NX, NY, alternative, alpha, diff, sigmax, x, strideX, sigmay, y, strideY, out ) + +Computes a two-sample Z-test for two single-precision floating-point strided arrays. + +```javascript +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +var y = new Float32Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); + +var results = new Results(); +var out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 2.0, y, 1, results ); +// returns {...} + +var bool = ( out === results ); +// returns true +``` + +The function has the following parameters: + +- **NX**: number of indexed elements in `x`. +- **NY**: number of indexed elements in `y`. +- **alternative**: [alternative hypothesis][@stdlib/stats/base/ztest/alternatives]. +- **alpha**: significance level. +- **diff**: difference in means under the null hypothesis. +- **sigmax**: known standard deviation of `x`. +- **x**: first input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: stride length for `x`. +- **sigmay**: known standard deviation of `y`. +- **y**: second input [`Float32Array`][@stdlib/array/float32]. +- **strideY**: stride length for `y`. +- **out**: output [results object][@stdlib/stats/base/ztest/two-sample/results/float32]. + +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to perform a two-sample Z-test over every other element in `x` and `y`, + +```javascript +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 4.0, 0.0, 4.0, 0.0, 6.0, 0.0, 6.0, 0.0, 5.0, 0.0 ] ); +var y = new Float32Array( [ 3.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0, 7.0, 0.0 ] ); + +var results = new Results(); +var out = sztest2( 5, 5, 'two-sided', 0.05, 0.0, 1.0, x, 2, 2.0, y, 2, results ); +// returns {...} + +var bool = ( out === results ); +// returns true +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var Float32Array = require( '@stdlib/array/float32' ); + +var x0 = new Float32Array( [ 0.0, 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var y0 = new Float32Array( [ 0.0, 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var results = new Results(); +var out = sztest2( 5, 5, 'two-sided', 0.05, 0.0, 1.0, x1, 1, 2.0, y1, 1, results ); +// returns {...} + +var bool = ( out === results ); +// returns true +``` + +#### sztest2.ndarray( NX, NY, alternative, alpha, diff, sigmax, x, strideX, offsetX, sigmay, y, strideY, offsetY, out ) + +Computes a two-sample Z-test for two single-precision floating-point strided arrays using alternative indexing semantics. + +```javascript +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +var y = new Float32Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); + +var results = new Results(); +var out = sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 2.0, y, 1, 0, results ); +// returns {...} + +var bool = ( out === results ); +// returns true +``` + +The function has the following additional parameters: + +- **offsetX**: starting index for `x`. +- **offsetY**: starting index for `y`. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to perform a two-sample Z-test over every other element in `x` and `y` starting from the second element + +```javascript +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var Float32Array = require( '@stdlib/array/float32' ); + +var x = new Float32Array( [ 0.0, 4.0, 0.0, 4.0, 0.0, 6.0, 0.0, 6.0, 0.0, 5.0 ] ); +var y = new Float32Array( [ 0.0, 3.0, 0.0, 3.0, 0.0, 5.0, 0.0, 7.0, 0.0, 7.0 ] ); + +var results = new Results(); +var out = sztest2.ndarray( 5, 5, 'two-sided', 0.05, 0.0, 1.0, x, 2, 1, 2.0, y, 2, 1, results ); +// returns {...} + +var bool = ( out === results ); +// returns true +``` + +
+ + + +
+ +## Notes + +- As a general rule of thumb, a Z-test is most reliable when `N >= 50`. For smaller sample sizes or when the standard deviations are unknown, prefer a t-test. + +
+ + + +
+ +## Examples + + + +```javascript +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var normal = require( '@stdlib/random/array/normal' ); +var sztest2 = require( '@stdlib/stats/strided/sztest2' ); + +var x = normal( 1000, 4.0, 2.0, { + 'dtype': 'float32' +}); +var y = normal( 800, 3.0, 2.0, { + 'dtype': 'float32' +}); + +var results = new Results(); +var out = sztest2( x.length, y.length, 'two-sided', 0.05, 1.0, 2.0, x, 1, 2.0, y, 1, results ); +// returns {...} + +console.log( out.toString() ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/strided/sztest2.h" +``` + +#### stdlib_strided_sztest2( NX, NY, alternative, alpha, diff, sigmax, \*X, strideX, sigmay, \*Y, strideY, \*results ) + +Computes a two-sample Z-test for two single-precision floating-point strided arrays. + +```c +#include "stdlib/stats/base/ztest/two-sample/results/float32.h" +#include "stdlib/stats/base/ztest/alternatives.h" + +struct stdlib_stats_ztest_two_sample_float32_results results = { + .rejected = false, + .alpha = 0.0f, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0f, + .statistic = 0.0f, + .ci = { 0.0f, 0.0f }, + .nullValue = 0.0f, + .xmean = 0.0f, + .ymean = 0.0f +}; + +const float x[] = { 4.0f, 4.0f, 6.0f, 6.0f, 5.0f }; +const float y[] = { 3.0f, 3.0f, 5.0f, 7.0f, 7.0f }; + +stdlib_strided_sztest2( 5, 5, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05f, 0.0f, 1.0f, x, 1, 2.0f, y, 1, &results ); +``` + +The function accepts the following arguments: + +- **NX**: `[in] CBLAS_INT` number of indexed elements in `x`. +- **NY**: `[in] CBLAS_INT` number of indexed elements in `y`. +- **alternative**: `[in] enum STDLIB_STATS_ZTEST_ALTERNATIVE` [alternative hypothesis][@stdlib/stats/base/ztest/alternatives]. +- **alpha**: `[in] float` significance level. +- **diff**: `[in] float` difference in means under the null hypothesis. +- **sigmax** `[in] float` known standard deviation of `x`. +- **X**: `[in] float*` first input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **sigmay** `[in] float` known standard deviation of `y`. +- **Y**: `[in] float*` second input [`Float32Array`][@stdlib/array/float32]. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. +- **results**: `[out] struct stdlib_stats_ztest_two_sample_results_float32*` output [results object][@stdlib/stats/base/ztest/two-sample/results/float32]. + +```c +void stdlib_strided_sztest2( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const float alpha, const float diff, const float sigmax, const float *X, const CBLAS_INT strideX, const float sigmay, const float *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float32_results *results ); +``` + +#### stdlib_strided_sztest2_ndarray( NX, NY, alternative, alpha, diff, sigmax, \*X, strideX, offsetX, sigmay, \*Y, strideY, offsetY, \*results ) + +Computes a two-sample Z-test for two single-precision floating-point strided arrays using alternative indexing semantics. + +```c +#include "stdlib/stats/base/ztest/two-sample/results/float32.h" +#include "stdlib/stats/base/ztest/alternatives.h" + +struct stdlib_stats_ztest_two_sample_float32_results results = { + .rejected = false, + .alpha = 0.0f, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0f, + .statistic = 0.0f, + .ci = { 0.0f, 0.0f }, + .nullValue = 0.0f, + .xmean = 0.0f, + .ymean = 0.0f +}; + +const float x[] = { 4.0f, 4.0f, 6.0f, 6.0f, 5.0f }; +const float y[] = { 3.0f, 3.0f, 5.0f, 7.0f, 7.0f }; + +stdlib_strided_sztest2_ndarray( 5, 5, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05f, 0.0f, 1.0f, x, 1, 0, 2.0f, y, 1, 0, &results ); +``` + +The function accepts the following arguments: + +- **NX**: `[in] CBLAS_INT` number of indexed elements in `x`. +- **NY**: `[in] CBLAS_INT` number of indexed elements in `y`. +- **alternative**: `[in] enum STDLIB_STATS_ZTEST_ALTERNATIVE` [alternative hypothesis][@stdlib/stats/base/ztest/alternatives]. +- **alpha**: `[in] float` significance level. +- **diff**: `[in] float` difference in means under the null hypothesis. +- **sigmax** `[in] float` known standard deviation of `x`. +- **X**: `[in] float*` first input [`Float32Array`][@stdlib/array/float32]. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **sigmay** `[in] float` known standard deviation of `y`. +- **Y**: `[in] float*` second input [`Float32Array`][@stdlib/array/float32]. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. +- **results**: `[out] struct stdlib_stats_ztest_two_sample_results_float32*` output [results object][@stdlib/stats/base/ztest/two-sample/results/float32]. + +```c +void stdlib_strided_sztest2_ndarray( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const float alpha, const float diff, const float sigmax, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float sigmay, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float32_results *results ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/strided/sztest2.h" +#include "stdlib/stats/base/ztest/two-sample/results/float32.h" +#include "stdlib/stats/base/ztest/alternatives.h" +#include +#include + +int main( void ) { + // Create a strided arrays: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + const float y[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int NX = 4; + const int NY = 4; + + // Specify the stride lengths: + const int strideX = 2; + const int strideY = 2; + + // Initialize a results object: + struct stdlib_stats_ztest_two_sample_float32_results results = { + .rejected = false, + .alpha = 0.0f, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0f, + .statistic = 0.0f, + .ci = { 0.0f, 0.0f }, + .nullValue = 0.0f, + .xmean = 0.0f, + .ymean = 0.0f + }; + + // Compute a Z-test: + stdlib_strided_sztest2( NX, NY, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05f, 5.0f, 3.0f, x, strideX, 3.0f, y, strideY, &results ); + + // Print the result: + printf( "Statistic: %f\n", results.statistic ); + printf( "Null hypothesis was %s\n", ( results.rejected ) ? "rejected" : "not rejected" ); +} +``` + +
+ + + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.js new file mode 100644 index 000000000000..cc1505e6d740 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.js @@ -0,0 +1,104 @@ +/** +* @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 normal = require( '@stdlib/random/array/normal' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var pkg = require( './../package.json' ).name; +var sztest2 = require( './../lib/sztest2.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var results; + var x; + var y; + + results = new Results(); + x = normal( len, 0.0, 1.0, options ); + y = normal( len, 0.0, 1.0, options ); + + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + if ( isnanf( out.statistic ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( out.statistic ) ) { + 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/strided/sztest2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.native.js new file mode 100644 index 000000000000..068c81a1d812 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.native.js @@ -0,0 +1,109 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var normal = require( '@stdlib/random/array/normal' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var sztest2 = tryRequire( resolve( __dirname, './../lib/sztest2.native.js' ) ); +var opts = { + 'skip': ( sztest2 instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var results; + var x; + var y; + + results = new Results(); + x = normal( len, 0.0, 1.0, options ); + y = normal( len, 0.0, 1.0, options ); + + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + if ( isnanf( out.statistic ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( out.statistic ) ) { + 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+'::native:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..7e2ad87c5cc1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.ndarray.js @@ -0,0 +1,104 @@ +/** +* @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 normal = require( '@stdlib/random/array/normal' ); +var isnanf = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var pkg = require( './../package.json' ).name; +var sztest2 = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var results; + var x; + var y; + + results = new Results(); + x = normal( len, 0.0, 1.0, options ); + y = normal( len, 0.0, 1.0, options ); + + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + if ( isnanf( out.statistic ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( out.statistic ) ) { + 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/strided/sztest2/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..b9b4e95010e3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/benchmark.ndarray.native.js @@ -0,0 +1,109 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var normal = require( '@stdlib/random/array/normal' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var sztest2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( sztest2 instanceof Error ) +}; +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var results; + var x; + var y; + + results = new Results(); + x = normal( len, 0.0, 1.0, options ); + y = normal( len, 0.0, 1.0, options ); + + return benchmark; + + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + if ( isnanf( out.statistic ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( out.statistic ) ) { + 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+'::native:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/c/Makefile new file mode 100644 index 000000000000..cce2c865d7ad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.length.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..40b774a9b9c9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/benchmark/c/benchmark.length.c @@ -0,0 +1,225 @@ +/** +* @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. +*/ + +#include "stdlib/stats/strided/sztest2.h" +#include "stdlib/stats/base/ztest/two-sample/results/float32.h" +#include "stdlib/stats/base/ztest/alternatives.h" +#include +#include +#include +#include +#include + +#define NAME "sztest2" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define MIN 1 +#define MAX 6 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param iterations number of iterations +* @param elapsed elapsed time in seconds +*/ +static void print_results( int iterations, double elapsed ) { + double rate = (double)iterations / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", iterations ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark1( int iterations, int len ) { + double elapsed; + float x[ len ]; + float y[ len ]; + double t; + int i; + + struct stdlib_stats_ztest_two_sample_float32_results results = { + .rejected = false, + .alpha = 0.0f, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0f, + .statistic = 0.0f, + .ci = { 0.0f, 0.0f }, + .nullValue = 0.0f, + .xmean = 0.0f, + .ymean = 0.0f + }; + + for ( i = 0; i < len; i++ ) { + x[ i ] = random_uniform( -5.0f, 5.0f ); + y[ i ] = random_uniform( -5.0f, 5.0f ); + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + stdlib_strided_sztest2( len, len, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05f, 0.0f, 1.0f, x, 1, 1.0f, y, 1, &results ); + if ( results.statistic != results.statistic ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( results.statistic != results.statistic ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len ]; + float y[ len ]; + double t; + int i; + + struct stdlib_stats_ztest_two_sample_float32_results results = { + .rejected = false, + .alpha = 0.0f, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0f, + .statistic = 0.0f, + .ci = { 0.0f, 0.0f }, + .nullValue = 0.0f, + .xmean = 0.0f, + .ymean = 0.0f + }; + + for ( i = 0; i < len; i++ ) { + x[ i ] = random_uniform( -5.0f, 5.0f ); + y[ i ] = random_uniform( -5.0f, 5.0f ); + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + stdlib_strided_sztest2_ndarray( len, len, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05f, 0.0f, 1.0f, x, 1, 0, 1.0f, y, 1, 0, &results ); + if ( results.statistic != results.statistic ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( results.statistic != results.statistic ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int count; + int iter; + int len; + int i; + int j; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + count = 0; + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:len=%d\n", NAME, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + print_summary( count, count ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/binding.gyp b/lib/node_modules/@stdlib/stats/strided/sztest2/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/binding.gyp @@ -0,0 +1,170 @@ +# @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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/docs/repl.txt b/lib/node_modules/@stdlib/stats/strided/sztest2/docs/repl.txt new file mode 100644 index 000000000000..0b1abf715d61 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/docs/repl.txt @@ -0,0 +1,145 @@ + +{{alias}}( NX, NY, alt, alpha, d, sdx, x, sx, sdy, y, sy, out ) + Computes a two-sample Z-test for two single-precision floating-point + strided arrays. + + The `N` and stride parameters determine which elements in the strided + arrays are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + Parameters + ---------- + NX: integer + Number of indexed elements in `x`. + + NY: integer + Number of indexed elements in `y`. + + alternative: string + Alternative hypothesis. Must be one of the following: + + - two-sided: `x` has the same mean as `y`. + - greater: `x` has a larger mean than `y`. + - less: `x` has a smaller mean than `y`. + + alpha: number + Significance level. + + d: number + Difference in means under the null hypothesis. + + sdx: number + Known standard deviation of `x`. + + x: Float32Array + First input array. + + strideX: integer + Stride length for `x`. + + sdy: number + Known standard deviation of `y`. + + y: Float32Array + Second input array. + + strideY: integer + Stride length for `y`. + + out: Object + Output results object. + + Returns + ------- + out: Object + Results object. + + Examples + -------- + > var x = new {{alias:@stdlib/array/float32}}( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); + > var y = new {{alias:@stdlib/array/float32}}( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); + > var NX = x.length; + > var NY = y.length; + > var alt = 'two-sided'; + > var out = new {{alias:@stdlib/stats/base/ztest/two-sample/results/float32}}(); + > var res = {{alias}}( NX, NY, alt, 0.05, 0.0, 1.0, x, 1, 2.0, y, 1, out ); + > res.toString() + + +{{alias}}.ndarray( NX, NY, alt, alpha, d, sdx, x, sx, ox, sdy, y, sy, oy, out ) + Computes a two-sample Z-test for two single-precision floating-point + strided arrays using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + NX: integer + Number of indexed elements in `x`. + + NY: integer + Number of indexed elements in `y`. + + alternative: string + Alternative hypothesis. Must be one of the following: + + - two-sided: `x` has the same mean as `y`. + - greater: `x` has a larger mean than `y`. + - less: `x` has a smaller mean than `y`. + + alpha: number + Significance level. + + d: number + Difference in means under the null hypothesis. + + sdx: number + Known standard deviation of `x`. + + x: Float32Array + First input array. + + strideX: integer + Stride length for `x`. + + offsetX: integer + Starting index for `x`. + + sdy: number + Known standard deviation of `y`. + + y: Float32Array + Second input array. + + strideY: integer + Stride length for `y`. + + offsetY: integer + Starting index for `y`. + + out: Object + Output results object. + + Returns + ------- + out: Object + Results object. + + Examples + -------- + > var x = new {{alias:@stdlib/array/float32}}( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); + > var y = new {{alias:@stdlib/array/float32}}( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); + > var NX = x.length; + > var NY = y.length; + > var alt = 'two-sided'; + > var out = new {{alias:@stdlib/stats/base/ztest/two-sample/results/float32}}(); + > var res = {{alias}}.ndarray( NX, NY, alt, 0.05, 0.0, 1.0, x, 1, 0, 2.0, x, 1, 0, out ); + > res.toString() + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/strided/sztest2/docs/types/index.d.ts new file mode 100644 index 000000000000..baa84592b4ee --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/docs/types/index.d.ts @@ -0,0 +1,243 @@ +/* +* @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 + +/** +* Alternative hypothesis. +*/ +type Alternative = 'two-sided' | 'greater' | 'less'; + +/** +* Interface describing options when serializing a results object to a string. +*/ +interface Options { + /** + * Number of digits to display after decimal points. Default: 4. + */ + digits?: number; + + /** + * Boolean indicating whether to show the test decision. Default: true. + */ + decision?: boolean; +} + +/** +* Serializes a results object as a string. +* +* @returns string representation +*/ +type toString = ( options?: Options ) => string; + +/** +* Serializes a results object as a JSON object. +* +* @returns JSON representation +*/ +type toJSON = () => BaseResults; + +/** +* Interface describing a "base" results object. +*/ +interface BaseResults { + /** + * Boolean indicating whether the null hypothesis was rejected. + */ + rejected: boolean; + + /** + * Alternative hypothesis. + */ + alternative: Alternative; + + /** + * Significance level. + */ + alpha: number; + + /** + * p-value. + */ + pValue: number; + + /** + * Test statistic. + */ + statistic: number; + + /** + * Confidence interval. + */ + ci: Float32Array; + + /** + * Value of the mean under the null hypothesis + */ + nullValue: number; + + /** + * Sample mean of `x`. + */ + xmean: number; + + /** + * Sample mean of `y`. + */ + ymean: number; +} + +/** +* Interface describing a results object. +*/ +interface Results extends BaseResults { + /** + * Serializes results as formatted test output. + */ + toString: toString; + + /** + * Serializes results as JSON. + */ + toJSON: toJSON; +} + +/** +* Interface describing `sztest2`. +*/ +interface Routine { + /** + * Computes a two-sample Z-test for two single-precision floating-point strided arrays. + * + * @param NX - number of indexed elements in `x` + * @param NY - number of indexed elements in `y` + * @param alternative - alternative hypothesis + * @param alpha - significance level + * @param diff - difference in means under the null hypothesis + * @param sigmax - known standard deviation of `x` + * @param x - first input array + * @param strideX - stride length for `x` + * @param sigmay - known standard deviation of `y` + * @param y - second input array + * @param strideY - stride length for `y` + * @param out - output results object + * @returns results object + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); + * + * var x = new Float32Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); + * var y = new Float32Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); + * + * var results = new Results(); + * var out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 2.0, y, 1, results ); + * // returns {...} + * + * var bool = ( out === results ); + * // returns true + */ + ( NX: number, NY: number, alternative: Alternative, alpha: number, diff: number, sigmax: number, x: Float32Array, strideX: number, sigmay: number, y: Float32Array, strideY: number, out: T ): Results; + + /** + * Computes a two-sample Z-test for two single-precision floating-point strided arrays using alternative indexing semantics. + * + * @param NX - number of indexed elements in `x` + * @param NY - number of indexed elements in `y` + * @param alternative - alternative hypothesis + * @param alpha - significance level + * @param diff - difference in means under the null hypothesis + * @param sigmax - known standard deviation of `x` + * @param x - first input array + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` + * @param sigmay - known standard deviation of `y` + * @param y - second input array + * @param strideY - stride length for `y` + * @param offsetY - starting index for `y` + * @param out - output results object + * @returns results object + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); + * + * var x = new Float32Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); + * var y = new Float32Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); + * + * var results = new Results(); + * var out = sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 2.0, y, 1, 0, results ); + * // returns {...} + * + * var bool = ( out === results ); + * // returns true + */ + ndarray( NX: number, NY: number, alternative: Alternative, alpha: number, diff: number, sigmax: number, x: Float32Array, strideX: number, offsetX: number, sigmay: number, y: Float32Array, strideY: number, offsetY: number, out: T ): Results; +} + +/** +* Computes a two-sample Z-test for two single-precision floating-point strided arrays. +* +* @param NX - number of indexed elements in `x` +* @param NY - number of indexed elements in `y` +* @param alternative - alternative hypothesis +* @param alpha - significance level +* @param diff - difference in means under the null hypothesis +* @param sigmax - known standard deviation of `x` +* @param x - first input array +* @param strideX - stride length for `x` +* @param sigmay - known standard deviation of `y` +* @param y - second input array +* @param strideY - stride length for `y` +* @param out - output results object +* @returns results object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +* +* var x = new Float32Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +* var y = new Float32Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +* +* var results = new Results(); +* var out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 2.0, y, 1, results ); +* // returns {...} +* +* var bool = ( out === results ); +* // returns true +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +* +* var x = new Float32Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +* var y = new Float32Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +* +* var results = new Results(); +* var out = sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 2.0, y, 1, 0, results ); +* // returns {...} +* +* var bool = ( out === results ); +* // returns true +*/ +declare var sztest2: Routine; + + +// EXPORTS // + +export = sztest2; diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/docs/types/test.ts b/lib/node_modules/@stdlib/stats/strided/sztest2/docs/types/test.ts new file mode 100644 index 000000000000..0f4e19be50df --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/docs/types/test.ts @@ -0,0 +1,475 @@ +/* +* @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. +*/ + +import Float32Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +import sztest2 = require( './index' ); + + +// TESTS // + +// The function returns a results object... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectType Results + sztest2( x.length, y.length, 'greater', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectType Results + sztest2( x.length, y.length, 'less', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectType Results +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( '10', y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( true, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( false, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( null, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( undefined, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( [], y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( {}, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( ( x: number ): number => x, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, '10', 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, true, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, false, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, null, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, undefined, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, [], 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, {}, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, ( x: number ): number => x, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a valid string... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, '10', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, true, 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, false, 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, null, 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, undefined, 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, [], 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, {}, 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, ( x: number ): number => x, 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', '10', 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', true, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', false, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', null, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', undefined, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', [], 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', {}, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', ( x: number ): number => x, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', 0.05, '10', 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, true, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, false, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, null, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, undefined, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, [], 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, {}, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, ( x: number ): number => x, 1.0, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, '10', x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, true, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, false, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, null, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, undefined, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, [], x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, {}, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, ( x: number ): number => x, x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not an array-like object... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 10, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, '10', 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, true, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, false, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, null, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, undefined, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, {}, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, ( x: number ): number => x, 1, 1.0, y, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, '10', 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, true, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, false, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, null, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, undefined, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, [], 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, {}, 1.0, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, ( x: number ): number => x, 1.0, y, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, '10', y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, true, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, false, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, null, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, undefined, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, [], y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, {}, y, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, ( x: number ): number => x, y, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not an array-like object... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, 10, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, '10', 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, true, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, false, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, null, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, undefined, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, {}, 1, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, ( x: number ): number => x, 1, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventh argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, '10', new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, true, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, false, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, null, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, undefined, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, [], new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, {}, new Float32Results() ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, ( x: number ): number => x, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the function is provided a twelfth argument which is not a results object... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, '10' ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, true ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, false ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, null ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, undefined ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, [] ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, {} ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2(); // $ExpectError + sztest2( x.length ); // $ExpectError + sztest2( x.length, y.length ); // $ExpectError + sztest2( x.length, y.length, 'two-sided' ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05 ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0 ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0 ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1 ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0 ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1 ); // $ExpectError + sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, new Float32Results(), {} ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a results object... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectType Results + sztest2.ndarray( x.length, y.length, 'greater', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectType Results + sztest2.ndarray( x.length, y.length, 'less', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectType Results +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( '10', y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( true, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( false, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( null, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( undefined, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( [], y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( {}, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( ( x: number ): number => x, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, '10', 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, true, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, false, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, null, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, undefined, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, [], 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, {}, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, ( x: number ): number => x, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a valid string... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, '10', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 5, 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, true, 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, false, 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, null, 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, undefined, 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, [], 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, {}, 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, ( x: number ): number => x, 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', '10', 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', true, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', false, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', null, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', undefined, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', [], 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', {}, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', ( x: number ): number => x, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, '10', 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, true, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, false, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, null, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, undefined, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, [], 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, {}, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, ( x: number ): number => x, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, '10', x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, true, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, false, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, null, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, undefined, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, [], x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, {}, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, ( x: number ): number => x, x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not an array-like object... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 10, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, '10', 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, true, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, false, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, null, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, undefined, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, {}, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, ( x: number ): number => x, 1, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, '10', 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, true, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, false, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, null, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, undefined, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, [], 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, {}, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, ( x: number ): number => x, 0, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a ninth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, '10', 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, true, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, false, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, null, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, undefined, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, [], 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, {}, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, ( x: number ): number => x, 1.0, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a tenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, '10', y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, true, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, false, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, null, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, undefined, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, [], y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, {}, y, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, ( x: number ): number => x, y, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eleventh argument which is not an array-like object... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, 10, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, '10', 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, true, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, false, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, null, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, undefined, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, {}, 1, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, ( x: number ): number => x, 1, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a twelfth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, '10', 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, true, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, false, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, null, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, undefined, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, [], 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, {}, 0, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, ( x: number ): number => x, 0, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a thirteenth argument which is not a number... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, '10', new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, true, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, false, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, null, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, undefined, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, [], new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, {}, new Float32Results() ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, ( x: number ): number => x, new Float32Results() ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourteenth argument which is not a results object... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, '10' ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, true ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, false ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, null ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, undefined ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, [] ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, {} ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float32Array( 10 ); + const y = new Float32Array( 10 ); + + sztest2.ndarray(); // $ExpectError + sztest2.ndarray( x.length ); // $ExpectError + sztest2.ndarray( x.length, y.length ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05 ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0 ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0 ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1 ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0 ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0 ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1 ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0 ); // $ExpectError + sztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, new Float32Results(), {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/examples/c/Makefile b/lib/node_modules/@stdlib/stats/strided/sztest2/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/examples/c/example.c b/lib/node_modules/@stdlib/stats/strided/sztest2/examples/c/example.c new file mode 100644 index 000000000000..561c619015e6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/examples/c/example.c @@ -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. +*/ + +#include "stdlib/stats/strided/sztest2.h" +#include "stdlib/stats/base/ztest/two-sample/results/float32.h" +#include "stdlib/stats/base/ztest/alternatives.h" +#include +#include + +int main( void ) { + // Create a strided arrays: + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + const float y[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + + // Specify the number of elements: + const int NX = 4; + const int NY = 4; + + // Specify the stride lengths: + const int strideX = 2; + const int strideY = 2; + + // Initialize a results object: + struct stdlib_stats_ztest_two_sample_float32_results results = { + .rejected = false, + .alpha = 0.0f, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0f, + .statistic = 0.0f, + .ci = { 0.0f, 0.0f }, + .nullValue = 0.0f, + .xmean = 0.0f, + .ymean = 0.0f + }; + + // Compute a Z-test: + stdlib_strided_sztest2( NX, NY, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05f, 5.0f, 3.0f, x, strideX, 3.0f, y, strideY, &results ); + + // Print the result: + printf( "Statistic: %f\n", results.statistic ); + printf( "Null hypothesis was %s\n", ( results.rejected ) ? "rejected" : "not rejected" ); +} diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/examples/index.js b/lib/node_modules/@stdlib/stats/strided/sztest2/examples/index.js new file mode 100644 index 000000000000..1679f81d3ca5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/examples/index.js @@ -0,0 +1,36 @@ +/** +* @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 Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var normal = require( '@stdlib/random/array/normal' ); +var sztest2 = require( './../lib' ); + +var x = normal( 1000, 4.0, 2.0, { + 'dtype': 'float32' +}); +var y = normal( 800, 3.0, 2.0, { + 'dtype': 'float32' +}); + +var results = new Results(); +var out = sztest2( x.length, y.length, 'two-sided', 0.05, 1.0, 2.0, x, 1, 2.0, y, 1, results ); +// returns {...} + +console.log( out.toString() ); diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/include.gypi b/lib/node_modules/@stdlib/stats/strided/sztest2/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/include.gypi @@ -0,0 +1,53 @@ +# @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. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' 1.0 + ) { + WORKSPACE[ 0 ] = NaN; + WORKSPACE[ 1 ] = NaN; + out.rejected = false; + out.alternative = alt; + out.alpha = NaN; + out.pValue = NaN; + out.statistic = NaN; + out.ci = WORKSPACE; + out.nullValue = NaN; + out.xmean = NaN; + out.ymean = NaN; + return out; + } + + // "Cast" input values to single-precision: + alpha = f32( alpha ); + diff = f32( diff ); + sigmax = f32( sigmax ); + sigmay = f32( sigmay ); + + // Compute the standard error of the mean: + xvar = sigmax * sigmax; + yvar = sigmay * sigmay; + stderr = sqrt( ( xvar / NX ) + ( yvar / NY ) ); + + // Compute the arithmetic means of the input arrays: + xmean = smean( NX, x, strideX, offsetX ); + ymean = smean( NY, y, strideY, offsetY ); + + // Compute the test statistic (i.e., the z-score, which is the standardized difference between the sample means of x and y, adjusted by the hypothesized difference, in units of the standard error): + stat = ( xmean - ymean - diff ) / stderr; + + // Compute the p-value and confidence interval... + if ( alt === 'less' ) { + pValue = normalCDF( stat ); + q = normalQuantile( 1.0 - alpha ); + WORKSPACE[ 0 ] = NINF; + WORKSPACE[ 1 ] = diff + ( ( stat + q ) * stderr ); + } else if ( alt === 'greater' ) { + pValue = 1.0 - normalCDF( stat ); + q = normalQuantile( 1.0 - alpha ); + WORKSPACE[ 0 ] = diff + ( ( stat - q ) * stderr ); + WORKSPACE[ 1 ] = PINF; + } else { // alt == 'two-sided' + pValue = 2.0 * normalCDF( -abs( stat ) ); + q = normalQuantile( 1.0 - ( alpha / 2.0 ) ); + WORKSPACE[ 0 ] = diff + ( ( stat - q ) * stderr ); + WORKSPACE[ 1 ] = diff + ( ( stat + q ) * stderr ); + } + // Return test results: + out.rejected = ( pValue <= alpha ); + out.alpha = alpha; + out.pValue = f32( pValue ); + out.statistic = f32( stat ); + out.ci = WORKSPACE; + out.alternative = alt; + out.nullValue = f32( diff ); + out.xmean = xmean; + out.ymean = ymean; + return out; +} + + +// EXPORTS // + +module.exports = sztest2; diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/sztest2/lib/ndarray.native.js new file mode 100644 index 000000000000..085278b15cab --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/lib/ndarray.native.js @@ -0,0 +1,70 @@ +/** +* @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 resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Computes a two-sample Z-test for two single-precision floating-point strided arrays using alternative indexing semantics. +* +* @param {PositiveInteger} NX - number of indexed elements in `x` +* @param {PositiveInteger} NY - number of indexed elements in `y` +* @param {(integer|string)} alternative - alternative hypothesis +* @param {number} alpha - significance level +* @param {number} diff - difference in means under the null hypothesis +* @param {PositiveNumber} sigmax - known standard deviation of `x` +* @param {Float32Array} x - first input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {PositiveNumber} sigmay - known standard deviation of `y` +* @param {Float32Array} y - second input array +* @param {integer} strideY - stride length for `y` +* @param {NonNegativeInteger} offsetY - starting index for `y` +* @param {Object} out - output results object +* @returns {Object} results object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +* +* var x = new Float32Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +* var y = new Float32Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +* +* var results = new Results(); +* var out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 2.0, y, 1, 0, results ); +* // returns {...} +* +* var bool = ( out === results ); +* // returns true +*/ +function sztest2( NX, NY, alternative, alpha, diff, sigmax, x, strideX, offsetX, sigmay, y, strideY, offsetY, out ) { // eslint-disable-line max-len, max-params + addon.ndarray( NX, NY, resolveEnum( alternative ), alpha, diff, sigmax, x, strideX, offsetX, sigmay, y, strideY, offsetY, out.toDataView() ); // eslint-disable-line max-len + return out; +} + + +// EXPORTS // + +module.exports = sztest2; diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/lib/sztest2.js b/lib/node_modules/@stdlib/stats/strided/sztest2/lib/sztest2.js new file mode 100644 index 000000000000..8f59b798fb54 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/lib/sztest2.js @@ -0,0 +1,67 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Computes a two-sample Z-test for two single-precision floating-point strided arrays. +* +* @param {PositiveInteger} NX - number of indexed elements in `x` +* @param {PositiveInteger} NY - number of indexed elements in `y` +* @param {(integer|string)} alternative - alternative hypothesis +* @param {number} alpha - significance level +* @param {number} diff - difference in means under the null hypothesis +* @param {PositiveNumber} sigmax - known standard deviation of `x` +* @param {Float32Array} x - first input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveNumber} sigmay - known standard deviation of `y` +* @param {Float32Array} y - second input array +* @param {integer} strideY - stride length for `y` +* @param {Object} out - output results object +* @returns {Object} results object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +* +* var x = new Float32Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +* var y = new Float32Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +* +* var results = new Results(); +* var out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 2.0, y, 1, results ); +* // returns {...} +* +* var bool = ( out === results ); +* // returns true +*/ +function sztest2( NX, NY, alternative, alpha, diff, sigmax, x, strideX, sigmay, y, strideY, out ) { // eslint-disable-line max-len, max-params + return ndarray( NX, NY, alternative, alpha, diff, sigmax, x, strideX, stride2offset( NX, strideX ), sigmay, y, strideY, stride2offset( NY, strideY ), out ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = sztest2; diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/lib/sztest2.native.js b/lib/node_modules/@stdlib/stats/strided/sztest2/lib/sztest2.native.js new file mode 100644 index 000000000000..576bcb97a986 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/lib/sztest2.native.js @@ -0,0 +1,68 @@ +/** +* @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 resolveEnum = require( '@stdlib/stats/base/ztest/alternative-resolve-enum' ); +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Computes a two-sample Z-test for two single-precision floating-point strided arrays. +* +* @param {PositiveInteger} NX - number of indexed elements in `x` +* @param {PositiveInteger} NY - number of indexed elements in `y` +* @param {(integer|string)} alternative - alternative hypothesis +* @param {number} alpha - significance level +* @param {number} diff - difference in means under the null hypothesis +* @param {PositiveNumber} sigmax - known standard deviation of `x` +* @param {Float32Array} x - first input array +* @param {integer} strideX - stride length for `x` +* @param {PositiveNumber} sigmay - known standard deviation of `y` +* @param {Float32Array} y - second input array +* @param {integer} strideY - stride length for `y` +* @param {Object} out - output results object +* @returns {Object} results object +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +* +* var x = new Float32Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +* var y = new Float32Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +* +* var results = new Results(); +* var out = sztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 2.0, y, 1, results ); +* // returns {...} +* +* var bool = ( out === results ); +* // returns true +*/ +function sztest2( NX, NY, alternative, alpha, diff, sigmax, x, strideX, sigmay, y, strideY, out ) { // eslint-disable-line max-len, max-params + addon( NX, NY, resolveEnum( alternative ), alpha, diff, sigmax, x, strideX, sigmay, y, strideY, out.toDataView() ); // eslint-disable-line max-len + return out; +} + + +// EXPORTS // + +module.exports = sztest2; diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/manifest.json b/lib/node_modules/@stdlib/stats/strided/sztest2/manifest.json new file mode 100644 index 000000000000..753e97b9fdf9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/manifest.json @@ -0,0 +1,141 @@ +{ + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-int32", + "@stdlib/napi/argv-float", + "@stdlib/napi/argv-dataview-cast", + "@stdlib/napi/argv-strided-float32array", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/stats/strided/smean", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/stats/base/dists/normal/quantile", + "@stdlib/stats/base/ztest/alternatives", + "@stdlib/stats/base/ztest/two-sample/results/float32", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/stats/strided/smean", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/stats/base/dists/normal/quantile", + "@stdlib/stats/base/ztest/alternatives", + "@stdlib/stats/base/ztest/two-sample/results/float32", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/stats/strided/smean", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/stats/base/dists/normal/quantile", + "@stdlib/stats/base/ztest/alternatives", + "@stdlib/stats/base/ztest/two-sample/results/float32", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/stats/strided/smean", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/stats/base/dists/normal/quantile", + "@stdlib/stats/base/ztest/alternatives", + "@stdlib/stats/base/ztest/two-sample/results/float32", + "@stdlib/constants/float32/pinf", + "@stdlib/constants/float32/ninf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/package.json b/lib/node_modules/@stdlib/stats/strided/sztest2/package.json new file mode 100644 index 000000000000..0064c0573482 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/stats/strided/sztest2", + "version": "0.0.0", + "description": "Compute a two-sample Z-test for two single-precision floating-point strided arrays.", + "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", + "browser": "./lib/main.js", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "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", + "strided", + "strided array", + "typed", + "array", + "float32", + "float", + "float32array", + "ztest", + "z-test", + "hypothesis", + "testing", + "normality" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/src/Makefile b/lib/node_modules/@stdlib/stats/strided/sztest2/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/src/addon.c b/lib/node_modules/@stdlib/stats/strided/sztest2/src/addon.c new file mode 100644 index 000000000000..8417bde5201b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/src/addon.c @@ -0,0 +1,83 @@ +/** +* @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. +*/ + +#include "stdlib/stats/strided/sztest2.h" +#include "stdlib/stats/base/ztest/two-sample/results/float32.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_int32.h" +#include "stdlib/napi/argv_strided_float32array.h" +#include "stdlib/napi/argv_dataview_cast.h" +#include "stdlib/napi/argv_float.h" +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 12 ); + STDLIB_NAPI_ARGV_INT64( env, NX, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, NY, argv, 1 ); + STDLIB_NAPI_ARGV_INT32( env, alternative, argv, 2 ); + STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 3 ); + STDLIB_NAPI_ARGV_FLOAT( env, diff, argv, 4 ); + STDLIB_NAPI_ARGV_FLOAT( env, sigmax, argv, 5 ); + STDLIB_NAPI_ARGV_FLOAT( env, sigmay, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, NX, strideX, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, NY, strideY, argv, 9 ); + STDLIB_NAPI_ARGV_DATAVIEW_CAST( env, results, struct stdlib_stats_ztest_two_sample_float32_results, argv, 11 ); + API_SUFFIX(stdlib_strided_sztest2)( NX, NY, alternative, alpha, diff, sigmax, X, strideX, sigmay, Y, strideY, results ); + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 14 ); + STDLIB_NAPI_ARGV_INT64( env, NX, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, NY, argv, 1 ); + STDLIB_NAPI_ARGV_INT32( env, alternative, argv, 2 ); + STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 3 ); + STDLIB_NAPI_ARGV_FLOAT( env, diff, argv, 4 ); + STDLIB_NAPI_ARGV_FLOAT( env, sigmax, argv, 5 ); + STDLIB_NAPI_ARGV_FLOAT( env, sigmay, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 7 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 11 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, NX, strideX, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, NY, strideY, argv, 10 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 12 ); + STDLIB_NAPI_ARGV_DATAVIEW_CAST( env, results, struct stdlib_stats_ztest_two_sample_float32_results, argv, 13 ); + API_SUFFIX(stdlib_strided_sztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, X, strideX, offsetX, sigmay, Y, strideY, offsetY, results ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/src/main.c b/lib/node_modules/@stdlib/stats/strided/sztest2/src/main.c new file mode 100644 index 000000000000..13d7073a4d0e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/src/main.c @@ -0,0 +1,152 @@ +/** +* @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. +*/ + +#include "stdlib/stats/strided/sztest2.h" +#include "stdlib/stats/base/ztest/alternatives.h" +#include "stdlib/stats/base/ztest/two-sample/results/float32.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/stats/strided/smean.h" +#include "stdlib/math/base/assert/is_nanf.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/math/base/special/abs.h" +#include "stdlib/stats/base/dists/normal/cdf.h" +#include "stdlib/stats/base/dists/normal/quantile.h" +#include "stdlib/constants/float32/pinf.h" +#include "stdlib/constants/float32/ninf.h" +#include + +/** +* Computes a two-sample Z-test for two single-precision floating-point strided arrays. +* +* @param NX number of indexed elements in `X` +* @param NY number of indexed elements in `Y` +* @param alternative alternative hypothesis +* @param alpha significance level +* @param diff difference in means under the null hypothesis +* @param sigmax known standard deviation of `X` +* @param X first input array +* @param strideX stride length for `X` +* @param sigmay known standard deviation of `Y` +* @param Y second input array +* @param strideY stride length for `Y` +* @param results output results object +*/ +void API_SUFFIX(stdlib_strided_sztest2)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const float alpha, const float diff, const float sigmax, const float *X, const CBLAS_INT strideX, const float sigmay, const float *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float32_results *results ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( NX, strideX ); + const CBLAS_INT oy = stdlib_strided_stride2offset( NY, strideY ); + API_SUFFIX(stdlib_strided_sztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, X, strideX, ox, sigmay, Y, strideY, oy, results ); +} + +/** +* Computes a two-sample Z-test for two single-precision floating-point strided arrays using alternative indexing semantics. +* +* @param NX number of indexed elements in `X` +* @param NY number of indexed elements in `Y` +* @param alternative alternative hypothesis +* @param alpha significance level +* @param diff difference in means under the null hypothesis +* @param sigmax known standard deviation of `X` +* @param X first input array +* @param strideX stride length for `X` +* @param offsetX starting index for `X` +* @param sigmay known standard deviation of `Y` +* @param Y second input array +* @param strideY stride length for `Y` +* @param offsetY starting index for `Y` +* @param results output results object +*/ +void API_SUFFIX(stdlib_strided_sztest2_ndarray)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const float alpha, const float diff, const float sigmax, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float sigmay, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float32_results *results ) { + double pValue; + double stderr; + double stat; + float xmean; + float ymean; + float xvar; + float yvar; + float *ci; + double q; + + if ( + NX <= 0 || + NY <= 0 || + stdlib_base_is_nanf( alpha ) || + stdlib_base_is_nanf( diff ) || + stdlib_base_is_nanf( sigmax ) || + stdlib_base_is_nanf( sigmay ) || + sigmax <= 0.0f || + sigmay <= 0.0f || + alpha < 0.0f || + alpha > 1.0f + ) { + results->rejected = false; + results->alternative = alternative; + + // Set all applicable fields to NaN... + results->alpha = 0.0f/0.0f; + results->pValue = 0.0f/0.0f; + results->statistic = 0.0f/0.0f; + results->ci[ 0 ] = 0.0f/0.0f; + results->ci[ 1 ] = 0.0f/0.0f; + results->nullValue = 0.0f/0.0f; + results->xmean = 0.0f/0.0f; + results->ymean = 0.0f/0.0f; + return; + } + // Resolve the array for storing the confidence interval: + ci = results->ci; + + // Compute the standard error of the mean: + xvar = sigmax * sigmay; + yvar = sigmay * sigmay; + stderr = stdlib_base_sqrt( ( xvar / (double)NX ) + ( yvar / (double)NY ) ); // note: intentionally evaluated in double-precision to avoid `NX` and `NY` exceeding max safe float32 integer + + // Compute the arithmetic means of the input arrays: + xmean = stdlib_strided_smean_ndarray( NX, X, strideX, offsetX ); + ymean = stdlib_strided_smean_ndarray( NY, Y, strideY, offsetY ); + + // Compute the test statistic (i.e., the z-score, which is the standardized difference between the sample means of x and y, adjusted by the hypothesized difference, in units of the standard error): + stat = ( (double)xmean - (double)ymean - (double)diff ) / stderr; + + // Compute the p-value and confidence interval... + if ( alternative == STDLIB_STATS_ZTEST_LESS ) { + pValue = stdlib_base_dists_normal_cdf( stat, 0.0, 1.0 ); + q = stdlib_base_dists_normal_quantile( 1.0-(double)alpha, 0.0, 1.0 ); + ci[ 0 ] = STDLIB_CONSTANT_FLOAT32_NINF; + ci[ 1 ] = (double)diff + ( (stat+q)*stderr ); + } else if ( alternative == STDLIB_STATS_ZTEST_GREATER ) { + pValue = 1.0 - stdlib_base_dists_normal_cdf( stat, 0.0, 1.0 ); + q = stdlib_base_dists_normal_quantile( 1.0-(double)alpha, 0.0, 1.0 ); + ci[ 0 ] = (double)diff + ( (stat-q)*stderr ); + ci[ 1 ] = STDLIB_CONSTANT_FLOAT32_PINF; + } else { // alternative == STDLIB_STATS_ZTEST_TWO_SIDED + pValue = 2.0 * stdlib_base_dists_normal_cdf( -stdlib_base_abs( stat ), 0.0, 1.0 ); + q = stdlib_base_dists_normal_quantile( 1.0-((double)alpha/2.0), 0.0, 1.0 ); + ci[ 0 ] = (double)diff + ( (stat-q)*stderr ); + ci[ 1 ] = (double)diff + ( (stat+q)*stderr ); + } + // Store test results: + results->rejected = ( pValue <= alpha ); + results->alternative = alternative; + results->alpha = alpha; + results->pValue = (float)pValue; + results->statistic = (float)stat; + results->nullValue = diff; + results->xmean = xmean; + results->ymean = ymean; +} diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.js b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.js new file mode 100644 index 000000000000..56d22979e2b8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.js @@ -0,0 +1,82 @@ +/** +* @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 proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var sztest2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sztest2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof sztest2.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var sztest2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( sztest2, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var sztest2; + var main; + + main = require( './../lib/sztest2.js' ); + + sztest2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( sztest2, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.ndarray.js new file mode 100644 index 000000000000..6798a2232853 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.ndarray.js @@ -0,0 +1,395 @@ +/** +* @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 Float32Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var isFinitef = require( '@stdlib/math/base/assert/is-finitef' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var sfill = require( '@stdlib/blas/ext/base/sfill' ).ndarray; +var normalFactory = require( '@stdlib/random/array/normal' ).factory; +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var sztest2 = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var normal = normalFactory({ + 'seed': 12345 +}); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sztest2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=two-sided)', function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 10.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 2.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=greater)', function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'greater', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'greater', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out.ci[ 1 ], PINF, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'greater', 0.1, -1.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'greater', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out.ci[ 1 ], PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=less)', function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'less', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'less', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( out.ci[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'less', 0.1, 1.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'less', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( out.ci[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `NX` or `NY` parameter less than or equal to `0`, the function returns `NaN` results', function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + x = normal( 10, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( 0, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( -1, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( x.length, 0, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( x.length, -1, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a stride parameter', function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, 2, 0, 1.0, y, 2, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 2.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 10.0, 1.0, x, 2, 0, 1.0, y, 2, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride parameter', function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, -2, (N-1)*2, 1.0, y, -2, (N-1)*2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 2.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 10.0, 1.0, x, -2, (N-1)*2, 1.0, y, -2, (N-1)*2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an offset parameter', function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 0 ); + sfill( N, NaN, y, 2, 0 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, 2, 1, 1.0, y, 2, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 2.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 0 ); + sfill( N, NaN, y, 2, 0 ); + + out = sztest2( N, N, 'two-sided', 0.1, 2.0, 1.0, x, 2, 1, 1.0, y, 2, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.ndarray.native.js new file mode 100644 index 000000000000..946474f9620c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.ndarray.native.js @@ -0,0 +1,400 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float32Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var isFinitef = require( '@stdlib/math/base/assert/is-finitef' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var sfill = require( '@stdlib/blas/ext/base/sfill' ).ndarray; +var normalFactory = require( '@stdlib/random/array/normal' ).factory; +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var sztest2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( sztest2 instanceof Error ) +}; +var normal = normalFactory({ + 'seed': 12345 +}); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sztest2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=two-sided)', opts, function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 10.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 2.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=greater)', opts, function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'greater', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'greater', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out.ci[ 1 ], PINF, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'greater', 0.1, -1.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'greater', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out.ci[ 1 ], PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=less)', opts, function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'less', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'less', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( out.ci[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'less', 0.1, 1.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'less', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( out.ci[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `NX` or `NY` parameter less than or equal to `0`, the function returns `NaN` results', opts, function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + x = normal( 10, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( 0, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( -1, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( x.length, 0, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( x.length, -1, 'two-sided', 0.1, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a stride parameter', opts, function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, 2, 0, 1.0, y, 2, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 2.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 10.0, 1.0, x, 2, 0, 1.0, y, 2, 0, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride parameter', opts, function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, -2, (N-1)*2, 1.0, y, -2, (N-1)*2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 2.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 10.0, 1.0, x, -2, (N-1)*2, 1.0, y, -2, (N-1)*2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports an offset parameter', opts, function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 0 ); + sfill( N, NaN, y, 2, 0 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, 2, 1, 1.0, y, 2, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 2.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 0 ); + sfill( N, NaN, y, 2, 0 ); + + out = sztest2( N, N, 'two-sided', 0.1, 2.0, 1.0, x, 2, 1, 1.0, y, 2, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.sztest2.js b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.sztest2.js new file mode 100644 index 000000000000..da4a0a197ca5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.sztest2.js @@ -0,0 +1,342 @@ +/** +* @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 Float32Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var isFinitef = require( '@stdlib/math/base/assert/is-finitef' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var sfill = require( '@stdlib/blas/ext/base/sfill' ).ndarray; +var normalFactory = require( '@stdlib/random/array/normal' ).factory; +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var sztest2 = require( './../lib/sztest2.js' ); + + +// VARIABLES // + +var normal = normalFactory({ + 'seed': 12345 +}); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sztest2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=two-sided)', function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 100.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 2.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=greater)', function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'greater', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'greater', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out.ci[ 1 ], PINF, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'greater', 0.1, -1.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'greater', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out.ci[ 1 ], PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=less)', function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'less', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'less', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( out.ci[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'less', 0.1, 1.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'less', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( out.ci[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `NX` or `NY` parameter less than or equal to `0`, the function returns `NaN` results', function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + x = normal( 10, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( 0, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( -1, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( x.length, 0, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( x.length, -1, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a stride parameter', function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, 2, 1.0, y, 2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 2.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 10.0, 1.0, x, 2, 1.0, y, 2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride parameter', function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, -2, 1.0, y, -2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 100.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 100.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, -2, 1.0, y, -2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.sztest2.native.js b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.sztest2.native.js new file mode 100644 index 000000000000..5e8b958052fc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/sztest2/test/test.sztest2.native.js @@ -0,0 +1,347 @@ +/** +* @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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var Float32Results = require( '@stdlib/stats/base/ztest/two-sample/results/float32' ); +var isFinitef = require( '@stdlib/math/base/assert/is-finitef' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var sfill = require( '@stdlib/blas/ext/base/sfill' ).ndarray; +var normalFactory = require( '@stdlib/random/array/normal' ).factory; +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var sztest2 = tryRequire( resolve( __dirname, './../lib/sztest2.native.js' ) ); +var opts = { + 'skip': ( sztest2 instanceof Error ) +}; +var normal = normalFactory({ + 'seed': 12345 +}); + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof sztest2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=two-sided)', opts, function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 100.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'two-sided', 0.1, 2.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=greater)', opts, function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'greater', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'greater', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out.ci[ 1 ], PINF, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'greater', 0.1, -1.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'greater', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( out.ci[ 1 ], PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function performs a two-sample Z-test over strided arrays (alternative=less)', opts, function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 2.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'less', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'less', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( out.ci[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10000, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( x.length, y.length, 'less', 0.1, 1.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'less', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( out.ci[ 0 ], NINF, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `NX` or `NY` parameter less than or equal to `0`, the function returns `NaN` results', opts, function test( t ) { + var results; + var out; + var x; + var y; + + results = new Float32Results(); + x = normal( 10, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( 10, 0.0, 1.0, { + 'dtype': 'float32' + }); + + out = sztest2( 0, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( -1, y.length, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( x.length, 0, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + out = sztest2( x.length, -1, 'two-sided', 0.1, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), true, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a stride parameter', opts, function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, 2, 1.0, y, 2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 4.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 2.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 10.0, 1.0, x, 2, 1.0, y, 2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a negative stride parameter', opts, function test( t ) { + var results; + var out; + var x; + var y; + var N; + + N = 10000; + results = new Float32Results(); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 0.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, -2, 1.0, y, -2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, false, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + // Generate arrays with a sufficiently large sample size to effectively guarantee expected results: + x = normal( N*2, 100.0, 1.0, { + 'dtype': 'float32' + }); + y = normal( N*2, 100.0, 1.0, { + 'dtype': 'float32' + }); + + sfill( N, NaN, x, 2, 1 ); + sfill( N, NaN, y, 2, 1 ); + + out = sztest2( N, N, 'two-sided', 0.1, 0.0, 1.0, x, -2, 1.0, y, -2, results ); + t.strictEqual( out, results, 'returns expected value' ); + t.strictEqual( out.rejected, true, 'returns expected value' ); + t.strictEqual( out.alternative, 'two-sided', 'returns expected value' ); + t.strictEqual( isnanf( out.statistic ), false, 'returns expected value' ); + t.strictEqual( isnanf( out.pValue ), false, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isFinitef( out.ci[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/strided/ztest2/README.md b/lib/node_modules/@stdlib/stats/strided/ztest2/README.md index 13faa8b11ec1..28af3b8df12e 100644 --- a/lib/node_modules/@stdlib/stats/strided/ztest2/README.md +++ b/lib/node_modules/@stdlib/stats/strided/ztest2/README.md @@ -219,8 +219,6 @@ console.log( out.toString() );