From 2005758c69a26888e1face60377c78804c9f0ca5 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Mon, 7 Jul 2025 09:05:54 +0000 Subject: [PATCH 1/7] feat: add `stats/strided/dztest2` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/strided/dztest2/README.md | 422 ++++++++++++++++++ .../@stdlib/stats/strided/dztest2/binding.gyp | 170 +++++++ .../stats/strided/dztest2/examples/index.js | 36 ++ .../stats/strided/dztest2/include.gypi | 53 +++ .../include/stdlib/stats/strided/dztest2.h | 47 ++ .../stats/strided/dztest2/lib/dztest2.js | 67 +++ .../strided/dztest2/lib/dztest2.native.js | 68 +++ .../stats/strided/dztest2/lib/index.js | 80 ++++ .../@stdlib/stats/strided/dztest2/lib/main.js | 35 ++ .../stats/strided/dztest2/lib/native.js | 35 ++ .../stats/strided/dztest2/lib/ndarray.js | 161 +++++++ .../strided/dztest2/lib/ndarray.native.js | 70 +++ .../stats/strided/dztest2/manifest.json | 141 ++++++ .../stats/strided/dztest2/package.json | 76 ++++ .../stats/strided/dztest2/src/Makefile | 70 +++ .../@stdlib/stats/strided/dztest2/src/addon.c | 83 ++++ .../@stdlib/stats/strided/dztest2/src/main.c | 152 +++++++ 17 files changed, 1766 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/README.md create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/include/stdlib/stats/strided/dztest2.h create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/package.json create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/README.md b/lib/node_modules/@stdlib/stats/strided/dztest2/README.md new file mode 100644 index 000000000000..a78d4ecee956 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/README.md @@ -0,0 +1,422 @@ + + + + +# dztest2 + +> Compute a two-sample Z-test for double-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 dztest2 = require( '@stdlib/stats/strided/dztest2' ); +``` + +#### dztest2( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, y, strideY, out ) + +Computes a two-sample Z-test for double-precision floating-point strided arrays. + +```javascript +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); + +var results = new Results(); +var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, 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`. +- **sigmay**: known standard deviation of `y`. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: stride length for `x`. +- **y**: input [`Float64Array`][@stdlib/array/float64]. +- **strideY**: stride length for `y`. +- **out**: output [results object][@stdlib/stats/base/ztest/two-sample/results/float64]. + +The `N` and stride parameters determine which elements in the strided array 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/float64' ); +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 4.0, 0.0, 4.0, 0.0, 6.0, 0.0, 6.0, 0.0, 5.0, 0.0 ] ); +var y = new Float64Array( [ 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 = dztest2( 5, 5, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 2, 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/float64' ); +var Float64Array = require( '@stdlib/array/float64' ); + +var x0 = new Float64Array( [ 0.0, 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var y0 = new Float64Array( [ 0.0, 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var results = new Results(); +var out = dztest2( 5, 5, 'two-sided', 0.05, 0.0, 1.0, 2.0, x1, 1, y1, 1, results ); +// returns {...} + +var bool = ( out === results ); +// returns true +``` + +#### dztest2.ndarray( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, offsetX, y, strideY, offsetY, out ) + +Computes a two-sample Z-test for double-precision floating-point strided arrays using alternative indexing semantics. + +```javascript +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); + +var results = new Results(); +var out = dztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, 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/float64' ); +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 0.0, 4.0, 0.0, 4.0, 0.0, 6.0, 0.0, 6.0, 0.0, 5.0 ] ); +var y = new Float64Array( [ 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 = dztest2.ndarray( 5, 5, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 2, 1, 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 deviation is unknown, prefer a t-test. + +
+ + + +
+ +## Examples + + + +```javascript +var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +var normal = require( '@stdlib/random/array/normal' ); +var dztest2 = require( '@stdlib/stats/strided/dztest2' ); + +var x = normal( 1000, 4.0, 2.0, { + 'dtype': 'float64' +}); +var y = normal( 800, 3.0, 2.0, { + 'dtype': 'float64' +}); + +var results = new Results(); +var out = dztest2( x.length, y.length, 'two-sided', 0.05, 1.0, 2.0, 2.0, x, 1, y, 1, results ); +// returns {...} + +console.log( out.toString() ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/strided/dztest2.h" +``` + +#### stdlib_strided_dztest2( NX, NY, alternative, alpha, diff, sigmax, sigmay, \*X, strideX, \*Y, strideY, \*results ) + +Computes a two-sample Z-test for double-precision floating-point strided arrays. + +```c +#include "stdlib/stats/base/ztest/two-sample/results/float64.h" +#include "stdlib/stats/base/ztest/alternatives.h" + +struct stdlib_stats_ztest_two_sample_float64_results results = { + .rejected = false, + .alpha = 0.0, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0, + .statistic = 0.0, + .ci = { 0.0, 0.0 }, + .nullValue = 0.0, + .xmean = 0.0, + .ymean = 0.0 +}; + +const double x[] = { 4.0, 4.0, 6.0, 6.0, 5.0 }; +const double y[] = { 3.0, 3.0, 5.0, 7.0, 7.0 }; + +stdlib_strided_dztest2( 5, 5, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 0.0, 1.0, 2.0, x, 1, 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] double` significance level. +- **diff**: `[in] double` difference in means under the null hypothesis. +- **sigmax** `[in] double` known standard deviation of `x`. +- **sigmay** `[in] double` known standard deviation of `y`. +- **X**: `[in] double*` input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **Y**: `[in] double*` input [`Float64Array`][@stdlib/array/float64]. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. +- **results**: `[out] struct stdlib_stats_ztest_two_sample_results_float64*` output [results object][@stdlib/stats/base/ztest/two-sample/results/float64]. + +```c +void stdlib_strided_dztest2( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float64_results *results ); +``` + +#### stdlib_strided_dztest2_ndarray( NX, NY, alternative, alpha, diff, sigmax, sigmay, \*X, strideX, offsetX, \*Y, strideY, offsetY, \*results ) + +Computes a two-sample Z-test for double-precision floating-point strided arrays using alternative indexing semantics. + +```c +#include "stdlib/stats/base/ztest/two-sample/results/float64.h" +#include "stdlib/stats/base/ztest/alternatives.h" + +struct stdlib_stats_ztest_two_sample_float64_results results = { + .rejected = false, + .alpha = 0.0, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0, + .statistic = 0.0, + .ci = { 0.0, 0.0 }, + .nullValue = 0.0, + .xmean = 0.0, + .ymean = 0.0 +}; + +const double x[] = { 4.0, 4.0, 6.0, 6.0, 5.0 }; +const double y[] = { 3.0, 3.0, 5.0, 7.0, 7.0 }; + +stdlib_strided_dztest2_ndarray( 5, 5, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 0.0, 1.0, 2.0, x, 1, 0, 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] double` significance level. +- **diff**: `[in] double` difference in means under the null hypothesis. +- **sigmax** `[in] double` known standard deviation of `x`. +- **sigmay** `[in] double` known standard deviation of `y`. +- **X**: `[in] double*` input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[in] double*` input [`Float64Array`][@stdlib/array/float64]. +- **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_float64*` output [results object][@stdlib/stats/base/ztest/two-sample/results/float64]. + +```c +void stdlib_strided_dztest2_ndarray( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float64_results *results ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/strided/dztest2.h" +#include "stdlib/stats/base/ztest/two-sample/results/float64.h" +#include "stdlib/stats/base/ztest/alternatives.h" +#include +#include + +int main( void ) { + // Create a strided arrays: + const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const double y[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + + // 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_float64_results results = { + .rejected = false, + .alpha = 0.0, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0, + .statistic = 0.0, + .ci = { 0.0, 0.0 }, + .nullValue = 0.0, + .xmean = 0.0, + .ymean = 0.0 + }; + + // Compute a Z-test: + stdlib_strided_dztest2( NX, NY, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 5.0, 3.0, 3.0, x, strideX, y, strideY, &results ); + + // Print the result: + printf( "Statistic: %lf\n", results.statistic ); + printf( "Null hypothesis was %s\n", ( results.rejected ) ? "rejected" : "not rejected" ); +} +``` + +
+ + + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/binding.gyp b/lib/node_modules/@stdlib/stats/strided/dztest2/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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/dztest2/examples/index.js b/lib/node_modules/@stdlib/stats/strided/dztest2/examples/index.js new file mode 100644 index 000000000000..ecb77d5161e9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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/float64' ); +var normal = require( '@stdlib/random/array/normal' ); +var dztest2 = require( './../lib' ); + +var x = normal( 1000, 4.0, 2.0, { + 'dtype': 'float64' +}); +var y = normal( 800, 3.0, 2.0, { + 'dtype': 'float64' +}); + +var results = new Results(); +var out = dztest2( x.length, y.length, 'two-sided', 0.05, 1.0, 2.0, 2.0, x, 1, y, 1, results ); +// returns {...} + +console.log( out.toString() ); diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/include.gypi b/lib/node_modules/@stdlib/stats/strided/dztest2/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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; + } + // 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 = dmean( NX, x, strideX, offsetX ); + ymean = dmean( 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 = pValue; + out.statistic = stat; + out.ci = WORKSPACE; + out.alternative = alt; + out.nullValue = diff; + out.xmean = xmean; + out.ymean = ymean; + return out; +} + + +// EXPORTS // + +module.exports = dztest2; diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js new file mode 100644 index 000000000000..774aceffa885 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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 double-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 {PositiveNumber} sigmay - known standard deviation of `y` +* @param {Collection} x - input array +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @param {Collection} y - 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 Float64Array = require( '@stdlib/array/float64' ); +* var Results = require( '@stdlib/stats/base/ztest/two-sample/results/float64' ); +* +* var x = new Float64Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); +* var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); +* +* var results = new Results(); +* var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, 0, y, 1, 0, results ); +* // returns {...} +* +* var bool = ( out === results ); +* // returns true +*/ +function dztest2( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, offsetX, y, strideY, offsetY, out ) { // eslint-disable-line max-len, max-params + addon.ndarray( NX, NY, resolveEnum( alternative ), alpha, diff, sigmax, sigmay, x, strideX, offsetX, y, strideY, offsetY, out.toDataView() ); // eslint-disable-line max-len + return out; +} + + +// EXPORTS // + +module.exports = dztest2; diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/manifest.json b/lib/node_modules/@stdlib/stats/strided/dztest2/manifest.json new file mode 100644 index 000000000000..85f7b7c8b9bc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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-double", + "@stdlib/napi/argv-dataview-cast", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/stats/strided/dmean", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/stats/base/dists/normal/quantile", + "@stdlib/stats/base/ztest/alternatives", + "@stdlib/stats/base/ztest/two-sample/results/float64", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/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-nan", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/stats/strided/dmean", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/stats/base/dists/normal/quantile", + "@stdlib/stats/base/ztest/alternatives", + "@stdlib/stats/base/ztest/two-sample/results/float64", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/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-nan", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/stats/strided/dmean", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/stats/base/dists/normal/quantile", + "@stdlib/stats/base/ztest/alternatives", + "@stdlib/stats/base/ztest/two-sample/results/float64", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/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-nan", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/abs", + "@stdlib/stats/strided/dmean", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/stats/base/dists/normal/quantile", + "@stdlib/stats/base/ztest/alternatives", + "@stdlib/stats/base/ztest/two-sample/results/float64", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/package.json b/lib/node_modules/@stdlib/stats/strided/dztest2/package.json new file mode 100644 index 000000000000..84bb88348b8f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/stats/strided/dztest2", + "version": "0.0.0", + "description": "Compute a two-sample Z-test for double-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", + "float64", + "double", + "float64array", + "ztest", + "z-test", + "hypothesis", + "testing", + "normality" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/src/Makefile b/lib/node_modules/@stdlib/stats/strided/dztest2/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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/dztest2/src/addon.c b/lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c new file mode 100644 index 000000000000..cccf359fa310 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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/dztest2.h" +#include "stdlib/stats/base/ztest/two-sample/results/float64.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_float64array.h" +#include "stdlib/napi/argv_dataview_cast.h" +#include "stdlib/napi/argv_double.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_DOUBLE( env, alpha, argv, 3 ); + STDLIB_NAPI_ARGV_DOUBLE( env, diff, argv, 4 ); + STDLIB_NAPI_ARGV_DOUBLE( env, sigmax, argv, 5 ); + STDLIB_NAPI_ARGV_DOUBLE( env, sigmay, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 9 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, NX, strideX, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, NY, strideY, argv, 10 ); + STDLIB_NAPI_ARGV_DATAVIEW_CAST( env, results, struct stdlib_stats_ztest_two_sample_float64_results, argv, 11 ); + API_SUFFIX(stdlib_strided_dztest2)( NX, NY, alternative, alpha, diff, sigmax, sigmay, X, strideX, 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_DOUBLE( env, alpha, argv, 3 ); + STDLIB_NAPI_ARGV_DOUBLE( env, diff, argv, 4 ); + STDLIB_NAPI_ARGV_DOUBLE( env, sigmax, argv, 5 ); + STDLIB_NAPI_ARGV_DOUBLE( env, sigmay, argv, 6 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 11 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, NX, strideX, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, NY, strideY, argv, 10 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 12 ); + STDLIB_NAPI_ARGV_DATAVIEW_CAST( env, results, struct stdlib_stats_ztest_two_sample_float64_results, argv, 13 ); + API_SUFFIX(stdlib_strided_dztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, sigmay, X, strideX, offsetX, 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/dztest2/src/main.c b/lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c new file mode 100644 index 000000000000..5bd6d54839c3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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/dztest2.h" +#include "stdlib/stats/base/ztest/alternatives.h" +#include "stdlib/stats/base/ztest/two-sample/results/float64.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/stats/strided/dmean.h" +#include "stdlib/math/base/assert/is_nan.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/float64/pinf.h" +#include "stdlib/constants/float64/ninf.h" +#include + +/** +* Computes a two-sample Z-test for double-precision floating-point strided arrays. +* +* @param NX number of indexed elements +* @param NY number of indexed elements +* @param alternative alternative hypothesis +* @param alpha significance level +* @param diff mean under the null hypothesis +* @param sigmax known standard deviation +* @param sigmay known standard deviation +* @param X input array +* @param strideX stride length +* @param Y input array +* @param strideY stride length +* @param results output results object +*/ +void API_SUFFIX(stdlib_strided_dztest2)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float64_results *results ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( NX, strideX ); + const CBLAS_INT oy = stdlib_strided_stride2offset( NY, strideY ); + API_SUFFIX(stdlib_strided_dztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, sigmay, X, strideX, ox, Y, strideY, oy, results ); +} + +/** +* Computes a two-sample Z-test for double-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 mean under the null hypothesis +* @param sigmax known standard deviation of `x` +* @param sigmay known standard deviation of `x` +* @param X input array +* @param strideX stride length for `x` +* @param offsetX starting index for `x` +* @param Y input array +* @param strideY stride length for `y` +* @param offsetY starting index for `y` +* @param results output results object +*/ +void API_SUFFIX(stdlib_strided_dztest2_ndarray)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float64_results *results ) { + double pValue; + double stderr; + double xmean; + double ymean; + double xvar; + double yvar; + double stat; + double *ci; + double q; + + if ( + NX <= 0 || + NY <= 0 || + stdlib_base_is_nan( alpha ) || + stdlib_base_is_nan( diff ) || + stdlib_base_is_nan( sigmax ) || + stdlib_base_is_nan( sigmay ) || + sigmax <= 0.0 || + sigmay <= 0.0 || + alpha < 0.0 || + alpha > 1.0 + ) { + results->rejected = false; + results->alternative = alternative; + + // Set all applicable fields to NaN... + results->alpha = 0.0/0.0; + results->pValue = 0.0/0.0; + results->statistic = 0.0/0.0; + results->ci[ 0 ] = 0.0/0.0; + results->ci[ 1 ] = 0.0/0.0; + results->nullValue = 0.0/0.0; + results->xmean = 0.0/0.0; + results->ymean = 0.0/0.0; + 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 ) ); + + // Compute the arithmetic mean of the input arrays: + xmean = stdlib_strided_dmean_ndarray( NX, X, strideX, offsetX ); + ymean = stdlib_strided_dmean_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 = ( xmean - ymean - 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-alpha, 0.0, 1.0 ); + ci[ 0 ] = STDLIB_CONSTANT_FLOAT64_NINF; + ci[ 1 ] = 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-alpha, 0.0, 1.0 ); + ci[ 0 ] = diff + ( (stat-q)*stderr ); + ci[ 1 ] = STDLIB_CONSTANT_FLOAT64_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-(alpha/2.0), 0.0, 1.0 ); + ci[ 0 ] = diff + ( (stat-q)*stderr ); + ci[ 1 ] = diff + ( (stat+q)*stderr ); + } + // Store test results: + results->rejected = ( pValue <= alpha ); + results->alternative = alternative; + results->alpha = alpha; + results->pValue = pValue; + results->statistic = stat; + results->nullValue = diff; + results->xmean = xmean; + results->ymean = ymean; +} From 6d2c29f3ef59dee4553fb41fd19c4b42c861f0a9 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Mon, 7 Jul 2025 18:18:18 +0000 Subject: [PATCH 2/7] feat: add C examples --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/strided/dztest2/examples/c/Makefile | 146 ++++++++++++++++++ .../strided/dztest2/examples/c/example.c | 57 +++++++ 2 files changed, 203 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/examples/c/example.c diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/examples/c/Makefile b/lib/node_modules/@stdlib/stats/strided/dztest2/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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/dztest2/examples/c/example.c b/lib/node_modules/@stdlib/stats/strided/dztest2/examples/c/example.c new file mode 100644 index 000000000000..14275f526f46 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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/dztest2.h" +#include "stdlib/stats/base/ztest/two-sample/results/float64.h" +#include "stdlib/stats/base/ztest/alternatives.h" +#include +#include + +int main( void ) { + // Create a strided arrays: + const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + const double y[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + + // 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_float64_results results = { + .rejected = false, + .alpha = 0.0, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0, + .statistic = 0.0, + .ci = { 0.0, 0.0 }, + .nullValue = 0.0, + .xmean = 0.0, + .ymean = 0.0 + }; + + // Compute a Z-test: + stdlib_strided_dztest2( NX, NY, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 5.0, 3.0, 3.0, x, strideX, y, strideY, &results ); + + // Print the result: + printf( "Statistic: %lf\n", results.statistic ); + printf( "Null hypothesis was %s\n", ( results.rejected ) ? "rejected" : "not rejected" ); +} From da1f089ed273fed55de570e61929da5a954f6645 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Wed, 9 Jul 2025 06:51:27 +0000 Subject: [PATCH 3/7] fix: correct argument indexing --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c b/lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c index cccf359fa310..c1c50ddc3061 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c @@ -45,9 +45,9 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_DOUBLE( env, sigmax, argv, 5 ); STDLIB_NAPI_ARGV_DOUBLE( env, sigmay, argv, 6 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 8 ); - STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 10 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, NX, strideX, argv, 7 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, NY, strideY, argv, 10 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, NY, strideY, argv, 9 ); STDLIB_NAPI_ARGV_DATAVIEW_CAST( env, results, struct stdlib_stats_ztest_two_sample_float64_results, argv, 11 ); API_SUFFIX(stdlib_strided_dztest2)( NX, NY, alternative, alpha, diff, sigmax, sigmay, X, strideX, Y, strideY, results ); return NULL; From 79c85fb81c8b02a8aa38cbd1551cd8a74967e91f Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Wed, 9 Jul 2025 07:29:19 +0000 Subject: [PATCH 4/7] fix: update parameter type --- lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js | 4 ++-- .../@stdlib/stats/strided/dztest2/lib/dztest2.native.js | 4 ++-- lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js | 4 ++-- .../@stdlib/stats/strided/dztest2/lib/ndarray.native.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js index 7711cac96418..c99059f53b42 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js @@ -36,9 +36,9 @@ var ndarray = require( './ndarray.js' ); * @param {number} diff - difference in means under the null hypothesis * @param {PositiveNumber} sigmax - known standard deviation of `x` * @param {PositiveNumber} sigmay - known standard deviation of `y` -* @param {Collection} x - input array +* @param {Float64Array} x - input array * @param {integer} strideX - stride length for `x` -* @param {Collection} y - input array +* @param {Float64Array} y - input array * @param {integer} strideY - stride length for `y` * @param {Object} out - output results object * @returns {Object} results object diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.native.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.native.js index 340b93636da6..2c788671984b 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.native.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.native.js @@ -36,9 +36,9 @@ var addon = require( './../src/addon.node' ); * @param {number} diff - difference in means under the null hypothesis * @param {PositiveNumber} sigmax - known standard deviation of `x` * @param {PositiveNumber} sigmay - known standard deviation of `y` -* @param {Collection} x - input array +* @param {Float64Array} x - input array * @param {integer} strideX - stride length for `x` -* @param {Collection} y - input array +* @param {Float64Array} y - input array * @param {integer} strideY - stride length for `y` * @param {Object} out - output results object * @returns {Object} results object diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js index d5bd62e1c840..159ee3e56d19 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js @@ -53,10 +53,10 @@ var WORKSPACE = new Float64Array( 2 ); * @param {number} diff - difference in means under the null hypothesis * @param {PositiveNumber} sigmax - known standard deviation of `x` * @param {PositiveNumber} sigmay - known standard deviation of `y` -* @param {Collection} x - input array +* @param {Float64Array} x - input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {Collection} y - input array +* @param {Float64Array} y - input array * @param {integer} strideY - stride length for `y` * @param {NonNegativeInteger} offsetY - starting index for `y` * @param {Object} out - output results object diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js index 774aceffa885..e01d0448b781 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js @@ -36,10 +36,10 @@ var addon = require( './../src/addon.node' ); * @param {number} diff - difference in means under the null hypothesis * @param {PositiveNumber} sigmax - known standard deviation of `x` * @param {PositiveNumber} sigmay - known standard deviation of `y` -* @param {Collection} x - input array +* @param {Float64Array} x - input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {Collection} y - input array +* @param {Float64Array} y - input array * @param {integer} strideY - stride length for `y` * @param {NonNegativeInteger} offsetY - starting index for `y` * @param {Object} out - output results object From 7fa3913ef4612526cf197e83de5eed04bf7ad5ba Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 11 Jul 2025 08:41:37 +0000 Subject: [PATCH 5/7] refactor: update parameter orders --- .../@stdlib/stats/strided/dztest2/README.md | 52 +++++++++---------- .../strided/dztest2/examples/c/example.c | 2 +- .../stats/strided/dztest2/examples/index.js | 2 +- .../include/stdlib/stats/strided/dztest2.h | 4 +- .../stats/strided/dztest2/lib/dztest2.js | 12 ++--- .../strided/dztest2/lib/dztest2.native.js | 12 ++--- .../stats/strided/dztest2/lib/index.js | 4 +- .../stats/strided/dztest2/lib/ndarray.js | 10 ++-- .../strided/dztest2/lib/ndarray.native.js | 12 ++--- .../@stdlib/stats/strided/dztest2/src/addon.c | 18 +++---- .../@stdlib/stats/strided/dztest2/src/main.c | 20 +++---- 11 files changed, 74 insertions(+), 74 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/README.md b/lib/node_modules/@stdlib/stats/strided/dztest2/README.md index a78d4ecee956..36ef7ec63ae3 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/README.md +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/README.md @@ -46,7 +46,7 @@ Here, `μX` and `μY` are the true population means of samples `X` and `Y`, resp var dztest2 = require( '@stdlib/stats/strided/dztest2' ); ``` -#### dztest2( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, y, strideY, out ) +#### dztest2( NX, NY, alternative, alpha, diff, sigmax, x, strideX, sigmay, y, strideY, out ) Computes a two-sample Z-test for double-precision floating-point strided arrays. @@ -58,7 +58,7 @@ var x = new Float64Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); var results = new Results(); -var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, y, 1, results ); +var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 2.0, y, 1, results ); // returns {...} var bool = ( out === results ); @@ -73,14 +73,14 @@ The function has the following parameters: - **alpha**: significance level. - **diff**: difference in means under the null hypothesis. - **sigmax**: known standard deviation of `x`. -- **sigmay**: known standard deviation of `y`. -- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **x**: first input [`Float64Array`][@stdlib/array/float64]. - **strideX**: stride length for `x`. -- **y**: input [`Float64Array`][@stdlib/array/float64]. +- **sigmay**: known standard deviation of `y`. +- **y**: second input [`Float64Array`][@stdlib/array/float64]. - **strideY**: stride length for `y`. - **out**: output [results object][@stdlib/stats/base/ztest/two-sample/results/float64]. -The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to perform a two-sample Z-test over every other element in `x` and `y`, +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/float64' ); @@ -90,7 +90,7 @@ var x = new Float64Array( [ 4.0, 0.0, 4.0, 0.0, 6.0, 0.0, 6.0, 0.0, 5.0, 0.0 ] ) var y = new Float64Array( [ 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 = dztest2( 5, 5, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 2, y, 2, results ); +var out = dztest2( 5, 5, 'two-sided', 0.05, 0.0, 1.0, x, 2, 2.0, y, 2, results ); // returns {...} var bool = ( out === results ); @@ -112,14 +112,14 @@ var y0 = new Float64Array( [ 0.0, 3.0, 3.0, 5.0, 7.0, 7.0 ] ); var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var results = new Results(); -var out = dztest2( 5, 5, 'two-sided', 0.05, 0.0, 1.0, 2.0, x1, 1, y1, 1, results ); +var out = dztest2( 5, 5, 'two-sided', 0.05, 0.0, 1.0, x1, 1, 2.0, y1, 1, results ); // returns {...} var bool = ( out === results ); // returns true ``` -#### dztest2.ndarray( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, offsetX, y, strideY, offsetY, out ) +#### dztest2.ndarray( NX, NY, alternative, alpha, diff, sigmax, x, strideX, offsetX, sigmay, y, strideY, offsetY, out ) Computes a two-sample Z-test for double-precision floating-point strided arrays using alternative indexing semantics. @@ -131,7 +131,7 @@ var x = new Float64Array( [ 4.0, 4.0, 6.0, 6.0, 5.0 ] ); var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); var results = new Results(); -var out = dztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, 0, y, 1, 0, results ); +var out = dztest2.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 ); @@ -153,7 +153,7 @@ var x = new Float64Array( [ 0.0, 4.0, 0.0, 4.0, 0.0, 6.0, 0.0, 6.0, 0.0, 5.0 ] ) var y = new Float64Array( [ 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 = dztest2.ndarray( 5, 5, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 2, 1, y, 2, 1, results ); +var out = dztest2.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 ); @@ -168,7 +168,7 @@ var bool = ( out === results ); ## Notes -- As a general rule of thumb, a Z-test is most reliable when `N >= 50`. For smaller sample sizes or when the standard deviation is unknown, prefer a t-test. +- 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. @@ -193,7 +193,7 @@ var y = normal( 800, 3.0, 2.0, { }); var results = new Results(); -var out = dztest2( x.length, y.length, 'two-sided', 0.05, 1.0, 2.0, 2.0, x, 1, y, 1, results ); +var out = dztest2( x.length, y.length, 'two-sided', 0.05, 1.0, 2.0, x, 1, 2.0, y, 1, results ); // returns {...} console.log( out.toString() ); @@ -229,7 +229,7 @@ console.log( out.toString() ); #include "stdlib/stats/strided/dztest2.h" ``` -#### stdlib_strided_dztest2( NX, NY, alternative, alpha, diff, sigmax, sigmay, \*X, strideX, \*Y, strideY, \*results ) +#### stdlib_strided_dztest2( NX, NY, alternative, alpha, diff, sigmax, \*X, strideX, sigmay, \*Y, strideY, \*results ) Computes a two-sample Z-test for double-precision floating-point strided arrays. @@ -252,7 +252,7 @@ struct stdlib_stats_ztest_two_sample_float64_results results = { const double x[] = { 4.0, 4.0, 6.0, 6.0, 5.0 }; const double y[] = { 3.0, 3.0, 5.0, 7.0, 7.0 }; -stdlib_strided_dztest2( 5, 5, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 0.0, 1.0, 2.0, x, 1, y, 1, &results ); +stdlib_strided_dztest2( 5, 5, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 0.0, 1.0, x, 1, 2.0, y, 1, &results ); ``` The function accepts the following arguments: @@ -263,18 +263,18 @@ The function accepts the following arguments: - **alpha**: `[in] double` significance level. - **diff**: `[in] double` difference in means under the null hypothesis. - **sigmax** `[in] double` known standard deviation of `x`. -- **sigmay** `[in] double` known standard deviation of `y`. -- **X**: `[in] double*` input [`Float64Array`][@stdlib/array/float64]. +- **X**: `[in] double*` first input [`Float64Array`][@stdlib/array/float64]. - **strideX**: `[in] CBLAS_INT` stride length for `X`. -- **Y**: `[in] double*` input [`Float64Array`][@stdlib/array/float64]. +- **sigmay** `[in] double` known standard deviation of `y`. +- **Y**: `[in] double*` second input [`Float64Array`][@stdlib/array/float64]. - **strideY**: `[in] CBLAS_INT` stride length for `Y`. - **results**: `[out] struct stdlib_stats_ztest_two_sample_results_float64*` output [results object][@stdlib/stats/base/ztest/two-sample/results/float64]. ```c -void stdlib_strided_dztest2( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float64_results *results ); +void stdlib_strided_dztest2( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double *X, const CBLAS_INT strideX, const double sigmay, const double *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float64_results *results ); ``` -#### stdlib_strided_dztest2_ndarray( NX, NY, alternative, alpha, diff, sigmax, sigmay, \*X, strideX, offsetX, \*Y, strideY, offsetY, \*results ) +#### stdlib_strided_dztest2_ndarray( NX, NY, alternative, alpha, diff, sigmax, \*X, strideX, offsetX, sigmay, \*Y, strideY, offsetY, \*results ) Computes a two-sample Z-test for double-precision floating-point strided arrays using alternative indexing semantics. @@ -297,7 +297,7 @@ struct stdlib_stats_ztest_two_sample_float64_results results = { const double x[] = { 4.0, 4.0, 6.0, 6.0, 5.0 }; const double y[] = { 3.0, 3.0, 5.0, 7.0, 7.0 }; -stdlib_strided_dztest2_ndarray( 5, 5, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 0.0, 1.0, 2.0, x, 1, 0, y, 1, 0, &results ); +stdlib_strided_dztest2_ndarray( 5, 5, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 0.0, 1.0, x, 1, 0, 2.0, y, 1, 0, &results ); ``` The function accepts the following arguments: @@ -308,17 +308,17 @@ The function accepts the following arguments: - **alpha**: `[in] double` significance level. - **diff**: `[in] double` difference in means under the null hypothesis. - **sigmax** `[in] double` known standard deviation of `x`. -- **sigmay** `[in] double` known standard deviation of `y`. -- **X**: `[in] double*` input [`Float64Array`][@stdlib/array/float64]. +- **X**: `[in] double*` first input [`Float64Array`][@stdlib/array/float64]. - **strideX**: `[in] CBLAS_INT` stride length for `X`. - **offsetX**: `[in] CBLAS_INT` starting index for `X`. -- **Y**: `[in] double*` input [`Float64Array`][@stdlib/array/float64]. +- **sigmay** `[in] double` known standard deviation of `y`. +- **Y**: `[in] double*` second input [`Float64Array`][@stdlib/array/float64]. - **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_float64*` output [results object][@stdlib/stats/base/ztest/two-sample/results/float64]. ```c -void stdlib_strided_dztest2_ndarray( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float64_results *results ); +void stdlib_strided_dztest2_ndarray( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double sigmay, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float64_results *results ); ``` @@ -373,7 +373,7 @@ int main( void ) { }; // Compute a Z-test: - stdlib_strided_dztest2( NX, NY, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 5.0, 3.0, 3.0, x, strideX, y, strideY, &results ); + stdlib_strided_dztest2( NX, NY, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 5.0, 3.0, x, strideX, 3.0, y, strideY, &results ); // Print the result: printf( "Statistic: %lf\n", results.statistic ); diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/examples/c/example.c b/lib/node_modules/@stdlib/stats/strided/dztest2/examples/c/example.c index 14275f526f46..003d039e7a96 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/examples/c/example.c @@ -49,7 +49,7 @@ int main( void ) { }; // Compute a Z-test: - stdlib_strided_dztest2( NX, NY, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 5.0, 3.0, 3.0, x, strideX, y, strideY, &results ); + stdlib_strided_dztest2( NX, NY, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 5.0, 3.0, x, strideX, 3.0, y, strideY, &results ); // Print the result: printf( "Statistic: %lf\n", results.statistic ); diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/examples/index.js b/lib/node_modules/@stdlib/stats/strided/dztest2/examples/index.js index ecb77d5161e9..0a87ce821511 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/examples/index.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/examples/index.js @@ -30,7 +30,7 @@ var y = normal( 800, 3.0, 2.0, { }); var results = new Results(); -var out = dztest2( x.length, y.length, 'two-sided', 0.05, 1.0, 2.0, 2.0, x, 1, y, 1, results ); +var out = dztest2( 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/dztest2/include/stdlib/stats/strided/dztest2.h b/lib/node_modules/@stdlib/stats/strided/dztest2/include/stdlib/stats/strided/dztest2.h index 312b6ed88b59..d7560b61e15f 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/include/stdlib/stats/strided/dztest2.h +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/include/stdlib/stats/strided/dztest2.h @@ -33,12 +33,12 @@ extern "C" { /** * Computes a two-sample Z-test for double-precision floating-point strided arrays. */ -void API_SUFFIX(stdlib_strided_dztest2)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float64_results *results ); +void API_SUFFIX(stdlib_strided_dztest2)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double *X, const CBLAS_INT strideX, const double sigmay, const double *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float64_results *results ); /** * Computes a two-sample Z-test for double-precision floating-point strided arrays using alternative indexing semantics. */ -void API_SUFFIX(stdlib_strided_dztest2_ndarray)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float64_results *results ); +void API_SUFFIX(stdlib_strided_dztest2_ndarray)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double sigmay, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float64_results *results ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js index c99059f53b42..251e373277ae 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.js @@ -35,10 +35,10 @@ var ndarray = require( './ndarray.js' ); * @param {number} alpha - significance level * @param {number} diff - difference in means under the null hypothesis * @param {PositiveNumber} sigmax - known standard deviation of `x` -* @param {PositiveNumber} sigmay - known standard deviation of `y` -* @param {Float64Array} x - input array +* @param {Float64Array} x - first input array * @param {integer} strideX - stride length for `x` -* @param {Float64Array} y - input array +* @param {PositiveNumber} sigmay - known standard deviation of `y` +* @param {Float64Array} y - second input array * @param {integer} strideY - stride length for `y` * @param {Object} out - output results object * @returns {Object} results object @@ -51,14 +51,14 @@ var ndarray = require( './ndarray.js' ); * var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); * * var results = new Results(); -* var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, y, 1, results ); +* var out = dztest2( 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 dztest2( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, y, strideY, out ) { // eslint-disable-line max-len, max-params - return ndarray( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, stride2offset( NX, strideX ), y, strideY, stride2offset( NY, strideY ), out ); // eslint-disable-line max-len +function dztest2( 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 } diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.native.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.native.js index 2c788671984b..1b840e865aba 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.native.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/dztest2.native.js @@ -35,10 +35,10 @@ var addon = require( './../src/addon.node' ); * @param {number} alpha - significance level * @param {number} diff - difference in means under the null hypothesis * @param {PositiveNumber} sigmax - known standard deviation of `x` -* @param {PositiveNumber} sigmay - known standard deviation of `y` -* @param {Float64Array} x - input array +* @param {Float64Array} x - first input array * @param {integer} strideX - stride length for `x` -* @param {Float64Array} y - input array +* @param {PositiveNumber} sigmay - known standard deviation of `y` +* @param {Float64Array} y - second input array * @param {integer} strideY - stride length for `y` * @param {Object} out - output results object * @returns {Object} results object @@ -51,14 +51,14 @@ var addon = require( './../src/addon.node' ); * var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); * * var results = new Results(); -* var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, y, 1, results ); +* var out = dztest2( 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 dztest2( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, y, strideY, out ) { // eslint-disable-line max-len, max-params - addon( NX, NY, resolveEnum( alternative ), alpha, diff, sigmax, sigmay, x, strideX, y, strideY, out.toDataView() ); // eslint-disable-line max-len +function dztest2( 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; } diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/index.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/index.js index d13e7fde60e3..2720bd1bfc87 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/index.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/index.js @@ -32,7 +32,7 @@ * var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); * * var results = new Results(); -* var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, y, 1, results ); +* var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 2.0, y, 1, results ); * // returns {...} * * var bool = ( out === results ); @@ -47,7 +47,7 @@ * var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); * * var results = new Results(); -* var out = dztest2.ndarray( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, 0, y, 1, 0, results ); +* var out = dztest2.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 ); diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js index 159ee3e56d19..b489e83010a0 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.js @@ -52,11 +52,11 @@ var WORKSPACE = new Float64Array( 2 ); * @param {number} alpha - significance level * @param {number} diff - difference in means under the null hypothesis * @param {PositiveNumber} sigmax - known standard deviation of `x` -* @param {PositiveNumber} sigmay - known standard deviation of `y` -* @param {Float64Array} x - input array +* @param {Float64Array} x - first input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {Float64Array} y - input array +* @param {PositiveNumber} sigmay - known standard deviation of `y` +* @param {Float64Array} y - second input array * @param {integer} strideY - stride length for `y` * @param {NonNegativeInteger} offsetY - starting index for `y` * @param {Object} out - output results object @@ -70,13 +70,13 @@ var WORKSPACE = new Float64Array( 2 ); * var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); * * var results = new Results(); -* var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, 0, y, 1, 0, results ); +* var out = dztest2( 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 dztest2( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, offsetX, y, strideY, offsetY, out ) { // eslint-disable-line max-len, max-params +function dztest2( NX, NY, alternative, alpha, diff, sigmax, x, strideX, offsetX, sigmay, y, strideY, offsetY, out ) { // eslint-disable-line max-len, max-params var pValue; var stderr; var xmean; diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js index e01d0448b781..6817ea75daf5 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/lib/ndarray.native.js @@ -35,11 +35,11 @@ var addon = require( './../src/addon.node' ); * @param {number} alpha - significance level * @param {number} diff - difference in means under the null hypothesis * @param {PositiveNumber} sigmax - known standard deviation of `x` -* @param {PositiveNumber} sigmay - known standard deviation of `y` -* @param {Float64Array} x - input array +* @param {Float64Array} x - first input array * @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` -* @param {Float64Array} y - input array +* @param {PositiveNumber} sigmay - known standard deviation of `y` +* @param {Float64Array} y - second input array * @param {integer} strideY - stride length for `y` * @param {NonNegativeInteger} offsetY - starting index for `y` * @param {Object} out - output results object @@ -53,14 +53,14 @@ var addon = require( './../src/addon.node' ); * var y = new Float64Array( [ 3.0, 3.0, 5.0, 7.0, 7.0 ] ); * * var results = new Results(); -* var out = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, 2.0, x, 1, 0, y, 1, 0, results ); +* var out = dztest2( 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 dztest2( NX, NY, alternative, alpha, diff, sigmax, sigmay, x, strideX, offsetX, y, strideY, offsetY, out ) { // eslint-disable-line max-len, max-params - addon.ndarray( NX, NY, resolveEnum( alternative ), alpha, diff, sigmax, sigmay, x, strideX, offsetX, y, strideY, offsetY, out.toDataView() ); // eslint-disable-line max-len +function dztest2( 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; } diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c b/lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c index c1c50ddc3061..4c6824d0de1a 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/src/addon.c @@ -43,13 +43,13 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 3 ); STDLIB_NAPI_ARGV_DOUBLE( env, diff, argv, 4 ); STDLIB_NAPI_ARGV_DOUBLE( env, sigmax, argv, 5 ); - STDLIB_NAPI_ARGV_DOUBLE( env, sigmay, argv, 6 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 8 ); + STDLIB_NAPI_ARGV_DOUBLE( env, sigmay, argv, 8 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 7 ); STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 10 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, NX, strideX, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, NX, strideX, argv, 6 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, NY, strideY, argv, 9 ); STDLIB_NAPI_ARGV_DATAVIEW_CAST( env, results, struct stdlib_stats_ztest_two_sample_float64_results, argv, 11 ); - API_SUFFIX(stdlib_strided_dztest2)( NX, NY, alternative, alpha, diff, sigmax, sigmay, X, strideX, Y, strideY, results ); + API_SUFFIX(stdlib_strided_dztest2)( NX, NY, alternative, alpha, diff, sigmax, X, strideX, sigmay, Y, strideY, results ); return NULL; } @@ -68,15 +68,15 @@ static napi_value addon_method( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_DOUBLE( env, alpha, argv, 3 ); STDLIB_NAPI_ARGV_DOUBLE( env, diff, argv, 4 ); STDLIB_NAPI_ARGV_DOUBLE( env, sigmax, argv, 5 ); - STDLIB_NAPI_ARGV_DOUBLE( env, sigmay, argv, 6 ); - STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 8 ); + STDLIB_NAPI_ARGV_DOUBLE( env, sigmay, argv, 9 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 7 ); STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 11 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, NX, strideX, argv, 7 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, NX, strideX, argv, 6 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, NY, strideY, argv, 10 ); - STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 9 ); + 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_float64_results, argv, 13 ); - API_SUFFIX(stdlib_strided_dztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, sigmay, X, strideX, offsetX, Y, strideY, offsetY, results ); + API_SUFFIX(stdlib_strided_dztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, X, strideX, offsetX, sigmay, Y, strideY, offsetY, results ); return NULL; } diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c b/lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c index 5bd6d54839c3..13c09e0ee2db 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c @@ -40,17 +40,17 @@ * @param alpha significance level * @param diff mean under the null hypothesis * @param sigmax known standard deviation -* @param sigmay known standard deviation -* @param X input array +* @param X first input array * @param strideX stride length -* @param Y input array +* @param sigmay known standard deviation +* @param Y second input array * @param strideY stride length * @param results output results object */ -void API_SUFFIX(stdlib_strided_dztest2)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float64_results *results ) { +void API_SUFFIX(stdlib_strided_dztest2)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double *X, const CBLAS_INT strideX, const double sigmay, const double *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float64_results *results ) { const CBLAS_INT ox = stdlib_strided_stride2offset( NX, strideX ); const CBLAS_INT oy = stdlib_strided_stride2offset( NY, strideY ); - API_SUFFIX(stdlib_strided_dztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, sigmay, X, strideX, ox, Y, strideY, oy, results ); + API_SUFFIX(stdlib_strided_dztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, X, strideX, sigmay, ox, Y, strideY, oy, results ); } /** @@ -62,16 +62,16 @@ void API_SUFFIX(stdlib_strided_dztest2)( const CBLAS_INT NX, const CBLAS_INT NY, * @param alpha significance level * @param diff mean under the null hypothesis * @param sigmax known standard deviation of `x` -* @param sigmay known standard deviation of `x` -* @param X input array +* @param X first input array * @param strideX stride length for `x` * @param offsetX starting index for `x` -* @param Y input array +* @param sigmay known standard deviation of `x` +* @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_dztest2_ndarray)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double sigmay, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float64_results *results ) { +void API_SUFFIX(stdlib_strided_dztest2_ndarray)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double sigmay, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, struct stdlib_stats_ztest_two_sample_float64_results *results ) { double pValue; double stderr; double xmean; @@ -116,7 +116,7 @@ void API_SUFFIX(stdlib_strided_dztest2_ndarray)( const CBLAS_INT NX, const CBLAS yvar = sigmay * sigmay; stderr = stdlib_base_sqrt( ( xvar / (double)NX ) + ( yvar / (double)NY ) ); - // Compute the arithmetic mean of the input arrays: + // Compute the arithmetic means of the input arrays: xmean = stdlib_strided_dmean_ndarray( NX, X, strideX, offsetX ); ymean = stdlib_strided_dmean_ndarray( NY, Y, strideY, offsetY ); From eeb29b02d5bc814cebde19f9d524ee6a50c50dbb Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 11 Jul 2025 10:22:02 +0000 Subject: [PATCH 6/7] fix: correct parameter order --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c b/lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c index 13c09e0ee2db..ca0e9d263db7 100644 --- a/lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/src/main.c @@ -50,7 +50,7 @@ void API_SUFFIX(stdlib_strided_dztest2)( const CBLAS_INT NX, const CBLAS_INT NY, const enum STDLIB_STATS_ZTEST_ALTERNATIVE alternative, const double alpha, const double diff, const double sigmax, const double *X, const CBLAS_INT strideX, const double sigmay, const double *Y, const CBLAS_INT strideY, struct stdlib_stats_ztest_two_sample_float64_results *results ) { const CBLAS_INT ox = stdlib_strided_stride2offset( NX, strideX ); const CBLAS_INT oy = stdlib_strided_stride2offset( NY, strideY ); - API_SUFFIX(stdlib_strided_dztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, X, strideX, sigmay, ox, Y, strideY, oy, results ); + API_SUFFIX(stdlib_strided_dztest2_ndarray)( NX, NY, alternative, alpha, diff, sigmax, X, strideX, ox, sigmay, Y, strideY, oy, results ); } /** From eb601640079ce61b79af1890059a05c46d535405 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Fri, 11 Jul 2025 10:22:20 +0000 Subject: [PATCH 7/7] feat: add benchmarks --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../strided/dztest2/benchmark/benchmark.js | 104 ++++++++ .../dztest2/benchmark/benchmark.native.js | 109 +++++++++ .../dztest2/benchmark/benchmark.ndarray.js | 104 ++++++++ .../benchmark/benchmark.ndarray.native.js | 109 +++++++++ .../strided/dztest2/benchmark/c/Makefile | 146 ++++++++++++ .../dztest2/benchmark/c/benchmark.length.c | 225 ++++++++++++++++++ 6 files changed, 797 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/benchmark.ndarray.native.js create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/c/benchmark.length.c diff --git a/lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/benchmark.js new file mode 100644 index 000000000000..d60bb28b694c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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 isnan = 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/float64' ); +var pkg = require( './../package.json' ).name; +var dztest2 = require( './../lib/dztest2.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// 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 = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + if ( isnan( out.statistic ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( 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/dztest2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/benchmark.native.js new file mode 100644 index 000000000000..86384ace550f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +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/float64' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dztest2 = tryRequire( resolve( __dirname, './../lib/dztest2.native.js' ) ); +var opts = { + 'skip': ( dztest2 instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// 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 = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 1.0, y, 1, results ); + if ( isnan( out.statistic ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( 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/dztest2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..3914c077955e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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 isnan = 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/float64' ); +var pkg = require( './../package.json' ).name; +var dztest2 = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// 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 = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + if ( isnan( out.statistic ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( 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/dztest2/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/benchmark.ndarray.native.js new file mode 100644 index 000000000000..55f44518ea2e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +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/float64' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var dztest2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); +var opts = { + 'skip': ( dztest2 instanceof Error ) +}; +var options = { + 'dtype': 'float64' +}; + + +// 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 = dztest2( x.length, y.length, 'two-sided', 0.05, 0.0, 1.0, x, 1, 0, 1.0, y, 1, 0, results ); + if ( isnan( out.statistic ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( 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/dztest2/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/c/Makefile new file mode 100644 index 000000000000..cce2c865d7ad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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/dztest2/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/strided/dztest2/benchmark/c/benchmark.length.c new file mode 100644 index 000000000000..2aa390754091 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/strided/dztest2/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/dztest2.h" +#include "stdlib/stats/base/ztest/two-sample/results/float64.h" +#include "stdlib/stats/base/ztest/alternatives.h" +#include +#include +#include +#include +#include + +#define NAME "dztest2" +#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 double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + 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; + double x[ len ]; + double y[ len ]; + double t; + int i; + + struct stdlib_stats_ztest_two_sample_float64_results results = { + .rejected = false, + .alpha = 0.0, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0, + .statistic = 0.0, + .ci = { 0.0, 0.0 }, + .nullValue = 0.0, + .xmean = 0.0, + .ymean = 0.0 + }; + + for ( i = 0; i < len; i++ ) { + x[ i ] = random_uniform( -5.0, 5.0 ); + y[ i ] = random_uniform( -5.0, 5.0 ); + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + stdlib_strided_dztest2( len, len, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 0.0, 1.0, x, 1, 1.0, 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; + double x[ len ]; + double y[ len ]; + double t; + int i; + + struct stdlib_stats_ztest_two_sample_float64_results results = { + .rejected = false, + .alpha = 0.0, + .alternative = STDLIB_STATS_ZTEST_TWO_SIDED, + .pValue = 0.0, + .statistic = 0.0, + .ci = { 0.0, 0.0 }, + .nullValue = 0.0, + .xmean = 0.0, + .ymean = 0.0 + }; + + for ( i = 0; i < len; i++ ) { + x[ i ] = random_uniform( -5.0, 5.0 ); + y[ i ] = random_uniform( -5.0, 5.0 ); + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + stdlib_strided_dztest2_ndarray( len, len, STDLIB_STATS_ZTEST_TWO_SIDED, 0.05, 0.0, 1.0, x, 1, 0, 1.0, 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 ); +}