From cf62100c3ef0fe8318291d861f7db73ff3acec33 Mon Sep 17 00:00:00 2001 From: Aayush Khanna <96649223+aayush0325@users.noreply.github.com> Date: Mon, 30 Sep 2024 06:52:14 +0530 Subject: [PATCH] refactor: update `blas/ext/base/dsort2ins` to follow current project conventions PR-URL: https://github.com/stdlib-js/stdlib/pull/2961 Closes: https://github.com/stdlib-js/stdlib/issues/1496 Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../@stdlib/blas/ext/base/dsort2ins/README.md | 18 +- .../blas/ext/base/dsort2ins/docs/repl.txt | 18 +- .../ext/base/dsort2ins/docs/types/index.d.ts | 4 +- .../blas/ext/base/dsort2ins/examples/index.js | 6 +- .../blas/ext/base/dsort2ins/include.gypi | 2 +- .../blas/ext/base/dsort2ins/manifest.json | 107 +++++++----- .../blas/ext/base/dsort2ins/package.json | 4 +- .../blas/ext/base/dsort2ins/src/addon.c | 46 +++++ .../blas/ext/base/dsort2ins/src/addon.cpp | 164 ------------------ 9 files changed, 134 insertions(+), 235 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsort2ins/src/addon.c delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dsort2ins/src/addon.cpp diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/README.md b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/README.md index 736b97d6454..43385ef2313 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/README.md @@ -58,17 +58,15 @@ The function has the following parameters: - **y**: second input [`Float64Array`][@stdlib/array/float64]. - **strideY**: `y` index increment. -The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to sort every other element +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to sort every other element ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); var y = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); -var N = floor( x.length / 2 ); -dsort2ins( N, -1.0, x, 2, y, 2 ); +dsort2ins( 2, -1.0, x, 2, y, 2 ); console.log( x ); // => [ 3.0, -2.0, 1.0, -4.0 ] @@ -81,7 +79,6 @@ 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' ); // Initial arrays... var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); @@ -90,10 +87,9 @@ var y0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] ); // Create offset views... var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length/2 ); // Sort every other element... -dsort2ins( N, -1.0, x1, 2, y1, 2 ); +dsort2ins( 2, -1.0, x1, 2, y1, 2 ); console.log( x0 ); // => [ 1.0, 4.0, 3.0, 2.0 ] @@ -126,7 +122,7 @@ The function has the following additional parameters: - **offsetX**: `x` starting index. - **offsetY**: `y` starting index. -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 access only the last three elements of `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 access only the last three elements of `x` ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -177,12 +173,10 @@ var dsort2ins = require( '@stdlib/blas/ext/base/dsort2ins' ); var rand; var sign; -var x; -var y; var i; -x = new Float64Array( 10 ); -y = new Float64Array( 10 ); // index array +var x = new Float64Array( 10 ); +var y = new Float64Array( 10 ); // index array for ( i = 0; i < x.length; i++ ) { rand = round( randu()*100.0 ); sign = randu(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/docs/repl.txt index f4160791159..5445eda4567 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/docs/repl.txt @@ -3,8 +3,8 @@ Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort. - 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 typed array views. @@ -57,7 +57,7 @@ Returns ------- x: Float64Array - Input array `x`. + Input array. Examples -------- @@ -69,11 +69,10 @@ > y [ 3.0, 1.0, 0.0, 2.0 ] - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); > y = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, -1, x, 2, y, 2 ) + > {{alias}}( 2, -1, x, 2, y, 2 ) [ 3.0, -2.0, 1.0, -4.0 ] > y [ 2.0, 1.0, 0.0, 3.0 ] @@ -83,14 +82,14 @@ > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > var y0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] ); > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > {{alias}}( N, 1, x1, 2, y1, 2 ) + > {{alias}}( 2, 1, x1, 2, y1, 2 ) [ -4.0, 3.0, -2.0 ] > x0 [ 1.0, -4.0, 3.0, -2.0 ] > y0 [ 0.0, 3.0, 2.0, 1.0 ] + {{alias}}.ndarray( N, order, x, strideX, offsetX, y, strideY, offsetY ) Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort and @@ -145,8 +144,7 @@ // Using an index offset: > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); > y = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0, 3.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, 1, x, 2, 1, y, 2, 1 ) + > {{alias}}.ndarray( 2, 1, x, 2, 1, y, 2, 1 ) [ 1.0, -4.0, 3.0, -2.0 ] > y [ 0.0, 3.0, 2.0, 1.0 ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/docs/types/index.d.ts index 002cf73f0de..511bf0f53b9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/docs/types/index.d.ts @@ -28,9 +28,9 @@ interface Routine { * @param N - number of indexed elements * @param order - sort order * @param x - first input array - * @param strideX - `x` stride length + * @param strideX - first stride length * @param y - second input array - * @param strideY - `y` stride length + * @param strideY - second stride length * @returns `x` * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/examples/index.js index 9e04c9eb8d1..1578dce41d3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/examples/index.js @@ -25,12 +25,10 @@ var dsort2ins = require( './../lib' ); var rand; var sign; -var x; -var y; var i; -x = new Float64Array( 10 ); -y = new Float64Array( 10 ); // index array +var x = new Float64Array( 10 ); +var y = new Float64Array( 10 ); // index array for ( i = 0; i < x.length; i++ ) { if ( randu() < 0.2 ) { x[ i ] = NaN; diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/include.gypi index 868c5c12e85..26476a8c265 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/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, 6 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_DOUBLE( env, order, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, Y, N, strideY, argv, 4 ); + c_dsort2ins( N, order, X, strideX, Y, strideY ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/src/addon.cpp deleted file mode 100644 index e4cdba515fc..00000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dsort2ins/src/addon.cpp +++ /dev/null @@ -1,164 +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/blas/ext/base/dsort2ins.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_dsort2ins { - - /** - * Simultaneously sorts two double-precision floating-point strided arrays based on the sort order of the first array using insertion sort. - * - * ## Notes - * - * - When called from JavaScript, the function expects six arguments: - * - * - `N`: number of indexed elements - * - `order`: sort order - * - `X`: first input array - * - `strideX`: `X` stride length - * - `Y`: second input array - * - `strideY`: `Y` stride length - */ - napi_value node_dsort2ins( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 6; - napi_value argv[ 6 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 6 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 6 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 res2; - status = napi_is_typedarray( env, argv[ 2 ], &res2 ); - assert( status == napi_ok ); - if ( res2 == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." ); - 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; - } - - bool res4; - status = napi_is_typedarray( env, argv[ 4 ], &res4 ); - assert( status == napi_ok ); - if ( res4 == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float64Array." ); - return nullptr; - } - - napi_valuetype vtype5; - status = napi_typeof( env, argv[ 5 ], &vtype5 ); - assert( status == napi_ok ); - if ( vtype5 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. Sixth argument must be a number." ); - return nullptr; - } - - int64_t N; - status = napi_get_value_int64( env, argv[ 0 ], &N ); - assert( status == napi_ok ); - - double order; - status = napi_get_value_double( env, argv[ 1 ], &order ); - assert( status == napi_ok ); - - int64_t strideX; - status = napi_get_value_int64( env, argv[ 3 ], &strideX ); - assert( status == napi_ok ); - - int64_t strideY; - status = napi_get_value_int64( env, argv[ 5 ], &strideY ); - 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_float64_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Third argument must be a Float64Array." ); - return nullptr; - } - if ( (N-1)*llabs(strideX) >= (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_typedarray_type vtype4; - size_t ylen; - void *Y; - status = napi_get_typedarray_info( env, argv[ 4 ], &vtype4, &ylen, &Y, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype4 != napi_float64_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float64Array." ); - return nullptr; - } - if ( (N-1)*llabs(strideY) >= (int64_t)ylen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Fifth argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - c_dsort2ins( N, order, (double *)X, strideX, (double *)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_dsort2ins, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_dsort2ins