From 28e349972b5197a7af86bfcd97046ed2b63bd5b1 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 10:26:44 +0530 Subject: [PATCH 01/17] update readme --- .../@stdlib/blas/base/snrm2/README.md | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/README.md b/lib/node_modules/@stdlib/blas/base/snrm2/README.md index 42d075a337a6..090ffb8ab4e1 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/README.md +++ b/lib/node_modules/@stdlib/blas/base/snrm2/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2020 The Stdlib Authors. +Copyright (c) 2023 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. @@ -67,16 +67,14 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **stride**: index increment for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [L2-norm][l2-norm] of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [L2-norm][l2-norm] of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var z = snrm2( N, x, 2 ); +var z = snrm2( 4, x, 2 ); // returns 5.0 ``` @@ -86,18 +84,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' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var z = snrm2( N, x1, 2 ); +var z = snrm2( 4, x1, 2 ); // returns 5.0 ``` -If either `N` or `stride` is less than or equal to `0`, the function returns `0`. +If either `N` or stride is less than or equal to `0`, the function returns `0`. #### snrm2.ndarray( N, x, stride, offset ) @@ -117,16 +112,14 @@ The function has the following additional parameters: - **offset**: starting index for `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 calculate the [L2-norm][l2-norm] for every other value in `x` starting from the second value +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 calculate the [L2-norm][l2-norm] for every other value in `x` starting from the second value ```javascript 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 N = floor( x.length / 2 ); -var z = snrm2.ndarray( N, x, 2, 1 ); +var z = snrm2.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -152,18 +145,11 @@ var z = snrm2.ndarray( N, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var snrm2 = require( '@stdlib/blas/base/snrm2' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); console.log( x ); var z = snrm2( x.length, x, 1 ); From 25cf500dcd5501ce8c968f643699ba015e285dfa Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 10:31:21 +0530 Subject: [PATCH 02/17] refactor docs/ --- .../@stdlib/blas/base/snrm2/docs/repl.txt | 13 +++++-------- .../@stdlib/blas/base/snrm2/docs/types/index.d.ts | 8 ++++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/snrm2/docs/repl.txt index 1dc15bd6235d..b426d7c10a2b 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/snrm2/docs/repl.txt @@ -2,8 +2,8 @@ {{alias}}( N, x, stride ) Computes the L2-norm of a single-precision floating-point vector. - The `N` and `stride` parameters determine which elements in `x` 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. @@ -35,17 +35,15 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, x, stride ) 3.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.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 ); > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 3, x1, stride ) 3.0 {{alias}}.ndarray( N, x, stride, offset ) @@ -84,8 +82,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) 3.0 See Also diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/snrm2/docs/types/index.d.ts index 3293523c8a8d..59cbe8868e77 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/snrm2/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -25,7 +25,7 @@ interface Routine { /** * Computes the L2-norm of a single-precision floating-point vector. * - * @param N - number of values over which to compute the L2-norm + * @param N - number of values * @param x - input array * @param stride - stride length * @returns L2-norm @@ -43,7 +43,7 @@ interface Routine { /** * Computes the L2-norm of a single-precision floating-point vector using alternative indexing semantics. * - * @param N - number of values over which to compute the L2-norm + * @param N - number of values * @param x - input array * @param stride - stride length * @param offset - starting index @@ -63,7 +63,7 @@ interface Routine { /** * Computes the L2-norm of a single-precision floating-point vector. * -* @param N - number of values over which to compute the L2-norm +* @param N - number of values * @param x - input array * @param stride - stride length * @returns L2-norm From 7f96b956d522a3ff2530efa0925661bcf5e5b602 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 10:47:42 +0530 Subject: [PATCH 03/17] refactor src/ --- .../@stdlib/blas/base/snrm2/src/addon.c | 48 +++++++ .../@stdlib/blas/base/snrm2/src/addon.cpp | 117 ------------------ .../@stdlib/blas/base/snrm2/src/snrm2.c | 4 +- .../@stdlib/blas/base/snrm2/src/snrm2.f | 8 +- .../@stdlib/blas/base/snrm2/src/snrm2_cblas.c | 4 +- .../@stdlib/blas/base/snrm2/src/snrm2_f.c | 4 +- .../@stdlib/blas/base/snrm2/src/snrm2sub.f | 6 +- 7 files changed, 61 insertions(+), 130 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c delete mode 100644 lib/node_modules/@stdlib/blas/base/snrm2/src/addon.cpp diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c b/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c new file mode 100644 index 000000000000..7484a2d7c69f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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/base/snrm2.h" +#include "stdlib/napi/export.h" +#include "stdlib/napi/argv.h" +#include "stdlib/napi/argv_float.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv_strided_float32array.h" +#include + + +/** +* Receives JavaScript callback invocation data. +* +* @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, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); + napi_value v; + status = napi_create_double( env, (double)c_snrm2( N, (float *)X, strideX ), &v ); + assert( status == napi_ok ); + + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.cpp b/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.cpp deleted file mode 100644 index 755cc9972682..000000000000 --- a/lib/node_modules/@stdlib/blas/base/snrm2/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/blas/base/snrm2.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_base_snrm2 { - - /** - * Computes the L2-norm of a single-precision floating-point vector. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `strideX`: `X` stride length - */ - napi_value node_snrm2( 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 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; - } - - 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 ); - - 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_value v; - status = napi_create_double( env, (double)c_snrm2( N, (float *)X, strideX ), &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_snrm2, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_base_snrm2 diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.c b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.c index baad15ef604b..ca97030230de 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.c +++ b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -22,7 +22,7 @@ /** * Computes the L2-norm of a single-precision floating-point vector. * -* @param N number of values over which to compute the norm +* @param N number of values * @param X input array * @param stride stride length * @return output value diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.f b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.f index 24338db6bb8e..41e61dcbd761 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.f +++ b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.f @@ -1,7 +1,7 @@ !> ! @license Apache-2.0 ! -! Copyright (c) 2020 The Stdlib Authors. +! Copyright (c) 2023 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. @@ -45,10 +45,10 @@ ! > ! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support. ! -! @param {integer} N - number of values over which to compute the norm +! @param {integer} N - number of value ! @param {Array} sx - array ! @param {integer} stride - stride length -! @returns {real} L2-norm +! @returns {real} output value !< real function snrm2( N, sx, stride ) implicit none @@ -91,4 +91,4 @@ real function snrm2( N, sx, stride ) end if end do snrm2 = scale * sqrt( ssq ) -end function snrm2 \ No newline at end of file +end function snrm2 diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2_cblas.c b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2_cblas.c index 6a3c9f43492f..2aa796c69961 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2_cblas.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -22,7 +22,7 @@ /** * Computes the L2-norm of a single-precision floating-point vector. * -* @param N number of values over which to compute the norm +* @param N number of values * @param X input array * @param stride stride length * @return output value diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2_f.c b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2_f.c index 1cbb340d5ba6..fa425f14df91 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2_f.c +++ b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2_f.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -22,7 +22,7 @@ /** * Computes the L2-norm of a single-precision floating-point vector. * -* @param N number of values over which to compute the norm +* @param N number of values * @param X input array * @param stride stride length * @return output value diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2sub.f b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2sub.f index 940e3a0ce848..9996f2760749 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2sub.f +++ b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2sub.f @@ -1,7 +1,7 @@ !> ! @license Apache-2.0 ! -! Copyright (c) 2020 The Stdlib Authors. +! Copyright (c) 2023 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. @@ -18,7 +18,7 @@ !> Wraps `snrm2` as a subroutine. ! -! @param {integer} N - number of values over which to compute the norm +! @param {integer} N - number of values ! @param {Array} sx - input array ! @param {integer} stride - stride length ! @param {real} nrm2 - output variable reference @@ -44,4 +44,4 @@ end function snrm2 ! Compute the L2-norm: nrm2 = snrm2( N, sx, stride ) return -end subroutine snrm2sub \ No newline at end of file +end subroutine snrm2sub From 797b952f4c35ba45d8498669304e7b8135f421b4 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 10:51:23 +0530 Subject: [PATCH 04/17] update include.gypi, manifest.json and package.json --- .../@stdlib/blas/base/snrm2/include.gypi | 4 +- .../@stdlib/blas/base/snrm2/manifest.json | 42 ++++++++++++++++--- .../@stdlib/blas/base/snrm2/package.json | 4 +- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/include.gypi b/lib/node_modules/@stdlib/blas/base/snrm2/include.gypi index 22e6289c74db..f8b01bfb52cb 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/include.gypi +++ b/lib/node_modules/@stdlib/blas/base/snrm2/include.gypi @@ -1,6 +1,6 @@ # @license Apache-2.0 # -# Copyright (c) 2018 The Stdlib Authors. +# Copyright (c) 2023 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. @@ -52,7 +52,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' Date: Tue, 24 Jan 2023 10:53:55 +0530 Subject: [PATCH 05/17] refactor lib/ --- .../@stdlib/blas/base/snrm2/lib/ndarray.js | 6 +++--- .../blas/base/snrm2/lib/ndarray.native.js | 19 ++++++++++--------- .../@stdlib/blas/base/snrm2/lib/snrm2.js | 6 +++--- .../blas/base/snrm2/lib/snrm2.native.js | 6 +++--- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js index e1245664c401..52a98661b15a 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -31,11 +31,11 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); /** * Computes the L2-norm of a single-precision floating-point vector. * -* @param {PositiveInteger} N - number of values over which to compute the L2-norm +* @param {PositiveInteger} N - number of values * @param {Float32Array} x - input array * @param {integer} stride - stride length * @param {NonNegativeInteger} offset - starting index -* @returns {number} L2-norm +* @returns {number} output value * * @example * var Float32Array = require( '@stdlib/array/float32' ); diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js index f6e8a6b7183b..a7838baa1345 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -20,7 +20,8 @@ // MODULES // -var Float32Array = require( '@stdlib/array/float32' ); +var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); +var offsetView = require( '@stdlib/strided/base/offset-view' ); var addon = require( './snrm2.native.js' ); @@ -29,11 +30,11 @@ var addon = require( './snrm2.native.js' ); /** * Computes the L2-norm of a single-precision floating-point vector. * -* @param {PositiveInteger} N - number of values over which to compute the L2-norm +* @param {PositiveInteger} N - number of values * @param {Float32Array} x - input array * @param {integer} stride - stride length * @param {NonNegativeInteger} offset - starting index -* @returns {number} L2-norm of `x` +* @returns {number} output value * * @example * var Float32Array = require( '@stdlib/array/float32' ); @@ -47,11 +48,11 @@ var addon = require( './snrm2.native.js' ); */ function snrm2( N, x, stride, offset ) { var view; - if ( stride < 0 ) { - stride *= -1; - offset -= (N-1) * stride; - } - view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len + + offset = minViewBufferIndex( N, stride, offset ); + + view = offsetView( x, offset ); + return addon( N, view, stride ); } diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.js index d652163e6a3a..bb7c9dc5d6f6 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -31,10 +31,10 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); /** * Computes the L2-norm of a single-precision floating-point vector. * -* @param {PositiveInteger} N - number of values over which to compute the L2-norm +* @param {PositiveInteger} N - number of values * @param {Float32Array} x - input array * @param {PositiveInteger} stride - stride length -* @returns {number} L2-norm +* @returns {number} output value * * @example * var Float32Array = require( '@stdlib/array/float32' ); diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.native.js index 6e9377c7c9ca..514fb3797833 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -28,10 +28,10 @@ var addon = require( './../src/addon.node' ); /** * Computes the L2-norm of a single-precision floating-point vector. * -* @param {PositiveInteger} N - number of values over which to compute the L2-norm +* @param {PositiveInteger} N - number of values * @param {Float32Array} x - input array * @param {PositiveInteger} stride - stride length -* @returns {number} L2-norm of `x` +* @returns {number} output value * * @example * var Float32Array = require( '@stdlib/array/float32' ); From 22a7e272c9f13a89d27041e41294d7622c795a44 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 11:02:45 +0530 Subject: [PATCH 06/17] refactor examples/ --- .../@stdlib/blas/base/snrm2/examples/index.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/examples/index.js b/lib/node_modules/@stdlib/blas/base/snrm2/examples/index.js index 3c8ccd3549d6..c2e8cf2d3fde 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -18,18 +18,11 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); var snrm2 = require( './../lib' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*10.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); console.log( x ); var z = snrm2( x.length, x, 1 ); From 02c5fa5f4927502aad41b05646924ade1599f7c6 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 11:06:36 +0530 Subject: [PATCH 07/17] update addon.c --- lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c b/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c index 7484a2d7c69f..9d4d55e17b2d 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c @@ -19,7 +19,6 @@ #include "stdlib/blas/base/snrm2.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" -#include "stdlib/napi/argv_float.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float32array.h" #include @@ -34,6 +33,8 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { + napi_status status; + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); From 793a9d38ba50293f309ac494f60c029598a81738 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 11:09:50 +0530 Subject: [PATCH 08/17] refactor benchmark/ --- .../blas/base/snrm2/benchmark/benchmark.js | 19 +++++++++---------- .../base/snrm2/benchmark/benchmark.native.js | 15 +++++---------- .../base/snrm2/benchmark/benchmark.ndarray.js | 19 +++++++++---------- .../benchmark/benchmark.ndarray.native.js | 15 +++++---------- 4 files changed, 28 insertions(+), 40 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.js index 4fe56bef14bb..96389a2aea56 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -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 snrm2 = require( './../lib/snrm2.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var snrm2 = require( './../lib/snrm2.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; 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/base/snrm2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.native.js index a72785d76756..9c274bb44dd4 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -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 snrm2 = tryRequire( resolve( __dirname, './../lib/snrm2.native.js' ) ); var opts = { 'skip': ( snrm2 instanceof Error ) }; +var rand = uniform( -10.0, 10.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 < x.length; 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/base/snrm2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.ndarray.js index 1c96d014489d..cdc60816eb83 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -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 snrm2 = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -10.0, 10.0 ); + + // FUNCTIONS // /** @@ -39,13 +44,7 @@ var snrm2 = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = new Float32Array( len ); - for ( i = 0; i < x.length; 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/base/snrm2/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.ndarray.native.js index 3d8e6cfabe18..71909d17690f 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/benchmark/benchmark.ndarray.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -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 snrm2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( snrm2 instanceof Error ) }; +var rand = uniform( -10.0, 10.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 < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { From 58fce9094d016e99f43acc12b2965fe5877f978b Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 11:21:41 +0530 Subject: [PATCH 09/17] refactor tests/ --- .../@stdlib/blas/base/snrm2/test/test.ndarray.js | 9 ++++----- .../@stdlib/blas/base/snrm2/test/test.snrm2.js | 7 +++---- .../@stdlib/blas/base/snrm2/test/test.snrm2.native.js | 7 +++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.js index dd1f2e99225c..1aafff21a194 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float32Array = require( '@stdlib/array/float32' ); var snrm2 = require( './../lib/ndarray.js' ); @@ -87,7 +86,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; z = snrm2( N, x, 2, 0 ); t.strictEqual( z, 5.0, 'returns expected value' ); @@ -110,7 +109,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); + N = 4; z = snrm2( N, x, -2, x.length-2 ); t.strictEqual( z, 5.0, 'returns expected value' ); @@ -132,7 +131,7 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); + N = 4; z = snrm2( N, x, 2, 1 ); t.strictEqual( z, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.js b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.js index eb34d9ee3d72..10a151653d5c 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float32Array = require( '@stdlib/array/float32' ); var snrm2 = require( './../lib/snrm2.js' ); @@ -87,7 +86,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; z = snrm2( N, x, 2 ); t.strictEqual( z, 5.0, 'returns expected value' ); @@ -128,7 +127,7 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); + N = 4; z = snrm2( N, x1, 2 ); t.strictEqual( z, 5.0, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.native.js index fbabb8ea61fd..b58590e889b1 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.snrm2.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -96,7 +95,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; z = snrm2( N, x, 2 ); t.strictEqual( z, 5.0, 'returns expected value' ); @@ -137,7 +136,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); + N = 4; z = snrm2( N, x1, 2 ); t.strictEqual( z, 5.0, 'returns expected value' ); From 511ec3076ed43c255d9c40ea847fa0e61c8ed65a Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 11:32:23 +0530 Subject: [PATCH 10/17] update lib/ndarray.native.js --- .../@stdlib/blas/base/snrm2/lib/ndarray.native.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js index a7838baa1345..c2effa75f664 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js @@ -38,12 +38,10 @@ var addon = require( './snrm2.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 N = floor( x.length / 2 ); * -* var z = snrm2( N, x, 2, 1 ); +* var z = snrm2( 4, x, 2, 1 ); * // returns 5.0 */ function snrm2( N, x, stride, offset ) { From 3b59e1ec94904124105566a5570dc5e4f5af4016 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Tue, 24 Jan 2023 12:05:13 +0530 Subject: [PATCH 11/17] update ndarray.js --- lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js index 52a98661b15a..cbe85a04f6eb 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js @@ -39,13 +39,11 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * * @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 N = floor( x.length / 2 ); * -* var z = snrm2( N, x, 2, 1 ); -* // returns 5.0 +* var z = snrm2( 3, x, 2, 1 ); +* // returns 3.0 */ function snrm2( N, x, stride, offset ) { var scale; From c7f2afa190dda95100e62775e1a0795baced435a Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Tue, 24 Jan 2023 12:06:14 +0530 Subject: [PATCH 12/17] Update lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js --- lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js index cbe85a04f6eb..5130e056d5aa 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js @@ -43,7 +43,7 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * * var z = snrm2( 3, x, 2, 1 ); -* // returns 3.0 +* // returns 5.0 */ function snrm2( N, x, stride, offset ) { var scale; From 6897b7d3994e5c555b22b86123c48fb87f8814eb Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Thu, 26 Jan 2023 10:37:18 +0530 Subject: [PATCH 13/17] temp commit --- .../@stdlib/blas/base/snrm2/test/test.ndarray.native.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.native.js index 83395a92f36e..d681360bf42d 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/test/test.ndarray.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 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. @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -96,7 +95,7 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); + N = 4; z = snrm2( N, x, 2, 0 ); t.strictEqual( z, 5.0, 'returns expected value' ); @@ -119,7 +118,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); + N = 4; z = snrm2( N, x, -2, x.length-2 ); t.strictEqual( z, 5.0, 'returns expected value' ); @@ -141,7 +140,7 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); + N = 4; z = snrm2( N, x, 2, 1 ); t.strictEqual( z, 5.0, 'returns expected value' ); From 9f918e9b4033a3028d5cb90ba1bc5fd04fd3ee0e Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Sun, 26 Feb 2023 14:45:44 +0530 Subject: [PATCH 14/17] Add logic to convert negative stride to positive --- .../@stdlib/blas/base/snrm2/lib/ndarray.native.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js index c2effa75f664..6e94a13e09dc 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js @@ -46,6 +46,10 @@ var addon = require( './snrm2.native.js' ); */ function snrm2( N, x, stride, offset ) { var view; + if ( stride < 0 ) { + stride *= -1; + offset -= (N-1) * stride; + } offset = minViewBufferIndex( N, stride, offset ); From 79059eec9f6e1674cf1dd640004f42ec7f83fff8 Mon Sep 17 00:00:00 2001 From: Pranavchiku Date: Sun, 26 Feb 2023 14:46:45 +0530 Subject: [PATCH 15/17] fix linting errors --- lib/node_modules/@stdlib/blas/base/snrm2/docs/repl.txt | 1 + lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/snrm2/docs/repl.txt index b426d7c10a2b..06f443ee8470 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/snrm2/docs/repl.txt @@ -46,6 +46,7 @@ > {{alias}}( 3, x1, stride ) 3.0 + {{alias}}.ndarray( N, x, stride, offset ) Computes the L2-norm of a single-precision floating-point vector using alternative indexing semantics. diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js index 5130e056d5aa..cbe85a04f6eb 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js @@ -43,7 +43,7 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * * var z = snrm2( 3, x, 2, 1 ); -* // returns 5.0 +* // returns 3.0 */ function snrm2( N, x, stride, offset ) { var scale; From 9302a5dbd811e23f22621b7e9728afe5887e3926 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 28 Feb 2023 22:30:27 -0800 Subject: [PATCH 16/17] docs: add backticks --- lib/node_modules/@stdlib/blas/base/snrm2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/README.md b/lib/node_modules/@stdlib/blas/base/snrm2/README.md index 090ffb8ab4e1..b27a5b7724dd 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/README.md +++ b/lib/node_modules/@stdlib/blas/base/snrm2/README.md @@ -92,7 +92,7 @@ var z = snrm2( 4, x1, 2 ); // returns 5.0 ``` -If either `N` or stride is less than or equal to `0`, the function returns `0`. +If either `N` or `stride` is less than or equal to `0`, the function returns `0`. #### snrm2.ndarray( N, x, stride, offset ) From 62885b39bffb480cbbd01d4078433095db3f3a29 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 28 Feb 2023 22:42:16 -0800 Subject: [PATCH 17/17] Apply suggestions from code review --- .../@stdlib/blas/base/snrm2/lib/ndarray.js | 6 +++--- .../@stdlib/blas/base/snrm2/lib/ndarray.native.js | 5 +---- .../@stdlib/blas/base/snrm2/lib/snrm2.js | 2 +- .../@stdlib/blas/base/snrm2/lib/snrm2.native.js | 2 +- lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c | 12 +++++------- lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.f | 2 +- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js index cbe85a04f6eb..9991ffe79a90 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.js @@ -35,15 +35,15 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * @param {Float32Array} x - input array * @param {integer} stride - stride length * @param {NonNegativeInteger} offset - starting index -* @returns {number} output value +* @returns {number} L2-norm * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * -* var z = snrm2( 3, x, 2, 1 ); -* // returns 3.0 +* var z = snrm2( 4, x, 2, 1 ); +* // returns 5.0 */ function snrm2( N, x, stride, offset ) { var scale; diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js index 6e94a13e09dc..26040692de8b 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/ndarray.native.js @@ -34,7 +34,7 @@ var addon = require( './snrm2.native.js' ); * @param {Float32Array} x - input array * @param {integer} stride - stride length * @param {NonNegativeInteger} offset - starting index -* @returns {number} output value +* @returns {number} L2-norm * * @example * var Float32Array = require( '@stdlib/array/float32' ); @@ -50,11 +50,8 @@ function snrm2( N, x, stride, offset ) { stride *= -1; offset -= (N-1) * stride; } - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - return addon( N, view, stride ); } diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.js index bb7c9dc5d6f6..d07b29f4090a 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.js @@ -34,7 +34,7 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * @param {PositiveInteger} N - number of values * @param {Float32Array} x - input array * @param {PositiveInteger} stride - stride length -* @returns {number} output value +* @returns {number} L2-norm * * @example * var Float32Array = require( '@stdlib/array/float32' ); diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.native.js b/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.native.js index 514fb3797833..f6e1e9376f54 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.native.js +++ b/lib/node_modules/@stdlib/blas/base/snrm2/lib/snrm2.native.js @@ -31,7 +31,7 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of values * @param {Float32Array} x - input array * @param {PositiveInteger} stride - stride length -* @returns {number} output value +* @returns {number} L2-norm * * @example * var Float32Array = require( '@stdlib/array/float32' ); diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c b/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c index 9d4d55e17b2d..fa9efd9ee9d6 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/snrm2/src/addon.c @@ -23,7 +23,6 @@ #include "stdlib/napi/argv_strided_float32array.h" #include - /** * Receives JavaScript callback invocation data. * @@ -33,17 +32,16 @@ * @return Node-API value */ static napi_value addon( napi_env env, napi_callback_info info ) { - napi_status status; - STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 1 ); - napi_value v; - status = napi_create_double( env, (double)c_snrm2( N, (float *)X, strideX ), &v ); - assert( status == napi_ok ); - return v; + napi_value v; + napi_status status = napi_create_double( env, (double)c_snrm2( N, (float *)X, strideX ), &v ); + assert( status == napi_ok ); + + return v; } STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.f b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.f index 41e61dcbd761..4734f40acecc 100644 --- a/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.f +++ b/lib/node_modules/@stdlib/blas/base/snrm2/src/snrm2.f @@ -45,7 +45,7 @@ ! > ! > * We will gladly answer any questions regarding the software. If a modification is done, however, it is the responsibility of the person who modified the routine to provide support. ! -! @param {integer} N - number of value +! @param {integer} N - number of values ! @param {Array} sx - array ! @param {integer} stride - stride length ! @returns {real} output value