From 21ec1752b6a2d60601c7ff5f115120fa17debf35 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Wed, 25 Dec 2024 10:30:16 +0000 Subject: [PATCH 1/9] feat: add C ndarray interface and refactor implementation --- .../include/stdlib/stats/base/dnanmaxabs.h | 9 +- .../stats/base/dnanmaxabs/src/addon.cpp | 117 ------------------ .../stats/base/dnanmaxabs/src/dnanmaxabs.c | 72 ----------- .../@stdlib/stats/base/dnanmaxabs/src/main.c | 83 +++++++++++++ 4 files changed, 90 insertions(+), 191 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/addon.cpp delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/dnanmaxabs.c create mode 100644 lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/main.c diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/include/stdlib/stats/base/dnanmaxabs.h b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/include/stdlib/stats/base/dnanmaxabs.h index 312a384f9da6..11fc86b71eb7 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/include/stdlib/stats/base/dnanmaxabs.h +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/include/stdlib/stats/base/dnanmaxabs.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_DNANMAXABS_H #define STDLIB_STATS_BASE_DNANMAXABS_H -#include +#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 maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values. */ -double stdlib_strided_dnanmaxabs( const int64_t N, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnanmaxabs)( 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_dnanmaxabs_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/dnanmaxabs/src/addon.cpp b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/addon.cpp deleted file mode 100644 index e2531309fa78..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/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/dnanmaxabs.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_stats_base_dnanmaxabs { - - /** - * Computes the maximum absolute value of a double-precision floating-point strided array, 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_dnanmaxabs( 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_dnanmaxabs( 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_dnanmaxabs, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_stats_base_dnanmaxabs diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/dnanmaxabs.c b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/dnanmaxabs.c deleted file mode 100644 index bdffc5c1ce31..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/dnanmaxabs.c +++ /dev/null @@ -1,72 +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/dnanmaxabs.h" -#include "stdlib/math/base/assert/is_nan.h" -#include -#include - -/** -* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values. -* -* @param N number of indexed elements -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dnanmaxabs( const int64_t N, const double *X, const int64_t stride ) { - double max; - int64_t ix; - int64_t i; - double v; - - if ( N <= 0 ) { - return 0.0 / 0.0; // NaN - } - if ( N == 1 || stride == 0 ) { - return fabs( X[ 0 ] ); - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - for ( i = 0; i < N; i++ ) { - v = X[ ix ]; - if ( v == v ) { - break; - } - ix += stride; - } - if ( i == N ) { - return 0.0 / 0.0; // NaN - } - max = fabs( v ); - i += 1; - for (; i < N; i++ ) { - ix += stride; - v = fabs( X[ ix ] ); - if ( stdlib_base_is_nan( v ) ) { - continue; - } - if ( v > max ) { - max = v; - } - } - return max; -} diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/main.c new file mode 100644 index 000000000000..38c252e9a0b6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/main.c @@ -0,0 +1,83 @@ +/** +* @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/dnanmaxabs.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/math/base/special/abs.h" +#include "stdlib/strided/base/stride2offset.h" + +/** +* Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanmaxabs)( 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_dnanmaxabs_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_dnanmaxabs_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + double max; + CBLAS_INT ix; + CBLAS_INT i; + double v; + + if ( N <= 0 ) { + return 0.0 / 0.0; // NaN + } + if ( N == 1 || strideX == 0 ) { + return stdlib_base_abs( X[ offsetX ] ); + } + ix = offsetX; + for ( i = 0; i < N; i++ ) { + v = X[ ix ]; + if ( v == v ) { + break; + } + ix += strideX; + } + if ( i == N ) { + return 0.0 / 0.0; // NaN + } + max = stdlib_base_abs( v ); + i += 1; + for (; i < N; i++ ) { + ix += strideX; + v = stdlib_base_abs( X[ ix ] ); + if ( stdlib_base_is_nan( v ) ) { + continue; + } + if ( v > max ) { + max = v; + } + } + return max; +} From ebcee0cf64119437395827bcd7d20a01a8d6c2fe Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Wed, 25 Dec 2024 11:06:52 +0000 Subject: [PATCH 2/9] feat: add C ndarray interface and refactor js implementation --- 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: passed - 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: passed - 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 --- --- .../stats/base/dnanmaxabs/include.gypi | 2 +- .../stats/base/dnanmaxabs/lib/dnanmaxabs.js | 51 ++----------- .../base/dnanmaxabs/lib/dnanmaxabs.native.js | 9 +-- .../stats/base/dnanmaxabs/lib/index.js | 7 +- .../stats/base/dnanmaxabs/lib/ndarray.js | 16 ++-- .../base/dnanmaxabs/lib/ndarray.native.js | 20 ++--- .../stats/base/dnanmaxabs/manifest.json | 75 +++++++++++++++++-- .../@stdlib/stats/base/dnanmaxabs/src/addon.c | 60 +++++++++++++++ 8 files changed, 157 insertions(+), 83 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/addon.c diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/include.gypi b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' max ) { - max = v; - } - } - return max; +function dnanmaxabs( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/dnanmaxabs.native.js b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/dnanmaxabs.native.js index 70957d663c8e..2cba1638cebd 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/dnanmaxabs.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/dnanmaxabs.native.js @@ -30,20 +30,19 @@ 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} maximum absolute value * * @example * var Float64Array = require( '@stdlib/array/float64' ); * * var x = new Float64Array( [ 1.0, -2.0, 2.0, NaN ] ); -* var N = x.length; * -* var v = dnanmaxabs( N, x, 1 ); +* var v = dnanmaxabs( x.length, x, 1 ); * // returns 2.0 */ -function dnanmaxabs( N, x, stride ) { - return addon( N, x, stride ); +function dnanmaxabs( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/index.js b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/index.js index 83b094f2e467..146a71a8e399 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/index.js @@ -28,20 +28,17 @@ * var dnanmaxabs = require( '@stdlib/stats/base/dnanmaxabs' ); * * var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -* var N = x.length; * -* var v = dnanmaxabs( N, x, 1 ); +* var v = dnanmaxabs( x.length, x, 1 ); * // returns 2.0 * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var dnanmaxabs = require( '@stdlib/stats/base/dnanmaxabs' ); * * var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanmaxabs.ndarray( N, x, 2, 1 ); +* var v = dnanmaxabs.ndarray( 5, x, 2, 1 ); * // returns 4.0 */ diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/ndarray.js index c22c1b9e8380..86b189cc00af 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/ndarray.js @@ -31,8 +31,8 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * @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} maximum absolute value * * @example @@ -45,7 +45,7 @@ var abs = require( '@stdlib/math/base/special/abs' ); * var v = dnanmaxabs( N, x, 2, 1 ); * // returns 4.0 */ -function dnanmaxabs( N, x, stride, offset ) { +function dnanmaxabs( N, x, strideX, offsetX ) { var max; var ix; var v; @@ -54,16 +54,16 @@ function dnanmaxabs( N, x, stride, offset ) { if ( N <= 0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { - return abs( x[ offset ] ); + if ( N === 1 || strideX === 0 ) { + return abs( x[ offsetX ] ); } - ix = offset; + ix = offsetX; for ( i = 0; i < N; i++ ) { v = x[ ix ]; if ( v === v ) { break; } - ix += stride; + ix += strideX; } if ( i === N ) { return NaN; @@ -71,7 +71,7 @@ function dnanmaxabs( N, x, stride, offset ) { max = abs( v ); i += 1; for ( i; i < N; i++ ) { - ix += stride; + ix += strideX; v = abs( x[ ix ] ); if ( isnan( v ) ) { continue; diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/ndarray.native.js index ad762159c8d5..9699e7c4f4d8 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float64Array = require( '@stdlib/array/float64' ); -var addon = require( './dnanmaxabs.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -31,27 +30,20 @@ var addon = require( './dnanmaxabs.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} maximum absolute value * * @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, NaN ] ); -* var N = floor( x.length / 2 ); * -* var v = dnanmaxabs( N, x, 2, 1 ); +* var v = dnanmaxabs( 5, x, 2, 1 ); * // returns 4.0 */ -function dnanmaxabs( 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 dnanmaxabs( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/manifest.json index a8ccf69a4239..2b2d07df022e 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/manifest.json @@ -1,5 +1,8 @@ { - "options": {}, + "options": { + "task": "build", + "wasm": false + }, "fields": [ { "field": "src", @@ -24,18 +27,80 @@ ], "confs": [ { + "task": "build", + "wasm": false, "src": [ - "./src/dnanmaxabs.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/special/abs", + "@stdlib/math/base/assert/is-nan", + "@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", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/abs" + ] + }, + { + "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/abs" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nan" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/abs" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/addon.c b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/addon.c new file mode 100644 index 000000000000..3e1823e87f77 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/addon.c @@ -0,0 +1,60 @@ +/** +* @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/dnanmaxabs.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" +#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, 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_dnanmaxabs( 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_dnanmaxabs_ndarray( N, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) From d2018d0f5e8c3633d5c8a60d374877175cd88fe8 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Wed, 25 Dec 2024 11:11:54 +0000 Subject: [PATCH 3/9] refactor: update tests --- 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: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed --- --- .../@stdlib/stats/base/dnanmaxabs/src/main.c | 2 +- .../stats/base/dnanmaxabs/test/test.dnanmaxabs.js | 13 +++---------- .../base/dnanmaxabs/test/test.dnanmaxabs.native.js | 13 +++---------- .../stats/base/dnanmaxabs/test/test.ndarray.js | 13 +++---------- .../base/dnanmaxabs/test/test.ndarray.native.js | 13 +++---------- 5 files changed, 13 insertions(+), 41 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/main.c b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/main.c index 38c252e9a0b6..28f2351556de 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/src/main.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2024 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.dnanmaxabs.js b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.dnanmaxabs.js index 7e68a25b83aa..2ab39864fef1 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.dnanmaxabs.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.dnanmaxabs.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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -96,7 +95,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; @@ -113,15 +111,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, 2 ); + v = dnanmaxabs( 5, x, 2 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -138,8 +134,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, -2 ); + v = dnanmaxabs( 5, x, -2 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); @@ -160,7 +155,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([ @@ -178,9 +172,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 = dnanmaxabs( N, x1, 2 ); + v = dnanmaxabs( 5, x1, 2 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.dnanmaxabs.native.js b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.dnanmaxabs.native.js index 2330c2d7d5c1..5d37bb55f5dd 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.dnanmaxabs.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.dnanmaxabs.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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -187,7 +186,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; @@ -204,15 +202,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, 2 ); + v = dnanmaxabs( 5, x, 2 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -229,8 +225,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, -2 ); + v = dnanmaxabs( 5, x, -2 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); @@ -251,7 +246,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([ @@ -269,9 +263,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 = dnanmaxabs( N, x1, 2 ); + v = dnanmaxabs( 5, x1, 2 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.ndarray.js index 4c0efe4521eb..206cf3c0d39d 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -96,7 +95,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; @@ -113,15 +111,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, 2, 0 ); + v = dnanmaxabs( 5, x, 2, 0 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -138,8 +134,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, -2, 8 ); + v = dnanmaxabs( 5, x, -2, 8 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); @@ -158,7 +153,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; @@ -174,9 +168,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, 2, 1 ); + v = dnanmaxabs( 5, x, 2, 1 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.ndarray.native.js index a45200d9c1e5..0aa09e5ce16b 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/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 isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' ); var Float64Array = require( '@stdlib/array/float64' ); @@ -105,7 +104,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; @@ -122,15 +120,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, 2, 0 ); + v = dnanmaxabs( 5, x, 2, 0 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -147,8 +143,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, -2, 8 ); + v = dnanmaxabs( 5, x, -2, 8 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); @@ -167,7 +162,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; @@ -183,9 +177,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = dnanmaxabs( N, x, 2, 1 ); + v = dnanmaxabs( 5, x, 2, 1 ); t.strictEqual( v, 4.0, 'returns expected value' ); t.end(); From ed3402043aa8d82f95cc613e6966393f37166f6d Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Wed, 25 Dec 2024 18:17:30 +0000 Subject: [PATCH 4/9] refactor: refactor docs and 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: passed - 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: passed - task: lint_c_benchmarks status: na - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../stats/base/dnanmaxabs/docs/repl.txt | 32 ++++++++----------- .../base/dnanmaxabs/docs/types/index.d.ts | 12 +++---- .../base/dnanmaxabs/examples/c/example.c | 9 +++--- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/docs/repl.txt index 5a1ebbc3560f..46ca21ade5a4 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the maximum absolute value of a double-precision floating-point strided array, 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. @@ -19,8 +19,8 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. Returns ------- @@ -34,22 +34,19 @@ > {{alias}}( x.length, x, 1 ) 2.0 - // 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, 2 ) 2.0 // 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, 2 ) 2.0 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. @@ -66,10 +63,10 @@ x: Float64Array Input array. - stride: integer - Index increment. + strideX: integer + Stride Length. - offset: integer + offsetX: integer Starting index. Returns @@ -86,8 +83,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 ) 2.0 See Also diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/docs/types/index.d.ts index aa7b413cecae..d259fe40ee1a 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/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 maximum absolute value * * @example @@ -38,15 +38,15 @@ interface Routine { * var v = dnanmaxabs( x.length, x, 1 ); * // returns 2.0 */ - ( N: number, x: Float64Array, stride: number ): number; + ( N: number, x: Float64Array, strideX: number ): number; /** * 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 stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns maximum absolute value * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = dnanmaxabs.ndarray( x.length, x, 1, 0 ); * // returns 2.0 */ - 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 maximum absolute value * * @example diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/examples/c/example.c index 0392b30fa4a5..b92145ce6ac5 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/dnanmaxabs.h" -#include #include int main( void ) { // Create a strided array: - double x[] = { 1.0, -2.0, -3.0, 4.0, -5.0, -6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 }; + const double x[] = { 1.0, -2.0, -3.0, 4.0, -5.0, -6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 }; // Specify the number of elements: - int64_t N = 5; + const int N = 5; // Specify the stride length: - int64_t stride = 2; + const int strideX = 2; // Compute the maximum absolute value: - double v = stdlib_strided_dnanmaxabs( N, x, stride ); + double v = stdlib_strided_dnanmaxabs( N, x, strideX ); // Print the result: printf( "maxabs: %lf\n", v ); From 0a4f57951aef2b9c70d07d0d18942b535b1ad8dc Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Wed, 25 Dec 2024 18:24:14 +0000 Subject: [PATCH 5/9] feat: add C ndarray 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: na - 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: passed - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../dnanmaxabs/benchmark/c/benchmark.length.c | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/benchmark/c/benchmark.length.c index fc0e1a1a8dc7..23d9ff2454e5 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/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; @@ -111,6 +111,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_dnanmaxabs( len, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -124,6 +125,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_dnanmaxabs_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. */ @@ -146,7 +185,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, 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 ); } From acc8468e4558a7c32bcc1bd53e68299a2f6d401d Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Wed, 25 Dec 2024 19:19:23 +0000 Subject: [PATCH 6/9] docs: update README.md --- 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: 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: passed - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/stats/base/dnanmaxabs/README.md | 148 +++++++++++++++--- .../@stdlib/stats/base/dnanmaxabs/src/main.c | 2 +- 2 files changed, 129 insertions(+), 21 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/README.md b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/README.md index 7d891dc1e842..3f665e74f3c4 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmaxabs/README.md +++ b/lib/node_modules/@stdlib/stats/base/dnanmaxabs/README.md @@ -36,7 +36,7 @@ limitations under the License. var dnanmaxabs = require( '@stdlib/stats/base/dnanmaxabs' ); ``` -#### dnanmaxabs( N, x, stride ) +#### dnanmaxabs( N, x, strideX ) Computes the maximum absolute value of a double-precision floating-point strided array `x`, ignoring `NaN` values. @@ -44,9 +44,8 @@ Computes the maximum absolute value of a double-precision floating-point strided var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = dnanmaxabs( N, x, 1 ); +var v = dnanmaxabs( x.length, x, 1 ); // returns 2.0 ``` @@ -54,18 +53,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 maximum absolute value 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 maximum absolute value 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, -7.0, -2.0, 4.0, 3.0, NaN, NaN ] ); -var N = floor( x.length / 2 ); -var v = dnanmaxabs( N, x, 2 ); +var v = dnanmaxabs( 4, x, 2 ); // returns 7.0 ``` @@ -75,18 +72,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, 3.0, 4.0, NaN, NaN ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = dnanmaxabs( N, x1, 2 ); +var v = dnanmaxabs( 4, x1, 2 ); // returns 4.0 ``` -#### dnanmaxabs.ndarray( N, x, stride, offset ) +#### dnanmaxabs.ndarray( N, x, strideX, offsetX ) Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. @@ -94,26 +88,23 @@ Computes the maximum absolute value of a double-precision floating-point strided var Float64Array = require( '@stdlib/array/float64' ); var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = dnanmaxabs.ndarray( N, x, 1, 0 ); +var v = dnanmaxabs.ndarray( x.length, x, 1, 0 ); // returns 2.0 ``` 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 maximum absolute value 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 maximum absolute value 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, 3.0, 4.0, NaN, NaN ] ); -var N = floor( x.length / 2 ); -var v = dnanmaxabs.ndarray( N, x, 2, 1 ); +var v = dnanmaxabs.ndarray( 4, x, 2, 1 ); // returns 4.0 ``` @@ -164,6 +155,123 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dnanmax.h" +``` + +#### stdlib_strided_dnanmax( N, \*X, strideX ) + +Computes the maximum absolute value of a double-precision floating-point strided array , ignoring `NaN` values. + +```c +const double x[] = { 1.0, -2.0, 0.0 / 0.0, -4.0 }; + +double v = stdlib_strided_dnanmax( 4, x, 1 ); +// returns 4.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`. + +```c +double stdlib_strided_dnanmax( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnanmax_ndarray( N, \*X, strideX, offsetX ) + +Computes the maximum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics. + +```c +const double x[] = { 1.0, -2.0, 0.0 / 0.0, -4.0 }; + +double v = stdlib_strided_dnanmax_ndarray( 4, x, 1, 0 ); +// returns 4.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_dnanmax_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dnanmaxabs.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, 0.0/0.0, 0.0/0.0 }; + + // Specify the number of elements: + const int N = 5; + + // Specify the stride length: + const int strideX = 2; + + // Compute the maximum absolute value: + double v = stdlib_strided_dnanmaxabs( N, x, strideX ); + + // Print the result: + printf( "maxabs: %lf\n", v ); +} +``` + +
+ + + +
+ + +