From c8985f24ec8929f5b539fbcdf782f5bc3a7a9242 Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Thu, 2 Mar 2023 06:00:46 +0530 Subject: [PATCH] refactor: update add-on, examples, benchmarks, and docs This commit migrates `@stdlib/blas/base/sdsdot` to use current project conventions, as discussed in https://github.com/stdlib-js/stdlib/issues/788. PR-URL: https://github.com/stdlib-js/stdlib/pull/799 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/blas/base/sdsdot/README.md | 38 ++-- .../blas/base/sdsdot/benchmark/benchmark.js | 23 ++- .../base/sdsdot/benchmark/benchmark.native.js | 19 +- .../sdsdot/benchmark/benchmark.ndarray.js | 23 ++- .../benchmark/benchmark.ndarray.native.js | 19 +- .../@stdlib/blas/base/sdsdot/docs/repl.txt | 21 +-- .../blas/base/sdsdot/docs/types/index.d.ts | 14 +- .../blas/base/sdsdot/examples/index.js | 24 +-- .../@stdlib/blas/base/sdsdot/include.gypi | 4 +- .../@stdlib/blas/base/sdsdot/lib/ndarray.js | 6 +- .../blas/base/sdsdot/lib/ndarray.native.js | 24 +-- .../@stdlib/blas/base/sdsdot/lib/sdsdot.js | 6 +- .../blas/base/sdsdot/lib/sdsdot.native.js | 6 +- .../@stdlib/blas/base/sdsdot/manifest.json | 48 ++++- .../@stdlib/blas/base/sdsdot/package.json | 5 +- .../@stdlib/blas/base/sdsdot/src/addon.c | 51 ++++++ .../@stdlib/blas/base/sdsdot/src/addon.cpp | 166 ------------------ .../@stdlib/blas/base/sdsdot/src/sdsdot.c | 6 +- .../@stdlib/blas/base/sdsdot/src/sdsdot.f | 8 +- .../blas/base/sdsdot/src/sdsdot_cblas.c | 6 +- .../@stdlib/blas/base/sdsdot/src/sdsdot_f.c | 6 +- .../@stdlib/blas/base/sdsdot/src/sdsdotsub.f | 4 +- 22 files changed, 202 insertions(+), 325 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/base/sdsdot/src/addon.c delete mode 100644 lib/node_modules/@stdlib/blas/base/sdsdot/src/addon.cpp diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/README.md b/lib/node_modules/@stdlib/blas/base/sdsdot/README.md index fe8a4f966e9..7238f2236d3 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/README.md +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/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. @@ -70,18 +70,15 @@ The function has the following parameters: - **y**: input [`Float32Array`][@stdlib/array/float32]. - **strideY**: index increment for `y`. -The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to calculate the dot product of every other value in `x` and the first `N` elements of `y` in reverse order, +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the dot product of every other value in `x` and the first `N` elements of `y` in reverse order, ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); -var N = floor( x.length / 2 ); - -var z = sdsdot( N, 0.0, x, 2, y, -1 ); +var z = sdsdot( 3, 0.0, x, 2, y, -1 ); // returns 9.0 ``` @@ -101,9 +98,7 @@ var y0 = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element -var N = floor( x0.length / 2 ); - -var z = sdsdot( N, 0.0, x1, -2, y1, 1 ); +var z = sdsdot( 3, 0.0, x1, -2, y1, 1 ); // returns 128.0 ``` @@ -126,18 +121,15 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsetX` and `offsetY` parameters support indexing semantics based on starting indices. For example, to calculate the dot product of every other value in `x` starting from the second value with the last 3 elements in `y` in reverse order +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameters support indexing semantics based on starting indices. For example, to calculate the dot product of every other value in `x` starting from the second value with the last 3 elements in `y` in reverse order ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); var y = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); -var N = floor( x.length / 2 ); - -var z = sdsdot.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); +var z = sdsdot.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 ); // returns 128.0 ``` @@ -163,22 +155,14 @@ var z = sdsdot.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-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 sdsdot = require( '@stdlib/blas/base/sdsdot' ); -var x; -var y; -var i; - -x = new Float32Array( 10 ); -y = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu() * 100.0 ); - y[ i ] = round( randu() * 10.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); console.log( x ); + +var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) ); console.log( y ); var z = sdsdot( x.length, 0.0, x, 1, y, -1 ); diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.js index 75cebf81195..e9d17a11819 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/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 sdsdot = require( './../lib/sdsdot.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,16 +44,8 @@ var sdsdot = require( './../lib/sdsdot.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - y[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); + var y = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.native.js index d70aaa377ff..0527a93d960 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/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 sdsdot = tryRequire( resolve( __dirname, './../lib/sdsdot.native.js' ) ); var opts = { 'skip': ( sdsdot instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,16 +49,8 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - y[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); + var y = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.ndarray.js index 52a84b24fb2..a3015e89c4e 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/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 sdsdot = require( './../lib/ndarray.js' ); +// VARIABLES // + +var rand = uniform( -100.0, 100.0 ); + + // FUNCTIONS // /** @@ -39,16 +44,8 @@ var sdsdot = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - y[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); + var y = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.ndarray.native.js index 5d4af456b36..8d194eace8b 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/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 sdsdot = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); var opts = { 'skip': ( sdsdot instanceof Error ) }; +var rand = uniform( -100.0, 100.0 ); // FUNCTIONS // @@ -48,16 +49,8 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = new Float32Array( len ); - y = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - y[ i ] = ( randu()*20.0 ) - 10.0; - } + var x = filledarrayBy( len, 'float32', rand ); + var y = filledarrayBy( len, 'float32', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/sdsdot/docs/repl.txt index 8505b469dbe..859b2a1b49c 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/docs/repl.txt @@ -3,8 +3,8 @@ Computes the dot product of two single-precision floating-point vectors with extended accumulation. - The `N`, `strideX`, and `strideY` 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 a typed array view. @@ -34,7 +34,7 @@ Returns ------- dot: number - The dot product of `x` and `y`. + The dot product. Examples -------- @@ -47,8 +47,7 @@ // Strides: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > dot = {{alias}}( N, 0.0, x, 2, y, -1 ) + > dot = {{alias}}( 3, 0.0, x, 2, y, -1 ) 9.0 // Using view offsets: @@ -56,10 +55,10 @@ > y = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x.buffer, x.BYTES_PER_ELEMENT*1 ); > var y1 = new {{alias:@stdlib/array/float32}}( y.buffer, y.BYTES_PER_ELEMENT*3 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > dot = {{alias}}( N, 0.0, x1, -2, y1, 1 ) + > dot = {{alias}}( 3, 0.0, x1, -2, y1, 1 ) 128.0 + {{alias}}.ndarray( N, scalar, x, strideX, offsetX, y, strideY, offsetY ) Computes the dot product of two single-precision floating-point vectors using alternative indexing semantics and with extended accumulation. @@ -97,7 +96,7 @@ Returns ------- dot: number - The dot product of `x` and `y`. + The dot product. Examples -------- @@ -110,15 +109,13 @@ // Strides: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > dot = {{alias}}.ndarray( N, 0.0, x, 2, 0, y, 2, 0 ) + > dot = {{alias}}.ndarray( 3, 0.0, x, 2, 0, y, 2, 0 ) 9.0 // Using offset indices: > x = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); > y = new {{alias:@stdlib/array/float32}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); - > N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > dot = {{alias}}.ndarray( N, 0.0, x, -2, x.length-1, y, 1, 3 ) + > dot = {{alias}}.ndarray( 3, 0.0, x, -2, x.length-1, y, 1, 3 ) 128.0 References diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/sdsdot/docs/types/index.d.ts index a88e8a975f6..a38854fc644 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/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,13 +25,13 @@ interface Routine { /** * Computes the dot product of two single-precision floating-point vectors with extended accumulation. * - * @param N - number of values over which to compute the dot product + * @param N - number of values * @param scalar - scalar constant added to dot product * @param x - first input array * @param strideX - `x` stride length * @param y - second input array * @param strideY - `y` stride length - * @returns dot product of `x` and `y` + * @returns dot product * * @example * var Float32Array = require( `@stdlib/array/float32` ); @@ -47,7 +47,7 @@ interface Routine { /** * Computes the dot product of two single-precision floating-point vectors using alternative indexing semantics and with extended accumulation. * - * @param N - number of values over which to compute the dot product + * @param N - number of values * @param scalar - scalar constant added to dot product * @param x - first input array * @param strideX - `x` stride length @@ -55,7 +55,7 @@ interface Routine { * @param y - second input array * @param strideY - `y` stride length * @param offsetY - starting index for `y` - * @returns dot product of `x` and `y` + * @returns dot product * * @example * var Float32Array = require( `@stdlib/array/float32` ); @@ -72,13 +72,13 @@ interface Routine { /** * Computes the dot product of two single-precision floating-point vectors with extended accumulation. * -* @param N - number of values over which to compute the dot product +* @param N - number of values * @param scalar - scalar constant added to dot product * @param x - first input array * @param strideX - `x` stride length * @param y - second input array * @param strideY - `y` stride length -* @returns dot product of `x` and `y` +* @returns dot product * * @example * var Float32Array = require( `@stdlib/array/float32` ); diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/examples/index.js b/lib/node_modules/@stdlib/blas/base/sdsdot/examples/index.js index ec424726224..202780c8682 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/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,23 +18,15 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); -var sdsdot = require( './../lib' ).ndarray; +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var sdsdot = require( './../lib' ); -var x; -var y; -var i; - -x = new Float32Array( 10 ); -y = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); - y[ i ] = round( randu()*10.0 ); -} +var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) ); console.log( x ); + +var y = filledarrayBy( x.length, 'float32', discreteUniform( 0, 10 ) ); console.log( y ); -var dot = sdsdot( x.length, 0.0, x, 1, 0, y, -1, y.length-1 ); +var dot = sdsdot( x.length, 0.0, x, 1, y, -1 ); console.log( dot ); diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/include.gypi b/lib/node_modules/@stdlib/blas/base/sdsdot/include.gypi index 22e6289c74d..f8b01bfb52c 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/include.gypi +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/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', ' + +/** +* 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, 6 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, scalar, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, strideY, argv, 5 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, Y, N, strideY, argv, 4 ); + + napi_value v; + napi_status status = napi_create_double( env, (double)c_sdsdot( N, scalar, (float *)X, strideX, (float *)Y, strideY ), &v ); + assert( status == napi_ok ); + + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/src/addon.cpp b/lib/node_modules/@stdlib/blas/base/sdsdot/src/addon.cpp deleted file mode 100644 index 995a362e0cf..00000000000 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/src/addon.cpp +++ /dev/null @@ -1,166 +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/sdsdot.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_base_sdsdot { - - /** - * Computes the dot product of two single-precision floating-point vectors with extended accumulation. - * - * ## Notes - * - * - When called from JavaScript, the function expects six arguments: - * - * - `N`: number of indexed elements - * - `scalar`: scalar constant to add to dot product - * - `X`: input array - * - `strideX`: `X` stride length - * - `Y`: destination array - * - `strideY`: `Y` stride length - */ - napi_value node_sdsdot( 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 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; - } - - 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 Float32Array." ); - 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 scalar; - status = napi_get_value_double( env, argv[ 1 ], &scalar ); - 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_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; - } - - 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_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Fifth argument must be a Float32Array." ); - 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; - } - - napi_value v; - status = napi_create_double( env, (double)c_sdsdot( N, (float)scalar, (float *)X, strideX, (float *)Y, strideY ), &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_sdsdot, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_base_sdsdot diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.c b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.c index feff0991e0a..358c9e12edc 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.c +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.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. @@ -26,13 +26,13 @@ /** * Computes the dot product of two single-precision floating-point vectors with extended accumulation. * -* @param N number of values over which to compute the dot product +* @param N number of values * @param scalar scalar constant added to the dot product * @param X first array * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product of X and Y +* @returns dot product */ float c_sdsdot( const int N, const float scalar, const float *X, const int strideX, const float *Y, const int strideY ) { double dot; diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.f b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.f index 5c97236df72..bfc197ea055 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.f +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot.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. @@ -60,13 +60,13 @@ ! > ! > * 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 dot product +! @param {integer} N - number of values ! @param {real} sb - scalar constant added to the dot product ! @param {Array} sx - first array ! @param {integer} strideX - `sx` stride length ! @param {Array} sy - second array ! @param {integer} strideY - `sy` stride length -! @returns {real} the dot product of `sx` and `sy` +! @returns {real} dot product !< real function sdsdot( N, sb, sx, strideX, sy, strideY ) implicit none @@ -134,4 +134,4 @@ real function sdsdot( N, sb, sx, strideX, sy, strideY ) endif sdsdot = real( dtemp ) return -end function sdsdot \ No newline at end of file +end function sdsdot diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_cblas.c b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_cblas.c index ffad84648be..62fcf288604 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_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,13 +22,13 @@ /** * Computes the dot product of two single-precision floating-point vectors with extended accumulation. * -* @param N number of values over which to compute the dot product +* @param N number of values * @param scalar scalar constant added to the dot product * @param X first array * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product of X and Y +* @returns dot product */ float c_sdsdot( const int N, const float scalar, const float *X, const int strideX, const float *Y, const int strideY ) { return cblas_sdsdot( N, scalar, X, strideX, Y, strideY ); diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_f.c b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_f.c index 15fd5b99c89..e2bccefeb22 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_f.c +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdot_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. @@ -29,13 +29,13 @@ * * Arguments are passed by reference to a Fortran subroutine implementing `sdsdot`. * -* @param N number of values over which to compute the dot product +* @param N number of values * @param scalar scalar constant added to the dot product * @param X first array * @param strideX X stride length * @param Y second array * @param strideY Y stride length -* @returns the dot product of X and Y +* @returns dot product */ float c_sdsdot( const int N, const float scalar, const float *X, const int strideX, const float *Y, const int strideY ) { float dot; diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdotsub.f b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdotsub.f index de33074654d..2f414c47af4 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdotsub.f +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/src/sdsdotsub.f @@ -18,7 +18,7 @@ !> Wraps `sdsdot` as a subroutine. ! -! @param {integer} N - number of values over which to compute the dot product +! @param {integer} N - number of values ! @param {real} sb - scalar constant added to the dot product ! @param {Array} sx - first array ! @param {integer} strideX - `sx` stride length @@ -47,4 +47,4 @@ end function sdsdot ! Compute the dot product: dot = sdsdot( N, sb, sx, strideX, sy, strideY ) return -end subroutine sdsdotsub \ No newline at end of file +end subroutine sdsdotsub