From 25e0e5ff694071fc83b90d0395abfd08a0fb1e1c Mon Sep 17 00:00:00 2001 From: rxbryan Date: Mon, 11 Mar 2024 10:10:34 +0100 Subject: [PATCH 01/14] refactor: update blas/ext/base/sapx update blas/ext/base/sapx to follow current project conventions Fixes: #1152 --- .../@stdlib/blas/ext/base/sapx/README.md | 38 ++---- .../blas/ext/base/sapx/benchmark/benchmark.js | 17 ++- .../base/sapx/benchmark/benchmark.native.js | 13 +- .../base/sapx/benchmark/benchmark.ndarray.js | 17 ++- .../benchmark/benchmark.ndarray.native.js | 13 +- .../blas/ext/base/sapx/examples/index.js | 23 +--- .../@stdlib/blas/ext/base/sapx/include.gypi | 2 +- .../blas/ext/base/sapx/lib/ndarray.native.js | 10 +- .../@stdlib/blas/ext/base/sapx/manifest.json | 82 +++++------ .../@stdlib/blas/ext/base/sapx/package.json | 4 +- .../@stdlib/blas/ext/base/sapx/src/addon.c | 51 +++++++ .../@stdlib/blas/ext/base/sapx/src/addon.cpp | 128 ------------------ .../blas/ext/base/sapx/test/test.ndarray.js | 4 +- .../ext/base/sapx/test/test.ndarray.native.js | 4 +- .../blas/ext/base/sapx/test/test.sapx.js | 4 +- .../ext/base/sapx/test/test.sapx.native.js | 4 +- 16 files changed, 151 insertions(+), 263 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.cpp diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md index f5d6a80ae23..11d6643dd3d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md @@ -50,16 +50,14 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to add a constant to every other element +The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to add a constant to every other element ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); -var N = floor( x.length / 2 ); -sapx( N, 5.0, x, 2 ); +sapx( 4, 5.0, x, 2 ); // x => [ 3.0, 1.0, 8.0, -5.0, 9.0, 0.0, 4.0, -3.0 ] ``` @@ -67,17 +65,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); // Initial array... var x0 = new Float32Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); // Create an offset view... var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length/2 ); // Add a constant to every other element... -sapx( N, 5.0, x1, 2 ); +sapx( 3, 5.0, x1, 2 ); // x0 => [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] ``` @@ -98,7 +94,7 @@ The function has the following additional parameters: - **offset**: 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 the strided array ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -117,7 +113,7 @@ sapx.ndarray( 3, 5.0, x, 1, x.length-3 ); ## Notes -- If `N <= 0`, both functions return `x` unchanged. +- If `N <= 0`, both functions return the input array unchanged. @@ -130,27 +126,13 @@ sapx.ndarray( 3, 5.0, x, 1, x.length-3 ); ```javascript -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float32Array = require( '@stdlib/array/float32' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var sapx = require( '@stdlib/blas/ext/base/sapx' ); -var rand; -var sign; -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - rand = round( randu()*100.0 ); - sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - x[ i ] = sign * rand; -} +var rand = uniform( -100.0, 100.0 ); + +var x = filledarrayBy( 10, 'float32', rand ); console.log( x ); sapx( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.js index fc8f8842039..ffd0ff4adca 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapx = require( './../lib/sapx.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var sapx = require( './../lib/sapx.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.native.js index ec66fd0dc0c..c0d5da97715 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var sapx = tryRequire( resolve( __dirname, './../lib/sapx.native.js' ) ); var opts = { 'skip': ( sapx instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.js index 29b81da7704..b98d981d2b0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.js @@ -21,14 +21,19 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var sapx = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var sapx = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.native.js index cd198d07eff..650ac428642 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +36,7 @@ var sapx = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( sapx instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,13 +49,7 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < len; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js index 650232f9d8e..73082767363 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js @@ -18,27 +18,14 @@ 'use strict'; -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); -var Float32Array = require( '@stdlib/array/float32' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var sapx = require( './../lib' ); -var rand; -var sign; -var x; -var i; +var rand = uniform( -100.0, 100.0 ); + +var x = filledarrayBy( 10, 'float32', rand ); -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - rand = round( randu()*100.0 ); - sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - x[ i ] = sign * rand; -} console.log( x ); sapx( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/sapx/include.gypi index 868c5c12e85..26476a8c265 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' + +/** +* Adds a constant to each element in a single-precision floating-point strided array. +* +* ## Notes +* +* - When called from JavaScript, the function expects four arguments: +* +* - `N`: number of indexed elements +* - `alpha`: scalar +* - `X`: input array +* - `strideX`: `X` stride length +*/ +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, alpha, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ) + + c_sapx( N, (float)alpha, (float *)X, strideX ); + + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.cpp deleted file mode 100644 index 2d511f5f5af..00000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.cpp +++ /dev/null @@ -1,128 +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/sapx.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_sapx { - - /** - * Adds a constant to each element in a single-precision floating-point strided array. - * - * ## Notes - * - * - When called from JavaScript, the function expects four arguments: - * - * - `N`: number of indexed elements - * - `alpha`: scalar - * - `X`: input array - * - `strideX`: `X` stride length - */ - napi_value node_sapx( 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 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 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 alpha; - status = napi_get_value_double( env, argv[ 1 ], &alpha ); - assert( status == napi_ok ); - - int64_t strideX; - status = napi_get_value_int64( env, argv[ 3 ], &strideX ); - 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(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; - } - - c_sapx( N, (float)alpha, (float *)X, strideX ); - - 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_sapx, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_sapx diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.js index d6af1182cc7..d0413321a0c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.js @@ -86,7 +86,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { var expected; var x; @@ -102,7 +102,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns `x` unchanged', function test( t ) { +tape( 'if `alpha` equals `0`, the function returns the input array unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.native.js index 4936985b82a..0b99f94efe6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.ndarray.native.js @@ -95,7 +95,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var x; @@ -111,7 +111,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns `x` unchanged', opts, function test( t ) { +tape( 'if `alpha` equals `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.js index 462982a6847..014e47e5ad8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.js @@ -86,7 +86,7 @@ tape( 'the function returns a reference to the input array', function test( t ) t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', function test( t ) { var expected; var x; @@ -102,7 +102,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns `x` unchanged', function test( t ) { +tape( 'if `alpha` equals `0`, the function returns the input array unchanged', function test( t ) { var expected; var x; diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.native.js index 88f1b812658..9f97b9f87a7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/test/test.sapx.native.js @@ -95,7 +95,7 @@ tape( 'the function returns a reference to the input array', opts, function test t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `x` unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var x; @@ -111,7 +111,7 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if `alpha` equals `0`, the function returns `x` unchanged', opts, function test( t ) { +tape( 'if `alpha` equals `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var x; From 569dbfe60a31f7921a00c186d494215e282720f5 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 17:36:26 -0700 Subject: [PATCH 02/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/sapx/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md index 11d6643dd3d..f7f1209044b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md @@ -50,7 +50,7 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment. -The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to add a constant to every other element +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to add a constant to every other element ```javascript var Float32Array = require( '@stdlib/array/float32' ); From 191cc490cd545fb32ac4d5ec8b5fc4e7aeec28da Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 17:38:06 -0700 Subject: [PATCH 03/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/sapx/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md index f7f1209044b..4c586daaceb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md @@ -131,7 +131,6 @@ var filledarrayBy = require( '@stdlib/array/filled-by' ); var sapx = require( '@stdlib/blas/ext/base/sapx' ); var rand = uniform( -100.0, 100.0 ); - var x = filledarrayBy( 10, 'float32', rand ); console.log( x ); From c495b971a1a93587182459e2b3f9411b3e409e14 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 17:38:51 -0700 Subject: [PATCH 04/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/sapx/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md index 4c586daaceb..4c14fd5482e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/README.md @@ -130,8 +130,7 @@ var uniform = require( '@stdlib/random/base/uniform' ).factory; var filledarrayBy = require( '@stdlib/array/filled-by' ); var sapx = require( '@stdlib/blas/ext/base/sapx' ); -var rand = uniform( -100.0, 100.0 ); -var x = filledarrayBy( 10, 'float32', rand ); +var x = filledarrayBy( 10, 'float32', uniform( -100.0, 100.0 ) ); console.log( x ); sapx( x.length, 5.0, x, 1 ); From 2d73d20bb7b8139bb268c0f113f6a5482b7eb5f7 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 17:39:47 -0700 Subject: [PATCH 05/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js index 73082767363..3e9bf3a73c8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/examples/index.js @@ -22,9 +22,7 @@ var uniform = require( '@stdlib/random/base/uniform' ).factory; var filledarrayBy = require( '@stdlib/array/filled-by' ); var sapx = require( './../lib' ); -var rand = uniform( -100.0, 100.0 ); - -var x = filledarrayBy( 10, 'float32', rand ); +var x = filledarrayBy( 10, 'float32', uniform( -100.0, 100.0 ) ); console.log( x ); From 162322ef85e3160eb87d93e39e2c5e5f17a51053 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 17:41:18 -0700 Subject: [PATCH 06/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json index 60128a8dcb1..6384f517450 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json @@ -38,7 +38,7 @@ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", - "@stdlib/napi/argv-double", + "@stdlib/napi/argv-float", "@stdlib/napi/argv-strided-float32array" ] } From 8fa21ac29b2794c4e48785ae84d4f4ce50ac94c0 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 17:41:53 -0700 Subject: [PATCH 07/14] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/blas/ext/base/sapx/lib/ndarray.native.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/sapx/lib/ndarray.native.js index b48fe887832..21a3eee655e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/lib/ndarray.native.js @@ -48,7 +48,6 @@ var addon = require( './sapx.native.js' ); */ function sapx( N, alpha, x, stride, offset ) { var view; - offset = minViewBufferIndex( N, stride, offset ); view = offsetView( x, offset ); addon( N, alpha, view, stride ); From 94b6e60e2f18eba7cd79f84692a030c818481f78 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 17:43:41 -0700 Subject: [PATCH 08/14] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/blas/ext/base/sapx/src/addon.c | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c index c6c8275609d..af06d62ec2d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c @@ -25,26 +25,20 @@ #include /** -* Adds a constant to each element in a single-precision floating-point strided array. +* Receives JavaScript callback invocation data. * -* ## Notes -* -* - When called from JavaScript, the function expects four arguments: -* -* - `N`: number of indexed elements -* - `alpha`: scalar -* - `X`: input array -* - `strideX`: `X` stride length +* @private +* @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, alpha, argv, 1 ); + STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 1 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ) - - c_sapx( N, (float)alpha, (float *)X, strideX ); - + stdlib_strided_sapx( N, alpha, X, strideX ); return NULL; } From f2d801754d16ffcf48dbd1cf493c0dab187ebfcf Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 17:44:18 -0700 Subject: [PATCH 09/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c index af06d62ec2d..b78956390e0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c @@ -38,7 +38,7 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV_FLOAT( env, alpha, argv, 1 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ) - stdlib_strided_sapx( N, alpha, X, strideX ); + c_sapx( N, alpha, X, strideX ); return NULL; } From 68a73fba22495940de00bf9815c7612868c7df93 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 17:47:37 -0700 Subject: [PATCH 10/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c index b78956390e0..45f5b485922 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/src/addon.c @@ -20,7 +20,7 @@ #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_float.h" #include "stdlib/napi/argv_strided_float32array.h" #include From 0ea7c6cc6d0319415ca1b6a9b4b4382beb2d91bb Mon Sep 17 00:00:00 2001 From: rxbryan Date: Thu, 21 Mar 2024 04:51:58 +0100 Subject: [PATCH 11/14] fix: implement changes from review update manifest.json, docs/repl.txt --- .../@stdlib/blas/ext/base/sapx/docs/repl.txt | 20 ++++++------- .../@stdlib/blas/ext/base/sapx/manifest.json | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt index 0c12d6d9d79..607ae0730f8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt @@ -1,15 +1,15 @@ {{alias}}( N, alpha, x, stride ) - Adds a constant to each element in a single-precision floating-point strided - array. + Adds a constant to each element in a single-precision floating-point + strided array. - The `N` and `stride` parameters determine which elements in `x` are accessed - at runtime. + The `N` and stride parameter determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N <= 0`, the function returns `x` unchanged. + If `N <= 0`, the function returns the strided array unchanged. Parameters ---------- @@ -40,23 +40,22 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); > alpha = 5.0; > var stride = 2; - > {{alias}}( N, alpha, x, stride ) + > {{alias}}( 3, alpha, x, stride ) [ 3.0, 1.0, 8.0, -5.0, 9.0, -1.0, -3.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); > alpha = 5.0; > stride = 2; - > {{alias}}( N, alpha, x1, stride ) + > {{alias}}( 3, alpha, x1, stride ) [ 3.0, 3.0, 1.0, 5.0, -1.0 ] > x0 [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] + {{alias}}.ndarray( N, alpha, x, stride, offset ) Adds a constant to each element in a single-precision floating-point strided array using alternative indexing semantics. @@ -97,10 +96,9 @@ // Using an index offset: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); > alpha = 5.0; > var stride = 2; - > {{alias}}.ndarray( N, alpha, x, stride, 1 ) + > {{alias}}.ndarray( 3, alpha, x, stride, 1 ) [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json index 6384f517450..4599eb5d7ca 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json @@ -24,6 +24,7 @@ ], "confs": [ { + "task": "build", "src": [ "./src/sapx.c" ], @@ -41,6 +42,34 @@ "@stdlib/napi/argv-float", "@stdlib/napi/argv-strided-float32array" ] + }, + { + "task": "benchmark", + "src": [ + "./src/sapx.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "src": [ + "./src/sapx.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] } ] } From 4b075256e21c27d0236a750cb4cf63812c115ae5 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 21:36:05 -0700 Subject: [PATCH 12/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt index 607ae0730f8..65d59f97d64 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt @@ -3,7 +3,7 @@ Adds a constant to each element in a single-precision floating-point strided array. - The `N` and stride parameter determine which elements in the strided array + The `N` and stride parameters determine which elements in the strided array are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use typed From c1d20f705eb27100aee45567b3de4c9ed08a4d48 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 21:36:55 -0700 Subject: [PATCH 13/14] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json index 4599eb5d7ca..7cef12cf17e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/manifest.json @@ -1,5 +1,7 @@ { - "options": {}, + "options": { + "task": "build" + }, "fields": [ { "field": "src", From 0d21a57830d5b62d30d01e19ec388d1298f33015 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 20 Mar 2024 21:39:14 -0700 Subject: [PATCH 14/14] docs: update descriptions Signed-off-by: Athan --- .../@stdlib/blas/ext/base/sapx/docs/repl.txt | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt index 65d59f97d64..42e084cc080 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/sapx/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( N, alpha, x, stride ) - Adds a constant to each element in a single-precision floating-point - strided array. + Adds a constant to each element in a single-precision floating-point strided + array. The `N` and stride parameters determine which elements in the strided array are accessed at runtime. @@ -23,34 +23,29 @@ Input array. stride: integer - Index increment for `x`. + Index increment. Returns ------- x: Float32Array - Input array `x`. + Input array. Examples -------- // Standard Usage: > var x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > var alpha = 5.0; - > {{alias}}( x.length, alpha, x, 1 ) + > {{alias}}( x.length, 5.0, x, 1 ) [ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ] // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > alpha = 5.0; - > var stride = 2; - > {{alias}}( 3, alpha, x, stride ) + > {{alias}}( 3, 5.0, x, 2 ) [ 3.0, 1.0, 8.0, -5.0, 9.0, -1.0, -3.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > alpha = 5.0; - > stride = 2; - > {{alias}}( 3, alpha, x1, stride ) + > {{alias}}( 3, 5.0, x1, 2 ) [ 3.0, 3.0, 1.0, 5.0, -1.0 ] > x0 [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] @@ -76,29 +71,26 @@ Input array. stride: integer - Index increment for `x`. + Index increment. offset: integer - Starting index of `x`. + Starting index. Returns ------- x: Float32Array - Input array `x`. + Input array. Examples -------- // Standard Usage: > var x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ] ); - > var alpha = 5.0; - > {{alias}}.ndarray( x.length, alpha, x, 1, 0 ) + > {{alias}}.ndarray( x.length, 5.0, x, 1, 0 ) [ 3.0, 6.0, 8.0, 0.0, 9.0, 4.0, 2.0 ] // Using an index offset: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); - > alpha = 5.0; - > var stride = 2; - > {{alias}}.ndarray( 3, alpha, x, stride, 1 ) + > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) [ 1.0, 3.0, 3.0, 1.0, 5.0, -1.0 ] See Also