From 402575fa7b1fc2dac49b16b07dc27ab4bd07b99d Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Fri, 24 Jan 2025 23:10:07 +0530 Subject: [PATCH 1/3] refactor: updated stats/base/dsvariancepn native addon from C++ to C --- 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 --- --- 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: na --- --- .../stats/base/dsvariancepn/include.gypi | 2 +- .../stats/base/dsvariancepn/manifest.json | 39 ++++++ .../stats/base/dsvariancepn/src/addon.c | 45 ++++++ .../stats/base/dsvariancepn/src/addon.cpp | 130 ------------------ 4 files changed, 85 insertions(+), 131 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.cpp diff --git a/lib/node_modules/@stdlib/stats/base/dsvariancepn/include.gypi b/lib/node_modules/@stdlib/stats/base/dsvariancepn/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/stats/base/dsvariancepn/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dsvariancepn/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' + +/** +* 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, 4 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dsvariancepn( N, correction, X, stride ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.cpp b/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.cpp deleted file mode 100644 index e7a2553202b5..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.cpp +++ /dev/null @@ -1,130 +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/dsvariancepn.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_stats_base_dsvariancepn { - - /** - * Computes the variance of a single-precision floating-point strided array using a two-pass algorithm with extended accumulation and returning an extended precision result. - * - * ## Notes - * - * - When called from JavaScript, the function expects four arguments: - * - * - `N`: number of indexed elements - * - `correction`: degrees of freedom adjustment - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_dsvariancepn( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 4; - napi_value argv[ 4 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 4 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 4 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; - } - - napi_valuetype vtype1; - status = napi_typeof( env, argv[ 1 ], &vtype1 ); - assert( status == napi_ok ); - if ( vtype1 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 2 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); - return nullptr; - } - - napi_valuetype vtype3; - status = napi_typeof( env, argv[ 3 ], &vtype3 ); - assert( status == napi_ok ); - if ( vtype3 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fourth argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - double correction; - status = napi_get_value_double( env, argv[ 1 ], &correction ); - assert( status == napi_ok ); - - int64_t stride; - status = napi_get_value_int64( env, argv[ 3 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype2; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 2 ], &vtype2, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype2 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Third 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_dsvariancepn( N, (float)correction, (float *)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_dsvariancepn, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_stats_base_dsvariancepn From 90c883412e879466306d6657cc10fd27c9268e33 Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Fri, 24 Jan 2025 23:54:14 +0530 Subject: [PATCH 2/3] chore: changes import statements --- 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 --- --- 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: na --- --- lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c b/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c index c0e7572f95c5..d37e73323769 100644 --- a/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c @@ -20,9 +20,9 @@ #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" -#include "stdlib/napi/argv_double.h" #include "stdlib/napi/argv_strided_float32array.h" #include "stdlib/napi/create_double.h" +#include "stdlib/napi/argv_double.h" #include /** From 4f7c0a0b4fedd331553943ee2d4fe34cd59febba Mon Sep 17 00:00:00 2001 From: JoyBoy <144602492+0PrashantYadav0@users.noreply.github.com> Date: Sun, 26 Jan 2025 15:44:33 +0530 Subject: [PATCH 3/3] chore: updated double to float --- 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 --- --- 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: na --- --- .../@stdlib/stats/base/dsvariancepn/manifest.json | 2 +- lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dsvariancepn/manifest.json b/lib/node_modules/@stdlib/stats/base/dsvariancepn/manifest.json index 8dc7d7b75c0a..a1b6eb5f634b 100644 --- a/lib/node_modules/@stdlib/stats/base/dsvariancepn/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dsvariancepn/manifest.json @@ -40,7 +40,7 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-double", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-strided-float32array", "@stdlib/napi/create-double" ] diff --git a/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c b/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c index d37e73323769..efc63d7a4352 100644 --- a/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dsvariancepn/src/addon.c @@ -22,7 +22,7 @@ #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float32array.h" #include "stdlib/napi/create_double.h" -#include "stdlib/napi/argv_double.h" +#include "stdlib/napi/argv_float.h" #include /** @@ -35,7 +35,7 @@ static napi_value addon( 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_DOUBLE( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ); STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dsvariancepn( N, correction, X, stride ), v );