From 9814a7e0a96d23233a3caa060000dc0019f89322 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 21 Dec 2024 01:49:02 +0530 Subject: [PATCH 1/4] refactor-dnanmeanpn --- .../stats/base/dnanmeanpn/include.gypi | 2 +- .../stats/base/dnanmeanpn/manifest.json | 42 ++++++- .../@stdlib/stats/base/dnanmeanpn/src/addon.c | 43 +++++++ .../stats/base/dnanmeanpn/src/addon.cpp | 117 ------------------ 4 files changed, 85 insertions(+), 119 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.c delete mode 100644 lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.cpp diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/include.gypi b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/include.gypi index 868c5c12e852..26476a8c2655 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#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 "stdlib/napi/export.h" +#include "stdlib/stats/base/dnanmeanpn.h" + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, stdlib_strided_dnanmeanpn( N, X, stride ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.cpp b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.cpp deleted file mode 100644 index 8c46b762906b..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/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/dnanmeanpn.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_stats_base_dnanmeanpn { - - /** - * Computes the arithmetic mean of a double-precision floating-point strided array, ignoring `NaN` values and using a two-pass error correction algorithm. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_dnanmeanpn( 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_dnanmeanpn( 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_dnanmeanpn, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_stats_base_dnanmeanpn From f078cfbc670353b4d117313158848135cc462630 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 21 Dec 2024 01:59:54 +0530 Subject: [PATCH 2/4] test error --- lib/node_modules/@stdlib/stats/base/dnanmeanpn/manifest.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/manifest.json index d1480b098a28..c7842d1523dd 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/manifest.json @@ -74,7 +74,9 @@ "-lm" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/ext/base/dmeanpn" + ] } ] } From ad404d58ed8f67334a1de3da2cbcfa603a9d28f1 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sat, 21 Dec 2024 02:05:44 +0530 Subject: [PATCH 3/4] test error --- .../@stdlib/stats/base/dnanmeanpn/manifest.json | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/manifest.json b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/manifest.json index c7842d1523dd..6548e169ddf8 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/manifest.json @@ -38,7 +38,6 @@ ], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dmeanpn", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -58,9 +57,7 @@ "-lm" ], "libpath": [], - "dependencies": [ - "@stdlib/blas/ext/base/dmeanpn" - ] + "dependencies": [] }, { "task": "examples", @@ -74,9 +71,7 @@ "-lm" ], "libpath": [], - "dependencies": [ - "@stdlib/blas/ext/base/dmeanpn" - ] + "dependencies": [] } ] } From fc6fd82fe226ee9a021e42e5413fc0bf76b1023e Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Fri, 27 Dec 2024 13:38:18 +0530 Subject: [PATCH 4/4] fix: stuff from code review --- lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.c b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.c index d818ff8e02d4..4345321001ac 100644 --- a/lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dnanmeanpn/src/addon.c @@ -16,13 +16,13 @@ * limitations under the License. */ -#include +#include "stdlib/stats/base/dnanmeanpn.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 "stdlib/napi/export.h" -#include "stdlib/stats/base/dnanmeanpn.h" +#include /** * Receives JavaScript callback invocation data.