From 31c07a67163280c98021538b5d2333af56825c06 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Mon, 13 Jan 2025 18:10:16 +0000 Subject: [PATCH] feat: finishing up --- 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: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/dmeanors/README.md | 146 ++++++++++++++---- .../base/dmeanors/benchmark/benchmark.js | 18 +-- .../dmeanors/benchmark/benchmark.native.js | 14 +- .../dmeanors/benchmark/benchmark.ndarray.js | 18 +-- .../benchmark/benchmark.ndarray.native.js | 14 +- .../dmeanors/benchmark/c/benchmark.length.c | 50 +++++- .../@stdlib/stats/base/dmeanors/docs/repl.txt | 32 ++-- .../stats/base/dmeanors/docs/types/index.d.ts | 12 +- .../stats/base/dmeanors/examples/c/example.c | 9 +- .../stats/base/dmeanors/examples/index.js | 14 +- .../@stdlib/stats/base/dmeanors/src/main.c | 2 +- .../stats/base/dmeanors/test/test.dmeanors.js | 13 +- .../dmeanors/test/test.dmeanors.native.js | 13 +- .../stats/base/dmeanors/test/test.ndarray.js | 13 +- .../base/dmeanors/test/test.ndarray.native.js | 13 +- 15 files changed, 233 insertions(+), 148 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dmeanors/README.md b/lib/node_modules/@stdlib/stats/base/dmeanors/README.md index ef5b9edb6552..93e949222b49 100644 --- a/lib/node_modules/@stdlib/stats/base/dmeanors/README.md +++ b/lib/node_modules/@stdlib/stats/base/dmeanors/README.md @@ -51,7 +51,7 @@ The [arithmetic mean][arithmetic-mean] is defined as var dmeanors = require( '@stdlib/stats/base/dmeanors' ); ``` -#### dmeanors( N, x, stride ) +#### dmeanors( N, x, strideX ) Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array `x` using ordinary recursive summation. @@ -59,9 +59,8 @@ Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-p var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dmeanors( N, x, 1 ); +var v = dmeanors( x.length, x, 1 ); // returns ~0.3333 ``` @@ -69,18 +68,16 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: stride length for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`, ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = dmeanors( N, x, 2 ); +var v = dmeanors( 4, x, 2 ); // returns 1.25 ``` @@ -90,18 +87,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dmeanors( N, x1, 2 ); +var v = dmeanors( 4, x1, 2 ); // returns 1.25 ``` -#### dmeanors.ndarray( N, x, stride, offset ) +#### dmeanors.ndarray( N, x, strideX, offsetX ) Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array using ordinary recursive summation and alternative indexing semantics. @@ -109,26 +103,23 @@ Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-p var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = dmeanors.ndarray( N, x, 1, 0 ); +var v = dmeanors.ndarray( x.length, x, 1, 0 ); // returns ~0.33333 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [arithmetic mean][arithmetic-mean] for every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [arithmetic mean][arithmetic-mean] for every other element in `x` starting from the second element ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = dmeanors.ndarray( N, x, 2, 1 ); +var v = dmeanors.ndarray( 4, x, 2, 1 ); // returns 1.25 ``` @@ -154,18 +145,12 @@ var v = dmeanors.ndarray( N, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var dmeanors = require( '@stdlib/stats/base/dmeanors' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float64' +}); console.log( x ); var v = dmeanors( x.length, x, 1 ); @@ -176,6 +161,107 @@ console.log( v ); + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dmeanors.h" +``` + +#### stdlib_strided_dmeanors( N, \*X, strideX ) + +Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array using ordinary recursive summation. + +```c +const double x[] = { 1.0, -2.0, 2.0 }; + +double v = stdlib_strided_dmeanors( 3, x, 1 ); +// returns ~0.3333 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +```c +double stdlib_strided_dmeanors( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dmeanors_ndarray( N, \*X, strideX, offsetX ) + +Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array using ordinary recursive summation and alternative indexing semantics. + +```c +const double x[] = { 1.0, -2.0, 2.0 }; + +double v = stdlib_strided_dmeanors_ndarray( 3, x, 1, 0 ); +// returns ~0.3333 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dmeanors_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dmeanors.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the arithmetic mean: + double v = stdlib_strided_dmeanors( N, x, strideX ); + + // Print the result: + printf( "mean: %lf\n", v ); +} +``` + +
+ + + + + + +