From 3ca878a20bf66db0055346fd482b89d40961e974 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Thu, 26 Dec 2024 14:20:59 +0530 Subject: [PATCH 1/9] feat: ndarray-dnanmeanwd --- .../stats/base/dnanmeanwd/include.gypi | 2 +- .../include/stdlib/stats/base/dnanmeanwd.h | 9 +- .../stats/base/dnanmeanwd/lib/dnanmeanwd.js | 42 ++----- .../base/dnanmeanwd/lib/dnanmeanwd.native.js | 8 +- .../stats/base/dnanmeanwd/lib/index.js | 6 +- .../stats/base/dnanmeanwd/lib/ndarray.js | 18 ++- .../base/dnanmeanwd/lib/ndarray.native.js | 20 +-- .../stats/base/dnanmeanwd/manifest.json | 69 ++++++++++- .../@stdlib/stats/base/dnanmeanwd/src/addon.c | 59 +++++++++ .../stats/base/dnanmeanwd/src/addon.cpp | 117 ------------------ .../dnanmeanwd/src/{dnanmeanwd.c => mian.c} | 34 +++-- .../base/dnanmeanwd/test/test.dnanmeanwd.js | 13 +- .../dnanmeanwd/test/test.dnanmeanwd.native.js | 13 +- .../base/dnanmeanwd/test/test.ndarray.js | 33 +---- .../dnanmeanwd/test/test.ndarray.native.js | 33 +---- 15 files changed, 193 insertions(+), 283 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/addon.cpp rename lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/{dnanmeanwd.c => mian.c} (68%) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/include.gypi b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#include "stdlib/blas/base/shared.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,12 @@ extern "C" { /** * Computes the arithmetic mean of a double-precision floating-point strided array, using Welford's algorithm and ignoring `NaN` values. */ -double stdlib_strided_dnanmeanwd( const int64_t N, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnanmeanwd)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); + +/** +* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics . +*/ +double API_SUFFIX(stdlib_strided_dnanmeanwd_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js index a258c5ddbb53..011c23d922b8 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js @@ -18,6 +18,10 @@ 'use strict'; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + // MAIN // /** @@ -43,7 +47,7 @@ * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} arithmetic mean * * @example @@ -52,41 +56,11 @@ * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); * var N = x.length; * -* var v = dnanmeanwd( N, x, 1 ); +* var v = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 */ -function dnanmeanwd( N, x, stride ) { - var mu; - var ix; - var v; - var n; - var i; - - if ( N <= 0 ) { - return NaN; - } - if ( N === 1 || stride === 0 ) { - return x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - mu = 0.0; - n = 0; - for ( i = 0; i < N; i++ ) { - v = x[ ix ]; - if ( v === v ) { - n += 1; - mu += ( v-mu ) / n; - } - ix += stride; - } - if ( n === 0 ) { - return NaN; - } - return mu; +function dnanmeanwd( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.native.js index 453518fe3e67..70584f0cd0ef 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.native.js @@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} arithmetic mean * * @example @@ -39,11 +39,11 @@ var addon = require( './../src/addon.node' ); * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); * var N = x.length; * -* var v = dnanmeanwd( N, x, 1 ); +* var v = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 */ -function dnanmeanwd( N, x, stride ) { - return addon( N, x, stride ); +function dnanmeanwd( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/index.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/index.js index 9bf3e4eb75e7..0d77b310119e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/index.js @@ -30,18 +30,16 @@ * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); * var N = 3; * -* var v = dnanmeanwd( N, x, 1 ); +* var v = dnanmeanwd( 5, x, 1 ); * // returns ~0.3333 * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var dnanmeanwd = require( '@stdlib/stats/base/dnanmeanwd' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanmeanwd.ndarray( N, x, 2, 1 ); +* var v = dnanmeanwd.ndarray( 5, x, 2, 1 ); * // returns 1.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.js index 3f76936b2e87..c37bfd4800a7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.js @@ -43,21 +43,17 @@ * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} arithmetic mean * * @example * 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, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanmeanwd( N, x, 2, 1 ); -* // returns 1.25 */ -function dnanmeanwd( N, x, stride, offset ) { +function dnanmeanwd( N, x, strideX, offsetX ) { var mu; var ix; var v; @@ -67,10 +63,10 @@ function dnanmeanwd( N, x, stride, offset ) { if ( N <= 0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { - return x[ offset ]; + if ( N === 1 || strideX === 0 ) { + return x[ offsetX ]; } - ix = offset; + ix = offsetX; mu = 0.0; n = 0; for ( i = 0; i < N; i++ ) { @@ -79,7 +75,7 @@ function dnanmeanwd( N, x, stride, offset ) { n += 1; mu += ( v-mu ) / n; } - ix += stride; + ix += strideX; } if ( n === 0 ) { return NaN; diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js index 3acbd37309a2..69987ae4079c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float64Array = require( '@stdlib/array/float64' ); -var addon = require( './dnanmeanwd.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -31,27 +30,20 @@ var addon = require( './dnanmeanwd.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} arithmetic mean * * @example * 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, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanmeanwd( N, x, 2, 1 ); +* var v = dnanmeanwd( 5, x, 2, 1 ); * // returns 1.25 */ -function dnanmeanwd( N, x, stride, offset ) { - var view; - if ( stride < 0 ) { - offset += (N-1) * stride; - } - view = new Float64Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len - return addon( N, view, stride ); +function dnanmeanwd( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/manifest.json index e629924be883..99aaf0c4da72 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/manifest.json @@ -1,5 +1,8 @@ { - "options": {}, + "options": { + "task": "build", + "wasm": false + }, "fields": [ { "field": "src", @@ -24,17 +27,73 @@ ], "confs": [ { + "task": "build", + "wasm": false, "src": [ - "./src/dnanmeanwd.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float64array", + "@stdlib/napi/create-double" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] } ] } diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/addon.c b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/addon.c new file mode 100644 index 000000000000..222f988aead4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/addon.c @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* 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/base/dnanmeanwd.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float64array.h" +#include "stdlib/napi/create_double.h" + +/** +* 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, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanmeanwd( N, X, strideX ), v ); + return v; +} + +/** +* 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, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanmeanwd_ndarray( N, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/addon.cpp b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/addon.cpp deleted file mode 100644 index edfde4f3ad45..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/addon.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2020 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -#include "stdlib/stats/base/dnanmeanwd.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_stats_base_dnanmeanwd { - - /** - * Computes the arithmetic mean of a double-precision floating-point strided array, using Welford's algorithm and ignoring `NaN` values. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_dnanmeanwd( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); - return nullptr; - } - - napi_valuetype vtype2; - status = napi_typeof( env, argv[ 2 ], &vtype2 ); - assert( status == napi_ok ); - if ( vtype2 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float64_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float64Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, stdlib_strided_dnanmeanwd( N, (double *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_dnanmeanwd, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_stats_base_dnanmeanwd diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/dnanmeanwd.c b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/mian.c similarity index 68% rename from lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/dnanmeanwd.c rename to lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/mian.c index ba1d54d3a05f..57bf5f35f2e5 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/dnanmeanwd.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/mian.c @@ -17,6 +17,8 @@ */ #include "stdlib/stats/base/dnanmeanwd.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" #include /** @@ -42,24 +44,38 @@ * * @param N number of indexed elements * @param X input array -* @param stride stride length +* @param strideX stride length * @return output value */ -double stdlib_strided_dnanmeanwd( const int64_t N, const double *X, const int64_t stride ) { - int64_t ix; - int64_t i; - int64_t n; +double API_SUFFIX(stdlib_strided_dnanmeanwd)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dnanmeanwd_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @param offsetX starting index for X +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanmeanwd_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + CBLAS_INT ix; + CBLAS_INT i; + CBLAS_INT n; double mu; double v; if ( N <= 0 ) { return 0.0 / 0.0; // NaN } - if ( N == 1 || stride == 0 ) { + if ( N == 1 || strideX == 0 ) { return X[ 0 ]; } - if ( stride < 0 ) { - ix = (1-N) * stride; + if ( strideX < 0 ) { + ix = (1-N) * strideX; } else { ix = 0; } @@ -71,7 +87,7 @@ double stdlib_strided_dnanmeanwd( const int64_t N, const double *X, const int64_ n += 1; mu += ( v-mu ) / (double)n; } - ix += stride; + ix += strideX; } if ( n == 0 ) { return 0.0 / 0.0; // NaN; diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.js index 8d3e5c441607..5d8dfac2ea9e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dnanmeanwd = require( './../lib/dnanmeanwd.js' ); @@ -90,7 +89,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -106,15 +104,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2 ); + v = dnanmeanwd( 5, x, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -130,8 +126,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) NaN // 0 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, -2 ); + v = dnanmeanwd( 5, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -152,7 +147,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -169,9 +163,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dnanmeanwd( N, x1, 2 ); + v = dnanmeanwd( 5, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.native.js index 86d88d56366d..ccad2611f919 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -181,7 +180,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -197,15 +195,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2 ); + v = dnanmeanwd( 5, x, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -221,8 +217,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test NaN // 0 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, -2 ); + v = dnanmeanwd( 5, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -243,7 +238,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -260,9 +254,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = dnanmeanwd( N, x1, 2 ); + v = dnanmeanwd( 5, x1, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.js index 7dd106806e3e..e184c5d52f13 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var dnanmeanwd = require( './../lib/ndarray.js' ); @@ -90,7 +89,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -106,32 +104,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2, 0 ); - - t.strictEqual( v, 1.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; - var x; - var v; - - x = new Float64Array([ - 1.0, // 4 - 2.0, - 2.0, // 3 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 1 - 2.0, - NaN // 0 - ]); - - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, -2, 6 ); + v = dnanmeanwd( 5, x, 2, 0 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -150,7 +123,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -166,9 +138,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2, 1 ); + v = dnanmeanwd( 5, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.native.js index b6e78c8c14ab..a035cc8ecbcc 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -99,7 +98,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -115,32 +113,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2, 0 ); - - t.strictEqual( v, 1.25, 'returns expected value' ); - t.end(); -}); - -tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; - var x; - var v; - - x = new Float64Array([ - 1.0, // 4 - 2.0, - 2.0, // 3 - -7.0, - -2.0, // 2 - 3.0, - 4.0, // 1 - 2.0, - NaN // 0 - ]); - - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, -2, 6 ); + v = dnanmeanwd( 5, x, 2, 0 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -159,7 +132,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -175,9 +147,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmeanwd( N, x, 2, 1 ); + v = dnanmeanwd( 5, x, 2, 1 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); From fddb7d1577dcacb008655d6247d9e71aba7cb1d6 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Thu, 26 Dec 2024 14:22:15 +0530 Subject: [PATCH 2/9] feat: Renaming files --- .../@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js | 2 -- .../@stdlib/stats/base/dnanmeanwd/src/{mian.c => main.c} | 0 2 files changed, 2 deletions(-) rename lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/{mian.c => main.c} (100%) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js index 69987ae4079c..bc9450cad47e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js @@ -39,8 +39,6 @@ var addon = require( './../src/addon.node' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); * -* var v = dnanmeanwd( 5, x, 2, 1 ); -* // returns 1.25 */ function dnanmeanwd( N, x, strideX, offsetX ) { return addon.ndarray( N, x, strideX, offsetX ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/mian.c b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/main.c similarity index 100% rename from lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/mian.c rename to lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/main.c From 27e23e1b5a75afe543cbe0d8d021db0924ce4647 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 28 Dec 2024 00:05:52 +0530 Subject: [PATCH 3/9] feat: updating files --- .../@stdlib/stats/base/dnanmeanwd/README.md | 144 +++++++++++++++--- .../base/dnanmeanwd/benchmark/benchmark.js | 29 ++-- .../dnanmeanwd/benchmark/benchmark.native.js | 29 ++-- .../dnanmeanwd/benchmark/benchmark.ndarray.js | 29 ++-- .../benchmark/benchmark.ndarray.native.js | 29 ++-- .../dnanmeanwd/benchmark/c/benchmark.length.c | 51 +++++++ .../stats/base/dnanmeanwd/docs/repl.txt | 25 ++- .../base/dnanmeanwd/docs/types/index.d.ts | 12 +- .../base/dnanmeanwd/examples/c/example.c | 9 +- 9 files changed, 261 insertions(+), 96 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md index 8392e1999459..07b64db5c191 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md @@ -51,7 +51,7 @@ The [arithmetic mean][arithmetic-mean] is defined as var dnanmeanwd = require( '@stdlib/stats/base/dnanmeanwd' ); ``` -#### dnanmeanwd( N, x, stride ) +#### dnanmeanwd( N, x, strideX ) Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array `x`, using Welford's algorithm and ignoring `NaN` values. @@ -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, NaN, 2.0 ] ); -var N = x.length; -var v = dnanmeanwd( N, x, 1 ); +var v = dnanmeanwd( x.length, x, 1 ); // returns ~0.3333 ``` @@ -69,18 +68,17 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: index increment 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 stride 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, NaN ] ); -var N = floor( x.length / 2 ); -var v = dnanmeanwd( N, x, 2 ); +var v = dnanmeanwd( 5, x, 2 ); // returns 1.25 ``` @@ -95,13 +93,11 @@ 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, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dnanmeanwd( N, x1, 2 ); +var v = dnanmeanwd( 5, x1, 2 ); // returns 1.25 ``` -#### dnanmeanwd.ndarray( N, x, stride, offset ) +#### dnanmeanwd.ndarray( N, x, strideX, offsetX ) Computes the [arithmetic mean][arithmetic-mean] of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. @@ -109,26 +105,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, NaN, 2.0 ] ); -var N = x.length; -var v = dnanmeanwd.ndarray( N, x, 1, 0 ); +var v = dnanmeanwd.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, NaN ] ); -var N = floor( x.length / 2 ); -var v = dnanmeanwd.ndarray( N, x, 2, 1 ); +var v = dnanmeanwd.ndarray( 5, x, 2, 1 ); // returns 1.25 ``` @@ -180,6 +173,121 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dnanmeanwd.h" +``` + +#### stdlib_strided_dnanmeanwd( N, \*X, strideX ) + +Computes the [range][range] of a double-precision floating-point strided array `x`, ignoring `NaN` values. + +```c +const double x[] = { 1.0, 0.0/0.0, 3.0, -4.0 }; + +double v = stdlib_strided_dnanmeanwd( 5, 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_dnanmeanwd( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnanmeanwd_ndarray( N, \*X, strideX, offsetX ) + +Computes the [range][range] of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. + +```c +const double x[] = { 1.0, 0.0/0.0, 3.0, -4.0 }; + +double v = stdlib_strided_dnanmeanwd_ndarray( 5, x, 1, 0 ); +// returns 7.0 +``` + +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_dnanmeanwd_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dnanmeanwd.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; + + // Specify the number of elements: + const int N = 6; + + // Specify the stride length: + const int strideX = 2; + + // Compute the arithmetic mean: + double v = stdlib_strided_dnanmeanwd( N, x, strideX ); + + // Print the result: + printf( "mean: %lf\n", v ); +} +``` + +
+ + + +
+ + + * * *
diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.js index 725749785047..d620bb29ea54 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.js @@ -21,16 +21,29 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dnanmeanwd = require( './../lib/dnanmeanwd.js' ); // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.2 ) ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -39,17 +52,7 @@ var dnanmeanwd = require( './../lib/dnanmeanwd.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.native.js index 49d5321307e9..dadc63fcaaf9 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -40,6 +41,18 @@ var opts = { // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.2 ) ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -48,17 +61,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.js index f2e9d31a0fc1..7318fcea24c2 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.js @@ -21,16 +21,29 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var pkg = require( './../package.json' ).name; var dnanmeanwd = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.2 ) ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -39,17 +52,7 @@ var dnanmeanwd = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.native.js index a62fc15c5406..84c3664e8075 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -40,6 +41,18 @@ var opts = { // FUNCTIONS // +/** +* Returns a random value or `NaN`. +* +* @returns {number} random number or `NaN` +*/ +function rand() { + if ( bernoulli( 0.2 ) ) { + return NaN; + } + return uniform( -10.0, 10.0 ); +} + /** * Creates a benchmark function. * @@ -48,17 +61,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float64Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*20.0 ) - 10.0; - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c index 3dce6d5a6c7f..6ad2693ba03d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c @@ -107,6 +107,7 @@ static double benchmark( int iterations, int len ) { v = 0.0; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_dnanmeanwd( len, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -120,6 +121,44 @@ static double benchmark( int iterations, int len ) { 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 v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + if ( rand_double() < 0.2 ) { + x[ i ] = 0.0 / 0.0; // NaN + } else { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar + v = stdlib_strided_dnanmeanwd_ndarray( len, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -142,6 +181,18 @@ int main( void ) { 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 ); elapsed = benchmark( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt index 33f938b1969d..b5ed0b1d64aa 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the arithmetic mean of a double-precision floating-point strided array, using Welford's algorithm and ignoring `NaN` values. - The `N` and `stride` parameters determine which elements in `x` are accessed + The `N` and stride parameters determine which elements in `x` are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed @@ -21,8 +21,8 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. Returns ------- @@ -36,19 +36,15 @@ > {{alias}}( x.length, x, 1 ) ~0.3333 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, x, stride ) ~0.3333 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 3, x1, stride ) ~-0.3333 {{alias}}.ndarray( N, x, stride, offset ) @@ -68,8 +64,8 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. offset: integer Starting index. @@ -88,8 +84,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) ~-0.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/types/index.d.ts index d674d840c966..9c5697ea52ca 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/types/index.d.ts @@ -27,7 +27,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns arithmetic mean * * @example @@ -38,15 +38,15 @@ interface Routine { * var v = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 */ - ( N: number, x: Float64Array, stride: number ): number; + ( N: number, x: Float64Array, strideX: number ): number; /** * Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns arithmetic mean * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = dnanmeanwd.ndarray( x.length, x, 1, 0 ); * // returns ~0.3333 */ - ndarray( N: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** @@ -65,7 +65,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns arithmetic mean * * @example diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/examples/c/example.c index 03e6af11ea32..8d795c27ee78 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dnanmeanwd.h" -#include #include int main( void ) { // Create a strided array: - double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; + const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; // Specify the number of elements: - int64_t N = 6; + const int N = 6; // Specify the stride length: - int64_t stride = 2; + const int strideX = 2; // Compute the arithmetic mean: - double v = stdlib_strided_dnanmeanwd( N, x, stride ); + double v = stdlib_strided_dnanmeanwd( N, x, strideX ); // Print the result: printf( "mean: %lf\n", v ); From 4d905ec2c9169628d1a6f0a3b5216a2f8169b554 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 28 Dec 2024 00:38:30 +0530 Subject: [PATCH 4/9] fix: lint error --- .../@stdlib/stats/base/dnanmeanwd/README.md | 26 ++++++++----------- .../dnanmeanwd/benchmark/c/benchmark.length.c | 2 +- .../stats/base/dnanmeanwd/docs/repl.txt | 9 ++++--- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md index 07b64db5c191..f5bbfd5c25d7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md @@ -92,9 +92,6 @@ 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, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - -var v = dnanmeanwd( 5, x1, 2 ); -// returns 1.25 ``` #### dnanmeanwd.ndarray( N, x, strideX, offsetX ) @@ -120,9 +117,6 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); - -var v = dnanmeanwd.ndarray( 5, x, 2, 1 ); -// returns 1.25 ```
@@ -211,6 +205,7 @@ double v = stdlib_strided_dnanmeanwd( 5, x, 1 ); ``` 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`. @@ -231,6 +226,7 @@ double v = stdlib_strided_dnanmeanwd_ndarray( 5, x, 1, 0 ); ``` 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`. @@ -264,19 +260,19 @@ double stdlib_strided_dnanmeanwd_ndarray( const CBLAS_INT N, const double *X, co int main( void ) { // Create a strided array: - const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; + const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; - // Specify the number of elements: - const int N = 6; + // Specify the number of elements: + const int N = 6; - // Specify the stride length: - const int strideX = 2; + // Specify the stride length: + const int strideX = 2; - // Compute the arithmetic mean: - double v = stdlib_strided_dnanmeanwd( N, x, strideX ); + // Compute the arithmetic mean: + double v = stdlib_strided_dnanmeanwd( N, x, strideX ); - // Print the result: - printf( "mean: %lf\n", v ); + // Print the result: + printf( "mean: %lf\n", v ); } ``` diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c index 6ad2693ba03d..2d2b844ea5d2 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double v; diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt index b5ed0b1d64aa..8e107d74b71e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt @@ -38,16 +38,17 @@ // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN ] ); - > {{alias}}( 3, x, stride ) + > {{alias}}( 3, x, strideX ) ~0.3333 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, x1, stride ) + > {{alias}}( 3, x1, strideX ) ~-0.3333 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. @@ -67,7 +68,7 @@ strideX: integer Stride Length. - offset: integer + offsetX: integer Starting index. Returns From 8d4f3d6ad0b39ee5fc25d6a7aeb44d24023f5675 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 28 Dec 2024 00:46:57 +0530 Subject: [PATCH 5/9] fix: CI error --- lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md | 6 +++--- .../stats/base/dnanmeanwd/benchmark/c/benchmark.length.c | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md index f5bbfd5c25d7..ed373e073906 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md @@ -195,7 +195,7 @@ console.log( v ); #### stdlib_strided_dnanmeanwd( N, \*X, strideX ) -Computes the [range][range] of a double-precision floating-point strided array `x`, ignoring `NaN` values. +Computes the [mean][mean] of a double-precision floating-point strided array `x`, ignoring `NaN` values. ```c const double x[] = { 1.0, 0.0/0.0, 3.0, -4.0 }; @@ -216,7 +216,7 @@ double stdlib_strided_dnanmeanwd( const CBLAS_INT N, const double *X, const CBLA #### stdlib_strided_dnanmeanwd_ndarray( N, \*X, strideX, offsetX ) -Computes the [range][range] of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. +Computes the [mean][mean] of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. ```c const double x[] = { 1.0, 0.0/0.0, 3.0, -4.0 }; @@ -259,7 +259,7 @@ double stdlib_strided_dnanmeanwd_ndarray( const CBLAS_INT N, const double *X, co #include int main( void ) { - // Create a strided array: + // Create a strided array: const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; // Specify the number of elements: diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c index 2d2b844ea5d2..7876ee3ceac5 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/c/benchmark.length.c @@ -193,7 +193,6 @@ int main( void ) { count += 1; printf( "# c::%s:ndarray:len=%d\n", NAME, len ); elapsed = benchmark2( iter, len ); - elapsed = benchmark( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } From dce813384ed7e8553b32bfe182415b0ef3d1f1ff Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 28 Dec 2024 00:58:30 +0530 Subject: [PATCH 6/9] fix: CI error --- lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md | 4 ++-- lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md index ed373e073906..0c08b7455510 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md @@ -195,7 +195,7 @@ console.log( v ); #### stdlib_strided_dnanmeanwd( N, \*X, strideX ) -Computes the [mean][mean] of a double-precision floating-point strided array `x`, ignoring `NaN` values. +Computes the mean value of a double-precision floating-point strided array `x`, ignoring `NaN` values. ```c const double x[] = { 1.0, 0.0/0.0, 3.0, -4.0 }; @@ -216,7 +216,7 @@ double stdlib_strided_dnanmeanwd( const CBLAS_INT N, const double *X, const CBLA #### stdlib_strided_dnanmeanwd_ndarray( N, \*X, strideX, offsetX ) -Computes the [mean][mean] of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. +Computes the mean value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. ```c const double x[] = { 1.0, 0.0/0.0, 3.0, -4.0 }; diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt index 8e107d74b71e..2c8059c0d0aa 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt @@ -38,13 +38,13 @@ // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN ] ); - > {{alias}}( 3, x, strideX ) + > {{alias}}( 3, x, 2 ) ~0.3333 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > {{alias}}( 3, x1, strideX ) + > {{alias}}( 3, x1, 2 ) ~-0.3333 From 6448072011e26bf4179b979ed7940ee97b7e3a12 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Fri, 3 Jan 2025 01:23:13 +0530 Subject: [PATCH 7/9] chore: minor clean up --- .../@stdlib/stats/base/dnanmeanwd/README.md | 26 +++++++++++-------- .../stats/base/dnanmeanwd/docs/repl.txt | 10 +++---- .../include/stdlib/stats/base/dnanmeanwd.h | 2 +- .../stats/base/dnanmeanwd/lib/dnanmeanwd.js | 1 - .../base/dnanmeanwd/lib/dnanmeanwd.native.js | 1 - .../stats/base/dnanmeanwd/lib/index.js | 5 ++-- .../stats/base/dnanmeanwd/lib/ndarray.js | 2 ++ .../base/dnanmeanwd/lib/ndarray.native.js | 2 ++ .../@stdlib/stats/base/dnanmeanwd/src/main.c | 18 +++++-------- .../base/dnanmeanwd/test/test.dnanmeanwd.js | 4 +-- .../dnanmeanwd/test/test.dnanmeanwd.native.js | 4 +-- .../base/dnanmeanwd/test/test.ndarray.js | 24 ++++++++++++++++- .../dnanmeanwd/test/test.ndarray.native.js | 24 ++++++++++++++++- 13 files changed, 84 insertions(+), 39 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md index 0c08b7455510..0aa7eae79bc2 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md @@ -74,11 +74,10 @@ The `N` and stride parameters determine which elements in the stride array are a ```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, NaN ] ); -var v = dnanmeanwd( 5, x, 2 ); +var v = dnanmeanwd( 4, x, 2 ); // returns 1.25 ``` @@ -88,10 +87,12 @@ 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, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var v = dnanmeanwd( 4, x1, 2 ); +// returns 1.25 ``` #### dnanmeanwd.ndarray( N, x, strideX, offsetX ) @@ -117,6 +118,9 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); + +var v = dnanmeanwd( 4, x, 2, 1 ); +// returns 1.25 ``` @@ -195,13 +199,13 @@ console.log( v ); #### stdlib_strided_dnanmeanwd( N, \*X, strideX ) -Computes the mean value of a double-precision floating-point strided array `x`, ignoring `NaN` values. +Computes the arithmetic mean of a double-precision floating-point strided array `x`, using Welford's algorithm and ignoring `NaN` values. ```c -const double x[] = { 1.0, 0.0/0.0, 3.0, -4.0 }; +const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; -double v = stdlib_strided_dnanmeanwd( 5, x, 1 ); -// returns 0.3333 +double v = stdlib_strided_dnanmeanwd( 6, x, 2 ); +// returns 1.25 ``` The function accepts the following arguments: @@ -216,13 +220,13 @@ double stdlib_strided_dnanmeanwd( const CBLAS_INT N, const double *X, const CBLA #### stdlib_strided_dnanmeanwd_ndarray( N, \*X, strideX, offsetX ) -Computes the mean value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. +Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. ```c -const double x[] = { 1.0, 0.0/0.0, 3.0, -4.0 }; +const double x[] = { 1.0, 2.0, 0.0/0.0, 3.0, 0.0/0.0, 4.0, 5.0, 6.0, 0.0/0.0, 7.0, 8.0, 0.0/0.0 }; -double v = stdlib_strided_dnanmeanwd_ndarray( 5, x, 1, 0 ); -// returns 7.0 +double v = stdlib_strided_dnanmeanwd_ndarray( 6, x, 2, 0 ); +// returns 1.25 ``` The function accepts the following arguments: diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt index 2c8059c0d0aa..9a707a6850a8 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/docs/repl.txt @@ -3,8 +3,8 @@ Computes the arithmetic mean of a double-precision floating-point strided array, using Welford's algorithm and ignoring `NaN` values. - The `N` and stride parameters determine which elements in `x` are accessed - at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -22,7 +22,7 @@ Input array. strideX: integer - Stride Length. + Stride length. Returns ------- @@ -54,7 +54,7 @@ indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters @@ -66,7 +66,7 @@ Input array. strideX: integer - Stride Length. + Stride length. offsetX: integer Starting index. diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/include/stdlib/stats/base/dnanmeanwd.h b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/include/stdlib/stats/base/dnanmeanwd.h index ecfdb5bcc818..8cbe79514434 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/include/stdlib/stats/base/dnanmeanwd.h +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/include/stdlib/stats/base/dnanmeanwd.h @@ -34,7 +34,7 @@ extern "C" { double API_SUFFIX(stdlib_strided_dnanmeanwd)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); /** -* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics . +* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. */ double API_SUFFIX(stdlib_strided_dnanmeanwd_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js index 011c23d922b8..918253cbd694 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js @@ -54,7 +54,6 @@ var ndarray = require( './ndarray.js' ); * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * * var v = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.native.js index 70584f0cd0ef..758ec4ccd4f5 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.native.js @@ -37,7 +37,6 @@ var addon = require( './../src/addon.node' ); * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * * var v = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/index.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/index.js index 0d77b310119e..9f251ed36e80 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/index.js @@ -28,9 +28,8 @@ * var dnanmeanwd = require( '@stdlib/stats/base/dnanmeanwd' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = 3; * -* var v = dnanmeanwd( 5, x, 1 ); +* var v = dnanmeanwd( x.length, x, 1 ); * // returns ~0.3333 * * @example @@ -39,7 +38,7 @@ * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); * -* var v = dnanmeanwd.ndarray( 5, x, 2, 1 ); +* var v = dnanmeanwd.ndarray( 4, x, 2, 1 ); * // returns 1.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.js index c37bfd4800a7..4beb52be8514 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.js @@ -52,6 +52,8 @@ * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); * +* var v = dnanmeanwd( 4, x, 2, 1 ); +* // returns 1.25 */ function dnanmeanwd( N, x, strideX, offsetX ) { var mu; diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js index bc9450cad47e..b10036df551d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/ndarray.native.js @@ -39,6 +39,8 @@ var addon = require( './../src/addon.node' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); * +* var v = dnanmeanwd( 4, x, 2, 1 ); +* // returns 1.25 */ function dnanmeanwd( N, x, strideX, offsetX ) { return addon.ndarray( N, x, strideX, offsetX ); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/main.c index 57bf5f35f2e5..a0a7c9c37e73 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* 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. @@ -42,10 +42,10 @@ * - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022](https://doi.org/10.1080/00401706.1962.10490022). * - van Reeken, A. J. 1968. "Letters to the Editor: Dealing with Neely's Algorithms." _Communications of the ACM_ 11 (3): 149–50. doi:[10.1145/362929.362961](https://doi.org/10.1145/362929.362961). * -* @param N number of indexed elements -* @param X input array +* @param N number of indexed elements +* @param X input array * @param strideX stride length -* @return output value +* @return output value */ double API_SUFFIX(stdlib_strided_dnanmeanwd)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) { const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); @@ -53,7 +53,7 @@ double API_SUFFIX(stdlib_strided_dnanmeanwd)( const CBLAS_INT N, const double *X } /** -* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. +* Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics. * * @param N number of indexed elements * @param X input array @@ -72,13 +72,9 @@ double API_SUFFIX(stdlib_strided_dnanmeanwd_ndarray)( const CBLAS_INT N, const d return 0.0 / 0.0; // NaN } if ( N == 1 || strideX == 0 ) { - return X[ 0 ]; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; + return X[ offsetX ]; } + ix = offsetX; mu = 0.0; n = 0; for ( i = 0; i < N; i++ ) { diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.js index 5d8dfac2ea9e..baed8323682c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.js @@ -104,7 +104,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN // 4 ]); - v = dnanmeanwd( 5, x, 2 ); + v = dnanmeanwd( 4, x, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -126,7 +126,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) NaN // 0 ]); - v = dnanmeanwd( 5, x, -2 ); + v = dnanmeanwd( 4, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.native.js index ccad2611f919..cf5754b12d8e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.dnanmeanwd.native.js @@ -195,7 +195,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN // 4 ]); - v = dnanmeanwd( 5, x, 2 ); + v = dnanmeanwd( 4, x, 2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); @@ -217,7 +217,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test NaN // 0 ]); - v = dnanmeanwd( 5, x, -2 ); + v = dnanmeanwd( 4, x, -2 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.js index e184c5d52f13..a911e86e95c7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.js @@ -104,7 +104,29 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN // 4 ]); - v = dnanmeanwd( 5, x, 2, 0 ); + v = dnanmeanwd( 4, x, 2, 0 ); + + t.strictEqual( v, 1.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', function test( t ) { + var x; + var v; + + x = new Float64Array([ + 1.0, // 4 + 2.0, + 2.0, // 3 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 1 + 2.0, + NaN // 0 + ]); + + v = dnanmeanwd( 4, x, -2, 6 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.native.js index a035cc8ecbcc..574982c528a2 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/test/test.ndarray.native.js @@ -113,7 +113,29 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN // 4 ]); - v = dnanmeanwd( 5, x, 2, 0 ); + v = dnanmeanwd( 4, x, 2, 0 ); + + t.strictEqual( v, 1.25, 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { + var x; + var v; + + x = new Float64Array([ + 1.0, // 4 + 2.0, + 2.0, // 3 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 1 + 2.0, + NaN // 0 + ]); + + v = dnanmeanwd( 4, x, -2, 6 ); t.strictEqual( v, 1.25, 'returns expected value' ); t.end(); From 5d38ef195c7fbc1f7c575762c492fdf240b43641 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 2 Jan 2025 15:12:13 -0800 Subject: [PATCH 8/9] docs: fix example Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md index 0aa7eae79bc2..2ee2d1fb9649 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/README.md @@ -119,7 +119,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); -var v = dnanmeanwd( 4, x, 2, 1 ); +var v = dnanmeanwd.ndarray( 4, x, 2, 1 ); // returns 1.25 ``` From 329395549877646ada68d2e41765ad56d549731e Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Fri, 3 Jan 2025 11:42:22 +0530 Subject: [PATCH 9/9] chore: bench clean up --- .../@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.js | 1 + .../@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.native.js | 1 + .../stats/base/dnanmeanwd/benchmark/benchmark.ndarray.js | 1 + .../stats/base/dnanmeanwd/benchmark/benchmark.ndarray.native.js | 1 + .../@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js | 2 ++ 5 files changed, 6 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.js index d620bb29ea54..5b3d7bd98e6f 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.js @@ -35,6 +35,7 @@ var dnanmeanwd = require( './../lib/dnanmeanwd.js' ); /** * Returns a random value or `NaN`. * +* @private * @returns {number} random number or `NaN` */ function rand() { diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.native.js index dadc63fcaaf9..45aaba61cc4c 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.native.js @@ -44,6 +44,7 @@ var opts = { /** * Returns a random value or `NaN`. * +* @private * @returns {number} random number or `NaN` */ function rand() { diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.js index 7318fcea24c2..c22b93247335 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.js @@ -35,6 +35,7 @@ var dnanmeanwd = require( './../lib/ndarray.js' ); /** * Returns a random value or `NaN`. * +* @private * @returns {number} random number or `NaN` */ function rand() { diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.native.js index 84c3664e8075..77bdfc9108e7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/benchmark/benchmark.ndarray.native.js @@ -44,6 +44,7 @@ var opts = { /** * Returns a random value or `NaN`. * +* @private * @returns {number} random number or `NaN` */ function rand() { diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js index 918253cbd694..26f73054c35b 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanwd/lib/dnanmeanwd.js @@ -18,6 +18,8 @@ 'use strict'; +// MODULES // + var stride2offset = require( '@stdlib/strided/base/stride2offset' ); var ndarray = require( './ndarray.js' );