From 6be9e846014b7b179adb1e762da13765d3031418 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Sat, 11 Jan 2025 15:29:11 +0000 Subject: [PATCH 1/6] feat: add C ndarray interface and refactor 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: 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 --- --- .../include/stdlib/stats/base/scuminabs.h | 9 +- .../stats/base/scuminabs/manifest.json | 74 ++++++++- .../@stdlib/stats/base/scuminabs/src/addon.c | 65 ++++++++ .../stats/base/scuminabs/src/addon.cpp | 151 ------------------ .../scuminabs/src/{scuminabs.c => main.c} | 47 +++--- 5 files changed, 170 insertions(+), 176 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/scuminabs/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/scuminabs/src/addon.cpp rename lib/node_modules/@stdlib/stats/base/scuminabs/src/{scuminabs.c => main.c} (53%) diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/include/stdlib/stats/base/scuminabs.h b/lib/node_modules/@stdlib/stats/base/scuminabs/include/stdlib/stats/base/scuminabs.h index 220b28d922a8..aad0ff74bac0 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/include/stdlib/stats/base/scuminabs.h +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/include/stdlib/stats/base/scuminabs.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_SCUMINABS_H #define STDLIB_STATS_BASE_SCUMINABS_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 cumulative minimum absolute value of single-precision floating-point strided array elements. */ -void stdlib_strided_scuminabs( const int64_t N, const float *X, const int64_t strideX, float *Y, const int64_t strideY ); +void API_SUFFIX(stdlib_strided_scuminabs)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ); + +/** +* Computes the cumulative minimum absolute value of single-precision floating-point strided array elements using alternative indexing semantics. +*/ +void API_SUFFIX(stdlib_strided_scuminabs_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/manifest.json b/lib/node_modules/@stdlib/stats/base/scuminabs/manifest.json index ab1d56169a3b..af15e5d2624a 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/manifest.json @@ -1,5 +1,8 @@ { - "options": {}, + "options": { + "task": "build", + "wasm": false + }, "fields": [ { "field": "src", @@ -24,18 +27,79 @@ ], "confs": [ { + "task": "build", + "wasm": false, "src": [ - "./src/scuminabs.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/absf", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/napi/export", + "@stdlib/napi/argv", + "@stdlib/napi/argv-int64", + "@stdlib/napi/argv-strided-float32array" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/absf", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/absf", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nanf" + "@stdlib/math/base/assert/is-nanf", + "@stdlib/math/base/special/absf", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/src/addon.c b/lib/node_modules/@stdlib/stats/base/scuminabs/src/addon.c new file mode 100644 index 000000000000..80604c48e58f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/src/addon.c @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/scuminabs.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float32array.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, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 4 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 3 ); + API_SUFFIX(stdlib_strided_scuminabs)( N, X, strideX, Y, strideY ); + return NULL; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 7 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetY, argv, 6 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); + API_SUFFIX(stdlib_strided_scuminabs_ndarray)( N, X, strideX, offsetX, Y, strideY, offsetY ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/src/addon.cpp b/lib/node_modules/@stdlib/stats/base/scuminabs/src/addon.cpp deleted file mode 100644 index d45aa2d13b77..000000000000 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/src/addon.cpp +++ /dev/null @@ -1,151 +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/scuminabs.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_scuminabs { - - /** - * Computes the cumulative minimum absolute value of single-precision floating-point strided array elements. - * - * ## Notes - * - * - When called from JavaScript, the function expects five arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `strideX`: `X` stride length - * - `Y`: output array - * - `strideY`: `Y` stride length - */ - napi_value node_scuminabs( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 5; - napi_value argv[ 5 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 5 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 5 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 res1; - status = napi_is_typedarray( env, argv[ 1 ], &res1 ); - assert( status == napi_ok ); - if ( res1 == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - 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; - } - - bool res3; - status = napi_is_typedarray( env, argv[ 3 ], &res3 ); - assert( status == napi_ok ); - if ( res3 == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype4; - status = napi_typeof( env, argv[ 4 ], &vtype4 ); - assert( status == napi_ok ); - if ( vtype4 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fifth 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 strideX; - status = napi_get_value_int64( env, argv[ 2 ], &strideX ); - assert( status == napi_ok ); - - int64_t strideY; - status = napi_get_value_int64( env, argv[ 4 ], &strideY ); - 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_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(strideX) >= (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_typedarray_type vtype3; - size_t ylen; - void *Y; - status = napi_get_typedarray_info( env, argv[ 3 ], &vtype3, &ylen, &Y, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype3 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Fourth argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - stdlib_strided_scuminabs( N, (float *)X, strideX, (float *)Y, strideY ); - - return nullptr; - } - - 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_scuminabs, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_scuminabs diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/src/scuminabs.c b/lib/node_modules/@stdlib/stats/base/scuminabs/src/main.c similarity index 53% rename from lib/node_modules/@stdlib/stats/base/scuminabs/src/scuminabs.c rename to lib/node_modules/@stdlib/stats/base/scuminabs/src/main.c index c49d3eb6d776..5e791f9e1beb 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/src/scuminabs.c +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/src/main.c @@ -18,8 +18,9 @@ #include "stdlib/stats/base/scuminabs.h" #include "stdlib/math/base/assert/is_nanf.h" -#include -#include +#include "stdlib/math/base/special/absf.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Computes the cumulative minimum absolute value of single-precision floating-point strided array elements. @@ -30,27 +31,37 @@ * @param Y output array * @param strideY Y stride length */ -void stdlib_strided_scuminabs( const int64_t N, const float *X, const int64_t strideX, float *Y, const int64_t strideY ) { - int64_t ix; - int64_t iy; - int64_t i; +void stdlib_strided_scuminabs( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ) { + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + const CBLAS_INT oy = stdlib_strided_stride2offset( N, strideY ); + API_SUFFIX(stdlib_strided_scuminabs_ndarray)( N, X, strideX, ox, Y, strideY, oy ); + return; +} + +/** +* Computes the cumulative minimum absolute value of single-precision floating-point strided array elements using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +* @param Y output array +* @param strideY Y stride length +* @param offsetY starting index for Y +*/ +void API_SUFFIX(stdlib_strided_scuminabs_ndarray)( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ) { + CBLAS_INT ix; + CBLAS_INT iy; + CBLAS_INT i; float min; float v; if ( N <= 0 ) { return; } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } - min = fabsf( X[ ix ] ); + ix = offsetX; + iy = offsetY; + min = stdlib_base_absf( X[ ix ] ); Y[ iy ] = min; iy += strideY; @@ -58,7 +69,7 @@ void stdlib_strided_scuminabs( const int64_t N, const float *X, const int64_t st if ( !stdlib_base_is_nanf( min ) ) { for (; i < N; i++ ) { ix += strideX; - v = fabsf( X[ ix ] ); + v = stdlib_base_absf( X[ ix ] ); if ( stdlib_base_is_nanf( v ) ) { min = v; break; From b90191be733fd20170c4dad0a05c4648abff3e2d Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Sun, 12 Jan 2025 05:00:59 +0000 Subject: [PATCH 2/6] refactor: update js implementation and 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: passed - 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: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/scuminabs/lib/index.js | 7 +-- .../stats/base/scuminabs/lib/ndarray.js | 10 ++-- .../base/scuminabs/lib/ndarray.native.js | 19 +------ .../stats/base/scuminabs/lib/scuminabs.js | 56 ++----------------- .../base/scuminabs/lib/scuminabs.native.js | 3 +- .../stats/base/scuminabs/test/test.ndarray.js | 25 ++------- .../scuminabs/test/test.ndarray.native.js | 25 ++------- .../base/scuminabs/test/test.scuminabs.js | 22 ++------ .../scuminabs/test/test.scuminabs.native.js | 22 ++------ 9 files changed, 38 insertions(+), 151 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/index.js b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/index.js index 927b1933216e..3071e225384a 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/index.js @@ -29,21 +29,18 @@ * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); * var y = new Float32Array( x.length ); -* var N = x.length; * -* scuminabs( N, x, 1, y, 1 ); +* scuminabs( x.length, x, 1, y, 1 ); * // y => [ 1.0, 1.0, 1.0 ] * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var scuminabs = require( '@stdlib/stats/base/scuminabs' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float32Array( x.length ); -* var N = floor( x.length / 2 ); * -* scuminabs.ndarray( N, x, 2, 1, y, 1, 0 ); +* scuminabs.ndarray( 4, x, 2, 1, y, 1, 0 ); * // y => [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] */ diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/ndarray.js index ef419862ac64..948e2536a7c4 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/ndarray.js @@ -21,7 +21,7 @@ // MODULES // var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var absf = require( '@stdlib/math/base/special/absf' ); // MAIN // @@ -40,13 +40,11 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float32Array( x.length ); -* var N = floor( x.length / 2 ); * -* var v = scuminabs( N, x, 2, 1, y, 1, 0 ); +* var v = scuminabs( 4, x, 2, 1, y, 1, 0 ); * // returns [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] */ function scuminabs( N, x, strideX, offsetX, y, strideY, offsetY ) { @@ -62,7 +60,7 @@ function scuminabs( N, x, strideX, offsetX, y, strideY, offsetY ) { ix = offsetX; iy = offsetY; - min = abs( x[ ix ] ); + min = absf( x[ ix ] ); y[ iy ] = min; iy += strideY; @@ -70,7 +68,7 @@ function scuminabs( N, x, strideX, offsetX, y, strideY, offsetY ) { if ( isnanf( min ) === false ) { for ( i; i < N; i++ ) { ix += strideX; - v = abs( x[ ix ] ); + v = absf( x[ ix ] ); if ( isnanf( v ) ) { min = v; break; diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/ndarray.native.js index 22fa6aa51f31..60dc69aaf2f3 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float32Array = require( '@stdlib/array/float32' ); -var addon = require( './scuminabs.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -40,27 +39,15 @@ var addon = require( './scuminabs.native.js' ); * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * var y = new Float32Array( x.length ); -* var N = floor( x.length / 2 ); * -* var v = scuminabs( N, x, 2, 1, y, 1, 0 ); +* var v = scuminabs( 4, x, 2, 1, y, 1, 0 ); * // returns [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] */ function scuminabs( N, x, strideX, offsetX, y, strideY, offsetY ) { - var viewX; - var viewY; - if ( strideX < 0 ) { - offsetX += (N-1) * strideX; - } - if ( strideY < 0 ) { - offsetY += (N-1) * strideY; - } - viewX = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offsetX), x.length-offsetX ); // eslint-disable-line max-len - viewY = new Float32Array( y.buffer, y.byteOffset+(y.BYTES_PER_ELEMENT*offsetY), y.length-offsetY ); // eslint-disable-line max-len - addon( N, viewX, strideX, viewY, strideY ); + addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ); return y; } diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/scuminabs.js b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/scuminabs.js index c810e436cced..979fa1e5c98f 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/scuminabs.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/scuminabs.js @@ -20,8 +20,8 @@ // MODULES // -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -41,58 +41,14 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); * var y = new Float32Array( x.length ); -* var N = x.length; * -* var v = scuminabs( N, x, 1, y, 1 ); +* var v = scuminabs( x.length, x, 1, y, 1 ); * // returns [ 1.0, 1.0, 1.0 ] */ function scuminabs( N, x, strideX, y, strideY ) { - var min; - var ix; - var iy; - var v; - var i; - - if ( N <= 0 ) { - return y; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } - min = abs( x[ ix ] ); - y[ iy ] = min; - - iy += strideY; - i = 1; - if ( isnanf( min ) === false ) { - for ( i; i < N; i++ ) { - ix += strideX; - v = abs( x[ ix ] ); - if ( isnanf( v ) ) { - min = v; - break; - } - if ( v < min ) { - min = v; - } - y[ iy ] = min; - iy += strideY; - } - } - if ( isnanf( min ) ) { - for ( i; i < N; i++ ) { - y[ iy ] = min; - iy += strideY; - } - } - return y; + var ox = stride2offset( N, strideX ); + var oy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ox, y, strideY, oy ); } diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/scuminabs.native.js b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/scuminabs.native.js index af658e0f5833..3f77171edc3e 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/lib/scuminabs.native.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/lib/scuminabs.native.js @@ -40,9 +40,8 @@ var addon = require( './../src/addon.node' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); * var y = new Float32Array( x.length ); -* var N = x.length; * -* var v = scuminabs( N, x, 1, y, 1 ); +* var v = scuminabs( x.length, x, 1, y, 1 ); * // returns [ 1.0, 1.0, 1.0 ] */ function scuminabs( N, x, strideX, y, strideY ) { diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.ndarray.js index df4d398225ad..e739da5141cd 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -150,7 +149,6 @@ tape( 'the function supports an `x` stride', function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -166,9 +164,8 @@ tape( 'the function supports an `x` stride', function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, 2, 0, y, 1, 0 ); + scuminabs( 3, x, 2, 0, y, 1, 0 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -180,7 +177,6 @@ tape( 'the function supports a `y` stride', function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -196,9 +192,8 @@ tape( 'the function supports a `y` stride', function test( t ) { 0.0, 0.0 // 2 ]); - N = 3; - scuminabs( N, x, 1, 0, y, 2, 0 ); + scuminabs( 3, x, 1, 0, y, 2, 0 ); expected = new Float32Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -210,7 +205,6 @@ tape( 'the function supports negative strides', function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 2 @@ -226,9 +220,8 @@ tape( 'the function supports negative strides', function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, -2, x.length-1, y, -1, 2 ); + scuminabs( 3, x, -2, x.length-1, y, -1, 2 ); expected = new Float32Array( [ 1.0, 3.0, 5.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -238,7 +231,6 @@ tape( 'the function supports negative strides', function test( t ) { tape( 'the function supports an `x` offset', function test( t ) { var expected; - var N; var x; var y; @@ -262,9 +254,8 @@ tape( 'the function supports an `x` offset', function test( t ) { 0.0, 0.0 ]); - N = floor( x.length / 2 ); - scuminabs( N, x, 2, 1, y, 1, 0 ); + scuminabs( 4, x, 2, 1, y, 1, 0 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -274,7 +265,6 @@ tape( 'the function supports an `x` offset', function test( t ) { tape( 'the function supports a `y` offset', function test( t ) { var expected; - var N; var x; var y; @@ -298,9 +288,8 @@ tape( 'the function supports a `y` offset', function test( t ) { 0.0, 0.0 // 3 ]); - N = floor( x.length / 2 ); - scuminabs( N, x, 1, 0, y, 2, 1 ); + scuminabs( 4, x, 1, 0, y, 2, 1 ); expected = new Float32Array( [ 0.0, 2.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -312,7 +301,6 @@ tape( 'the function supports complex access patterns', function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -330,9 +318,8 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, 2, 0, y, -1, 2 ); + scuminabs( 3, x, 2, 0, y, -1, 2 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.ndarray.native.js index b43f172484e6..4a343d7a7643 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/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 isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -159,7 +158,6 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -175,9 +173,8 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, 2, 0, y, 1, 0 ); + scuminabs( 3, x, 2, 0, y, 1, 0 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -189,7 +186,6 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -205,9 +201,8 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { 0.0, 0.0 // 2 ]); - N = 3; - scuminabs( N, x, 1, 0, y, 2, 0 ); + scuminabs( 3, x, 1, 0, y, 2, 0 ); expected = new Float32Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -219,7 +214,6 @@ tape( 'the function supports negative strides', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 2 @@ -235,9 +229,8 @@ tape( 'the function supports negative strides', opts, function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, -2, x.length-1, y, -1, 2 ); + scuminabs( 3, x, -2, x.length-1, y, -1, 2 ); expected = new Float32Array( [ 1.0, 3.0, 5.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -247,7 +240,6 @@ tape( 'the function supports negative strides', opts, function test( t ) { tape( 'the function supports an `x` offset', opts, function test( t ) { var expected; - var N; var x; var y; @@ -271,9 +263,8 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { 0.0, 0.0 ]); - N = floor( x.length / 2 ); - scuminabs( N, x, 2, 1, y, 1, 0 ); + scuminabs( 4, x, 2, 1, y, 1, 0 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -283,7 +274,6 @@ tape( 'the function supports an `x` offset', opts, function test( t ) { tape( 'the function supports a `y` offset', opts, function test( t ) { var expected; - var N; var x; var y; @@ -307,9 +297,8 @@ tape( 'the function supports a `y` offset', opts, function test( t ) { 0.0, 0.0 // 3 ]); - N = floor( x.length / 2 ); - scuminabs( N, x, 1, 0, y, 2, 1 ); + scuminabs( 4, x, 1, 0, y, 2, 1 ); expected = new Float32Array( [ 0.0, 2.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -321,7 +310,6 @@ tape( 'the function supports complex access patterns', opts, function test( t ) var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -339,9 +327,8 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, 2, 0, y, -1, 2 ); + scuminabs( 3, x, 2, 0, y, -1, 2 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.scuminabs.js b/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.scuminabs.js index 8990e619233f..86f5222e2922 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.scuminabs.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.scuminabs.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -150,7 +149,6 @@ tape( 'the function supports an `x` stride', function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -166,9 +164,8 @@ tape( 'the function supports an `x` stride', function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, 2, y, 1 ); + scuminabs( 3, x, 2, y, 1 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -180,7 +177,6 @@ tape( 'the function supports a `y` stride', function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -196,9 +192,8 @@ tape( 'the function supports a `y` stride', function test( t ) { 0.0, 0.0 // 2 ]); - N = 3; - scuminabs( N, x, 1, y, 2 ); + scuminabs( 3, x, 1, y, 2 ); expected = new Float32Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -210,7 +205,6 @@ tape( 'the function supports negative strides', function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 2 @@ -226,9 +220,8 @@ tape( 'the function supports negative strides', function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, -2, y, -1 ); + scuminabs( 3, x, -2, y, -1 ); expected = new Float32Array( [ 1.0, 3.0, 5.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -240,7 +233,6 @@ tape( 'the function supports complex access patterns', function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -258,9 +250,8 @@ tape( 'the function supports complex access patterns', function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, 2, y, -1 ); + scuminabs( 3, x, 2, y, -1 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -274,7 +265,6 @@ tape( 'the function supports view offsets', function test( t ) { var y0; var x1; var y1; - var N; // Initial arrays... x0 = new Float32Array([ @@ -298,9 +288,7 @@ tape( 'the function supports view offsets', function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - N = floor( x0.length / 2 ); - - scuminabs( N, x1, -2, y1, 1 ); + scuminabs( 3, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 4.0, 2.0 ] ); t.deepEqual( y0, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.scuminabs.native.js b/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.scuminabs.native.js index a3f464bc026c..8c41a4ce71d7 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.scuminabs.native.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/test/test.scuminabs.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -159,7 +158,6 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -175,9 +173,8 @@ tape( 'the function supports an `x` stride', opts, function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, 2, y, 1 ); + scuminabs( 3, x, 2, y, 1 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -189,7 +186,6 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -205,9 +201,8 @@ tape( 'the function supports a `y` stride', opts, function test( t ) { 0.0, 0.0 // 2 ]); - N = 3; - scuminabs( N, x, 1, y, 2 ); + scuminabs( 3, x, 1, y, 2 ); expected = new Float32Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -219,7 +214,6 @@ tape( 'the function supports negative strides', opts, function test( t ) { var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 2 @@ -235,9 +229,8 @@ tape( 'the function supports negative strides', opts, function test( t ) { 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, -2, y, -1 ); + scuminabs( 3, x, -2, y, -1 ); expected = new Float32Array( [ 1.0, 3.0, 5.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -249,7 +242,6 @@ tape( 'the function supports complex access patterns', opts, function test( t ) var expected; var x; var y; - var N; x = new Float32Array([ 1.0, // 0 @@ -267,9 +259,8 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 0.0, 0.0 ]); - N = 3; - scuminabs( N, x, 2, y, -1 ); + scuminabs( 3, x, 2, y, -1 ); expected = new Float32Array( [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] ); t.deepEqual( y, expected, 'returns expected value' ); @@ -283,7 +274,6 @@ tape( 'the function supports view offsets', opts, function test( t ) { var y0; var x1; var y1; - var N; // Initial arrays... x0 = new Float32Array([ @@ -307,9 +297,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // begin at the 4th element - N = floor( x0.length / 2 ); - - scuminabs( N, x1, -2, y1, 1 ); + scuminabs( 3, x1, -2, y1, 1 ); expected = new Float32Array( [ 0.0, 0.0, 0.0, 6.0, 4.0, 2.0 ] ); t.deepEqual( y0, expected, 'returns expected value' ); From f2445565f8da44a256e830c6d6532562f60731d2 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Sun, 12 Jan 2025 05:15:52 +0000 Subject: [PATCH 3/6] refactor: update examples and docs --- 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: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/base/scuminabs/docs/repl.txt | 24 +++++++++---------- .../stats/base/scuminabs/examples/c/example.c | 16 ++++++------- .../stats/base/scuminabs/examples/index.js | 16 ++++--------- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/scuminabs/docs/repl.txt index b079282df8a9..c2c5280c0784 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/docs/repl.txt @@ -3,8 +3,8 @@ Computes the cumulative minimum absolute value of single-precision floating- point strided array elements. - The `N` and `stride` parameters determine which elements in `x` and `y` are - accessed at runtime. + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -20,13 +20,13 @@ Input array. strideX: integer - Index increment for `x`. + Stride Length for `x`. y: Float32Array Output array. strideY: integer - Index increment for `y`. + Stride Length for `y`. Returns ------- @@ -41,11 +41,10 @@ > {{alias}}( x.length, x, 1, y, 1 ) [ 1.0, 1.0, 1.0 ] - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, x, 2, y, 2 ) + > {{alias}}( 3, x, 2, y, 2 ) [ 2.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] // Using view offsets: @@ -53,12 +52,12 @@ > var y0 = new {{alias:@stdlib/array/float32}}( x0.length ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > var y1 = new {{alias:@stdlib/array/float32}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > {{alias}}( N, x1, 2, y1, 1 ) + > {{alias}}( 3, x1, 2, y1, 1 ) [ 2.0, 2.0, 1.0 ] > y0 [ 0.0, 0.0, 0.0, 2.0, 2.0, 1.0 ] + {{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) Computes the cumulative minimum absolute value of single-precision floating- point strided array elements using alternative indexing semantics. @@ -76,7 +75,7 @@ Input array. strideX: integer - Index increment for `x`. + Stride Length for `x`. offsetX: integer Starting index for `x`. @@ -85,7 +84,7 @@ Output array. strideY: integer - Index increment for `y`. + Stride Length for `y`. offsetY: integer Starting index for `y`. @@ -106,8 +105,7 @@ // Advanced indexing: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > y = new {{alias:@stdlib/array/float32}}( x.length ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1, y, -1, y.length-1 ) + > {{alias}}.ndarray( 3, x, 2, 1, y, -1, y.length-1 ) [ 0.0, 0.0, 0.0, 1.0, 2.0, 2.0 ] See Also diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/scuminabs/examples/c/example.c index 39b213aeadc6..77bc33633950 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/examples/c/example.c @@ -17,27 +17,25 @@ */ #include "stdlib/stats/base/scuminabs.h" -#include #include -#include int main( void ) { // Create strided arrays: - float x[] = { 1.0, 2.0, -3.0, 4.0, -5.0, 6.0, 7.0, 8.0 }; - float y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + const float x[] = { 1.0f, 2.0f, -3.0f, 4.0f, -5.0f, 6.0f, 7.0f, 8.0f }; + float y[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; // Specify the number of elements: - int64_t N = 4; + const int N = 4; // Specify stride lengths: - int64_t strideX = 2; - int64_t strideY = -2; + const int strideX = 2; + const int strideY = -2; // Compute the cumulative minimum absolute value: stdlib_strided_scuminabs( N, x, strideX, y, strideY ); // Print the result: - for ( int64_t i = 0; i < 8; i++ ) { - printf( "y[ %"PRId64" ] = %f\n", i, y[ i ] ); + for ( int i = 0; i < 8; i++ ) { + printf( "y[ %d ] = %f\n", i, y[ i ] ); } } diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/examples/index.js b/lib/node_modules/@stdlib/stats/base/scuminabs/examples/index.js index beecfea76164..f49a8c9d160e 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/examples/index.js @@ -18,20 +18,14 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var Float32Array = require( '@stdlib/array/float32' ); var scuminabs = require( './../lib' ); -var y; -var x; -var i; - -x = new Float32Array( 10 ); -y = new Float32Array( x.length ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +var y = new Float32Array( x.length ); console.log( x ); console.log( y ); From 4459deecb4e3d86ef6a3f701f3674f08f28e6891 Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Sun, 12 Jan 2025 05:19:34 +0000 Subject: [PATCH 4/6] refactor: update benchmarks --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: 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 --- --- .../base/scuminabs/benchmark/benchmark.js | 20 ++++---- .../scuminabs/benchmark/benchmark.native.js | 16 +++--- .../scuminabs/benchmark/benchmark.ndarray.js | 20 ++++---- .../benchmark/benchmark.ndarray.native.js | 16 +++--- .../scuminabs/benchmark/c/benchmark.length.c | 49 ++++++++++++++++++- 5 files changed, 79 insertions(+), 42 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.js index 7fae59e43ad1..fa0eea7d43d6 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -29,6 +29,13 @@ var pkg = require( './../package.json' ).name; var scuminabs = require( './../lib/scuminabs.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,15 +46,8 @@ var scuminabs = require( './../lib/scuminabs.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var y; - var x; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); + var y = new Float32Array( len ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.native.js index 53588610f0a3..69554253f4cc 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -36,6 +36,9 @@ var scuminabs = tryRequire( resolve( __dirname, './../lib/scuminabs.native.js' ) var opts = { 'skip': ( scuminabs instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -48,15 +51,8 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); + var y = new Float32Array( len ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.ndarray.js index 298e574aa2de..5ae76af75328 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.ndarray.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -29,6 +29,13 @@ var pkg = require( './../package.json' ).name; var scuminabs = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -39,15 +46,8 @@ var scuminabs = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); + var y = new Float32Array( len ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.ndarray.native.js index c30783a52b33..d2b9725c47a6 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/benchmark.ndarray.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); var pow = require( '@stdlib/math/base/special/pow' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -36,6 +36,9 @@ var scuminabs = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ) var opts = { 'skip': ( scuminabs instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -48,15 +51,8 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = uniform( len, -10.0, 10.0, options ); + var y = new Float32Array( len ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/c/benchmark.length.c index 17c665a5545b..d18c9efcd6c8 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static float rand_float( 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; float x[ len ]; float y[ len ]; @@ -121,6 +121,40 @@ 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; + float x[ len ]; + float y[ len ]; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + y[ i ] = 0.0f; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + x[ 0 ] += 1.0f; + stdlib_strided_scuminabs_ndarray( len, x, 1, 0, y, 1, 0 ); + if ( y[ 0 ] != y[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y[ len-1 ] != y[ len-1 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -143,7 +177,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 7b746856f08f4c0048bb666d05a647d5b3666d8e Mon Sep 17 00:00:00 2001 From: aayush0325 Date: Sun, 12 Jan 2025 05:30:11 +0000 Subject: [PATCH 5/6] docs: update README --- 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: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/stats/base/scuminabs/README.md | 151 ++++++++++++++++-- 1 file changed, 136 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/README.md b/lib/node_modules/@stdlib/stats/base/scuminabs/README.md index 6c08a6d35ca9..4dae4be2d004 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/README.md +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/README.md @@ -54,11 +54,11 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float32Array`][@stdlib/array/float32]. -- **strideX**: index increment for `x`. +- **strideX**: stride length for `x`. - **y**: output [`Float32Array`][@stdlib/array/float32]. -- **strideY**: index increment for `y`. +- **strideY**: stride length for `y`. -The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative minimum absolute value of every other element in `x`, +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative minimum absolute value of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -108,7 +108,7 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative minimum absolute value of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative minimum absolute value of every other element in `x` starting from the second element and to store in the last `N` elements of `y` starting from the last element ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -141,20 +141,14 @@ scuminabs.ndarray( 4, x, 2, 1, y, -1, y.length-1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var Float32Array = require( '@stdlib/array/float32' ); var scuminabs = require( '@stdlib/stats/base/scuminabs' ); -var y; -var x; -var i; - -x = new Float32Array( 10 ); -y = new Float32Array( x.length ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); +var y = new Float32Array( x.length ); console.log( x ); console.log( y ); @@ -166,6 +160,133 @@ console.log( y ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/scuminabs.h" +``` + +#### stdlib_strided_scuminabs( N, \*X, strideX, \*Y, strideY ) + +Computes the cumulative minumum absolute value of single-precision floating-point strided array elements. + +```c +const float x[] = { 1.0f, 2.0f, -3.0f, 4.0f, -5.0f, 6.0f, 7.0f, 8.0f }; +float y[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + +stdlib_strided_scuminabs( 4, x, 2, y, -2 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **Y**: `[out] float*` output array. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. + +```c +void stdlib_strided_scuminabs( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY ); +``` + +#### stdlib_strided_scuminabs_ndarray(N, \*X, strideX, offsetX, \*Y, strideY, offsetY) + +Computes the cumulative minumum absolute value of single-precision floating-point strided array elements using alternative indexing semantics. + +```c +const float x[] = { 1.0f, 2.0f, -3.0f, 4.0f, -5.0f, 6.0f, 7.0f, 8.0f }; +float y[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + +stdlib_strided_scuminabs_ndarray( 4, x, 2, 0, y, -2, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. +- **Y**: `[out] float*` output array. +- **strideY**: `[in] CBLAS_INT` stride length for `Y`. +- **offsetY**: `[in] CBLAS_INT` starting index for `Y`. + +```c +void stdlib_strided_scuminabs_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/scuminabs.h" +#include + +int main( void ) { + // Create strided arrays: + const float x[] = { 1.0f, 2.0f, -3.0f, 4.0f, -5.0f, 6.0f, 7.0f, 8.0f }; + float y[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; + + + // Specify the number of elements: + const int N = 4; + + // Specify stride lengths: + const int strideX = 2; + const int strideY = -2; + + // Compute the cumulative minumum absolute value: + stdlib_strided_scuminabs( N, x, strideX, y, strideY ); + + // Print the result: + for ( int i = 0; i < 8; i++ ) { + printf( "y[ %d ] = %f\n", i, y[ i ] ); + } +} +``` + +
+ + + +
+ + +
From ba65e028c9dd3dfc9f5d0dc63903fafaadfc83fe Mon Sep 17 00:00:00 2001 From: Aayush Khanna <96649223+aayush0325@users.noreply.github.com> Date: Fri, 17 Jan 2025 01:21:00 +0530 Subject: [PATCH 6/6] chore: cleaning up --- lib/node_modules/@stdlib/stats/base/scuminabs/README.md | 2 +- .../@stdlib/stats/base/scuminabs/docs/repl.txt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/README.md b/lib/node_modules/@stdlib/stats/base/scuminabs/README.md index 4dae4be2d004..835d95b79ca9 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/README.md +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/README.md @@ -108,7 +108,7 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative minimum absolute value of every other element in `x` starting from the second element and to store in the last `N` elements of `y` starting from the last element +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to calculate the cumulative minimum absolute value of every other element in `x` starting from the second element and to store in the last `N` elements of `y` starting from the last element ```javascript var Float32Array = require( '@stdlib/array/float32' ); diff --git a/lib/node_modules/@stdlib/stats/base/scuminabs/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/scuminabs/docs/repl.txt index c2c5280c0784..a26002517d0a 100644 --- a/lib/node_modules/@stdlib/stats/base/scuminabs/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/scuminabs/docs/repl.txt @@ -20,13 +20,13 @@ Input array. strideX: integer - Stride Length for `x`. + Stride length for `x`. y: Float32Array Output array. strideY: integer - Stride Length for `y`. + Stride length for `y`. Returns ------- @@ -75,7 +75,7 @@ Input array. strideX: integer - Stride Length for `x`. + Stride length for `x`. offsetX: integer Starting index for `x`. @@ -84,7 +84,7 @@ Output array. strideY: integer - Stride Length for `y`. + Stride length for `y`. offsetY: integer Starting index for `y`.