From ea7b34499a4847bd917e120595a0c677fe8bddb9 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 5 Oct 2024 03:16:21 +0500 Subject: [PATCH 01/50] feat: add C `ndarray` API and refactor `blas/ext/base/dnanasum` PR-URL: https://github.com/stdlib-js/stdlib/pull/2984 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Signed-off-by: Athan Reines --- .../@stdlib/blas/ext/base/dnanasum/README.md | 129 +++++++++++++++++- .../dnanasum/benchmark/c/benchmark.length.c | 52 ++++++- .../blas/ext/base/dnanasum/docs/repl.txt | 16 +-- .../ext/base/dnanasum/docs/types/index.d.ts | 12 +- .../ext/base/dnanasum/examples/c/example.c | 7 +- .../include/stdlib/blas/ext/base/dnanasum.h | 9 +- .../blas/ext/base/dnanasum/lib/dnanasum.js | 9 +- .../ext/base/dnanasum/lib/dnanasum.native.js | 6 +- .../blas/ext/base/dnanasum/lib/ndarray.js | 8 +- .../ext/base/dnanasum/lib/ndarray.native.js | 17 +-- .../blas/ext/base/dnanasum/manifest.json | 45 ++++-- .../blas/ext/base/dnanasum/src/addon.c | 30 ++-- .../blas/ext/base/dnanasum/src/dnanasum.c | 33 ----- .../@stdlib/blas/ext/base/dnanasum/src/main.c | 48 +++++++ .../ext/base/dnanasum/test/test.dnanasum.js | 4 +- .../dnanasum/test/test.dnanasum.native.js | 4 +- .../ext/base/dnanasum/test/test.ndarray.js | 4 +- .../base/dnanasum/test/test.ndarray.native.js | 4 +- 18 files changed, 323 insertions(+), 114 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/dnanasum.c create mode 100644 lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/main.c diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/README.md b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/README.md index 4b66f7d3180..4dc05bcc22a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/README.md @@ -51,7 +51,7 @@ The [_L1_ norm][l1norm] is defined as var dnanasum = require( '@stdlib/blas/ext/base/dnanasum' ); ``` -#### dnanasum( N, x, stride ) +#### dnanasum( N, x, strideX ) Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision floating-point strided array elements, ignoring `NaN` values. @@ -69,9 +69,9 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Float64Array`][@stdlib/array/float64]. -- **stride**: index increment for `x`. +- **strideX**: index increment for `x`. -The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of absolute values ([_L1_ norm][l1norm]) every other element in the strided array, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of absolute values ([_L1_ norm][l1norm]) for every other element in the strided array, ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -96,7 +96,7 @@ var v = dnanasum( 4, x1, 2 ); // returns 9.0 ``` -#### dnanasum.ndarray( N, x, stride, offset ) +#### dnanasum.ndarray( N, x, strideX, offsetX ) Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. @@ -111,9 +111,9 @@ var v = dnanasum.ndarray( 4, x, 1, 0 ); The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: 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 sum of absolute values ([_L1_ norm][l1norm]) every other value in the strided array 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 sum of absolute values ([_L1_ norm][l1norm]) for every other value in the strided array starting from the second value ```javascript var Float64Array = require( '@stdlib/array/float64' ); @@ -169,6 +169,123 @@ console.log( v ); + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/blas/ext/base/dnanasum.h" +``` + +#### stdlib_strided_dnanasum( N, \*X, strideX ) + +Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision floating-point strided array elements, ignoring `NaN` values. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; + +double v = stdlib_strided_dnanasum( 4, x, 1 ); +// returns 7.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. + +```c +double stdlib_strided_dnanasum( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_dnanasum_ndarray( N, \*X, strideX, offsetX ) + +Computes the sum of absolute values ([_L1_ norm][l1norm]) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. + +```c +const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 }; + +double v = stdlib_strided_dnanasum_ndarray( 4, x, 1, 0 ); +// returns 7.0 +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **X**: `[in] double*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +double stdlib_strided_dnanasum_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/blas/ext/base/dnanasum.h" +#include + +int main( void ) { + // Create a strided array: + const double x[] = { 1.0, 2.0, -3.0, -4.0, 5.0, -6.0, -7.0, 8.0, 0.0/0.0, 0.0/0.0 }; + + // Specify the number of elements: + const int N = 5; + + // Specify the stride length: + const int strideX = 2; + + // Compute the sum: + double v = stdlib_strided_dnanasum( N, x, strideX ); + + // Print the result: + printf( "sumabs: %lf\n", v ); +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/benchmark/c/benchmark.length.c index 6928051d755..250c9eaccb5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static double rand_double( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; double x[ len ]; double v; @@ -124,6 +124,43 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + double x[ len ]; + double v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + if ( rand_double() < 0.2 ) { + x[ i ] = 0.0 / 0.0; // NaN + } else { + x[ i ] = ( rand_double() * 20000.0 ) - 10000.0; + } + } + v = 0.0; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + v = stdlib_strided_dnanasum_ndarray( len, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -146,7 +183,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/docs/repl.txt index 5af6fed5186..b9507afefb7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of absolute values (L1 norm) of double-precision floating- point strided array elements, ignoring `NaN` values. - The `N` and `stride` parameters determine which elements in the strided + 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 a typed @@ -19,7 +19,7 @@ x: Float64Array Input array. - stride: integer + strideX: integer Index increment. Returns @@ -46,14 +46,14 @@ 5.0 -{{alias}}.ndarray( N, x, stride, offset ) +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of absolute values (L1 norm) of double-precision floating- point strided array elements, ignoring `NaN` values and using alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a - starting index. + buffer, the offset parameter supports indexing semantics based on a starting + index. Parameters ---------- @@ -63,10 +63,10 @@ x: Float64Array Input array. - stride: integer + strideX: integer Index increment. - offset: integer + offsetX: integer Starting index. Returns diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/docs/types/index.d.ts index fae056169f9..8d6fa250d90 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/docs/types/index.d.ts @@ -27,7 +27,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -38,15 +38,15 @@ interface Routine { * var v = dnanasum( x.length, x, 1 ); * // returns 5.0 */ - ( N: number, x: Float64Array, stride: number ): number; + ( N: number, x: Float64Array, strideX: number ): number; /** * Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns sum * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = dnanasum.ndarray( x.length, x, 1, 0 ); * // returns 5.0 */ - ndarray( N: number, x: Float64Array, stride: number, offset: number ): number; + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number ): number; } /** @@ -65,7 +65,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns sum * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/examples/c/example.c b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/examples/c/example.c index 670d0fc0f32..b2d86206c99 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/examples/c/example.c @@ -17,7 +17,6 @@ */ #include "stdlib/blas/ext/base/dnanasum.h" -#include #include int main( void ) { @@ -25,13 +24,13 @@ int main( void ) { const double x[] = { 1.0, 2.0, -3.0, -4.0, 5.0, -6.0, -7.0, 8.0, 0.0/0.0, 0.0/0.0 }; // Specify the number of elements: - const int64_t N = 5; + const int N = 5; // Specify the stride length: - const int64_t stride = 2; + const int strideX = 2; // Compute the sum: - double v = stdlib_strided_dnanasum( N, x, stride ); + double v = stdlib_strided_dnanasum( N, x, strideX ); // Print the result: printf( "sumabs: %lf\n", v ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/include/stdlib/blas/ext/base/dnanasum.h b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/include/stdlib/blas/ext/base/dnanasum.h index d4ddb166685..7972855e209 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/include/stdlib/blas/ext/base/dnanasum.h +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/include/stdlib/blas/ext/base/dnanasum.h @@ -19,7 +19,7 @@ #ifndef STDLIB_BLAS_EXT_BASE_DNANASUM_H #define STDLIB_BLAS_EXT_BASE_DNANASUM_H -#include +#include "stdlib/blas/base/shared.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,12 @@ extern "C" { /** * Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values. */ -double stdlib_strided_dnanasum( const int64_t N, const double *X, const int64_t stride ); +double API_SUFFIX(stdlib_strided_dnanasum)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ); + +/** +* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. +*/ +double API_SUFFIX(stdlib_strided_dnanasum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/dnanasum.js b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/dnanasum.js index 9b6abf71ecb..1aeb9ff104d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/dnanasum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/dnanasum.js @@ -20,7 +20,8 @@ // MODULES // -var dnanasumors = require( '@stdlib/blas/ext/base/dnanasumors' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -30,7 +31,7 @@ var dnanasumors = require( '@stdlib/blas/ext/base/dnanasumors' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -41,8 +42,8 @@ var dnanasumors = require( '@stdlib/blas/ext/base/dnanasumors' ); * var v = dnanasum( 4, x, 1 ); * // returns 5.0 */ -function dnanasum( N, x, stride ) { - return dnanasumors( N, x, stride ); +function dnanasum( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/dnanasum.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/dnanasum.native.js index d43c8af134c..4c0f583d3cb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/dnanasum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/dnanasum.native.js @@ -30,7 +30,7 @@ var addon = require( './../src/addon.node' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example @@ -41,8 +41,8 @@ var addon = require( './../src/addon.node' ); * var v = dnanasum( 4, x, 1 ); * // returns 5.0 */ -function dnanasum( N, x, stride ) { - return addon( N, x, stride ); +function dnanasum( N, x, strideX ) { + return addon( N, x, strideX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/ndarray.js index 01b133e7239..03ff28237f0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/ndarray.js @@ -30,8 +30,8 @@ var dnanasumors = require( '@stdlib/blas/ext/base/dnanasumors' ).ndarray; * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - index increment +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -43,8 +43,8 @@ var dnanasumors = require( '@stdlib/blas/ext/base/dnanasumors' ).ndarray; * var v = dnanasum( 5, x, 2, 1 ); * // returns 9.0 */ -function dnanasum( N, x, stride, offset ) { - return dnanasumors( N, x, stride, offset ); +function dnanasum( N, x, strideX, offsetX ) { + return dnanasumors( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/ndarray.native.js index 51895d9dfef..4e38b92160f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/lib/ndarray.native.js @@ -20,9 +20,7 @@ // MODULES // -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); -var offsetView = require( '@stdlib/strided/base/offset-view' ); -var addon = require( './dnanasum.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,8 +30,8 @@ var addon = require( './dnanasum.native.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Float64Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - index increment +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} sum * * @example @@ -44,13 +42,8 @@ var addon = require( './dnanasum.native.js' ); * var v = dnanasum( 5, x, 2, 1 ); * // returns 9.0 */ -function dnanasum( N, x, stride, offset ) { - var view; - - offset = minViewBufferIndex( N, stride, offset ); - view = offsetView( x, offset ); - - return addon( N, view, stride ); +function dnanasum( N, x, strideX, offsetX ) { + return addon.ndarray( N, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/manifest.json b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/manifest.json index f440a7444ef..cf4e398c32f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/manifest.json +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/manifest.json @@ -28,53 +28,70 @@ { "task": "build", "src": [ - "./src/dnanasum.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-float64array", - "@stdlib/blas/ext/base/dnanasumors" + "@stdlib/blas/ext/base/dnanasumors", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", + "@stdlib/napi/create-double" ] }, { "task": "benchmark", "src": [ - "./src/dnanasum.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/ext/base/dnanasumors", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" + ] + }, + { + "task": "examples", + "src": [ + "./src/main.c" ], + "include": [ + "./include" + ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dnanasumors" + "@stdlib/blas/ext/base/dnanasumors", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { "task": "test", "src": [ - "./src/dnanasum.c" + "./src/main.c" ], "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/ext/base/dnanasumors" + "@stdlib/blas/ext/base/dnanasumors", + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/addon.c b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/addon.c index 5c9a07abb16..765e9fd0537 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/addon.c +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/addon.c @@ -17,12 +17,13 @@ */ #include "stdlib/blas/ext/base/dnanasum.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" #include "stdlib/napi/argv_strided_float64array.h" +#include "stdlib/napi/create_double.h" #include -#include /** * Receives JavaScript callback invocation data. @@ -34,14 +35,27 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, stride, argv, 1 ); - - napi_value v; - napi_status status = napi_create_double( env, stdlib_strided_dnanasum( N, X, stride ), &v ); - assert( status == napi_ok ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanasum)( N, X, strideX ), v ); + return v; +} +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( 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_INT64( env, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT64ARRAY( env, X, N, strideX, argv, 1 ); + STDLIB_NAPI_CREATE_DOUBLE( env, API_SUFFIX(stdlib_strided_dnanasum_ndarray)( N, X, strideX, offsetX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/dnanasum.c b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/dnanasum.c deleted file mode 100644 index 88b7ba6efc0..00000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/dnanasum.c +++ /dev/null @@ -1,33 +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/dnanasum.h" -#include "stdlib/blas/ext/base/dnanasumors.h" -#include - -/** -* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values. -* -* @param N number of indexed elements -* @param X input array -* @param stride stride length -* @return output value -*/ -double stdlib_strided_dnanasum( const int64_t N, const double *X, const int64_t stride ) { - return stdlib_strided_dnanasumors( N, X, stride ); -} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/main.c b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/main.c new file mode 100644 index 00000000000..43ee9d02a0a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/src/main.c @@ -0,0 +1,48 @@ +/** +* @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/dnanasum.h" +#include "stdlib/blas/ext/base/dnanasumors.h" +#include "stdlib/strided/base/stride2offset.h" +#include "stdlib/blas/base/shared.h" + +/** +* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values. +* +* @param N number of indexed elements +* @param X input array +* @param strideX stride length +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanasum)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_dnanasum_ndarray)( N, X, strideX, ox ); +} + +/** +* Computes the sum of absolute values (L1 norm) of double-precision floating-point strided array elements, ignoring `NaN` values and using alternative indexing semantics. +* +* @param N number of indexed elements +* @param X input array +* @param strideX index increment +* @param offsetX starting index +* @return output value +*/ +double API_SUFFIX(stdlib_strided_dnanasum_ndarray)( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + return API_SUFFIX(stdlib_strided_dnanasumors_ndarray)( N, X, strideX, offsetX ); +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.dnanasum.js b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.dnanasum.js index 31dc16d5be1..5037b5ffe4a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.dnanasum.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.dnanasum.js @@ -150,14 +150,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnanasum( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.dnanasum.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.dnanasum.native.js index 5b544d313bd..27a97e90c6c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.dnanasum.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.dnanasum.native.js @@ -241,14 +241,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', opts, function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnanasum( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.ndarray.js index bb1da774ef4..201e2ae3fb4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.ndarray.js @@ -150,14 +150,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnanasum( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.ndarray.native.js index 9f9a1cbdd1c..6177740e454 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/dnanasum/test/test.ndarray.native.js @@ -159,14 +159,14 @@ tape( 'the function supports a negative `stride` parameter', opts, function test t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', opts, function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', opts, function test( t ) { var x; var v; x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); v = dnanasum( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); From 2b6f932477bdbbfe755ee3ff9bd0a04020b049bd Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Sun, 6 Oct 2024 03:41:15 +0530 Subject: [PATCH 02/50] build: add WebAssembly configuration to `math/base/special/abs2` and `math/base/special/sqrt` PR-URL: https://github.com/stdlib-js/stdlib/pull/2989 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../math/base/special/abs2/manifest.json | 147 +++++++++------- .../math/base/special/sqrt/manifest.json | 161 ++++++++++-------- 2 files changed, 172 insertions(+), 136 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/abs2/manifest.json b/lib/node_modules/@stdlib/math/base/special/abs2/manifest.json index 71594be6d46..1adbebbed4e 100644 --- a/lib/node_modules/@stdlib/math/base/special/abs2/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/abs2/manifest.json @@ -1,67 +1,84 @@ { - "options": { - "task": "build" - }, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "task": "build", - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [ - "@stdlib/math/base/napi/unary" - ] - }, - { - "task": "benchmark", - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - }, - { - "task": "examples", - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - } - ] + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/unary" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + { + "task": "build", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] } diff --git a/lib/node_modules/@stdlib/math/base/special/sqrt/manifest.json b/lib/node_modules/@stdlib/math/base/special/sqrt/manifest.json index dd5d0762bc3..acc5d09fc9f 100644 --- a/lib/node_modules/@stdlib/math/base/special/sqrt/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/sqrt/manifest.json @@ -1,73 +1,92 @@ { - "options": { - "task": "build" - }, - "fields": [ - { - "field": "src", - "resolve": true, - "relative": true - }, - { - "field": "include", - "resolve": true, - "relative": true - }, - { - "field": "libraries", - "resolve": false, - "relative": false - }, - { - "field": "libpath", - "resolve": true, - "relative": false - } - ], - "confs": [ - { - "task": "build", - "src": [ - "./src/sqrt.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [ - "@stdlib/math/base/napi/unary" - ] - }, - { - "task": "benchmark", - "src": [ - "./src/sqrt.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [] - }, - { - "task": "examples", - "src": [ - "./src/sqrt.c" - ], - "include": [ - "./include" - ], - "libraries": [ - "-lm" - ], - "libpath": [], - "dependencies": [] - } - ] + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "wasm": false, + "src": [ + "./src/sqrt.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/unary" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/sqrt.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/sqrt.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + }, + { + "task": "build", + "wasm": true, + "src": [ + "./src/sqrt.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + } + ] } From ec4730b90a45d2c968405a5d158d7a52b1389272 Mon Sep 17 00:00:00 2001 From: Shubh Mehta <93862397+Shubh942@users.noreply.github.com> Date: Sun, 6 Oct 2024 07:08:10 +0530 Subject: [PATCH 03/50] refactor: improve type specificity for `utils/group-own` PR-URL: #1436 Closes: #1085 --------- Signed-off-by: Shubh Mehta <93862397+Shubh942@users.noreply.github.com> Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../utils/group-own/docs/types/index.d.ts | 132 ++++++++++++++---- .../utils/group-own/docs/types/test.ts | 27 +++- 2 files changed, 125 insertions(+), 34 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/group-own/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/group-own/docs/types/index.d.ts index fc10b592ee3..3cdcc72fda6 100644 --- a/lib/node_modules/@stdlib/utils/group-own/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/group-own/docs/types/index.d.ts @@ -38,7 +38,7 @@ interface Options { * * @returns group key */ -type Nullary = () => string | symbol; +type Nullary = () => K; /** * Specifies which group a property belongs to. @@ -46,7 +46,7 @@ type Nullary = () => string | symbol; * @param value - object value * @returns group key */ -type Unary = ( value: any ) => string | symbol; +type Unary = ( value: V ) => K; /** * Specifies which group a property belongs to. @@ -55,7 +55,7 @@ type Unary = ( value: any ) => string | symbol; * @param key - object key * @returns group key */ -type Binary = ( value: any, key: string | symbol ) => string | symbol; +type Binary = ( value: V, key: string ) => K; /** * Specifies which group a property belongs to. @@ -64,7 +64,7 @@ type Binary = ( value: any, key: string | symbol ) => string | symbol; * @param key - object key * @returns group key */ -type Indicator = Nullary | Unary | Binary; +type Indicator = Nullary | Unary | Binary; /** * Groups an object's own property values according to an indicator function. @@ -93,15 +93,18 @@ type Indicator = Nullary | Unary | Binary; * return v[ 0 ]; * } * var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' +* 'a': 'apple', +* 'b': 'banana', +* 'c': 'cherry', +* 'd': 'date' * }; * var out = groupOwn( obj, indicator ); -* // e.g., returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] } +* // e.g., returns { 'a': [ 'apple' ], 'b': [ 'banana' ], 'c': [ 'cherry' ], 'd': [ 'date' ] } */ -declare function groupOwn( obj: any, indicator: Indicator ): any; +declare function groupOwn( + obj: T, + indicator: Indicator +): { [P in K]: Array }; /** * Groups an object's own property values according to an indicator function. @@ -124,7 +127,7 @@ declare function groupOwn( obj: any, indicator: Indicator ): any; * @param obj - input object * @param options - function options * @param options.thisArg - execution context -* @param options.returns - if `values`, values are returned; if `keys`, keys are returned; if `*`, both keys and values are returned (default: 'values') +* @param options.returns - if `'values'`, values are returned; if `'indices'`, indices are returned; if `'*'`, both indices and values are returned (default: 'values') * @param indicator - indicator function indicating which group an element in the input object belongs to * @returns group results * @@ -133,47 +136,116 @@ declare function groupOwn( obj: any, indicator: Indicator ): any; * return v[ 0 ]; * } * var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' +* 'a': 'apple', +* 'b': 'banana', +* 'c': 'cherry', +* 'd': 'date' * }; -* var out = groupOwn( obj, indicator ); -* // e.g., returns { 'b': [ 'beep', 'boop', 'bar' ], 'f': [ 'foo' ] } +* var opts = { +* 'returns': 'indices' +* }; +* var out = groupOwn( obj, opts, indicator ); +* // e.g., returns { 'a': [ 'a' ], 'b': [ 'b' ], 'c': [ 'c' ], 'd': [ 'd' ] } +*/ +declare function groupOwn( + obj: T, + options: Options & { returns: 'indices' }, + indicator: Indicator +): { [P in K]: Array }; + +/** +* Groups an object's own property values according to an indicator function. +* +* ## Notes +* +* - When invoked, the indicator function is provided two arguments: +* +* - `value`: object value +* - `key`: object key +* +* - The value returned by an indicator function should be a value which can be serialized as an object key. +* +* - If provided an empty object, the function returns an empty object. +* +* - The function iterates over an object's own properties. +* +* - Key iteration order is **not** guaranteed, and, thus, result order is **not** guaranteed. +* +* @param obj - input object +* @param options - function options +* @param options.thisArg - execution context +* @param options.returns - if `'values'`, values are returned; if `'indices'`, indices are returned; if `'*'`, both indices and values are returned (default: 'values') +* @param indicator - indicator function indicating which group an element in the input object belongs to +* @returns group results * * @example * function indicator( v ) { * return v[ 0 ]; * } * var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' +* 'a': 'apple', +* 'b': 'banana', +* 'c': 'cherry', +* 'd': 'date' * }; * var opts = { -* 'returns': 'keys' +* 'returns': '*' * }; * var out = groupOwn( obj, opts, indicator ); -* // e.g., returns { 'b': [ 'a', 'b', 'd' ], 'f': [ 'c' ] } +* // e.g., returns { 'a': [ [ 'a', 'apple' ] ], 'b': [ [ 'b', 'banana' ] ], 'c': [ [ 'c', 'cherry' ] ], 'd': [ [ 'd', 'date' ] ] } +*/ +declare function groupOwn( + obj: T, + options: Options & { returns: '*' }, + indicator: Indicator +): { [P in K]: Array<[keyof T, T[keyof T]]> }; + +/** +* Groups an object's own property values according to an indicator function. +* +* ## Notes +* +* - When invoked, the indicator function is provided two arguments: +* +* - `value`: object value +* - `key`: object key +* +* - The value returned by an indicator function should be a value which can be serialized as an object key. +* +* - If provided an empty object, the function returns an empty object. +* +* - The function iterates over an object's own properties. +* +* - Key iteration order is **not** guaranteed, and, thus, result order is **not** guaranteed. +* +* @param obj - input object +* @param options - function options +* @param options.thisArg - execution context +* @param options.returns - if `'values'`, values are returned; if `'indices'`, indices are returned; if `'*'`, both indices and values are returned (default: 'values') +* @param indicator - indicator function indicating which group an element in the input object belongs to +* @returns group results * * @example * function indicator( v ) { * return v[ 0 ]; * } * var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' +* 'a': 'apple', +* 'b': 'banana', +* 'c': 'cherry', +* 'd': 'date' * }; * var opts = { -* 'returns': '*' +* 'returns': 'values' * }; * var out = groupOwn( obj, opts, indicator ); -* // e.g., returns { 'b': [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], 'f': [ [ 'c', 'foo' ] ] } +* // e.g., returns { 'a': [ 'apple' ], 'b': [ 'banana' ], 'c': [ 'cherry' ], 'd': [ 'date' ] } */ -declare function groupOwn( obj: any, options: Options, indicator: Indicator ): any; +declare function groupOwn( + obj: T, + options: Options & { returns?: 'values' }, + indicator: Indicator +): { [P in K]: Array }; // EXPORTS // diff --git a/lib/node_modules/@stdlib/utils/group-own/docs/types/test.ts b/lib/node_modules/@stdlib/utils/group-own/docs/types/test.ts index 65e2c9cf75a..4b2a72c3b2b 100644 --- a/lib/node_modules/@stdlib/utils/group-own/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/group-own/docs/types/test.ts @@ -46,12 +46,31 @@ class Foo { // The function returns an object... { const obj = new Foo(); - groupOwn( obj, indicator ); // $ExpectType any - groupOwn( {}, indicator ); // $ExpectType any + groupOwn( obj, indicator ); // $ExpectType { [x: string]: string[]; } + groupOwn( {}, indicator ); // $ExpectType { [x: string]: never[]; } const opts = { - 'returns': 'indices' as 'indices' + 'returns': 'indices' as const }; - groupOwn( obj, opts, indicator ); // $ExpectType any + groupOwn( obj, opts, indicator ); // $ExpectType { [x: string]: (keyof Foo)[]; } + + const opts2 = { + 'returns': 'values' as const + }; + groupOwn( obj, opts2, indicator ); // $ExpectType { [x: string]: string[]; } + + const opts3 = { + 'returns': '*' as const + }; + groupOwn( obj, opts3, indicator ); // $ExpectType { [x: string]: [keyof Foo, string][]; } + + const obj2 = { + 'beep': 'boop', + 'foo': 'bar' + } as const; + + groupOwn( obj2, opts, indicator ); // $ExpectType { [x: string]: ("beep" | "foo")[]; } + groupOwn( obj2, opts2, indicator ); // $ExpectType { [x: string]: ("boop" | "bar")[]; } + groupOwn( obj2, opts3, indicator ); // $ExpectType { [x: string]: ["beep" | "foo", "boop" | "bar"][]; } } // The compiler throws an error if the function is provided a last argument which is not a function... From c00f27afb4b1853a7f4377fbbab7aec1dab9e34c Mon Sep 17 00:00:00 2001 From: Soumajit Chatterjee <121816890+soumajit23@users.noreply.github.com> Date: Tue, 8 Oct 2024 06:43:28 +0530 Subject: [PATCH 04/50] docs: improve examples of `array/base/assert` namespace PR-URL: #1955 Closes: #1545 --------- Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../@stdlib/array/base/assert/README.md | 68 ++++++++++++++++++- .../array/base/assert/examples/index.js | 68 ++++++++++++++++++- 2 files changed, 132 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/assert/README.md b/lib/node_modules/@stdlib/array/base/assert/README.md index 173c9888d61..df4e0d20416 100644 --- a/lib/node_modules/@stdlib/array/base/assert/README.md +++ b/lib/node_modules/@stdlib/array/base/assert/README.md @@ -83,10 +83,74 @@ The namespace exports the following: ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); var ns = require( '@stdlib/array/base/assert' ); +var dtype = require( '@stdlib/array/dtype' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Complex128Array = require( '@stdlib/array/complex128' ); -console.log( objectKeys( ns ) ); +// Create various arrays: +var arr1 = new Float64Array( [ 1.1, 2.2, 3.3 ] ); +var arr2 = new Int32Array( [ 1, 2, 3 ] ); +var arr3 = new Uint8Array( [ 1, 2, 3 ] ); +var arr4 = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ); // two complex numbers: 1+1i, 2+2i + +// Get data types: +var dt1 = dtype( arr1 ); +var dt2 = dtype( arr2 ); +var dt3 = dtype( arr3 ); +var dt4 = dtype( arr4 ); + +// Check data types: +console.log( dt1 + ' is floating-point data type: ' + ns.isFloatingPointDataType( dt1 ) ); +// => 'float64 is floating-point data type: true' + +console.log( dt2 + ' is integer data type: ' + ns.isIntegerDataType( dt2 ) ); +// => 'int32 is integer data type: true' + +console.log( dt3 + ' is unsigned integer data type: ' + ns.isUnsignedIntegerDataType( dt3 ) ); +// => 'uint8 is unsigned integer data type: true' + +console.log( dt4 + ' is complex floating-point data type: ' + ns.isComplexFloatingPointDataType( dt4 ) ); +// => 'complex128 is complex floating-point data type: true' + +// Check if arrays have the same values: +console.log( 'arr2 and arr3 have same values: ' + ns.hasSameValues( arr2, arr3 ) ); +// => 'arr2 and arr3 have same values: true' + +console.log( 'arr1 and arr2 have same values: ' + ns.hasSameValues( arr1, arr2 ) ); +// => 'arr1 and arr2 have same values: false' + +// Check safe data type casts: +console.log( 'Can safely cast from ' + dt2 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt2, dt1 ) ); +// => 'Can safely cast from int32 to float64: true' + +console.log( 'Can safely cast from ' + dt1 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt1, dt2 ) ); +// => 'Can safely cast from float64 to int32: false' + +console.log( 'Can safely cast from ' + dt3 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt3, dt2 ) ); +// => 'Can safely cast from uint8 to int32: true' + +console.log( 'Can safely cast from ' + dt4 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt4, dt1 ) ); +// => 'Can safely cast from complex128 to float64: false' + +// Check if arrays contain specific values: +console.log( 'arr1 contains 2.2: ' + ns.contains( arr1, 2.2 ) ); +// => 'arr1 contains 2.2: true' + +console.log( 'arr2 contains 2: ' + ns.contains( arr2, 2 ) ); +// => 'arr2 contains 2: true' + +console.log( 'arr2 contains 2.2: ' + ns.contains( arr2, 2.2 ) ); +// => 'arr2 contains 2.2: false' + +// Check complex array types: +console.log( 'arr4 is Complex128Array: ' + ns.isComplex128Array( arr4 ) ); +// => 'arr4 is Complex128Array: true' + +console.log( 'arr4 is complex typed array: ' + ns.isComplexTypedArray( arr4 ) ); +// => 'arr4 is complex typed array: true' ``` diff --git a/lib/node_modules/@stdlib/array/base/assert/examples/index.js b/lib/node_modules/@stdlib/array/base/assert/examples/index.js index d903e87cb0a..971ecff1786 100644 --- a/lib/node_modules/@stdlib/array/base/assert/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/assert/examples/index.js @@ -18,7 +18,71 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); +var dtype = require( '@stdlib/array/dtype' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Complex128Array = require( '@stdlib/array/complex128' ); var ns = require( './../lib' ); -console.log( objectKeys( ns ) ); +// Create various arrays: +var arr1 = new Float64Array( [ 1.1, 2.2, 3.3 ] ); +var arr2 = new Int32Array( [ 1, 2, 3 ] ); +var arr3 = new Uint8Array( [ 1, 2, 3 ] ); +var arr4 = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0 ] ); // two complex numbers: 1+1i, 2+2i + +// Get data types: +var dt1 = dtype( arr1 ); +var dt2 = dtype( arr2 ); +var dt3 = dtype( arr3 ); +var dt4 = dtype( arr4 ); + +// Check data types: +console.log( dt1 + ' is floating-point data type: ' + ns.isFloatingPointDataType( dt1 ) ); +// => 'float64 is floating-point data type: true' + +console.log( dt2 + ' is integer data type: ' + ns.isIntegerDataType( dt2 ) ); +// => 'int32 is integer data type: true' + +console.log( dt3 + ' is unsigned integer data type: ' + ns.isUnsignedIntegerDataType( dt3 ) ); +// => 'uint8 is unsigned integer data type: true' + +console.log( dt4 + ' is complex floating-point data type: ' + ns.isComplexFloatingPointDataType( dt4 ) ); +// => 'complex128 is complex floating-point data type: true' + +// Check if arrays have the same values: +console.log( 'arr2 and arr3 have same values: ' + ns.hasSameValues( arr2, arr3 ) ); +// => 'arr2 and arr3 have same values: true' + +console.log( 'arr1 and arr2 have same values: ' + ns.hasSameValues( arr1, arr2 ) ); +// => 'arr1 and arr2 have same values: false' + +// Check safe data type casts: +console.log( 'Can safely cast from ' + dt2 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt2, dt1 ) ); +// => 'Can safely cast from int32 to float64: true' + +console.log( 'Can safely cast from ' + dt1 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt1, dt2 ) ); +// => 'Can safely cast from float64 to int32: false' + +console.log( 'Can safely cast from ' + dt3 + ' to ' + dt2 + ': ' + ns.isSafeDataTypeCast( dt3, dt2 ) ); +// => 'Can safely cast from uint8 to int32: true' + +console.log( 'Can safely cast from ' + dt4 + ' to ' + dt1 + ': ' + ns.isSafeDataTypeCast( dt4, dt1 ) ); +// => 'Can safely cast from complex128 to float64: false' + +// Check if arrays contain specific values: +console.log( 'arr1 contains 2.2: ' + ns.contains( arr1, 2.2 ) ); +// => 'arr1 contains 2.2: true' + +console.log( 'arr2 contains 2: ' + ns.contains( arr2, 2 ) ); +// => 'arr2 contains 2: true' + +console.log( 'arr2 contains 2.2: ' + ns.contains( arr2, 2.2 ) ); +// => 'arr2 contains 2.2: false' + +// Check complex array types: +console.log( 'arr4 is Complex128Array: ' + ns.isComplex128Array( arr4 ) ); +// => 'arr4 is Complex128Array: true' + +console.log( 'arr4 is complex typed array: ' + ns.isComplexTypedArray( arr4 ) ); +// => 'arr4 is complex typed array: true' From 61912b7eed6c5f60d074210347d31472da963b22 Mon Sep 17 00:00:00 2001 From: UtkershBasnet <119008923+UtkershBasnet@users.noreply.github.com> Date: Tue, 8 Oct 2024 07:06:05 +0530 Subject: [PATCH 05/50] docs: improve examples of `stats/base/dists/exponential` namespace PR-URL: #2688 Closes: #1624 --------- Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../stats/base/dists/exponential/README.md | 45 ++++++++++++++++++- .../base/dists/exponential/examples/index.js | 45 ++++++++++++++++++- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/exponential/README.md b/lib/node_modules/@stdlib/stats/base/dists/exponential/README.md index 27b7e0a6f73..6be2ae17e1f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/exponential/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/exponential/README.md @@ -109,10 +109,51 @@ var y = dist.logpdf( 0.8 ); ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); +var Float64Array = require( '@stdlib/array/float64' ); +var randomExponential = require( '@stdlib/random/array/exponential' ); +var dcusum = require( '@stdlib/blas/ext/base/dcusum' ); var exponential = require( '@stdlib/stats/base/dists/exponential' ); -console.log( objectKeys( exponential ) ); +// Simulate interarrival times of customers entering a store: +var lambda = 0.5; // Average rate (customers per minute) +var numCustomers = 10; + +// Generate interarrival times using the exponential distribution: +var interarrivalTimes = randomExponential( numCustomers, lambda, { + 'dtype': 'float64' +}); + +console.log( 'Simulated interarrival times for ' + numCustomers + ' customers:' ); +console.log( interarrivalTimes ); + +// Calculate cumulative arrival times by computing the cumulative sum of interarrival times: +var arrivalTimes = new Float64Array( interarrivalTimes.length ); +dcusum( interarrivalTimes.length, 0.0, interarrivalTimes, 1, arrivalTimes, 1 ); + +console.log( '\nCustomer arrival times:' ); +console.log( arrivalTimes ); + +// Probability that a customer arrives within two minutes: +var x = 2.0; +var prob = exponential.cdf( x, lambda ); +console.log( '\nProbability that a customer arrives within ' + x + ' minutes: ' + prob.toFixed(4) ); + +// Expected time until the next customer arrives: +var mean = exponential.mean( lambda ); +console.log( 'Expected interarrival time: ' + mean + ' minutes' ); + +var dist = new exponential.Exponential( lambda ); + +var median = dist.median; +console.log( 'Median interarrival time: ' + median + ' minutes' ); + +// Evaluate the PDF at x = 1.0: +var out = dist.pdf( 1.0 ); +console.log( 'PDF at x = 1: ' + out.toFixed(4) ); + +// Evaluate the MGF at t = 0.1: +out = dist.mgf( 0.1 ); +console.log( 'MGF at t = 0.5: ' + out.toFixed(4) ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/exponential/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/exponential/examples/index.js index c983a77fc53..ed12ae6c03e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/exponential/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/exponential/examples/index.js @@ -18,7 +18,48 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); +var Float64Array = require( '@stdlib/array/float64' ); +var randomExponential = require( '@stdlib/random/array/exponential' ); +var dcusum = require( '@stdlib/blas/ext/base/dcusum' ); var exponential = require( './../lib' ); -console.log( objectKeys( exponential ) ); +// Simulate interarrival times of customers entering a store: +var lambda = 0.5; // Average rate (customers per minute) +var numCustomers = 10; + +// Generate interarrival times using the exponential distribution: +var interarrivalTimes = randomExponential( numCustomers, lambda, { + 'dtype': 'float64' +}); + +console.log( 'Simulated interarrival times for ' + numCustomers + ' customers:' ); +console.log( interarrivalTimes ); + +// Calculate cumulative arrival times by computing the cumulative sum of interarrival times: +var arrivalTimes = new Float64Array( interarrivalTimes.length ); +dcusum( interarrivalTimes.length, 0.0, interarrivalTimes, 1, arrivalTimes, 1 ); + +console.log( '\nCustomer arrival times:' ); +console.log( arrivalTimes ); + +// Probability that a customer arrives within two minutes: +var x = 2.0; +var prob = exponential.cdf( x, lambda ); +console.log( '\nProbability that a customer arrives within ' + x + ' minutes: ' + prob.toFixed(4) ); + +// Expected time until the next customer arrives: +var mean = exponential.mean( lambda ); +console.log( 'Expected interarrival time: ' + mean + ' minutes' ); + +var dist = new exponential.Exponential( lambda ); + +var median = dist.median; +console.log( 'Median interarrival time: ' + median + ' minutes' ); + +// Evaluate the PDF at x = 1.0: +var out = dist.pdf( 1.0 ); +console.log( 'PDF at x = 1: ' + out.toFixed(4) ); + +// Evaluate the MGF at t = 0.1: +out = dist.mgf( 0.1 ); +console.log( 'MGF at t = 0.5: ' + out.toFixed(4) ); From 4927336d5b2b4a7d2baf0e7d854b406d309fac17 Mon Sep 17 00:00:00 2001 From: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> Date: Tue, 8 Oct 2024 08:02:39 +0530 Subject: [PATCH 06/50] feat: add `assert/is-same-typed-array-like` PR-URL: https://github.com/stdlib-js/stdlib/pull/2939 Closes: https://github.com/stdlib-js/stdlib/issues/2887 Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt Reviewed-by: Jaysukh Makvana --- .../assert/is-same-typed-array-like/README.md | 100 ++++++++++++ .../benchmark/benchmark.length.js | 96 ++++++++++++ .../is-same-typed-array-like/docs/repl.txt | 36 +++++ .../docs/types/index.d.ts | 50 ++++++ .../docs/types/test.ts | 40 +++++ .../examples/index.js | 35 +++++ .../is-same-typed-array-like/lib/index.js | 56 +++++++ .../is-same-typed-array-like/lib/main.js | 66 ++++++++ .../is-same-typed-array-like/package.json | 77 +++++++++ .../is-same-typed-array-like/test/test.js | 146 ++++++++++++++++++ 10 files changed, 702 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/README.md create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/benchmark/benchmark.length.js create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/examples/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/lib/index.js create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/lib/main.js create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/package.json create mode 100644 lib/node_modules/@stdlib/assert/is-same-typed-array-like/test/test.js diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/README.md b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/README.md new file mode 100644 index 00000000000..187ade975de --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/README.md @@ -0,0 +1,100 @@ + + +# isSameArrayLike + +> Test if two arguments are both typed-array-like objects and have the [same values][@stdlib/assert/is-same-value]. + +
+ +## Usage + +```javascript +var isSameTypedArrayLike = require( '@stdlib/assert/is-same-typed-array-like' ); +``` + +#### isSameTypedArrayLike( v1, v2 ) + +Tests if two arguments are both typed-array-like objects and have the [same values][@stdlib/assert/is-same-value]. + +```javascript +var Int8Array = require( '@stdlib/array/int8' ); +var Int16Array = require( '@stdlib/array/int16' ); + +var x = new Int8Array( [ 1.0, 2.0 ] ); +var y = new Int16Array( [ 1.0, 2.0 ] ); +var bool = isSameTypedArrayLike( x, y ); +// returns true + +bool = isSameTypedArrayLike( x, new Int8Array( [ -1.0, 2.0 ] ) ); +// returns false +``` + +
+ + + +
+ +## Examples + + + +```javascript +var Int8Array = require( '@stdlib/array/int8' ); +var Int16Array = require( '@stdlib/array/int16' ); +var isSameTypedArrayLike = require( '@stdlib/assert/is-same-typed-array-like' ); + +var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +var y = new Int16Array( [ 1.0, 2.0, 3.0 ] ); +var out = isSameTypedArrayLike( x, y ); +// returns true + +x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +y = new Int16Array( [ 1.0, 2.0, 4.0 ] ); +out = isSameTypedArrayLike( x, y ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/benchmark/benchmark.length.js new file mode 100644 index 00000000000..49c0ad961f8 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/benchmark/benchmark.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pow = require( '@stdlib/math/base/special/pow' ); +var Int8Array = require( '@stdlib/array/int8' ); +var pkg = require( './../package.json' ).name; +var isSameTypedArrayLike = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = new Int8Array( len ); + var y = new Int8Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = isSameTypedArrayLike( x, y ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/repl.txt b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/repl.txt new file mode 100644 index 00000000000..ff6cc272106 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( v1, v2 ) + Tests if two arguments are both typed-array-like objects and have the same + values. + + Parameters + ---------- + v1: any + First input value. + + v2: any + Second input value. + + Returns + ------- + bool: boolean + Boolean indicating whether two arguments are both typed-array-like + objects and have the same values. + + Examples + -------- + > var Int8Array = require( '@stdlib/array/int8' ); + > var Int16Array = require( '@stdlib/array/int16' ); + > var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); + > var y = new Int16Array( [ 1.0, 2.0, 3.0 ] ); + > var bool = {{alias}}( x, y ) + true + + > x = new Int8Array( [ 1.0, 2.0, 4.0 ] ); + > y = new Int8Array( [ 1.0, 2.0, 3.0 ] ); + > bool = {{alias}}( x, y ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/index.d.ts new file mode 100644 index 00000000000..2485bfd39cc --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/index.d.ts @@ -0,0 +1,50 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/** +* Tests if two arguments are both typed-array-like objects and have the same values. +* +* @param v1 - first input value +* @param v2 - second input value +* @returns boolean indicating whether the two arguments are both typed-array-like objects with the same values +* +* @example +* var Int8Array = require( '@stdlib/array/int8' ); +* var Int16Array = require( '@stdlib/array/int16' ); +* var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Int16Array( [ 1.0, 2.0, 3.0 ] ); +* +* var out = isSameTypedArrayLike( x, y ); +* // returns true +* +* @example +* var Int8Array = require( '@stdlib/array/int8' ); +* var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Int8Array( [ 1.0, 2.0, 4.0 ] ); +* +* var out = isSameTypedArrayLike( x, y ); +* // returns false +*/ +declare function isSameTypedArrayLike( v1: any, v2: any ): boolean; + + +// EXPORTS // + +export = isSameTypedArrayLike; diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/test.ts b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/test.ts new file mode 100644 index 00000000000..19129aaa1d4 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/test.ts @@ -0,0 +1,40 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +import Int16Array = require( '@stdlib/array/int16' ); +import Int8Array = require( '@stdlib/array/int8' ); +import isSameTypedArrayLike = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isSameTypedArrayLike( new Int8Array( [ 1.0, 2.0, 3.0 ] ), new Int16Array( [ 1.0, 2.0, 3.0 ] ) ); // $ExpectType boolean + isSameTypedArrayLike( new Int8Array( [ 1.0, 2.0, 3.0 ] ), new Int8Array( [ 1.0, 2.0, 4.0 ] ) ); // $ExpectType boolean + isSameTypedArrayLike( 3.14, 3.14 ); // $ExpectType boolean + isSameTypedArrayLike( null, null ); // $ExpectType boolean + isSameTypedArrayLike( 'beep', 'boop' ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isSameTypedArrayLike(); // $ExpectError + isSameTypedArrayLike( 3.14 ); // $ExpectError + isSameTypedArrayLike( 'beep', 'beep', 3.14 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/examples/index.js b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/examples/index.js new file mode 100644 index 00000000000..2731f7e9d6a --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/examples/index.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var Int8Array = require( '@stdlib/array/int8' ); +var Int16Array = require( '@stdlib/array/int16' ); +var isSameTypedArrayLike = require( './../lib' ); + +var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +var y = new Int16Array( [ 1.0, 2.0, 3.0 ] ); +var out = isSameTypedArrayLike( x, y ); +console.log( out ); +// => true + +x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +y = new Int16Array( [ 1.0, 2.0, 4.0 ] ); +out = isSameTypedArrayLike( x, y ); +console.log( out ); +// => false diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/lib/index.js b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/lib/index.js new file mode 100644 index 00000000000..d42555d8fc5 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/lib/index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* Test if two arguments are both typed-array-like objects and have the same values. +* +* @module @stdlib/assert/is-same-typed-array-like +* +* @example +* var Int8Array = require( '@stdlib/array/int8' ); +* var Int16Array = require( '@stdlib/array/int16' ); +* var isSameTypedArrayLike = require( '@stdlib/assert/is-same-typed-array-like' ); +* +* var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Int16Array( [ 1.0, 2.0, 3.0 ] ); +* +* var out = isSameTypedArrayLike( x, y ); +* // returns true +* +* @example +* var Int8Array = require( '@stdlib/array/int8' ); +* var Int16Array = require( '@stdlib/array/int16' ); +* var isSameTypedArrayLike = require( '@stdlib/assert/is-same-typed-array-like' ); +* +* var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Int16Array( [ 1.0, 2.0, 4.0 ] ); +* +* var out = isSameTypedArrayLike( x, y ); +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/lib/main.js b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/lib/main.js new file mode 100644 index 00000000000..1844db52843 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/lib/main.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' ); +var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' ); + + +// MAIN // + +/** +* Tests if two arguments are both typed-array-like objects and have the same values. +* +* @param {*} v1 - first value +* @param {*} v2 - second value +* @returns {boolean} boolean indicating if two arguments are both typed-array-like objects with the same values +* +* @example +* var Int8Array = require( '@stdlib/array/int8' ); +* var Int16Array = require( '@stdlib/array/int16' ); +* +* var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Int16Array( [ 1.0, 2.0, 3.0 ] ); +* +* var out = isSameTypedArrayLike( x, y ); +* // returns true +* +* @example +* var Int8Array = require( '@stdlib/array/int8' ); +* var Int16Array = require( '@stdlib/array/int16' ); +* +* var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); +* var y = new Int16Array( [ 1.0, 2.0, 4.0 ] ); +* +* var out = isSameTypedArrayLike( x, y ); +* // returns false +*/ +function isSameTypedArrayLike( v1, v2 ) { + if ( isTypedArrayLike( v1 ) && isTypedArrayLike( v2 ) ) { + return hasSameValues( v1, v2 ); + } + return false; +} + + +// EXPORTS // + +module.exports = isSameTypedArrayLike; diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/package.json b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/package.json new file mode 100644 index 00000000000..af9388eec6e --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/package.json @@ -0,0 +1,77 @@ +{ + "name": "@stdlib/assert/is-same-typed-array-like", + "version": "0.0.0", + "description": "Test if two arguments are both typed-array-like object and have the same values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "equal", + "same", + "strict", + "is", + "issame", + "issamevalue", + "isequal", + "isstrictequal", + "type", + "check", + "valid", + "validate", + "test", + "typed", + "array", + "generic" + ] +} diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/test/test.js b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/test/test.js new file mode 100644 index 00000000000..ab2e89ffabb --- /dev/null +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/test/test.js @@ -0,0 +1,146 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Int8Array = require( '@stdlib/array/int8' ); +var Int16Array = require( '@stdlib/array/int16' ); +var isSameTypedArrayLike = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isSameTypedArrayLike, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided two typed-array-like objects having the same contents', function test( t ) { + var x; + var y; + + x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); + t.strictEqual( isSameTypedArrayLike( x, x ), true, 'returns expected value' ); + + x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); + y = new Int16Array( [ 1.0, 2.0, 3.0 ] ); + t.strictEqual( isSameTypedArrayLike( x, y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `false` if provided two typed-array-like objects having the different contents', function test( t ) { + var x; + var y; + + x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); + y = new Int16Array( [ 1.0, 2.0, 4.0 ] ); + t.strictEqual( isSameTypedArrayLike( x, y ), false, 'returns expected value' ); + + x = new Int8Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + y = new Int8Array( [ 1.0, 2.0, 3.0 ] ); + t.strictEqual( isSameTypedArrayLike( x, y ), false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `false` when one of the provided objects is not typed-array-like', function test( t ) { + var x; + var y; + + x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); + y = 'beep'; + t.strictEqual( isSameTypedArrayLike( x, y ), false, 'returns expected value' ); + + x = new Int8Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + y = 12; + t.strictEqual( isSameTypedArrayLike( x, y ), false, 'returns expected value' ); + + x = new Int8Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + y = null; + t.strictEqual( isSameTypedArrayLike( x, y ), false, 'returns expected value' ); + + x = new Int8Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + y = undefined; + t.strictEqual( isSameTypedArrayLike( x, y ), false, 'returns expected value' ); + + x = new Int8Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + y = {}; + t.strictEqual( isSameTypedArrayLike( x, y ), false, 'returns expected value' ); + + x = new Int8Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + y = true; + t.strictEqual( isSameTypedArrayLike( x, y ), false, 'returns expected value' ); + + x = new Int8Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + y = [ 1.0, 2.0, 3.0, 4.0 ]; + t.strictEqual( isSameTypedArrayLike( x, y ), false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `false` if not provided two typed-array-like objects having the same contents', function test( t ) { + var x; + var y; + var i; + + x = [ + '', + 'beep', + 5, + 3.14, + -3.14, + 0.0, + -0.0, + true, + false, + null, + void 0, + [ 1.0 ], + {}, + function noop() {}, + [ 1.0, 2.0, 3.0 ], + [ -0.0, -0.0, -0.0 ] + ]; + y = [ + 'abc', + 'boop', + -5, + -3.14, + 3.14, + -0.0, + 0.0, + false, + true, + void 0, + null, + [ -1.0 ], + {}, + function noop() {}, + [ 2.0, 4.0, 6.0 ], + [ 0.0, 0.0, 0.0 ] + ]; + for ( i = 0; i < x.length; i++ ) { + t.strictEqual( isSameTypedArrayLike( x[ i ], y[ i ] ), false, 'returns expected value when provided '+x[ i ]+' and '+y[ i ] ); + } + t.end(); +}); From 783c5d60fa197f8fa6a7eedc2497d610e541f6cb Mon Sep 17 00:00:00 2001 From: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> Date: Tue, 8 Oct 2024 08:33:01 +0530 Subject: [PATCH 07/50] feat: add `iter/cunone` PR-URL: https://github.com/stdlib-js/stdlib/pull/2978 Closes: https://github.com/stdlib-js/stdlib/issues/2333 Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../@stdlib/iter/cunone/README.md | 160 +++++++++ .../iter/cunone/benchmark/benchmark.js | 75 ++++ .../@stdlib/iter/cunone/docs/repl.txt | 44 +++ .../@stdlib/iter/cunone/docs/types/index.d.ts | 64 ++++ .../@stdlib/iter/cunone/docs/types/test.ts | 69 ++++ .../@stdlib/iter/cunone/examples/index.js | 49 +++ .../@stdlib/iter/cunone/lib/index.js | 60 ++++ .../@stdlib/iter/cunone/lib/main.js | 145 ++++++++ .../@stdlib/iter/cunone/package.json | 66 ++++ .../@stdlib/iter/cunone/test/test.js | 322 ++++++++++++++++++ 10 files changed, 1054 insertions(+) create mode 100644 lib/node_modules/@stdlib/iter/cunone/README.md create mode 100644 lib/node_modules/@stdlib/iter/cunone/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/iter/cunone/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/iter/cunone/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/iter/cunone/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/iter/cunone/examples/index.js create mode 100644 lib/node_modules/@stdlib/iter/cunone/lib/index.js create mode 100644 lib/node_modules/@stdlib/iter/cunone/lib/main.js create mode 100644 lib/node_modules/@stdlib/iter/cunone/package.json create mode 100644 lib/node_modules/@stdlib/iter/cunone/test/test.js diff --git a/lib/node_modules/@stdlib/iter/cunone/README.md b/lib/node_modules/@stdlib/iter/cunone/README.md new file mode 100644 index 00000000000..34bbac5bd3d --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/README.md @@ -0,0 +1,160 @@ + + +# iterCuNone + +> Create an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value is falsy. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var iterCuNone = require( '@stdlib/iter/cunone' ); +``` + +#### iterCuNone( iterator ) + +Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every +iterated value is falsy. + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +var arr = array2iterator( [ 0, 0, 0, 1, 0 ] ); + +var it = iterCuNone( arr ); +// returns + +var v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +var bool = it.next().done; +// returns true +``` + +The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + + + + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/iter/randu' ); +var iterMap = require( '@stdlib/iter/map' ); +var iterCuNone = require( '@stdlib/iter/cunone' ); + +function threshold( r ) { + return ( r > 0.95 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which applies a threshold to generated numbers: +var miter = iterMap( riter, threshold ); + +// Create an iterator which cumulatively tests whether every iterated value is falsy. +var it = iterCuNone( miter ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/iter/cunone/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/cunone/benchmark/benchmark.js new file mode 100644 index 00000000000..5c2b7085fa7 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/benchmark/benchmark.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var iterConstant = require( '@stdlib/iter/constant' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var iterCuNone = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var iter; + var it; + var i; + + it = iterConstant( 3.14 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = iterCuNone( it ); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iteration', function benchmark( b ) { + var iter; + var v; + var i; + + iter = iterCuNone( iterConstant( 3.14 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = iter.next().value; + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/iter/cunone/docs/repl.txt b/lib/node_modules/@stdlib/iter/cunone/docs/repl.txt new file mode 100644 index 00000000000..d8c8aea8cba --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/docs/repl.txt @@ -0,0 +1,44 @@ + +{{alias}}( iterator ) + Returns an iterator which cumulatively tests whether every iterated value is + falsy. + + If an environment supports Symbol.iterator and a provided iterator is + iterable, the returned iterator is iterable. + + Parameters + ---------- + iterator: Object + Input iterator. + + Returns + ------- + iterator: Object + Iterator. + + iterator.next(): Function + Returns an iterator protocol-compliant object containing the next + iterated value (if one exists) and a boolean flag indicating whether the + iterator is finished. + + iterator.return( [value] ): Function + Finishes an iterator and returns a provided value. + + Examples + -------- + > var arr = {{alias:@stdlib/array/to-iterator}}( [ 0, 0, 0, 1, 0 ] ); + > var it = {{alias}}( arr ); + > var v = it.next().value + true + > v = it.next().value + true + > v = it.next().value + true + > v = it.next().value + false + > v = it.next().value + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/iter/cunone/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/cunone/docs/types/index.d.ts new file mode 100644 index 00000000000..057b26ad583 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = Iter | IterableIterator; + +/** +* Returns an iterator which cumulatively tests whether every iterated value is falsy. +* +* @param iterator - input iterator +* @returns iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* var arr = array2iterator( [ false, false, false, true, false ] ); +* +* var it = iterCuNone( arr ); +* +* var v = it.next().value; +* returns true +* +* v = it.next().value; +* returns true +* +* v = it.next().value; +* returns true +* +* v = it.next().value; +* returns false +* +* v = it.next().value; +* returns false +* +* var bool = it.next().done; +* returns true +*/ +declare function iterCuNone( iterator: Iterator ): Iterator; + + +// EXPORTS // + +export = iterCuNone; diff --git a/lib/node_modules/@stdlib/iter/cunone/docs/types/test.ts b/lib/node_modules/@stdlib/iter/cunone/docs/types/test.ts new file mode 100644 index 00000000000..cb02cca9139 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +import { Iterator, IteratorResult } from '@stdlib/types/iter'; +import iterCuNone = require( './index' ); + +/** +* Implements the iterator protocol `next` method. +* +* @returns iterator protocol-compliant object +*/ +function next(): IteratorResult { + return { + 'value': true, + 'done': false + }; +} + +/** +* Returns an iterator protocol-compliant object. +* +* @returns iterator protocol-compliant object +*/ +function iterator(): Iterator { + return { + 'next': next + }; +} + + +// TESTS // + +// The function returns an iterator... +{ + iterCuNone( iterator() ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a value other than an iterator protocol-compliant object... +{ + iterCuNone( '5' ); // $ExpectError + iterCuNone( 5 ); // $ExpectError + iterCuNone( true ); // $ExpectError + iterCuNone( false ); // $ExpectError + iterCuNone( null ); // $ExpectError + iterCuNone( undefined ); // $ExpectError + iterCuNone( [] ); // $ExpectError + iterCuNone( {} ); // $ExpectError + iterCuNone( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + iterCuNone(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/iter/cunone/examples/index.js b/lib/node_modules/@stdlib/iter/cunone/examples/index.js new file mode 100644 index 00000000000..30df5870845 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/examples/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/iter/randu' ); +var iterMap = require( '@stdlib/iter/map' ); +var iterCuNone = require( './../lib' ); + +function threshold( r ) { + return ( r > 0.95 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which applies a threshold to generated numbers: +var miter = iterMap( riter, threshold ); + +// Create an iterator which cumulatively tests whether every iterated value is falsy: +var it = iterCuNone( miter ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} diff --git a/lib/node_modules/@stdlib/iter/cunone/lib/index.js b/lib/node_modules/@stdlib/iter/cunone/lib/index.js new file mode 100644 index 00000000000..5fb39d0207c --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/lib/index.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* Create an iterator which cumulatively tests whether every iterated value is falsy. +* +* @module @stdlib/iter/cunone +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* var iterCuNone = require( '@stdlib/iter/cunone' ); +* +* var arr = array2iterator( [ false, false, false, true, false ] ); +* +* var it = iterCuNone( arr ); +* +* var v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* var bool = it.next().done; +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/iter/cunone/lib/main.js b/lib/node_modules/@stdlib/iter/cunone/lib/main.js new file mode 100644 index 00000000000..c6a9686cfc0 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/lib/main.js @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an iterator which cumulatively tests whether every iterated value is falsy. +* +* @param {Iterator} iterator - input iterator +* @throws {TypeError} first argument must be an iterator +* @returns {Iterator} iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* var arr = array2iterator( [ 0, 0, 0, 1, 0 ] ); +* +* var it = iterCuNone( arr ); +* +* var v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* var bool = it.next().done; +* // returns true +*/ +function iterCuNone( iterator ) { + var value; + var iter; + var FLG; + if ( !isIteratorLike( iterator ) ) { + throw new TypeError( format( 'invalid argument. Must provide an iterator. Value: `%s`.', iterator ) ); + } + value = true; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator` and the provided iterator is iterable, make the iterator iterable: + if ( iteratorSymbol && isFunction( iterator[ iteratorSymbol ] ) ) { + setReadOnly( iter, iteratorSymbol, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + var v; + if ( FLG ) { + return { + 'done': true + }; + } + v = iterator.next(); + if ( v.done ) { + FLG = true; + return v; + } + if ( v.value ) { + value = false; + } + return { + 'value': value, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return iterCuNone( iterator[ iteratorSymbol ]() ); + } +} + + +// EXPORTS // + +module.exports = iterCuNone; diff --git a/lib/node_modules/@stdlib/iter/cunone/package.json b/lib/node_modules/@stdlib/iter/cunone/package.json new file mode 100644 index 00000000000..c4d588a4188 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/iter/cunone", + "version": "0.0.0", + "description": "Create an iterator which cumulatively tests whether every iterated value is falsy.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "test", + "none", + "iterate", + "iterator", + "iter", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/iter/cunone/test/test.js b/lib/node_modules/@stdlib/iter/cunone/test/test.js new file mode 100644 index 00000000000..fe739cf2cb8 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cunone/test/test.js @@ -0,0 +1,322 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var array2iterator = require( '@stdlib/array/to-iterator' ); +var randu = require( '@stdlib/random/iter/randu' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var iterCuNone = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterCuNone, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided an iterator protocol-compliant object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuNone( value ); + }; + } +}); + +tape( 'the function returns an iterator protocol-compliant object', function test( t ) { + var arr; + var it; + var r; + var i; + + arr = array2iterator( [ 0, 0, 1, 0, 1 ] ); + it = iterCuNone( arr ); + for ( i = 0; i < 5; i++ ) { + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + } + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + t.end(); +}); + +tape( 'if all upstream iterator values are truthy, the function returns an iterator protocol-compliant object which returns all `false` values', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 1, 1, 1, 1 ]; + expected = [ + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuNone( array2iterator( values ) ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'if at least one upstream iterator value is truthy, the function returns an iterator protocol-compliant object which returns `false` values upon encountering the first truthy value', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 0, 0, 1, 0 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuNone( array2iterator( values ) ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'if all upstream iterator values are falsy, the function returns an iterator protocol-compliant object which always returns truthy values', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 0, 0, 0, 0 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuNone( array2iterator( values ) ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var it; + var r; + + it = iterCuNone( randu() ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var it; + var r; + + it = iterCuNone( randu() ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return( 'finished' ); + t.equal( r.value, 'finished', 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator` and the provided iterator is iterable, the returned iterator is iterable', function test( t ) { + var iterCuNone; + var opts; + var rand; + var it1; + var it2; + var i; + + iterCuNone = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + opts = { + 'seed': 12345 + }; + rand = randu( opts ); + rand[ '__ITERATOR_SYMBOL__' ] = factory; + + it1 = iterCuNone( rand ); + t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.equal( typeof it2, 'object', 'returns an object' ); + t.equal( typeof it2.next, 'function', 'has method' ); + t.equal( typeof it2.return, 'function', 'has method' ); + + for ( i = 0; i < 100; i++ ) { + t.equal( it2.next().value, it1.next().value, 'returns expected value' ); + } + t.end(); + + function factory() { + return randu( opts ); + } +}); + +tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { + var iterCuNone; + var it; + + iterCuNone = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + it = iterCuNone( randu() ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); + +tape( 'if a provided iterator is not iterable, the returned iterator is not iterable', function test( t ) { + var iterCuNone; + var rand; + var it; + + iterCuNone = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + rand = randu(); + rand[ '__ITERATOR_SYMBOL__' ] = null; + + it = iterCuNone( rand ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); From 9680c81c32c100a5fbafacce7d1e840561ad95d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:30:54 -0700 Subject: [PATCH 08/50] docs: update list of contributors PR-URL: https://github.com/stdlib-js/stdlib/pull/2992 Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt Signed-off-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index d74d10f3f9c..752104235d6 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -94,6 +94,7 @@ Tudor Pagu <104032457+tudor-pagu@users.noreply.github.com> Tufailahmed Bargir <142114244+Tufailahmed-Bargir@users.noreply.github.com> Utkarsh Utkarsh Raj +UtkershBasnet <119008923+UtkershBasnet@users.noreply.github.com> Vaibhav Patel <98279986+noobCoderVP@users.noreply.github.com> Varad Gupta Xiaochuan Ye From 16b37682c43d8b1223904dac5f31b06637d26796 Mon Sep 17 00:00:00 2001 From: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com> Date: Wed, 9 Oct 2024 05:51:07 +0530 Subject: [PATCH 09/50] feat: add `iter/cuevery` PR-URL: https://github.com/stdlib-js/stdlib/pull/2955 Closes: https://github.com/stdlib-js/stdlib/issues/2332 Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../@stdlib/iter/cuevery/README.md | 159 +++++++++ .../iter/cuevery/benchmark/benchmark.js | 75 ++++ .../@stdlib/iter/cuevery/docs/repl.txt | 44 +++ .../iter/cuevery/docs/types/index.d.ts | 64 ++++ .../@stdlib/iter/cuevery/docs/types/test.ts | 69 ++++ .../@stdlib/iter/cuevery/examples/index.js | 49 +++ .../@stdlib/iter/cuevery/lib/index.js | 60 ++++ .../@stdlib/iter/cuevery/lib/main.js | 145 ++++++++ .../@stdlib/iter/cuevery/package.json | 66 ++++ .../@stdlib/iter/cuevery/test/test.js | 322 ++++++++++++++++++ 10 files changed, 1053 insertions(+) create mode 100644 lib/node_modules/@stdlib/iter/cuevery/README.md create mode 100644 lib/node_modules/@stdlib/iter/cuevery/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/iter/cuevery/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/iter/cuevery/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/iter/cuevery/examples/index.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery/lib/index.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery/lib/main.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery/package.json create mode 100644 lib/node_modules/@stdlib/iter/cuevery/test/test.js diff --git a/lib/node_modules/@stdlib/iter/cuevery/README.md b/lib/node_modules/@stdlib/iter/cuevery/README.md new file mode 100644 index 00000000000..65ce2dc0d87 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/README.md @@ -0,0 +1,159 @@ + + +# iterCuEvery + +> Create an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value is truthy. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var iterCuEvery = require( '@stdlib/iter/cuevery' ); +``` + +#### iterCuEvery( iterator ) + +Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value is truthy. + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +var arr = array2iterator( [ 1, 1, 1, 0, 1 ] ); + +var it = iterCuEvery( arr ); +// returns + +var v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +var bool = it.next().done; +// returns true +``` + +The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + + + + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/iter/randu' ); +var iterMap = require( '@stdlib/iter/map' ); +var iterCuEvery = require( '@stdlib/iter/cuevery' ); + +function threshold( r ) { + return ( r > 0.1 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which applies a threshold to generated numbers: +var miter = iterMap( riter, threshold ); + +// Create an iterator which cumulatively tests whether every iterated value is truthy: +var it = iterCuEvery( miter ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/iter/cuevery/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/cuevery/benchmark/benchmark.js new file mode 100644 index 00000000000..35343b2cc42 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/benchmark/benchmark.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var iterConstant = require( '@stdlib/iter/constant' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var iterCuEvery = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var iter; + var it; + var i; + + it = iterConstant( 3.14 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = iterCuEvery( it ); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iteration', function benchmark( b ) { + var iter; + var v; + var i; + + iter = iterCuEvery( iterConstant( 3.14 ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = iter.next().value; + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/iter/cuevery/docs/repl.txt b/lib/node_modules/@stdlib/iter/cuevery/docs/repl.txt new file mode 100644 index 00000000000..68af81a19c7 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/docs/repl.txt @@ -0,0 +1,44 @@ + +{{alias}}( iterator ) + Returns an iterator which cumulatively tests whether every iterated value is + truthy. + + If an environment supports Symbol.iterator and a provided iterator is + iterable, the returned iterator is iterable. + + Parameters + ---------- + iterator: Object + Input iterator. + + Returns + ------- + iterator: Object + Iterator. + + iterator.next(): Function + Returns an iterator protocol-compliant object containing the next + iterated value (if one exists) and a boolean flag indicating whether the + iterator is finished. + + iterator.return( [value] ): Function + Finishes an iterator and returns a provided value. + + Examples + -------- + > var arr = {{alias:@stdlib/array/to-iterator}}( [ 1, 1, 1, 0, 1 ] ); + > var it = {{alias}}( arr ); + > var v = it.next().value + true + > v = it.next().value + true + > v = it.next().value + true + > v = it.next().value + false + > v = it.next().value + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/iter/cuevery/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/cuevery/docs/types/index.d.ts new file mode 100644 index 00000000000..202ab2a41c7 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = Iter | IterableIterator; + +/** +* Returns an iterator which cumulatively tests whether every iterated value is truthy. +* +* @param iterator - input iterator +* @returns iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* var arr = array2iterator( [ true, true, true, false, true ] ); +* +* var it = iterCuEvery( arr ); +* +* var v = it.next().value; +* returns true +* +* v = it.next().value; +* returns true +* +* v = it.next().value; +* returns true +* +* v = it.next().value; +* returns false +* +* v = it.next().value; +* returns false +* +* var bool = it.next().done; +* returns true +*/ +declare function iterCuEvery( iterator: Iterator ): Iterator; + + +// EXPORTS // + +export = iterCuEvery; diff --git a/lib/node_modules/@stdlib/iter/cuevery/docs/types/test.ts b/lib/node_modules/@stdlib/iter/cuevery/docs/types/test.ts new file mode 100644 index 00000000000..297181ab950 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +import { Iterator, IteratorResult } from '@stdlib/types/iter'; +import iterCuEvery = require( './index' ); + +/** +* Implements the iterator protocol `next` method. +* +* @returns iterator protocol-compliant object +*/ +function next(): IteratorResult { + return { + 'value': true, + 'done': false + }; +} + +/** +* Returns an iterator protocol-compliant object. +* +* @returns iterator protocol-compliant object +*/ +function iterator(): Iterator { + return { + 'next': next + }; +} + + +// TESTS // + +// The function returns an iterator... +{ + iterCuEvery( iterator() ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a value other than an iterator protocol-compliant object... +{ + iterCuEvery( '5' ); // $ExpectError + iterCuEvery( 5 ); // $ExpectError + iterCuEvery( true ); // $ExpectError + iterCuEvery( false ); // $ExpectError + iterCuEvery( null ); // $ExpectError + iterCuEvery( undefined ); // $ExpectError + iterCuEvery( [] ); // $ExpectError + iterCuEvery( {} ); // $ExpectError + iterCuEvery( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + iterCuEvery(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/iter/cuevery/examples/index.js b/lib/node_modules/@stdlib/iter/cuevery/examples/index.js new file mode 100644 index 00000000000..aa23bb62973 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/examples/index.js @@ -0,0 +1,49 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/iter/randu' ); +var iterMap = require( '@stdlib/iter/map' ); +var iterCuEvery = require( './../lib' ); + +function threshold( r ) { + return ( r > 0.1 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which applies a threshold to generated numbers: +var miter = iterMap( riter, threshold ); + +// Create an iterator which cumulatively tests whether every iterated value is truthy: +var it = iterCuEvery( miter ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} diff --git a/lib/node_modules/@stdlib/iter/cuevery/lib/index.js b/lib/node_modules/@stdlib/iter/cuevery/lib/index.js new file mode 100644 index 00000000000..cca0d28e523 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/lib/index.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* Create an iterator which cumulatively tests whether every iterated value is truthy. +* +* @module @stdlib/iter/cuevery +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* var iterCuEvery = require( '@stdlib/iter/cuevery' ); +* +* var arr = array2iterator( [ true, true, false, true, false ] ); +* +* var it = iterCuEvery( arr ); +* +* var v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* var bool = it.next().done; +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/iter/cuevery/lib/main.js b/lib/node_modules/@stdlib/iter/cuevery/lib/main.js new file mode 100644 index 00000000000..37f000d2ebb --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/lib/main.js @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an iterator which cumulatively tests whether every iterated value is truthy. +* +* @param {Iterator} iterator - input iterator +* @throws {TypeError} first argument must be an iterator +* @returns {Iterator} iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* var arr = array2iterator( [ 1, 1, 0, 1, 0 ] ); +* +* var it = iterCuEvery( arr ); +* +* var v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* var bool = it.next().done; +* // returns true +*/ +function iterCuEvery( iterator ) { + var value; + var iter; + var FLG; + if ( !isIteratorLike( iterator ) ) { + throw new TypeError( format( 'invalid argument. Must provide an iterator. Value: `%s`.', iterator ) ); + } + value = true; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator` and the provided iterator is iterable, make the iterator iterable: + if ( iteratorSymbol && isFunction( iterator[ iteratorSymbol ] ) ) { + setReadOnly( iter, iteratorSymbol, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + var v; + if ( FLG ) { + return { + 'done': true + }; + } + v = iterator.next(); + if ( v.done ) { + FLG = true; + return v; + } + if ( !v.value ) { + value = false; + } + return { + 'value': value, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return iterCuEvery( iterator[ iteratorSymbol ]() ); + } +} + + +// EXPORTS // + +module.exports = iterCuEvery; diff --git a/lib/node_modules/@stdlib/iter/cuevery/package.json b/lib/node_modules/@stdlib/iter/cuevery/package.json new file mode 100644 index 00000000000..0966ca87f90 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/iter/cuevery", + "version": "0.0.0", + "description": "Create an iterator which cumulatively tests whether every iterated value is truthy.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "test", + "every", + "iterate", + "iterator", + "iter", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/iter/cuevery/test/test.js b/lib/node_modules/@stdlib/iter/cuevery/test/test.js new file mode 100644 index 00000000000..fd18bf673f8 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery/test/test.js @@ -0,0 +1,322 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var array2iterator = require( '@stdlib/array/to-iterator' ); +var randu = require( '@stdlib/random/iter/randu' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var iterCuEvery = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterCuEvery, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided an iterator protocol-compliant object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuEvery( value ); + }; + } +}); + +tape( 'the function returns an iterator protocol-compliant object', function test( t ) { + var arr; + var it; + var r; + var i; + + arr = array2iterator( [ 0, 0, 1, 0, 1 ] ); + it = iterCuEvery( arr ); + for ( i = 0; i < 5; i++ ) { + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + } + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + t.end(); +}); + +tape( 'if no upstream iterator values are falsy, the function returns an iterator protocol-compliant object which returns all truthy values', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 1, 1, 1, 1 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuEvery( array2iterator( values ) ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'if at least one upstream iterator value is falsy, the function returns an iterator protocol-compliant object which returns falsy values upon encountering the first falsy value', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 1, 1, 0, 1 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuEvery( array2iterator( values ) ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'if all upstream iterator values are truthy, the function returns an iterator protocol-compliant object which always returns truthy values', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 1, 1, 1, 1 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuEvery( array2iterator( values ) ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var it; + var r; + + it = iterCuEvery( randu() ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var it; + var r; + + it = iterCuEvery( randu() ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return( 'finished' ); + t.equal( r.value, 'finished', 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator` and the provided iterator is iterable, the returned iterator is iterable', function test( t ) { + var iterCuEvery; + var opts; + var rand; + var it1; + var it2; + var i; + + iterCuEvery = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + opts = { + 'seed': 12345 + }; + rand = randu( opts ); + rand[ '__ITERATOR_SYMBOL__' ] = factory; + + it1 = iterCuEvery( rand ); + t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.equal( typeof it2, 'object', 'returns an object' ); + t.equal( typeof it2.next, 'function', 'has method' ); + t.equal( typeof it2.return, 'function', 'has method' ); + + for ( i = 0; i < 100; i++ ) { + t.equal( it2.next().value, it1.next().value, 'returns expected value' ); + } + t.end(); + + function factory() { + return randu( opts ); + } +}); + +tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { + var iterCuEvery; + var it; + + iterCuEvery = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + it = iterCuEvery( randu() ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); + +tape( 'if a provided iterator is not iterable, the returned iterator is not iterable', function test( t ) { + var iterCuEvery; + var rand; + var it; + + iterCuEvery = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + rand = randu(); + rand[ '__ITERATOR_SYMBOL__' ] = null; + + it = iterCuEvery( rand ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); From 8d51aebea63f63f3d328c7dd5b402b327d52ff8e Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 8 Oct 2024 20:41:10 -0400 Subject: [PATCH 10/50] fix: properly increment iteration index --- lib/node_modules/@stdlib/iter/cunone-by/lib/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/iter/cunone-by/lib/main.js b/lib/node_modules/@stdlib/iter/cunone-by/lib/main.js index d93c22dc47c..8ee2c6b00b3 100644 --- a/lib/node_modules/@stdlib/iter/cunone-by/lib/main.js +++ b/lib/node_modules/@stdlib/iter/cunone-by/lib/main.js @@ -111,6 +111,7 @@ function iterCuNoneBy( iterator, predicate, thisArg ) { FLG = true; return v; } + i += 1; if ( value && predicate.call( thisArg, v.value, i ) ) { value = false; } From d90fdb967ee785786f1fc37c148a17a8fa2e1db7 Mon Sep 17 00:00:00 2001 From: Kaif Mohd | MERN | Javascript | Langchainjs Date: Wed, 9 Oct 2024 06:37:07 +0545 Subject: [PATCH 11/50] feat: add `iter/cuevery-by` package PR-URL: https://github.com/stdlib-js/stdlib/pull/2838 Closes: https://github.com/stdlib-js/stdlib/issues/2336 Co-authored-by: Kaif Mohd Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../@stdlib/iter/cuevery-by/README.md | 202 ++++++++++ .../iter/cuevery-by/benchmark/benchmark.js | 89 +++++ .../@stdlib/iter/cuevery-by/docs/repl.txt | 64 +++ .../iter/cuevery-by/docs/types/index.d.ts | 98 +++++ .../iter/cuevery-by/docs/types/test.ts | 109 ++++++ .../@stdlib/iter/cuevery-by/examples/index.js | 45 +++ .../@stdlib/iter/cuevery-by/lib/index.js | 65 ++++ .../@stdlib/iter/cuevery-by/lib/main.js | 158 ++++++++ .../@stdlib/iter/cuevery-by/package.json | 68 ++++ .../@stdlib/iter/cuevery-by/test/test.js | 364 ++++++++++++++++++ 10 files changed, 1262 insertions(+) create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/README.md create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/package.json create mode 100644 lib/node_modules/@stdlib/iter/cuevery-by/test/test.js diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/README.md b/lib/node_modules/@stdlib/iter/cuevery-by/README.md new file mode 100644 index 00000000000..4cf25c970db --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/README.md @@ -0,0 +1,202 @@ + + +# iterCuEveryBy + +> Create an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var iterCuEveryBy = require( '@stdlib/iter/cuevery-by' ); +``` + +#### iterCuEveryBy( iterator, predicate\[, thisArg] ) + +Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value passes a test implemented by a `predicate` function. + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function predicate( v ) { + return ( v > 0 ); +} + +var arr = array2iterator( [ 1, 1, 1, 0, 1 ] ); + +var it = iterCuEveryBy( arr, predicate ); + +var v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +var bool = it.next().done; +// returns true +``` + +The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + +A `predicate` function is provided two arguments: + +- **value**: iterated value +- **index**: iteration index (zero-based) + +To set the `predicate` function execution context, provide a `thisArg`. + + + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function predicate( v ) { + this.count += 1; + return ( v > 0 ); +} + +var ctx = { + 'count': 0 +}; + +var it = iterCuEveryBy( array2iterator( [ 1, 2, 3, 4 ] ), predicate, ctx ); +// returns + +var v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +var count = ctx.count; +// returns 4 +``` + + + + + + + +
+ +## Notes + +- A `predicate` function is invoked for each iterated value until the first falsy `predicate` function return value. Upon encountering the first falsy return value, the returned iterator ceases to invoke the `predicate` function and returns `false` for each subsequent iterated value of the provided input `iterator`. + +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/iter/randu' ); +var iterCuEveryBy = require( '@stdlib/iter/cuevery-by' ); + +function threshold( r ) { + return ( r > 0.05 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which cumulatively tests whether every iterated value passes a test: +var it = iterCuEveryBy( riter, threshold ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js new file mode 100644 index 00000000000..63a4037b3de --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/benchmark/benchmark.js @@ -0,0 +1,89 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var iterConstant = require( '@stdlib/iter/constant' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var iterCuEveryBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {*} value - value +* @returns {boolean} result +*/ +function predicate( value ) { + return ( value > 0 ); +} + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var iter; + var it; + var i; + + it = iterConstant( 3.14 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = iterCuEveryBy( it, predicate ); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iteration', function benchmark( b ) { + var iter; + var v; + var i; + + iter = iterCuEveryBy( iterConstant( 3.14 ), predicate ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = iter.next().value; + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt b/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt new file mode 100644 index 00000000000..34f203364bf --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/repl.txt @@ -0,0 +1,64 @@ + +{{alias}}( iterator, predicate[, thisArg] ) + Returns an iterator which cumulatively tests whether every iterated value + passes a test implemented by a predicate function. + + If an environment supports Symbol.iterator and a provided iterator is + iterable, the returned iterator is iterable. + + The predicate function is provided two arguments: + + - value: iterated value + - index: iteration index + + A predicate function is invoked for each iterated value until the first + falsy predicate function return value. Upon encountering the first falsy + return value, the returned iterator ceases to invoke the predicate function + and returns `false` for each subsequent iterated value of the provided input + iterator. + + If provided an iterator which does not return any iterated values, the + function returns an iterator which is also empty. + + Parameters + ---------- + iterator: Object + Input iterator. + + predicate: Function + The test function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + iterator: Object + Iterator. + + iterator.next(): Function + Returns an iterator protocol-compliant object containing the next + iterated value (if one exists) and a boolean flag indicating whether the + iterator is finished. + + iterator.return( [value] ): Function + Finishes an iterator and returns a provided value. + + Examples + -------- + > var arr = {{alias:@stdlib/array/to-iterator}}( [ 1, 1, 1, 0, 1 ] ); + > function fcn( v ) { return ( v > 0 ); }; + > var it = {{alias}}( arr, fcn ); + > var v = it.next().value + true + > v = it.next().value + true + > v = it.next().value + true + > v = it.next().value + false + > v = it.next().value + false + + See Also + -------- diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts new file mode 100644 index 00000000000..34b5672200c --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/index.d.ts @@ -0,0 +1,98 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = TypedIterator | TypedIterableIterator; + +/** +* Checks whether an iterated value passes a test. +* +* @returns boolean indicating whether an iterated value passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @returns boolean indicating whether an iterated value passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @param index - iteration index +* @returns boolean indicating whether an iterated value passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @param index - iteration index +* @returns boolean indicating whether an iterated value passes a test +*/ +type Predicate = Nullary | Unary | Binary; + +/** +* Returns an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function. +* +* @param iterator - source iterator +* @param predicate - predicate function +* @param thisArg - execution context +* @returns iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* function isPositive( v ) { +* return ( v > 0 ); +* } +* +* var it = iterCuEveryBy( array2iterator( [ 1, 1, 1, 0, 1 ] ), isPositive ); +* +* var v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +*/ +declare function iterCuEveryBy( iterator: Iterator, predicate: Predicate, thisArg?: ThisParameterType> ): Iterator; + + +// EXPORTS // + +export = iterCuEveryBy ; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts new file mode 100644 index 00000000000..d756e029c94 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/docs/types/test.ts @@ -0,0 +1,109 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +import { TypedIterator, TypedIteratorResult } from '@stdlib/types/iter'; +import iterCuEveryBy = require( './index' ); + +/** +* Implements the iterator protocol `next` method. +* +* @returns iterator protocol-compliant object +*/ +function next(): TypedIteratorResult { + return { + 'value': 2.0, + 'done': false + }; +} + +/** +* Returns an iterator protocol-compliant object. +* +* @returns iterator protocol-compliant object +*/ +function iterator(): TypedIterator { + return { + 'next': next + }; +} + +/** +* Predicate function. +* +* @param _v - iterated value +* @param i - iteration index +* @returns a boolean +*/ +function predicate1( _v: any, i: number ): boolean { + return ( i > 10 ); +} + +/** +* Predicate function. +* +* @param v - iterated value +* @returns a boolean +*/ +function predicate2( v: any ): boolean { + return ( v !== v ); +} + + +// TESTS // + +// The function returns an iterator... +{ + iterCuEveryBy( iterator(), predicate1 ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate2 ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate1, {} ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate2, {} ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate1, null ); // $ExpectType Iterator + iterCuEveryBy( iterator(), predicate2, null ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a first argument which is not an iterator protocol-compliant object... +{ + iterCuEveryBy( '5', predicate1 ); // $ExpectError + iterCuEveryBy( 5, predicate1 ); // $ExpectError + iterCuEveryBy( true, predicate1 ); // $ExpectError + iterCuEveryBy( false, predicate1 ); // $ExpectError + iterCuEveryBy( null, predicate1 ); // $ExpectError + iterCuEveryBy( undefined, predicate1 ); // $ExpectError + iterCuEveryBy( [], predicate1 ); // $ExpectError + iterCuEveryBy( {}, predicate1 ); // $ExpectError + iterCuEveryBy( ( x: number ): number => x, predicate1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a predicate function... +{ + iterCuEveryBy( iterator(), '5' ); // $ExpectError + iterCuEveryBy( iterator(), 5 ); // $ExpectError + iterCuEveryBy( iterator(), true ); // $ExpectError + iterCuEveryBy( iterator(), false ); // $ExpectError + iterCuEveryBy( iterator(), null ); // $ExpectError + iterCuEveryBy( iterator(), undefined ); // $ExpectError + iterCuEveryBy( iterator(), [] ); // $ExpectError + iterCuEveryBy( iterator(), {} ); // $ExpectError + iterCuEveryBy( iterator(), ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + iterCuEveryBy(); // $ExpectError + iterCuEveryBy( iterator() ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js b/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js new file mode 100644 index 00000000000..ccc710f03ac --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/iter/randu' ); +var iterCuEveryBy = require( './../lib' ); + +function threshold( r ) { + return ( r > 0.05 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which cumulatively tests whether every iterated value passes a test: +var it = iterCuEveryBy( riter, threshold ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js b/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js new file mode 100644 index 00000000000..83db4b7e121 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/lib/index.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* Create an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function. +* +* @module @stdlib/iter/cuevery-by +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* var iterCuEveryBy = require( '@stdlib/iter/cuevery-by' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var arr = array2iterator( [ 1, 1, 1, 0, 1 ] ); +* +* var it = iterCuEveryBy( arr, isPositive ); +* +* var v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* var bool = it.next().done; +* // returns true +*/ + + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js b/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js new file mode 100644 index 00000000000..56a68824e91 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/lib/main.js @@ -0,0 +1,158 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function. +* +* @param {Iterator} iterator - input iterator +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - execution context +* @throws {TypeError} first argument must be an iterator +* @throws {TypeError} second argument must be a predicate function +* @returns {Iterator} iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var arr = array2iterator( [ 1, 1, 1, 0, 1 ] ); +* +* var it = iterCuEveryBy( arr, isPositive ); +* +* var v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* var bool = it.next().done; +* // returns true +*/ +function iterCuEveryBy( iterator, predicate, thisArg ) { + var value; + var iter; + var FLG; + var i; + if ( !isIteratorLike( iterator ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an iterator. Value: `%s`.', iterator ) ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) ); + } + value = true; + i = -1; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator`, make the iterator iterable: + if ( iteratorSymbol && isFunction( iterator[ iteratorSymbol ] ) ) { + setReadOnly( iter, iteratorSymbol, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + var v; + if ( FLG ) { + return { + 'done': true + }; + } + v = iterator.next(); + if ( v.done ) { + FLG = true; + return v; + } + i += 1; + if ( value && !predicate.call( thisArg, v.value, i ) ) { + value = false; + } + return { + 'value': value, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return iterCuEveryBy( iterator[ iteratorSymbol ](), predicate, thisArg ); + } +} + + +// EXPORTS // + +module.exports = iterCuEveryBy; diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/package.json b/lib/node_modules/@stdlib/iter/cuevery-by/package.json new file mode 100644 index 00000000000..4aef4d53cae --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/iter/cuevery-by", + "version": "0.0.0", + "description": "Create an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "none", + "every", + "all", + "cuevery", + "iterator", + "iterate", + "iteration", + "iter" + ] +} diff --git a/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js b/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js new file mode 100644 index 00000000000..7b0ae0c7cc6 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuevery-by/test/test.js @@ -0,0 +1,364 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var array2iterator = require( '@stdlib/array/to-iterator' ); +var randu = require( '@stdlib/random/iter/randu' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var noop = require( '@stdlib/utils/noop' ); +var iterCuEveryBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {*} value - value +* @returns {boolean} result +*/ +function predicate( value ) { + return ( value > 0 ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterCuEveryBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided an iterator', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuEveryBy( value, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a predicate function as a second argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 0, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuEveryBy( array2iterator( [ 1, 2, 3 ] ), value ); + }; + } +}); + +tape( 'the function returns an iterator protocol-compliant object', function test( t ) { + var arr; + var it; + var r; + var i; + + arr = array2iterator( [ 0, 0, 1, 0, 1 ] ); + it = iterCuEveryBy( arr, predicate ); + for ( i = 0; i < 5; i++ ) { + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + } + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an "empty" iterator, the function returns an iterator which is also empty', function test( t ) { + var arr; + var it; + var v; + + arr = array2iterator( [] ); + it = iterCuEveryBy( arr, predicate ); + + v = it.next(); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 1, 1, 0, 0, 0, 0 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuEveryBy( array2iterator( values ), predicate ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var it; + var r; + + it = iterCuEveryBy( randu(), predicate ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var it; + var r; + + it = iterCuEveryBy( randu(), predicate ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return( 'foo' ); + t.equal( r.value, 'foo', 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator` and the provided iterator is iterable, the returned iterator is iterable', function test( t ) { + var iterCuEveryBy; + var opts; + var rand; + var it1; + var it2; + var i; + + iterCuEveryBy = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + opts = { + 'seed': 12345 + }; + rand = randu( opts ); + rand[ '__ITERATOR_SYMBOL__' ] = factory; + + it1 = iterCuEveryBy( rand, predicate ); + t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.equal( typeof it2, 'object', 'returns an object' ); + t.equal( typeof it2.next, 'function', 'has method' ); + t.equal( typeof it2.return, 'function', 'has method' ); + + for ( i = 0; i < 100; i++ ) { + t.equal( it2.next().value, it1.next().value, 'returns expected value' ); + } + t.end(); + + function factory() { + return randu( opts ); + } +}); + +tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { + var iterCuEveryBy; + var it; + + iterCuEveryBy = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + it = iterCuEveryBy( randu(), predicate); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); + +tape( 'if a provided iterator is not iterable, the returned iterator is not iterable', function test( t ) { + var iterCuEveryBy; + var rand; + var it; + + iterCuEveryBy = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + rand = randu(); + rand[ '__ITERATOR_SYMBOL__' ] = null; + + it = iterCuEveryBy( rand, predicate ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); +tape( 'the function supports specifying the predicate function execution context', function test( t ) { + var expected; + var actual; + var values; + var ctx; + var it; + var i; + + ctx = { + 'count': 0 + }; + + values = [ 1, 3, -2, 0, 1 ]; + expected = [ + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuEveryBy( array2iterator( values ), predicate, ctx ); + t.equal( it.next.length, 0, 'has zero arity' ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.equal( ctx.count, 3, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); From bd3c83a593cbd8c1ffecbc7d60f233492db25613 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Wed, 9 Oct 2024 06:38:43 +0530 Subject: [PATCH 12/50] feat: add `iter/cuany-by` PR-URL: https://github.com/stdlib-js/stdlib/pull/2837 Closes: https://github.com/stdlib-js/stdlib/issues/2335 Co-authored-by: Gururaj Gurram Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../@stdlib/iter/cuany-by/README.md | 202 ++++++++++ .../iter/cuany-by/benchmark/benchmark.js | 89 +++++ .../@stdlib/iter/cuany-by/docs/repl.txt | 64 +++ .../iter/cuany-by/docs/types/index.d.ts | 98 +++++ .../@stdlib/iter/cuany-by/docs/types/test.ts | 109 ++++++ .../@stdlib/iter/cuany-by/examples/index.js | 45 +++ .../@stdlib/iter/cuany-by/lib/index.js | 65 ++++ .../@stdlib/iter/cuany-by/lib/main.js | 158 ++++++++ .../@stdlib/iter/cuany-by/package.json | 66 ++++ .../@stdlib/iter/cuany-by/test/test.js | 365 ++++++++++++++++++ 10 files changed, 1261 insertions(+) create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/README.md create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/package.json create mode 100644 lib/node_modules/@stdlib/iter/cuany-by/test/test.js diff --git a/lib/node_modules/@stdlib/iter/cuany-by/README.md b/lib/node_modules/@stdlib/iter/cuany-by/README.md new file mode 100644 index 00000000000..4d5a558dadf --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/README.md @@ -0,0 +1,202 @@ + + +# iterCuAnyBy + +> Create an iterator which cumulatively tests whether at least one iterated value passes a test implemented by a predicate function. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var iterCuAnyBy = require( '@stdlib/iter/cuany-by' ); +``` + +#### iterCuAnyBy( iterator, predicate\[, thisArg] ) + +Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether at least one iterated value passes a test implemented by a `predicate` function. + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function predicate( v ) { + return ( v > 0 ); +} + +var arr = array2iterator( [ 0, 0, 0, 1, 0 ] ); + +var it = iterCuAnyBy( arr, predicate ); + +var v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +var bool = it.next().done; +// returns true +``` + +The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + +A `predicate` function is provided two arguments: + +- **value**: iterated value +- **index**: iteration index (zero-based) + +To set the `predicate` function execution context, provide a `thisArg`. + + + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function predicate( v ) { + this.count += 1; + return ( v < 0 ); +} + +var ctx = { + 'count': 0 +}; + +var it = iterCuAnyBy( array2iterator( [ 1, 2, -1, 4 ] ), predicate, ctx ); +// returns + +var v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +v = it.next().value; +// returns true + +v = it.next().value; +// returns true + +var count = ctx.count; +// returns 3 +``` + + + + + + + +
+ +## Notes + +- A `predicate` function is invoked for each iterated value until the first truthy `predicate` function return value. Upon encountering the first truthy return value, the returned iterator ceases to invoke the `predicate` function and returns `true` for each subsequent iterated value of the provided input `iterator`. + +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/iter/randu' ); +var iterCuAnyBy = require( '@stdlib/iter/cuany-by' ); + +function threshold( r ) { + return ( r > 0.95 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which cumulatively tests whether at least one iterated value passes a test implemented by a predicate function: +var it = iterCuAnyBy( riter, threshold ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/iter/cuany-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/cuany-by/benchmark/benchmark.js new file mode 100644 index 00000000000..8305898f3aa --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/benchmark/benchmark.js @@ -0,0 +1,89 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var iterConstant = require( '@stdlib/iter/constant' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var iterCuAnyBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {*} value - value +* @returns {boolean} result +*/ +function predicate( value ) { + return ( value < 0 ); +} + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var iter; + var it; + var i; + + it = iterConstant( 3.14 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = iterCuAnyBy( it, predicate ); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iteration', function benchmark( b ) { + var iter; + var v; + var i; + + iter = iterCuAnyBy( iterConstant( 3.14 ), predicate ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = iter.next().value; + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/iter/cuany-by/docs/repl.txt b/lib/node_modules/@stdlib/iter/cuany-by/docs/repl.txt new file mode 100644 index 00000000000..963c58fc713 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/docs/repl.txt @@ -0,0 +1,64 @@ + +{{alias}}( iterator, predicate[, thisArg] ) + Returns an iterator which cumulatively tests whether at least one iterated + value passes a test implemented by a predicate function. + + If an environment supports Symbol.iterator and a provided iterator is + iterable, the returned iterator is iterable. + + The predicate function is provided two arguments: + + - value: iterated value + - index: iteration index + + A predicate function is invoked for each iterated value until the first + truthy predicate function return value. Upon encountering the first truthy + return value, the returned iterator ceases to invoke the predicate function + and returns `true` for each subsequent iterated value of the provided input + iterator. + + If provided an iterator which does not return any iterated values, the + function returns an iterator which is also empty. + + Parameters + ---------- + iterator: Object + Input iterator. + + predicate: Function + The test function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + iterator: Object + Iterator. + + iterator.next(): Function + Returns an iterator protocol-compliant object containing the next + iterated value (if one exists) and a boolean flag indicating + whether the iterator is finished. + + iterator.return( [value] ): Function + Finishes an iterator and returns a provided value. + + Examples + -------- + > var arr = {{alias:@stdlib/array/to-iterator}}( [ 0, 0, 0, 1, 0 ] ); + > function fcn( v ) { return ( v > 0 ); }; + > var it = {{alias}}( arr, fcn ); + > var v = it.next().value + false + > v = it.next().value + false + > v = it.next().value + false + > v = it.next().value + true + > v = it.next().value + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/iter/cuany-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/cuany-by/docs/types/index.d.ts new file mode 100644 index 00000000000..07d61e3cfb6 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/docs/types/index.d.ts @@ -0,0 +1,98 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = TypedIterator | TypedIterableIterator; + +/** +* Checks whether an iterated value passes a test. +* +* @returns boolean indicating whether an iterated value passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @returns boolean indicating whether an iterated value passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @param index - iteration index +* @returns boolean indicating whether an iterated value passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @param index - iteration index +* @returns boolean indicating whether an iterated value passes a test +*/ +type Predicate = Nullary | Unary | Binary; + +/** +* Returns an iterator which cumulatively tests whether at least one iterated value passes a test implemented by a predicate function. +* +* @param iterator - source iterator +* @param predicate - predicate function +* @param thisArg - execution context +* @returns iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* function isPositive( v ) { +* return ( v > 0 ); +* } +* +* var it = iterCuAnyBy( array2iterator( [ 0, 0, 0, 1, 0 ] ), isPositive ); +* +* var v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +*/ +declare function iterCuAnyBy( iterator: Iterator, predicate: Predicate, thisArg?: ThisParameterType> ): Iterator; + + +// EXPORTS // + +export = iterCuAnyBy ; diff --git a/lib/node_modules/@stdlib/iter/cuany-by/docs/types/test.ts b/lib/node_modules/@stdlib/iter/cuany-by/docs/types/test.ts new file mode 100644 index 00000000000..63f44165e16 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/docs/types/test.ts @@ -0,0 +1,109 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +import { TypedIterator, TypedIteratorResult } from '@stdlib/types/iter'; +import iterCuAnyBy = require( './index' ); + +/** +* Implements the iterator protocol `next` method. +* +* @returns iterator protocol-compliant object +*/ +function next(): TypedIteratorResult { + return { + 'value': 2.0, + 'done': false + }; +} + +/** +* Returns an iterator protocol-compliant object. +* +* @returns iterator protocol-compliant object +*/ +function iterator(): TypedIterator { + return { + 'next': next + }; +} + +/** +* Predicate function. +* +* @param _v - iterated value +* @param i - iteration index +* @returns a boolean +*/ +function predicate1( _v: any, i: number ): boolean { + return ( i > 10 ); +} + +/** +* Predicate function. +* +* @param v - iterated value +* @returns a boolean +*/ +function predicate2( v: any ): boolean { + return ( v !== v ); +} + + +// TESTS // + +// The function returns an iterator... +{ + iterCuAnyBy( iterator(), predicate1 ); // $ExpectType Iterator + iterCuAnyBy( iterator(), predicate2 ); // $ExpectType Iterator + iterCuAnyBy( iterator(), predicate1, {} ); // $ExpectType Iterator + iterCuAnyBy( iterator(), predicate2, {} ); // $ExpectType Iterator + iterCuAnyBy( iterator(), predicate1, null ); // $ExpectType Iterator + iterCuAnyBy( iterator(), predicate2, null ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a first argument which is not an iterator protocol-compliant object... +{ + iterCuAnyBy( '5', predicate1 ); // $ExpectError + iterCuAnyBy( 5, predicate1 ); // $ExpectError + iterCuAnyBy( true, predicate1 ); // $ExpectError + iterCuAnyBy( false, predicate1 ); // $ExpectError + iterCuAnyBy( null, predicate1 ); // $ExpectError + iterCuAnyBy( undefined, predicate1 ); // $ExpectError + iterCuAnyBy( [], predicate1 ); // $ExpectError + iterCuAnyBy( {}, predicate1 ); // $ExpectError + iterCuAnyBy( ( x: number ): number => x, predicate1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a predicate function... +{ + iterCuAnyBy( iterator(), '5' ); // $ExpectError + iterCuAnyBy( iterator(), 5 ); // $ExpectError + iterCuAnyBy( iterator(), true ); // $ExpectError + iterCuAnyBy( iterator(), false ); // $ExpectError + iterCuAnyBy( iterator(), null ); // $ExpectError + iterCuAnyBy( iterator(), undefined ); // $ExpectError + iterCuAnyBy( iterator(), [] ); // $ExpectError + iterCuAnyBy( iterator(), {} ); // $ExpectError + iterCuAnyBy( iterator(), ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + iterCuAnyBy(); // $ExpectError + iterCuAnyBy( iterator() ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/iter/cuany-by/examples/index.js b/lib/node_modules/@stdlib/iter/cuany-by/examples/index.js new file mode 100644 index 00000000000..fa74098fc6c --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/iter/randu' ); +var iterCuAnyBy = require( './../lib' ); + +function threshold( r ) { + return ( r > 0.95 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which cumulatively tests whether at least one iterated value passes a test implemented by a predicate function: +var it = iterCuAnyBy( riter, threshold ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} diff --git a/lib/node_modules/@stdlib/iter/cuany-by/lib/index.js b/lib/node_modules/@stdlib/iter/cuany-by/lib/index.js new file mode 100644 index 00000000000..30e1bee7b40 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/lib/index.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* Create an iterator which cumulatively tests whether at least one iterated value passes a test implemented by a predicate function. +* +* @module @stdlib/iter/cuany-by +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* var iterCuAnyBy = require( '@stdlib/iter/cuany-by' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var arr = array2iterator( [ 0, 0, 0, 1, 0 ] ); +* +* var it = iterCuNoneBy( arr, isPositive ); +* +* var v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* var bool = it.next().done; +* // returns true +*/ + + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/iter/cuany-by/lib/main.js b/lib/node_modules/@stdlib/iter/cuany-by/lib/main.js new file mode 100644 index 00000000000..79a52fe1816 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/lib/main.js @@ -0,0 +1,158 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns an iterator which cumulatively tests whether at least one iterated value passes a test implemented by a predicate function. +* +* @param {Iterator} iterator - input iterator +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - execution context +* @throws {TypeError} first argument must be an iterator +* @throws {TypeError} second argument must be a predicate function +* @returns {Iterator} iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var arr = array2iterator( [ 0, 0, 0, 1, 0 ] ); +* +* var it = iterCuAnyBy( arr, isPositive ); +* +* var v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns true +* +* v = it.next().value; +* // returns true +* +* var bool = it.next().done; +* // returns true +*/ +function iterCuAnyBy( iterator, predicate, thisArg ) { + var value; + var iter; + var FLG; + var i; + if ( !isIteratorLike( iterator ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an iterator. Value: `%s`.', iterator ) ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) ); + } + value = false; + i = -1; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator`, make the iterator iterable: + if ( iteratorSymbol && isFunction( iterator[ iteratorSymbol ] ) ) { + setReadOnly( iter, iteratorSymbol, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @returns {Object} iterator protocol-compliant object + */ + function next() { + var v; + if ( FLG ) { + return { + 'done': true + }; + } + v = iterator.next(); + if ( v.done ) { + FLG = true; + return v; + } + i += 1; + if ( !value && predicate.call( thisArg, v.value, i ) ) { + value = true; + } + return { + 'value': value, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return iterCuAnyBy( iterator[ iteratorSymbol ](), predicate, thisArg ); + } +} + + +// EXPORTS // + +module.exports = iterCuAnyBy; diff --git a/lib/node_modules/@stdlib/iter/cuany-by/package.json b/lib/node_modules/@stdlib/iter/cuany-by/package.json new file mode 100644 index 00000000000..04231925dd3 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/iter/cuany-by", + "version": "0.0.0", + "description": "Create an iterator which cumulatively tests whether at least one iterated value passes a test implemented by a predicate function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "test", + "any", + "iterate", + "iterator", + "iter", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/iter/cuany-by/test/test.js b/lib/node_modules/@stdlib/iter/cuany-by/test/test.js new file mode 100644 index 00000000000..47a93b6717b --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cuany-by/test/test.js @@ -0,0 +1,365 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var array2iterator = require( '@stdlib/array/to-iterator' ); +var randu = require( '@stdlib/random/iter/randu' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); +var noop = require( '@stdlib/utils/noop' ); +var iterCuAnyBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {*} value - value +* @returns {boolean} result +*/ +function predicate( value ) { + return ( value > 0 ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterCuAnyBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided an iterator', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuAnyBy( value, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a predicate function as a second argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 0, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuAnyBy( array2iterator( [ 1, 2, 3 ] ), value ); + }; + } +}); + +tape( 'the function returns an iterator protocol-compliant object', function test( t ) { + var arr; + var it; + var r; + var i; + + arr = array2iterator( [ 0, 0, 1, 0, 1 ] ); + it = iterCuAnyBy( arr, predicate ); + for ( i = 0; i < 5; i++ ) { + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + } + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an "empty" iterator, the function returns an iterator which is also empty', function test( t ) { + var arr; + var it; + var v; + + arr = array2iterator( [] ); + it = iterCuAnyBy( arr, predicate ); + + v = it.next(); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an iterator which cumulatively tests whether at least one iterated value passes a test implemented by a predicate function', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 0, 0, 1, 1, 0, 0 ]; + expected = [ + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuAnyBy( array2iterator( values ), predicate ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var it; + var r; + + it = iterCuAnyBy( randu(), predicate ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var it; + var r; + + it = iterCuAnyBy( randu(), predicate ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return( 'foo' ); + t.equal( r.value, 'foo', 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if an environment supports `Symbol.iterator` and the provided iterator is iterable, the returned iterator is iterable', function test( t ) { + var iterCuAnyBy; + var opts; + var rand; + var it1; + var it2; + var i; + + iterCuAnyBy = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + opts = { + 'seed': 12345 + }; + rand = randu( opts ); + rand[ '__ITERATOR_SYMBOL__' ] = factory; + + it1 = iterCuAnyBy( rand, predicate ); + t.equal( typeof it1[ '__ITERATOR_SYMBOL__' ], 'function', 'has method' ); + t.equal( it1[ '__ITERATOR_SYMBOL__' ].length, 0, 'has zero arity' ); + + it2 = it1[ '__ITERATOR_SYMBOL__' ](); + t.equal( typeof it2, 'object', 'returns an object' ); + t.equal( typeof it2.next, 'function', 'has method' ); + t.equal( typeof it2.return, 'function', 'has method' ); + + for ( i = 0; i < 100; i++ ) { + t.equal( it2.next().value, it1.next().value, 'returns expected value' ); + } + t.end(); + + function factory() { + return randu( opts ); + } +}); + +tape( 'if an environment does not support `Symbol.iterator`, the returned iterator is not "iterable"', function test( t ) { + var iterCuAnyBy; + var it; + + iterCuAnyBy = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': false + }); + + it = iterCuAnyBy( randu(), predicate); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); + +tape( 'if a provided iterator is not iterable, the returned iterator is not iterable', function test( t ) { + var iterCuAnyBy; + var rand; + var it; + + iterCuAnyBy = proxyquire( './../lib/main.js', { + '@stdlib/symbol/iterator': '__ITERATOR_SYMBOL__' + }); + + rand = randu(); + rand[ '__ITERATOR_SYMBOL__' ] = null; + + it = iterCuAnyBy( rand, predicate ); + t.equal( it[ iteratorSymbol ], void 0, 'does not have property' ); + + t.end(); +}); + +tape( 'the function supports specifying the predicate function execution context', function test( t ) { + var expected; + var actual; + var values; + var ctx; + var it; + var i; + + ctx = { + 'count': 0 + }; + + values = [ -1, -3, 2, 0, 1 ]; + expected = [ + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuAnyBy( array2iterator( values ), predicate, ctx ); + t.equal( it.next.length, 0, 'has zero arity' ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.equal( ctx.count, 3, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); From fd271bef99fe3d5d1ce3c578e10094bce146981e Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Wed, 9 Oct 2024 06:51:55 +0530 Subject: [PATCH 13/50] feat: add `iter/cusome-by` PR-URL: https://github.com/stdlib-js/stdlib/pull/2826 Closes: https://github.com/stdlib-js/stdlib/issues/2338 Co-authored-by: Gururaj Gurram Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt Signed-off-by: Gururaj Gurram --- .../@stdlib/iter/cusome-by/README.md | 207 ++++++++++ .../iter/cusome-by/benchmark/benchmark.js | 93 +++++ .../@stdlib/iter/cusome-by/docs/repl.txt | 67 ++++ .../iter/cusome-by/docs/types/index.d.ts | 99 +++++ .../@stdlib/iter/cusome-by/docs/types/test.ts | 122 ++++++ .../@stdlib/iter/cusome-by/examples/index.js | 45 +++ .../@stdlib/iter/cusome-by/lib/index.js | 65 +++ .../@stdlib/iter/cusome-by/lib/main.js | 174 ++++++++ .../@stdlib/iter/cusome-by/package.json | 73 ++++ .../@stdlib/iter/cusome-by/test/test.js | 377 ++++++++++++++++++ 10 files changed, 1322 insertions(+) create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/README.md create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/package.json create mode 100644 lib/node_modules/@stdlib/iter/cusome-by/test/test.js diff --git a/lib/node_modules/@stdlib/iter/cusome-by/README.md b/lib/node_modules/@stdlib/iter/cusome-by/README.md new file mode 100644 index 00000000000..95fee4c4755 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/README.md @@ -0,0 +1,207 @@ + + +# iterCuSomeBy + +> Create an iterator which cumulatively tests whether at least `n` iterated values pass a test implemented by a predicate function. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var iterCuSomeBy = require( '@stdlib/iter/cusome-by' ); +``` + +#### iterCuSomeBy( iterator, n, predicate\[, thisArg] ) + +Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether at least `n` iterated values pass a test implemented by a `predicate` function. + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function isPositive( v ) { + return ( v > 0 ); +} + +var arr = array2iterator( [ 0, 0, 0, 1, 1 ] ); + +var it = iterCuSomeBy( arr, 2, isPositive ); + +var v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +v = it.next().value; +// returns true + +var bool = it.next().done; +// returns true +``` + +The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties: + +- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished. +- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + +A `predicate` function is provided two arguments: + +- **value**: iterated value +- **index**: iteration index (zero-based) + +To set the `predicate` function execution context, provide a `thisArg`. + + + +```javascript +var array2iterator = require( '@stdlib/array/to-iterator' ); + +function predicate( v ) { + this.count += 1; + return ( v > 0 ); +} + +var arr = array2iterator( [ 0, 0, 1, 1, 1 ] ); + +var ctx = { + 'count': 0 +}; + +var it = iterCuSomeBy( arr, 3, predicate, ctx ); +// returns + +var v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +v = it.next().value; +// returns false + +v = it.next().value; +// returns true + +var count = ctx.count; +// returns 5 +``` + + + + + + + +
+ +## Notes + +- A `predicate` function is invoked for each iterated value until the `nth` truthy `predicate` function return value. The returned iterator continues iterating until it reaches the end of the input iterator, even after the condition is met. + +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/iter/randu' ); +var iterCuSomeBy = require( '@stdlib/iter/cusome-by' ); + +function threshold( r ) { + return ( r > 0.95 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which tracks whether at least two values have exceeded the threshold: +var it = iterCuSomeBy( riter, 2, threshold ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/iter/cusome-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/iter/cusome-by/benchmark/benchmark.js new file mode 100644 index 00000000000..85100e3659b --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/benchmark/benchmark.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var iterConstant = require( '@stdlib/iter/constant' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var iterCuSomeBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {*} value - value +* @returns {boolean} result +*/ + +// MAIN // + +bench( pkg, function benchmark( b ) { + var iter; + var it; + var i; + + function predicate( value ) { + return ( value < 0 ); + } + + it = iterConstant( 3.14 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + iter = iterCuSomeBy( it, 2, predicate ); + if ( typeof iter !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isIteratorLike( iter ) ) { + b.fail( 'should return an iterator protocol-compliant object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::iteration', function benchmark( b ) { + var iter; + var v; + var i; + + function predicate( value ) { + return ( value < 0 ); + } + + iter = iterCuSomeBy( iterConstant( 3.14 ), 2, predicate ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = iter.next().value; + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( v ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/iter/cusome-by/docs/repl.txt b/lib/node_modules/@stdlib/iter/cusome-by/docs/repl.txt new file mode 100644 index 00000000000..a2ac3c5d8f3 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/docs/repl.txt @@ -0,0 +1,67 @@ + +{{alias}}( iterator, n, predicate[, thisArg] ) + Returns an iterator which cumulatively tests whether at least `n` iterated + values pass a test implemented by a predicate function. + + If an environment supports Symbol.iterator and a provided iterator is + iterable, the returned iterator is iterable. + + The predicate function is provided two arguments: + + - value: iterated value + - index: iteration index + + A predicate function is invoked for each iterated value until the n + truthy predicate function return value. Upon encountering the nth truthy + return value, the returned iterator ceases to invoke the predicate function + and returns `true` for each subsequent iterated value of the provided input + iterator. + + If provided an iterator which does not return any iterated values, the + function returns an iterator which is also empty. + + Parameters + ---------- + iterator: Object + Input iterator. + + n: integer + Number of successful values to check for. + + predicate: Function + The test function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + iterator: Object + Iterator. + + iterator.next(): Function + Returns an iterator protocol-compliant object containing the next + iterated value (if one exists) and a boolean flag indicating + whether the iterator is finished. + + iterator.return( [value] ): Function + Finishes an iterator and returns a provided value. + + Examples + -------- + > var arr = {{alias:@stdlib/array/to-iterator}}( [ 0, 0, 0, 1, 1 ] ); + > function fcn( v ) { return ( v > 0 ); }; + > var it = {{alias}}( arr, 2, fcn ); + > var v = it.next().value + false + > v = it.next().value + false + > v = it.next().value + false + > v = it.next().value + false + > v = it.next().value + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/iter/cusome-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/iter/cusome-by/docs/types/index.d.ts new file mode 100644 index 00000000000..5751a84d315 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/docs/types/index.d.ts @@ -0,0 +1,99 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { TypedIterator, TypedIterableIterator } from '@stdlib/types/iter'; + +// Define a union type representing both iterable and non-iterable iterators: +type Iterator = TypedIterator | TypedIterableIterator; + +/** +* Checks whether an iterated value passes a test. +* +* @returns boolean indicating whether an iterated value passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @returns boolean indicating whether an iterated value passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @param index - iteration index +* @returns boolean indicating whether an iterated value passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Checks whether an iterated value passes a test. +* +* @param value - iterated value +* @param index - iteration index +* @returns boolean indicating whether an iterated value passes a test +*/ +type Predicate = Nullary | Unary | Binary; + +/** +* Returns an iterator which cumulatively tests whether at least `n` iterated values pass a test implemented by a predicate function. +* +* @param iterator - source iterator +* @param n - minimum number of truthy elements +* @param predicate - predicate function +* @param thisArg - execution context +* @returns iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* function isPositive( v ) { +* return ( v > 0 ); +* } +* +* var it = iterCuSomeBy( array2iterator( [ 0, 0, 0, 1, 1 ] ), 2, isPositive ); +* +* var v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns true +*/ +declare function iterCuSomeBy( iterator: Iterator, n: number, predicate: Predicate, thisArg?: ThisParameterType> ): Iterator; + + +// EXPORTS // + +export = iterCuSomeBy; diff --git a/lib/node_modules/@stdlib/iter/cusome-by/docs/types/test.ts b/lib/node_modules/@stdlib/iter/cusome-by/docs/types/test.ts new file mode 100644 index 00000000000..fb3ff0120c4 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/docs/types/test.ts @@ -0,0 +1,122 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +import { TypedIterator, TypedIteratorResult } from '@stdlib/types/iter'; +import iterCuSomeBy = require( './index' ); + +/** +* Implements the iterator protocol `next` method. +* +* @returns iterator protocol-compliant object +*/ +function next(): TypedIteratorResult { + return { + 'value': 2.0, + 'done': false + }; +} + +/** +* Returns an iterator protocol-compliant object. +* +* @returns iterator protocol-compliant object +*/ +function iterator(): TypedIterator { + return { + 'next': next + }; +} + +/** +* Predicate function. +* +* @param _v - iterated value +* @param i - iteration index +* @returns a boolean +*/ +function predicate1( _v: any, i: number ): boolean { + return ( i > 10 ); +} + +/** +* Predicate function. +* +* @param v - iterated value +* @returns a boolean +*/ +function predicate2( v: any ): boolean { + return ( v !== v ); +} + + +// TESTS // + +// The function returns an iterator... +{ + iterCuSomeBy( iterator(), 3, predicate1 ); // $ExpectType Iterator + iterCuSomeBy( iterator(), 3, predicate2 ); // $ExpectType Iterator + iterCuSomeBy( iterator(), 3, predicate1, {} ); // $ExpectType Iterator + iterCuSomeBy( iterator(), 3, predicate2, {} ); // $ExpectType Iterator + iterCuSomeBy( iterator(), 3, predicate1, null ); // $ExpectType Iterator + iterCuSomeBy( iterator(), 3, predicate2, null ); // $ExpectType Iterator +} + +// The compiler throws an error if the function is provided a first argument which is not an iterator protocol-compliant object... +{ + iterCuSomeBy( '5', 3, predicate1 ); // $ExpectError + iterCuSomeBy( 5, 3, predicate1 ); // $ExpectError + iterCuSomeBy( true, 3, predicate1 ); // $ExpectError + iterCuSomeBy( false, 3, predicate1 ); // $ExpectError + iterCuSomeBy( null, 3, predicate1 ); // $ExpectError + iterCuSomeBy( undefined, 3, predicate1 ); // $ExpectError + iterCuSomeBy( [], 3, predicate1 ); // $ExpectError + iterCuSomeBy( {}, 3, predicate1 ); // $ExpectError + iterCuSomeBy( ( x: number ): number => x, 3, predicate1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + iterCuSomeBy( iterator(), '5', predicate1 ); // $ExpectError + iterCuSomeBy( iterator(), true, predicate1 ); // $ExpectError + iterCuSomeBy( iterator(), false, predicate1 ); // $ExpectError + iterCuSomeBy( iterator(), null, predicate1 ); // $ExpectError + iterCuSomeBy( iterator(), undefined, predicate1 ); // $ExpectError + iterCuSomeBy( iterator(), [], predicate1 ); // $ExpectError + iterCuSomeBy( iterator(), {}, predicate1 ); // $ExpectError + iterCuSomeBy( iterator(), ( x: number ): number => x, predicate1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a predicate function... +{ + iterCuSomeBy( iterator(), 3, '5' ); // $ExpectError + iterCuSomeBy( iterator(), 3, 5 ); // $ExpectError + iterCuSomeBy( iterator(), 3, true ); // $ExpectError + iterCuSomeBy( iterator(), 3, false ); // $ExpectError + iterCuSomeBy( iterator(), 3, null ); // $ExpectError + iterCuSomeBy( iterator(), 3, undefined ); // $ExpectError + iterCuSomeBy( iterator(), 3, [] ); // $ExpectError + iterCuSomeBy( iterator(), 3, {} ); // $ExpectError + iterCuSomeBy( iterator(), 3, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + iterCuSomeBy(); // $ExpectError + iterCuSomeBy( iterator() ); // $ExpectError + iterCuSomeBy( iterator(), 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/iter/cusome-by/examples/index.js b/lib/node_modules/@stdlib/iter/cusome-by/examples/index.js new file mode 100644 index 00000000000..b1e304103f6 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/iter/randu' ); +var iterCuSomeBy = require( './../lib' ); + +function threshold( r ) { + return ( r >= 0.95 ); +} + +// Create an iterator which generates uniformly distributed pseudorandom numbers: +var opts = { + 'iter': 100 +}; +var riter = randu( opts ); + +// Create an iterator which tracks whether at least two values have exceeded the threshold: +var it = iterCuSomeBy( riter, 2, threshold ); + +// Perform manual iteration... +var r; +while ( true ) { + r = it.next(); + if ( r.done ) { + break; + } + console.log( r.value ); +} diff --git a/lib/node_modules/@stdlib/iter/cusome-by/lib/index.js b/lib/node_modules/@stdlib/iter/cusome-by/lib/index.js new file mode 100644 index 00000000000..7811880d97c --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/lib/index.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* Create an iterator which cumulatively tests whether at least `n` iterated values pass a test implemented by a predicate function. +* +* @module @stdlib/iter/cusome-by +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* var iterCuSomeBy = require( '@stdlib/iter/cusome-by' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var arr = array2iterator( [ 0, 0, 0, 1, 1 ] ); +* +* var it = iterCuSomeBy( arr, 2, isPositive ); +* +* var v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns true +* +* var bool = it.next().done; +* // returns true +*/ + + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/iter/cusome-by/lib/main.js b/lib/node_modules/@stdlib/iter/cusome-by/lib/main.js new file mode 100644 index 00000000000..293cabd74e5 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/lib/main.js @@ -0,0 +1,174 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var isIteratorLike = require( '@stdlib/assert/is-iterator-like' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); +var iteratorSymbol = require( '@stdlib/symbol/iterator' ); + + +// MAIN // + +/** +* Returns an iterator which cumulatively tests whether at least `n` iterated values pass a test implemented by a predicate function. +* +* @param {Iterator} iterator - input iterator +* @param {number} n - the number of items +* @param {Function} predicate - predicate function +* @param {*} [thisArg] - execution context +* @throws {TypeError} first argument must be an iterator +* @throws {TypeError} second argument must be a positive integer +* @throws {TypeError} third argument must be a predicate function +* @returns {Iterator} iterator +* +* @example +* var array2iterator = require( '@stdlib/array/to-iterator' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var arr = array2iterator( [ 0, 0, 0, 1, 1 ] ); +* +* var it = iterCuSomeBy( arr, 2, isPositive ); +* +* var v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns false +* +* v = it.next().value; +* // returns true +* +* var bool = it.next().done; +* // returns true +*/ +function iterCuSomeBy( iterator, n, predicate, thisArg ) { + var count; + var value; + var iter; + var FLG; + var i; + if ( !isIteratorLike( iterator ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an iterator. Value: `%s`.', iterator ) ); + } + if ( !isPositiveInteger( n ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', n ) ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', predicate ) ); + } + count = 0; + i = -1; + value = false; + + // Create an iterator protocol-compliant object: + iter = {}; + setReadOnly( iter, 'next', next ); + setReadOnly( iter, 'return', end ); + + // If an environment supports `Symbol.iterator` and the provided iterator is iterable, make the iterator iterable: + if ( iteratorSymbol && isFunction( iterator[ iteratorSymbol ] ) ) { + setReadOnly( iter, iteratorSymbol, factory ); + } + return iter; + + /** + * Returns an iterator protocol-compliant object containing the next iterated value. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function next() { + var v; + if ( FLG ) { + return { + 'done': true + }; + } + v = iterator.next(); + if ( v.done ) { + FLG = true; + return v; + } + i += 1; + if ( !value && predicate.call( thisArg, v.value, i ) ) { + count += 1; + if ( count === n ) { + value = true; + return { + 'value': true, + 'done': false + }; + } + } + return { + 'value': value, + 'done': false + }; + } + + /** + * Finishes an iterator. + * + * @private + * @param {*} [value] - value to return + * @returns {Object} iterator protocol-compliant object + */ + function end( value ) { + FLG = true; + if ( arguments.length ) { + return { + 'value': value, + 'done': true + }; + } + return { + 'done': true + }; + } + + /** + * Returns a new iterator. + * + * @private + * @returns {Iterator} iterator + */ + function factory() { + return iterCuSomeBy( iterator[ iteratorSymbol ](), n, predicate, thisArg ); + } +} + + +// EXPORTS // + +module.exports = iterCuSomeBy; diff --git a/lib/node_modules/@stdlib/iter/cusome-by/package.json b/lib/node_modules/@stdlib/iter/cusome-by/package.json new file mode 100644 index 00000000000..baddd3c9508 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/iter/cusome-by", + "version": "0.0.0", + "description": "Create an iterator which cumulatively tests whether at least `n` iterated values pass a test implemented by a predicate function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "test", + "some", + "any", + "every", + "all", + "iterate", + "iterator", + "iter", + "validate", + "predicate", + "cumulative", + "cusome", + "transform" + ] +} diff --git a/lib/node_modules/@stdlib/iter/cusome-by/test/test.js b/lib/node_modules/@stdlib/iter/cusome-by/test/test.js new file mode 100644 index 00000000000..cc8f1df03d3 --- /dev/null +++ b/lib/node_modules/@stdlib/iter/cusome-by/test/test.js @@ -0,0 +1,377 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var array2iterator = require( '@stdlib/array/to-iterator' ); +var noop = require( '@stdlib/utils/noop' ); +var iterCuSomeBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {*} value - value +* @returns {boolean} result +*/ +function predicate( value ) { + return ( value > 0 ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof iterCuSomeBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided an iterator', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuSomeBy( value, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a positive integer as a second argument', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 0, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuSomeBy( array2iterator( [ 1, 2, 3 ] ), value, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a predicate function as a third argument', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + iterCuSomeBy( array2iterator( [ 1, 2, 3 ] ), 3, value ); + }; + } +}); + +tape( 'the function returns an iterator protocol-compliant object', function test( t ) { + var arr; + var it; + var r; + var i; + + arr = array2iterator( [ 0, 0, 1, 0, 1 ] ); + it = iterCuSomeBy( arr, 3, predicate ); + for ( i = 0; i < 5; i++ ) { + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + } + t.equal( typeof r.done, 'boolean', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an "empty" iterator, the function returns an iterator which is also empty', function test( t ) { + var arr; + var it; + var v; + + arr = array2iterator( [] ); + it = iterCuSomeBy( arr, 3, predicate ); + + v = it.next(); + t.strictEqual( v.done, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an iterator which cumulatively tests whether at least `n` iterated values pass a test', function test( t ) { + var expected; + var actual; + var values; + var it; + var i; + + values = [ 0, 0, 1, 1, 0, 0 ]; + expected = [ + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': false, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'value': true, + 'done': false + }, + { + 'done': true + } + ]; + + it = iterCuSomeBy( array2iterator( values ), 2, predicate ); + + actual = []; + for ( i = 0; i < expected.length; i++ ) { + actual.push( it.next() ); + } + t.deepEqual( actual, expected, 'returns expected values' ); + t.end(); +}); + +tape( 'the function returns an iterator which cumulatively tests whether at least `n` iterated values pass a test', function test( t ) { + var expected; + var values; + var it; + var v; + var i; + + values = [ 0, 0, 1, 1, 0, 1 ]; + expected = [ false, false, false, true, true, true ]; + + it = iterCuSomeBy( array2iterator( values ), 2, predicate ); + t.equal( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < values.length; i++ ) { + v = it.next(); + t.equal( v.value, expected[i], 'returns expected value' ); + t.equal( v.done, false, 'returns expected value' ); + } + v = it.next(); + t.equal( v.value, undefined, 'returns expected value' ); + t.equal( v.done, true, 'returns expected value' ); + + values = [ 0, 0, 1, 1, 0, 1 ]; + expected = [ false, false, false, false, false, true ]; + + it = iterCuSomeBy( array2iterator( values ), 3, predicate ); + t.equal( typeof it.next, 'function', 'has next method' ); + + for ( i = 0; i < values.length; i++ ) { + v = it.next(); + t.equal( v.value, expected[i], 'returns expected value' ); + t.equal( v.done, false, 'returns expected value' ); + } + v = it.next(); + t.equal( v.value, undefined, 'returns expected value' ); + t.equal( v.done, true, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return ( v > 0 ); + } +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (no argument)', function test( t ) { + var it; + var r; + + it = iterCuSomeBy( array2iterator( [ 1, 1, 1, 0, 0 ] ), 3, predicate ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns a boolean' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns a boolean' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns expected value' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return ( v > 0 ); + } +}); + +tape( 'the returned iterator has a `return` method for closing an iterator (argument)', function test( t ) { + var it; + var r; + + it = iterCuSomeBy( array2iterator( [ 1, 1, 1, 0, 0 ] ), 3, predicate ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns a boolean' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.next(); + t.equal( typeof r.value, 'boolean', 'returns a boolean' ); + t.equal( r.done, false, 'returns expected value' ); + + r = it.return( 'finished' ); + t.equal( r.value, 'finished', 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + r = it.next(); + t.equal( r.value, void 0, 'returns expected value' ); + t.equal( r.done, true, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + return ( v > 0 ); + } +}); + +tape( 'if an environment supports `Symbol.iterator`, the returned iterator is iterable', function test( t ) { + var iterCuSomeBy; + var it1; + var it2; + var i; + + iterCuSomeBy = require( './../lib' ); + + it1 = iterCuSomeBy( array2iterator( [ 1, 1, 0, 0, 1 ] ), 3, predicate ); + t.equal( typeof it1[ Symbol.iterator ], 'function', 'has method' ); + + it2 = it1[ Symbol.iterator ](); + t.equal( typeof it2, 'object', 'returns an object' ); + t.equal( typeof it2.next, 'function', 'has method' ); + t.equal( typeof it2.return, 'function', 'has method' ); + + for ( i = 0; i < 6; i++ ) { + t.equal( it2.next().value, it1.next().value, 'returns expected value' ); + } + t.end(); + + function predicate( v ) { + return ( v > 0 ); + } +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var ctx; + var it; + var i; + + ctx = { + 'count': 0 + }; + + it = iterCuSomeBy( array2iterator( [ 1, 1, 0, 1, 1 ] ), 3, predicate, ctx ); + for ( i = 0; i < 5; i++ ) { + it.next(); + } + + t.strictEqual( ctx.count, 4, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +}); From 656fde0183a8ce9af1a1012274705b2bca692989 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:45:01 -0700 Subject: [PATCH 14/50] docs: update list of contributors PR-URL: #2995 Signed-off-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 752104235d6..f1b00f3f813 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -28,6 +28,7 @@ EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com> Frank Kovacs Golden Kumar <103646877+AuenKr@users.noreply.github.com> Gunj Joshi +Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> HarshaNP <96897754+GittyHarsha@users.noreply.github.com> Harshita Kalani Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com> From 6c3b2492906413f1d994aebe9dbc12b11245f108 Mon Sep 17 00:00:00 2001 From: Shivam <11shivam00@gmail.com> Date: Thu, 10 Oct 2024 06:49:14 +0530 Subject: [PATCH 15/50] docs: improve README examples of `stats/base/dists/invgamma namespace` PR-URL: https://github.com/stdlib-js/stdlib/pull/1808 Ref: https://github.com/stdlib-js/stdlib/issues/1631 Co-authored-by: Philipp Burckhardt Co-authored-by: shivam Ahir <11shivam00@gmail.com> Reviewed-by: Philipp Burckhardt --- .../stats/base/dists/invgamma/README.md | 64 ++++++++++++++++++- .../base/dists/invgamma/examples/index.js | 64 ++++++++++++++++++- 2 files changed, 124 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/invgamma/README.md b/lib/node_modules/@stdlib/stats/base/dists/invgamma/README.md index f093105b0f9..8b4b1391258 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/invgamma/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/invgamma/README.md @@ -106,10 +106,70 @@ var y = dist.cdf( 0.5 ); ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); +var invgammaRandomFactory = require( '@stdlib/random/base/invgamma' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var variance = require( '@stdlib/stats/base/variance' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var gamma = require( '@stdlib/stats/base/dists/gamma' ); +var mean = require( '@stdlib/stats/base/mean' ); +var abs = require( '@stdlib/math/base/special/abs' ); var invgamma = require( '@stdlib/stats/base/dists/invgamma' ); -console.log( objectKeys( invgamma ) ); +// Define the shape and scale parameters: +var alpha = 5.0; // shape parameter (α) +var beta = 1.0; // scale parameter (β) + +// Generate an array of x values: +var x = linspace( 0.01, 3.0, 100 ); + +// Compute the PDF for each x: +var invgammaPDF = invgamma.pdf.factory( alpha, beta ); +var pdf = filledarrayBy( x.length, 'float64', invgammaPDF ); + +// Compute the CDF for each x: +var invgammaCDF = invgamma.cdf.factory( alpha, beta ); +var cdf = filledarrayBy( x.length, 'float64', invgammaCDF ); + +// Output the PDF and CDF values: +console.log( 'x values:', x ); +console.log( 'PDF values:', pdf ); +console.log( 'CDF values:', cdf ); + +// Compute statistical properties: +var theoreticalMean = invgamma.mean( alpha, beta ); +var theoreticalVariance = invgamma.variance( alpha, beta ); +var theoreticalSkewness = invgamma.skewness( alpha, beta ); +var theoreticalKurtosis = invgamma.kurtosis( alpha, beta ); + +console.log( 'Theoretical Mean:', theoreticalMean ); +console.log( 'Theoretical Variance:', theoreticalVariance ); +console.log( 'Skewness:', theoreticalSkewness ); +console.log( 'Kurtosis:', theoreticalKurtosis ); + +// Generate random samples from the inverse gamma distribution: +var rinvGamma = invgammaRandomFactory( alpha, beta ); +var n = 1000; +var samples = filledarrayBy( n, 'float64', rinvGamma ); + +// Compute sample mean and variance: +var sampleMean = mean( n, samples, 1 ); +var sampleVariance = variance( n, 1, samples, 1 ); + +console.log( 'Sample Mean:', sampleMean ); +console.log( 'Sample Variance:', sampleVariance ); + +// Compare sample statistics to theoretical values: +console.log( 'Difference in Mean:', abs( mean - sampleMean ) ); +console.log( 'Difference in Variance:', abs( variance - sampleVariance ) ); + +// Demonstrate the relationship between inverse gamma and gamma distributions: +var y = 0.5; +var invGammaCDF = invgamma.cdf( y, alpha, beta ); +var gammaCDF = 1.0 - gamma.cdf( 1.0 / y, alpha, 1.0 / beta ); + +console.log( 'Inverse Gamma CDF at y =', y, ':', invGammaCDF ); +console.log( '1 - Gamma CDF at 1/y =', 1 / y, ':', gammaCDF ); +console.log( 'Difference:', abs( invGammaCDF - gammaCDF ) ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/invgamma/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/invgamma/examples/index.js index 6c0efb767d8..1438ae755b0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/invgamma/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/invgamma/examples/index.js @@ -18,7 +18,67 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); +var invgammaRandomFactory = require( '@stdlib/random/base/invgamma' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var variance = require( '@stdlib/stats/base/variance' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var gamma = require( '@stdlib/stats/base/dists/gamma' ); +var mean = require( '@stdlib/stats/base/mean' ); +var abs = require( '@stdlib/math/base/special/abs' ); var invgamma = require( './../lib' ); -console.log( objectKeys( invgamma ) ); +// Define the shape and scale parameters: +var alpha = 5.0; // shape parameter (α) +var beta = 1.0; // scale parameter (β) + +// Generate an array of x values: +var x = linspace( 0.01, 3.0, 100 ); + +// Compute the PDF for each x: +var invgammaPDF = invgamma.pdf.factory( alpha, beta ); +var pdf = filledarrayBy( x.length, 'float64', invgammaPDF ); + +// Compute the CDF for each x: +var invgammaCDF = invgamma.cdf.factory( alpha, beta ); +var cdf = filledarrayBy( x.length, 'float64', invgammaCDF ); + +// Output the PDF and CDF values: +console.log( 'x values:', x ); +console.log( 'PDF values:', pdf ); +console.log( 'CDF values:', cdf ); + +// Compute statistical properties: +var theoreticalMean = invgamma.mean( alpha, beta ); +var theoreticalVariance = invgamma.variance( alpha, beta ); +var theoreticalSkewness = invgamma.skewness( alpha, beta ); +var theoreticalKurtosis = invgamma.kurtosis( alpha, beta ); + +console.log( 'Theoretical Mean:', theoreticalMean ); +console.log( 'Theoretical Variance:', theoreticalVariance ); +console.log( 'Skewness:', theoreticalSkewness ); +console.log( 'Kurtosis:', theoreticalKurtosis ); + +// Generate random samples from the inverse gamma distribution: +var rinvGamma = invgammaRandomFactory( alpha, beta ); +var n = 1000; +var samples = filledarrayBy( n, 'float64', rinvGamma ); + +// Compute sample mean and variance: +var sampleMean = mean( n, samples, 1 ); +var sampleVariance = variance( n, 1, samples, 1 ); + +console.log( 'Sample Mean:', sampleMean ); +console.log( 'Sample Variance:', sampleVariance ); + +// Compare sample statistics to theoretical values: +console.log( 'Difference in Mean:', abs( mean - sampleMean ) ); +console.log( 'Difference in Variance:', abs( variance - sampleVariance ) ); + +// Demonstrate the relationship between inverse gamma and gamma distributions: +var y = 0.5; +var invGammaCDF = invgamma.cdf( y, alpha, beta ); +var gammaCDF = 1.0 - gamma.cdf( 1.0 / y, alpha, 1.0 / beta ); + +console.log( 'Inverse Gamma CDF at y =', y, ':', invGammaCDF ); +console.log( '1 - Gamma CDF at 1/y =', 1 / y, ':', gammaCDF ); +console.log( 'Difference:', abs( invGammaCDF - gammaCDF ) ); From e399bfd09baf0b50ea9beb49f65867cd1a1e45b7 Mon Sep 17 00:00:00 2001 From: Shivam <11shivam00@gmail.com> Date: Thu, 10 Oct 2024 06:56:49 +0530 Subject: [PATCH 16/50] docs: improve README examples of `stats/base/dists/gamma` namespace PR-URL: https://github.com/stdlib-js/stdlib/pull/1804 Ref: https://github.com/stdlib-js/stdlib/issues/1627 Co-authored-by: Philipp Burckhardt Co-authored-by: shivam Ahir <11shivam00@gmail.com> Reviewed-by: Philipp Burckhardt --- .../@stdlib/stats/base/dists/gamma/README.md | 85 ++++++++++++++++++- .../stats/base/dists/gamma/examples/index.js | 85 ++++++++++++++++++- 2 files changed, 166 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/gamma/README.md b/lib/node_modules/@stdlib/stats/base/dists/gamma/README.md index bf6aefdbac2..2b20d12458a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/gamma/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/gamma/README.md @@ -108,10 +108,91 @@ var y = dist.cdf( 0.5 ); ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); +var gammaRandomFactory = require( '@stdlib/random/base/gamma' ).factory; +var filledarrayby = require( '@stdlib/array/filled-by' ); +var Float64Array = require( '@stdlib/array/float64' ); +var variance = require( '@stdlib/stats/base/variance' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var mean = require( '@stdlib/stats/base/mean' ); +var abs = require( '@stdlib/math/base/special/abs' ); var gamma = require( '@stdlib/stats/base/dists/gamma' ); -console.log( objectKeys( gamma ) ); +// Define the shape and scale parameters: +var alpha = 3.0; // shape parameter (α) +var beta = 2.0; // scale parameter (β) + +// Generate an array of x values: +var x = linspace( 0.0, 20.0, 100 ); + +// Compute the PDF for each x: +var gammaPDF = gamma.pdf.factory( alpha, beta ); +var pdf = filledarrayby( x.length, 'float64', gammaPDF ); + +// Compute the CDF for each x: +var gammaCDF = gamma.cdf.factory( alpha, beta ); +var cdf = filledarrayby( x.length, 'float64', gammaCDF ); + +// Output the PDF and CDF values: +console.log( 'x values:', x ); +console.log( 'PDF values:', pdf ); +console.log( 'CDF values:', cdf ); + +// Compute statistical properties: +var theoreticalMean = gamma.mean( alpha, beta ); +var theoreticalVariance = gamma.variance( alpha, beta ); +var theoreticalSkewness = gamma.skewness( alpha, beta ); +var theoreticalKurtosis = gamma.kurtosis( alpha, beta ); + +console.log( 'Theoretical Mean:', theoreticalMean ); +console.log( 'Theoretical Variance:', theoreticalVariance ); +console.log( 'Skewness:', theoreticalSkewness ); +console.log( 'Kurtosis:', theoreticalKurtosis ); + +// Generate random samples from the gamma distribution: +var rgamma = gammaRandomFactory( alpha, beta ); +var n = 300; +var samples = filledarrayby( n, 'float64', rgamma ); + +// Compute sample mean and variance: +var sampleMean = mean( n, samples, 1 ); +var sampleVariance = variance( n, 1, samples, 1 ); + +console.log( 'Sample Mean:', sampleMean ); +console.log( 'Sample Variance:', sampleVariance ); + +// Compare sample statistics to theoretical values: +console.log( 'Difference in Mean:', abs( theoreticalMean - sampleMean ) ); +console.log( 'Difference in Variance:', abs( theoreticalVariance - sampleVariance ) ); + +// Demonstrate that the sum of `k` gamma variables is a gamma-distributed sum of `k` gamma(α, β) variables with same β is `gamma(k*α, β)`: +var k = 5; +var sumSamples = new Float64Array( n ); + +var sum; +var i; +var j; +for ( i = 0; i < sumSamples.length; i++ ) { + sum = 0.0; + for ( j = 0; j < k; j++ ) { + sum += rgamma(); + } + sumSamples[ i ] = sum; +} + +// Theoretical parameters for the sum: +var sumAlpha = k * alpha; +var sumMean = gamma.mean( sumAlpha, beta ); +var sumVariance = gamma.variance( sumAlpha, beta ); + +console.log( 'Sum Theoretical Mean:', sumMean ); +console.log( 'Sum Theoretical Variance:', sumVariance ); + +// Compute sample mean and variance for the sum: +var sumSampleMean = mean( sumSamples.length, sumSamples, 1 ); +var sumSampleVariance = variance( sumSamples.length, 1, sumSamples, 1 ); + +console.log( 'Sum Sample Mean:', sumSampleMean ); +console.log( 'Sum Sample Variance:', sumSampleVariance ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/gamma/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/gamma/examples/index.js index 47a663fd945..5cb61caad8a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/gamma/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/gamma/examples/index.js @@ -18,7 +18,88 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); +var gammaRandomFactory = require( '@stdlib/random/base/gamma' ).factory; +var filledarrayby = require( '@stdlib/array/filled-by' ); +var Float64Array = require( '@stdlib/array/float64' ); +var variance = require( '@stdlib/stats/base/variance' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var mean = require( '@stdlib/stats/base/mean' ); +var abs = require( '@stdlib/math/base/special/abs' ); var gamma = require( './../lib' ); -console.log( objectKeys( gamma ) ); +// Define the shape and scale parameters: +var alpha = 3.0; // shape parameter (α) +var beta = 2.0; // scale parameter (β) + +// Generate an array of x values: +var x = linspace( 0.0, 20.0, 100 ); + +// Compute the PDF for each x: +var gammaPDF = gamma.pdf.factory( alpha, beta ); +var pdf = filledarrayby( x.length, 'float64', gammaPDF ); + +// Compute the CDF for each x: +var gammaCDF = gamma.cdf.factory( alpha, beta ); +var cdf = filledarrayby( x.length, 'float64', gammaCDF ); + +// Output the PDF and CDF values: +console.log( 'x values:', x ); +console.log( 'PDF values:', pdf ); +console.log( 'CDF values:', cdf ); + +// Compute statistical properties: +var theoreticalMean = gamma.mean( alpha, beta ); +var theoreticalVariance = gamma.variance( alpha, beta ); +var theoreticalSkewness = gamma.skewness( alpha, beta ); +var theoreticalKurtosis = gamma.kurtosis( alpha, beta ); + +console.log( 'Theoretical Mean:', theoreticalMean ); +console.log( 'Theoretical Variance:', theoreticalVariance ); +console.log( 'Skewness:', theoreticalSkewness ); +console.log( 'Kurtosis:', theoreticalKurtosis ); + +// Generate random samples from the gamma distribution: +var rgamma = gammaRandomFactory( alpha, beta ); +var n = 300; +var samples = filledarrayby( n, 'float64', rgamma ); + +// Compute sample mean and variance: +var sampleMean = mean( n, samples, 1 ); +var sampleVariance = variance( n, 1, samples, 1 ); + +console.log( 'Sample Mean:', sampleMean ); +console.log( 'Sample Variance:', sampleVariance ); + +// Compare sample statistics to theoretical values: +console.log( 'Difference in Mean:', abs( theoreticalMean - sampleMean ) ); +console.log( 'Difference in Variance:', abs( theoreticalVariance - sampleVariance ) ); + +// Demonstrate that the sum of `k` gamma variables is a gamma-distributed sum of `k` gamma(α, β) variables with same β is `gamma(k*α, β)`: +var k = 5; +var sumSamples = new Float64Array( n ); + +var sum; +var i; +var j; +for ( i = 0; i < sumSamples.length; i++ ) { + sum = 0.0; + for ( j = 0; j < k; j++ ) { + sum += rgamma(); + } + sumSamples[ i ] = sum; +} + +// Theoretical parameters for the sum: +var sumAlpha = k * alpha; +var sumMean = gamma.mean( sumAlpha, beta ); +var sumVariance = gamma.variance( sumAlpha, beta ); + +console.log( 'Sum Theoretical Mean:', sumMean ); +console.log( 'Sum Theoretical Variance:', sumVariance ); + +// Compute sample mean and variance for the sum: +var sumSampleMean = mean( sumSamples.length, sumSamples, 1 ); +var sumSampleVariance = variance( sumSamples.length, 1, sumSamples, 1 ); + +console.log( 'Sum Sample Mean:', sumSampleMean ); +console.log( 'Sum Sample Variance:', sumSampleVariance ); From 3a595acf04202235c63824e0ebe99f584d83ce47 Mon Sep 17 00:00:00 2001 From: Gunj Joshi Date: Thu, 10 Oct 2024 18:35:08 +0530 Subject: [PATCH 17/50] docs: update function description in `math/base/special/max` PR-URL: #2999 Signed-off-by: Gunj Joshi Reviewed-by: Philipp Burckhardt --- lib/node_modules/@stdlib/math/base/special/max/lib/native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/max/lib/native.js b/lib/node_modules/@stdlib/math/base/special/max/lib/native.js index 6b07a8efed1..38f3282aafd 100644 --- a/lib/node_modules/@stdlib/math/base/special/max/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/max/lib/native.js @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Return the maximum value. +* Returns the maximum value. * * @private * @param {number} x - first number From 4a94497c4e429430d5409d65ef55c0077ca1edbd Mon Sep 17 00:00:00 2001 From: Gunj Joshi Date: Thu, 10 Oct 2024 18:35:46 +0530 Subject: [PATCH 18/50] docs: update function description in `math/base/special/min` PR-URL: #2998 Signed-off-by: Gunj Joshi Reviewed-by: Philipp Burckhardt --- lib/node_modules/@stdlib/math/base/special/min/lib/native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/min/lib/native.js b/lib/node_modules/@stdlib/math/base/special/min/lib/native.js index 09864154b59..06008a3e75c 100644 --- a/lib/node_modules/@stdlib/math/base/special/min/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/min/lib/native.js @@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Return the minimum value. +* Returns the minimum value. * * @private * @param {number} x - first number From caaf0d9f3597fac939a52fb15bdf6465fa0a3125 Mon Sep 17 00:00:00 2001 From: Shivam <11shivam00@gmail.com> Date: Fri, 11 Oct 2024 06:42:23 +0530 Subject: [PATCH 19/50] docs: improve README examples of `stats/base/dists/geometric` namespace PR-URL: https://github.com/stdlib-js/stdlib/pull/1801 Ref: https://github.com/stdlib-js/stdlib/issues/1628 Co-authored-by: Philipp Burckhardt Co-authored-by: shivam Ahir <11shivam00@gmail.com> Reviewed-by: Philipp Burckhardt --- .../stats/base/dists/geometric/README.md | 90 ++++++++++++++++++- .../base/dists/geometric/examples/index.js | 90 ++++++++++++++++++- 2 files changed, 176 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md b/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md index 84b79d9d4cc..fd921a584bb 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md @@ -112,10 +112,96 @@ y = dist.logpmf( 2.3 ); ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); +var geometricRandomFactory = require( '@stdlib/random/base/geometric' ).factory; +var negativeBinomial = require( '@stdlib/stats/base/dists/negative-binomial' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var variance = require( '@stdlib/stats/base/variance' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var mean = require( '@stdlib/stats/base/mean' ); +var abs = require( '@stdlib/math/base/special/abs' ); var geometric = require( '@stdlib/stats/base/dists/geometric' ); -console.log( objectKeys( geometric ) ); +// Define the success probability: +var p = 0.3; // Probability of success on each trial + +// Generate an array of x values (number of failures before first success): +var x = linspace( 0, 10, 11 ); // Geometric distribution is discrete + +// Compute the PMF for each x: +var geometricPMF = geometric.pmf.factory( p ); +var pmf = filledarrayBy( x.length, 'float64', geometricPMF ); + +// Compute the CDF for each x: +var geometricCDF = geometric.cdf.factory( p ); +var cdf = filledarrayBy( x.length, 'float64', geometricCDF ); + +// Output the PMF and CDF values: +console.log( 'x values:', x ); +console.log( 'PMF values:', pmf ); +console.log( 'CDF values:', cdf ); + +// Compute statistical properties: +var theoreticalMean = geometric.mean( p ); +var theoreticalVariance = geometric.variance( p ); +var theoreticalSkewness = geometric.skewness( p ); +var theoreticalKurtosis = geometric.kurtosis( p ); + +console.log( 'Theoretical Mean:', theoreticalMean ); +console.log( 'Theoretical Variance:', theoreticalVariance ); +console.log( 'Skewness:', theoreticalSkewness ); +console.log( 'Kurtosis:', theoreticalKurtosis ); + +// Generate random samples from the geometric distribution: +var rgeom = geometricRandomFactory( p ); +var n = 1000; +var samples = filledarrayBy( n, 'float64', rgeom ); + +// Compute sample mean and variance: +var sampleMean = mean( n, samples, 1 ); +var sampleVariance = variance( n, 1, samples, 1 ); + +console.log( 'Sample Mean:', sampleMean ); +console.log( 'Sample Variance:', sampleVariance ); + +// Demonstrate the memoryless property: +var s = 2.0; +var t = 3.0; +var prob1 = ( 1.0 - geometric.cdf( s + t - 1.0, p ) ) / + ( 1.0 - geometric.cdf( s - 1.0, p )); +var prob2 = 1.0 - geometric.cdf( t - 1.0, p ); + +console.log( 'P(X > s + t | X > s):', prob1 ); +console.log( 'P(X > t):', prob2 ); +console.log( 'Difference:', abs( prob1 - prob2 ) ); + +// Demonstrate that the sum of k independent geometric random variables follows a negative binomial distribution: +var k = 5; +function drawSum() { + var sum = 0; + var j; + for ( j = 0; j < k; j++ ) { + sum += rgeom(); + } + return sum; +} +var sumSamples = filledarrayBy( n, 'float64', drawSum ); + +// Compute sample mean and variance for the sum: +var sumSampleMean = mean( n, sumSamples, 1 ); +var sumSampleVariance = variance( n, 1, sumSamples, 1 ); + +// Theoretical mean and variance of Negative Binomial distribution: +var nbMean = negativeBinomial.mean( k, p ); +var nbVariance = negativeBinomial.variance( k, p ); + +console.log( 'Sum Sample Mean:', sumSampleMean ); +console.log( 'Sum Sample Variance:', sumSampleVariance ); +console.log( 'Negative Binomial Mean:', nbMean ); +console.log( 'Negative Binomial Variance:', nbVariance ); + +// Compare sample statistics to theoretical values: +console.log( 'Difference in Mean:', abs( nbMean - sumSampleMean ) ); +console.log( 'Difference in Variance:', abs( nbVariance - sumSampleVariance ) ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js index d7eeccd51c6..edf38c65b64 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js @@ -18,7 +18,93 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); +var geometricRandomFactory = require( '@stdlib/random/base/geometric' ).factory; +var negativeBinomial = require( '@stdlib/stats/base/dists/negative-binomial' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var variance = require( '@stdlib/stats/base/variance' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var mean = require( '@stdlib/stats/base/mean' ); +var abs = require( '@stdlib/math/base/special/abs' ); var geometric = require( './../lib' ); -console.log( objectKeys( geometric ) ); +// Define the success probability: +var p = 0.3; // Probability of success on each trial + +// Generate an array of x values (number of failures before first success): +var x = linspace( 0, 10, 11 ); // Geometric distribution is discrete + +// Compute the PMF for each x: +var geometricPMF = geometric.pmf.factory( p ); +var pmf = filledarrayBy( x.length, 'float64', geometricPMF ); + +// Compute the CDF for each x: +var geometricCDF = geometric.cdf.factory( p ); +var cdf = filledarrayBy( x.length, 'float64', geometricCDF ); + +// Output the PMF and CDF values: +console.log( 'x values:', x ); +console.log( 'PMF values:', pmf ); +console.log( 'CDF values:', cdf ); + +// Compute statistical properties: +var theoreticalMean = geometric.mean( p ); +var theoreticalVariance = geometric.variance( p ); +var theoreticalSkewness = geometric.skewness( p ); +var theoreticalKurtosis = geometric.kurtosis( p ); + +console.log( 'Theoretical Mean:', theoreticalMean ); +console.log( 'Theoretical Variance:', theoreticalVariance ); +console.log( 'Skewness:', theoreticalSkewness ); +console.log( 'Kurtosis:', theoreticalKurtosis ); + +// Generate random samples from the geometric distribution: +var rgeom = geometricRandomFactory( p ); +var n = 1000; +var samples = filledarrayBy( n, 'float64', rgeom ); + +// Compute sample mean and variance: +var sampleMean = mean( n, samples, 1 ); +var sampleVariance = variance( n, 1, samples, 1 ); + +console.log( 'Sample Mean:', sampleMean ); +console.log( 'Sample Variance:', sampleVariance ); + +// Demonstrate the memoryless property: +var s = 2.0; +var t = 3.0; +var prob1 = ( 1.0 - geometric.cdf( s + t - 1.0, p ) ) / + ( 1.0 - geometric.cdf( s - 1.0, p )); +var prob2 = 1.0 - geometric.cdf( t - 1.0, p ); + +console.log( 'P(X > s + t | X > s):', prob1 ); +console.log( 'P(X > t):', prob2 ); +console.log( 'Difference:', abs( prob1 - prob2 ) ); + +// Demonstrate that the sum of k independent geometric random variables follows a negative binomial distribution: +var k = 5; +function drawSum() { + var sum = 0; + var j; + for ( j = 0; j < k; j++ ) { + sum += rgeom(); + } + return sum; +} +var sumSamples = filledarrayBy( n, 'float64', drawSum ); + +// Compute sample mean and variance for the sum: +var sumSampleMean = mean( n, sumSamples, 1 ); +var sumSampleVariance = variance( n, 1, sumSamples, 1 ); + +// Theoretical mean and variance of Negative Binomial distribution: +var nbMean = negativeBinomial.mean( k, p ); +var nbVariance = negativeBinomial.variance( k, p ); + +console.log( 'Sum Sample Mean:', sumSampleMean ); +console.log( 'Sum Sample Variance:', sumSampleVariance ); +console.log( 'Negative Binomial Mean:', nbMean ); +console.log( 'Negative Binomial Variance:', nbVariance ); + +// Compare sample statistics to theoretical values: +console.log( 'Difference in Mean:', abs( nbMean - sumSampleMean ) ); +console.log( 'Difference in Variance:', abs( nbVariance - sumSampleVariance ) ); From f0ab00bf081e55b928de80320c75dc42e713ad3d Mon Sep 17 00:00:00 2001 From: Shivam <11shivam00@gmail.com> Date: Fri, 11 Oct 2024 07:01:21 +0530 Subject: [PATCH 20/50] docs: improve README examples of `stats/base/dists/chi` namespace PR-URL: #1803 Ref: #1618 Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../@stdlib/stats/base/dists/chi/README.md | 84 ++++++++++++++++++- .../stats/base/dists/chi/examples/index.js | 82 +++++++++++++++++- 2 files changed, 160 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/chi/README.md b/lib/node_modules/@stdlib/stats/base/dists/chi/README.md index 0e2ccf260b9..15972576c5a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chi/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/chi/README.md @@ -101,15 +101,91 @@ var mu = dist.mean; ## Examples - - ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); +var chiRandomFactory = require( '@stdlib/random/base/chi' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var variance = require( '@stdlib/stats/base/variance' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var rayleigh = require( '@stdlib/stats/base/dists/rayleigh' ); +var mean = require( '@stdlib/stats/base/mean' ); +var abs = require( '@stdlib/math/base/special/abs' ); var chi = require( '@stdlib/stats/base/dists/chi' ); -console.log( objectKeys( chi ) ); +// Define the degrees of freedom parameter: +var k = 2; + +// Generate an array of x values: +var x = linspace( 0, 10, 100 ); + +// Compute the PDF for each x: +var chiPDF = chi.pdf.factory( k ); +var pdf = filledarrayBy( x.length, 'float64', chiPDF ); + +// Compute the CDF for each x: +var chiCDF = chi.cdf.factory( k ); +var cdf = filledarrayBy( x.length, 'float64', chiCDF ); + +// Output the PDF and CDF values: +console.log( 'x values:', x ); +console.log( 'PDF values:', pdf ); +console.log( 'CDF values:', cdf ); + +// Compute statistical properties: +var theoreticalMean = chi.mean( k ); +var theoreticalVariance = chi.variance( k ); +var theoreticalSkewness = chi.skewness( k ); +var theoreticalKurtosis = chi.kurtosis( k ); + +console.log( 'Theoretical Mean:', theoreticalMean ); +console.log( 'Theoretical Variance:', theoreticalVariance ); +console.log( 'Skewness:', theoreticalSkewness ); +console.log( 'Kurtosis:', theoreticalKurtosis ); + +// Generate random samples from the Chi distribution: +var rchi = chiRandomFactory( k ); +var n = 1000; +var samples = filledarrayBy( n, 'float64', rchi ); + +// Compute sample mean and variance: +var sampleMean = mean( n, samples, 1 ); +var sampleVariance = variance( n, 1, samples, 1 ); + +console.log( 'Sample Mean:', sampleMean ); +console.log( 'Sample Variance:', sampleVariance ); + +// Compare sample statistics to theoretical values: +console.log( 'Difference in Mean:', abs( theoreticalMean - sampleMean ) ); +console.log( 'Difference in Variance:', abs( theoreticalVariance - sampleVariance ) ); + +// Demonstrate the relationship with the Rayleigh distribution when k=2: +var rayleighPDF = rayleigh.pdf.factory( 1.0 ); +var rayleighCDF = rayleigh.cdf.factory( 1.0 ); + +// Compute Rayleigh PDF and CDF for each x: +var rayleighPDFValues = filledarrayBy( x.length, 'float64', rayleighPDF ); + +var rayleighCDFValues = filledarrayBy( x.length, 'float64', rayleighCDF ); + +// Compare Chi and Rayleigh PDFs and CDFs: +var maxDiffPDF = 0.0; +var maxDiffCDF = 0.0; +var diffPDF; +var diffCDF; +var i; +for ( i = 0; i < x.length; i++ ) { + diffPDF = abs( pdf[ i ] - rayleighPDFValues[ i ] ); + if ( diffPDF > maxDiffPDF ) { + maxDiffPDF = diffPDF; + } + diffCDF = abs( cdf[ i ] - rayleighCDFValues[ i ] ); + if ( diffCDF > maxDiffCDF ) { + maxDiffCDF = diffCDF; + } +} +console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF:', maxDiffPDF ); +console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF:', maxDiffCDF ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js index 0d941342e11..6857d460c06 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js @@ -18,7 +18,85 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); +var chiRandomFactory = require( '@stdlib/random/base/chi' ).factory; +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var variance = require( '@stdlib/stats/base/variance' ); +var linspace = require( '@stdlib/array/base/linspace' ); +var rayleigh = require( '@stdlib/stats/base/dists/rayleigh' ); +var mean = require( '@stdlib/stats/base/mean' ); +var abs = require( '@stdlib/math/base/special/abs' ); var chi = require( './../lib' ); -console.log( objectKeys( chi ) ); +// Define the degrees of freedom parameter: +var k = 2; + +// Generate an array of x values: +var x = linspace( 0, 10, 100 ); + +// Compute the PDF for each x: +var chiPDF = chi.pdf.factory( k ); +var pdf = filledarrayBy( x.length, 'float64', chiPDF ); + +// Compute the CDF for each x: +var chiCDF = chi.cdf.factory( k ); +var cdf = filledarrayBy( x.length, 'float64', chiCDF ); + +// Output the PDF and CDF values: +console.log( 'x values:', x ); +console.log( 'PDF values:', pdf ); +console.log( 'CDF values:', cdf ); + +// Compute statistical properties: +var theoreticalMean = chi.mean( k ); +var theoreticalVariance = chi.variance( k ); +var theoreticalSkewness = chi.skewness( k ); +var theoreticalKurtosis = chi.kurtosis( k ); + +console.log( 'Theoretical Mean:', theoreticalMean ); +console.log( 'Theoretical Variance:', theoreticalVariance ); +console.log( 'Skewness:', theoreticalSkewness ); +console.log( 'Kurtosis:', theoreticalKurtosis ); + +// Generate random samples from the Chi distribution: +var rchi = chiRandomFactory( k ); +var n = 1000; +var samples = filledarrayBy( n, 'float64', rchi ); + +// Compute sample mean and variance: +var sampleMean = mean( n, samples, 1 ); +var sampleVariance = variance( n, 1, samples, 1 ); + +console.log( 'Sample Mean:', sampleMean ); +console.log( 'Sample Variance:', sampleVariance ); + +// Compare sample statistics to theoretical values: +console.log( 'Difference in Mean:', abs( theoreticalMean - sampleMean ) ); +console.log( 'Difference in Variance:', abs( theoreticalVariance - sampleVariance ) ); + +// Demonstrate the relationship with the Rayleigh distribution when k=2: +var rayleighPDF = rayleigh.pdf.factory( 1.0 ); +var rayleighCDF = rayleigh.cdf.factory( 1.0 ); + +// Compute Rayleigh PDF and CDF for each x: +var rayleighPDFValues = filledarrayBy( x.length, 'float64', rayleighPDF ); + +var rayleighCDFValues = filledarrayBy( x.length, 'float64', rayleighCDF ); + +// Compare Chi and Rayleigh PDFs and CDFs: +var maxDiffPDF = 0.0; +var maxDiffCDF = 0.0; +var diffPDF; +var diffCDF; +var i; +for ( i = 0; i < x.length; i++ ) { + diffPDF = abs( pdf[ i ] - rayleighPDFValues[ i ] ); + if ( diffPDF > maxDiffPDF ) { + maxDiffPDF = diffPDF; + } + diffCDF = abs( cdf[ i ] - rayleighCDFValues[ i ] ); + if ( diffCDF > maxDiffCDF ) { + maxDiffCDF = diffCDF; + } +} +console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF:', maxDiffPDF ); +console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF:', maxDiffCDF ); From efbff479674b3a3941278a245dedda41baf137a3 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:47:46 +0530 Subject: [PATCH 21/50] refactor: `blas/ext/base/snansumkbn2` according to current project conventions PR-URL: https://github.com/stdlib-js/stdlib/pull/3002 Closes: https://github.com/stdlib-js/stdlib/issues/1530 Ref: https://github.com/stdlib-js/stdlib/issues/1152 Co-authored-by: Gururaj Gurram Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../blas/ext/base/snansumkbn2/README.md | 42 +++---- .../base/snansumkbn2/benchmark/benchmark.js | 20 ++- .../snansumkbn2/benchmark/benchmark.native.js | 20 ++- .../benchmark/benchmark.ndarray.js | 20 ++- .../benchmark/benchmark.ndarray.native.js | 20 ++- .../blas/ext/base/snansumkbn2/docs/repl.txt | 20 ++- .../ext/base/snansumkbn2/examples/index.js | 21 ++-- .../blas/ext/base/snansumkbn2/include.gypi | 2 +- .../blas/ext/base/snansumkbn2/lib/index.js | 7 +- .../blas/ext/base/snansumkbn2/lib/ndarray.js | 4 +- .../base/snansumkbn2/lib/ndarray.native.js | 13 +- .../ext/base/snansumkbn2/lib/snansumkbn2.js | 3 +- .../snansumkbn2/lib/snansumkbn2.native.js | 3 +- .../blas/ext/base/snansumkbn2/manifest.json | 85 +++++++++---- .../blas/ext/base/snansumkbn2/src/addon.c | 47 +++++++ .../blas/ext/base/snansumkbn2/src/addon.cpp | 117 ------------------ .../ext/base/snansumkbn2/test/test.ndarray.js | 15 +-- .../snansumkbn2/test/test.ndarray.native.js | 15 +-- .../base/snansumkbn2/test/test.snansumkbn2.js | 15 +-- .../test/test.snansumkbn2.native.js | 15 +-- 20 files changed, 205 insertions(+), 299 deletions(-) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/addon.c delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/addon.cpp diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/README.md b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/README.md index aed8f3771a2..befddaa0ee6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/README.md @@ -44,9 +44,8 @@ Computes the sum of single-precision floating-point strided array elements, igno var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = snansumkbn2( N, x, 1 ); +var v = snansumkbn2( 4, x, 1 ); // returns 1.0 ``` @@ -56,16 +55,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 sum 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 sum 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, NaN, -7.0, NaN, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = snansumkbn2( N, x, 2 ); +var v = snansumkbn2( 4, x, 2 ); // returns 5.0 ``` @@ -75,14 +72,11 @@ 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, NaN, -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 v = snansumkbn2( N, x1, 2 ); +var v = snansumkbn2( 4, x1, 2 ); // returns 5.0 ``` @@ -94,9 +88,8 @@ Computes the sum of single-precision floating-point strided array elements, igno var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] ); -var N = x.length; -var v = snansumkbn2.ndarray( N, x, 1, 0 ); +var v = snansumkbn2.ndarray( 4, x, 1, 0 ); // returns 1.0 ``` @@ -108,12 +101,10 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = snansumkbn2.ndarray( N, x, 2, 1 ); +var v = snansumkbn2.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -138,22 +129,19 @@ var v = snansumkbn2.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' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var snansumkbn2 = require( '@stdlib/blas/ext/base/snansumkbn2' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( randu()*100.0 ); +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return discreteUniform( 0, 100 ); } + return NaN; } + +var x = filledarrayBy( 10, 'float32', rand ); console.log( x ); var v = snansumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.js index 67474d58fd0..6f9a72b5f9f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.js @@ -21,10 +21,11 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +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 snansumkbn2 = require( './../lib/snansumkbn2.js' ); @@ -39,18 +40,15 @@ var snansumkbn2 = require( './../lib/snansumkbn2.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float32', rand ); + return benchmark; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*10.0 ) - 20.0; + function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); } + return NaN; } - return benchmark; function benchmark( b ) { var v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.native.js index 8e5a80ab57a..96130fbe2fa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +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; @@ -48,18 +49,15 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float32', rand ); + return benchmark; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*10.0 ) - 20.0; + function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); } + return NaN; } - return benchmark; function benchmark( b ) { var v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.js index 80e496f9ac3..081da343946 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.js @@ -21,10 +21,11 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +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 snansumkbn2 = require( './../lib/ndarray.js' ); @@ -39,18 +40,15 @@ var snansumkbn2 = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float32', rand ); + return benchmark; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*10.0 ) - 20.0; + function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); } + return NaN; } - return benchmark; function benchmark( b ) { var v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.native.js index 15c5708fe2e..f9a68f2913c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/benchmark/benchmark.ndarray.native.js @@ -22,10 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +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; @@ -48,18 +49,15 @@ var opts = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; + var x = filledarrayBy( len, 'float32', rand ); + return benchmark; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = ( randu()*10.0 ) - 20.0; + function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return uniform( -10.0, 10.0 ); } + return NaN; } - return benchmark; function benchmark( b ) { var v; diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/docs/repl.txt index 905c4fdcad6..dcffb1c463c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/docs/repl.txt @@ -4,11 +4,11 @@ ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm. - 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 + array are accessed at runtime. - Indexing is relative to the first index. To introduce an offset, use a typed - array view. + Indexing is relative to the first index. To introduce an offset, + use a typed array view. If `N <= 0`, the function returns `0.0`. @@ -35,21 +35,20 @@ > {{alias}}( x.length, x, 1 ) 1.0 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 4, x, stride ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); > 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}}( 4, x1, stride ) -1.0 + {{alias}}.ndarray( N, x, stride, offset ) Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška @@ -87,8 +86,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 4, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/index.js index fd1595a3e92..217c933a1cf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/examples/index.js @@ -18,22 +18,19 @@ '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' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var snansumkbn2 = require( './../lib' ); -var x; -var i; - -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( randu()*100.0 ); +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return discreteUniform( 0, 100 ); } + return NaN; } + +var x = filledarrayBy( 10, 'float32', rand ); console.log( x ); var v = snansumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/include.gypi b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/include.gypi index 868c5c12e85..26476a8c265 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/include.gypi +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/include.gypi @@ -36,7 +36,7 @@ # Source files: 'src_files': [ - '<(src_dir)/addon.cpp', + '<(src_dir)/addon.c', ' +#include + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 3 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, stride, argv, 2 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 1 ); + + napi_value v; + napi_status status = napi_create_double( env, stdlib_strided_snansumkbn2( N, X, stride ), &v ); + assert( status == napi_ok ); + + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/addon.cpp b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/src/addon.cpp deleted file mode 100644 index c06d66a1402..00000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/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/ext/base/snansumkbn2.h" -#include -#include -#include -#include -#include - -/** -* Add-on namespace. -*/ -namespace stdlib_blas_ext_base_snansumkbn2 { - - /** - * Computes the sum of single-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm. - * - * ## Notes - * - * - When called from JavaScript, the function expects three arguments: - * - * - `N`: number of indexed elements - * - `X`: input array - * - `stride`: stride length - */ - napi_value node_snansumkbn2( napi_env env, napi_callback_info info ) { - napi_status status; - - size_t argc = 3; - napi_value argv[ 3 ]; - status = napi_get_cb_info( env, info, &argc, argv, nullptr, nullptr ); - assert( status == napi_ok ); - - if ( argc < 3 ) { - napi_throw_error( env, nullptr, "invalid invocation. Must provide 3 arguments." ); - return nullptr; - } - - napi_valuetype vtype0; - status = napi_typeof( env, argv[ 0 ], &vtype0 ); - assert( status == napi_ok ); - if ( vtype0 != napi_number ) { - napi_throw_type_error( env, nullptr, "invalid argument. First argument must be a number." ); - return nullptr; - } - - bool res; - status = napi_is_typedarray( env, argv[ 1 ], &res ); - assert( status == napi_ok ); - if ( res == false ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a 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 stride; - status = napi_get_value_int64( env, argv[ 2 ], &stride ); - assert( status == napi_ok ); - - napi_typedarray_type vtype1; - size_t xlen; - void *X; - status = napi_get_typedarray_info( env, argv[ 1 ], &vtype1, &xlen, &X, nullptr, nullptr ); - assert( status == napi_ok ); - if ( vtype1 != napi_float32_array ) { - napi_throw_type_error( env, nullptr, "invalid argument. Second argument must be a Float32Array." ); - return nullptr; - } - if ( (N-1)*llabs(stride) >= (int64_t)xlen ) { - napi_throw_range_error( env, nullptr, "invalid argument. Second argument has insufficient elements based on the associated stride and the number of indexed elements." ); - return nullptr; - } - - napi_value v; - status = napi_create_double( env, (double)stdlib_strided_snansumkbn2( N, (float *)X, stride ), &v ); - assert( status == napi_ok ); - - return v; - } - - napi_value Init( napi_env env, napi_value exports ) { - napi_status status; - napi_value fcn; - status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, node_snansumkbn2, NULL, &fcn ); - assert( status == napi_ok ); - return fcn; - } - - NAPI_MODULE( NODE_GYP_MODULE_NAME, Init ) -} // end namespace stdlib_blas_ext_base_snansumkbn2 diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.js index 3bcdd964e99..add8a34c679 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float32Array = require( '@stdlib/array/float32' ); var snansumkbn2 = require( './../lib/ndarray.js' ); @@ -35,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 4', function test( t ) { - t.strictEqual( snansumkbn2.length, 4, 'has expected arity' ); + t.strictEqual( snansumkbn2.length, 4, 'returns expected value' ); t.end(); }); @@ -106,7 +105,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -123,15 +121,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, 2, 0 ); + v = snansumkbn2( 5, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -148,8 +144,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, -2, 8 ); + v = snansumkbn2( 5, x, -2, 8 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -168,7 +163,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -184,9 +178,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, 2, 1 ); + v = snansumkbn2( 5, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.native.js index 31596c5dbe1..37d36862f1e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.ndarray.native.js @@ -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' ); @@ -44,7 +43,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 4', opts, function test( t ) { - t.strictEqual( snansumkbn2.length, 4, 'has expected arity' ); + t.strictEqual( snansumkbn2.length, 4, 'returns expected value' ); t.end(); }); @@ -115,7 +114,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -132,15 +130,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, 2, 0 ); + v = snansumkbn2( 5, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -157,8 +153,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, -2, 8 ); + v = snansumkbn2( 5, x, -2, 8 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -177,7 +172,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -193,9 +187,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { NaN, NaN // 4 ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, 2, 1 ); + v = snansumkbn2( 5, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.js index 36b8873cdf3..757d4f4680d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.js +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float32Array = require( '@stdlib/array/float32' ); var snansumkbn2 = require( './../lib/snansumkbn2.js' ); @@ -35,7 +34,7 @@ tape( 'main export is a function', function test( t ) { }); tape( 'the function has an arity of 3', function test( t ) { - t.strictEqual( snansumkbn2.length, 3, 'has expected arity' ); + t.strictEqual( snansumkbn2.length, 3, 'returns expected value' ); t.end(); }); @@ -106,7 +105,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -123,15 +121,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, 2 ); + v = snansumkbn2( 5, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -148,8 +144,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, -2 ); + v = snansumkbn2( 5, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -170,7 +165,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -188,9 +182,8 @@ 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); - v = snansumkbn2( N, x1, 2 ); + v = snansumkbn2( 5, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.native.js b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.native.js index 8a55c1f4f2e..d04b0c4fc2d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.native.js +++ b/lib/node_modules/@stdlib/blas/ext/base/snansumkbn2/test/test.snansumkbn2.native.js @@ -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' ); @@ -44,7 +43,7 @@ tape( 'main export is a function', opts, function test( t ) { }); tape( 'the function has an arity of 3', opts, function test( t ) { - t.strictEqual( snansumkbn2.length, 3, 'has expected arity' ); + t.strictEqual( snansumkbn2.length, 3, 'returns expected value' ); t.end(); }); @@ -197,7 +196,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -214,15 +212,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { NaN ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, 2 ); + v = snansumkbn2( 5, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -239,8 +235,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = snansumkbn2( N, x, -2 ); + v = snansumkbn2( 5, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -261,7 +256,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -279,9 +273,8 @@ 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); - v = snansumkbn2( N, x1, 2 ); + v = snansumkbn2( 5, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); From 43e7a3386606e54475e872d24ddf11fa6c122c42 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 12 Oct 2024 13:37:18 -0400 Subject: [PATCH 22/50] chore: minor clean-up after code review --- .../assert/is-same-typed-array-like/README.md | 2 +- .../docs/types/index.d.ts | 2 + .../@stdlib/iter/cunone/README.md | 5 +-- .../@stdlib/stats/base/dists/chi/README.md | 40 +++++++++---------- .../stats/base/dists/chi/examples/index.js | 40 +++++++++---------- .../stats/base/dists/exponential/README.md | 6 +-- .../base/dists/exponential/examples/index.js | 6 +-- .../stats/base/dists/geometric/README.md | 38 +++++++++--------- .../base/dists/geometric/examples/index.js | 38 +++++++++--------- 9 files changed, 87 insertions(+), 90 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/README.md b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/README.md index 187ade975de..b5fc51528ef 100644 --- a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/README.md +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# isSameArrayLike +# isSameTypedArrayLike > Test if two arguments are both typed-array-like objects and have the [same values][@stdlib/assert/is-same-value]. diff --git a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/index.d.ts index 2485bfd39cc..4d439e42331 100644 --- a/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/assert/is-same-typed-array-like/docs/types/index.d.ts @@ -28,6 +28,7 @@ * @example * var Int8Array = require( '@stdlib/array/int8' ); * var Int16Array = require( '@stdlib/array/int16' ); +* * var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); * var y = new Int16Array( [ 1.0, 2.0, 3.0 ] ); * @@ -36,6 +37,7 @@ * * @example * var Int8Array = require( '@stdlib/array/int8' ); +* * var x = new Int8Array( [ 1.0, 2.0, 3.0 ] ); * var y = new Int8Array( [ 1.0, 2.0, 4.0 ] ); * diff --git a/lib/node_modules/@stdlib/iter/cunone/README.md b/lib/node_modules/@stdlib/iter/cunone/README.md index 34bbac5bd3d..0145cb4ca50 100644 --- a/lib/node_modules/@stdlib/iter/cunone/README.md +++ b/lib/node_modules/@stdlib/iter/cunone/README.md @@ -42,8 +42,7 @@ var iterCuNone = require( '@stdlib/iter/cunone' ); #### iterCuNone( iterator ) -Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every -iterated value is falsy. +Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value is falsy. ```javascript var array2iterator = require( '@stdlib/array/to-iterator' ); @@ -115,7 +114,7 @@ var riter = randu( opts ); // Create an iterator which applies a threshold to generated numbers: var miter = iterMap( riter, threshold ); -// Create an iterator which cumulatively tests whether every iterated value is falsy. +// Create an iterator which cumulatively tests whether every iterated value is falsy: var it = iterCuNone( miter ); // Perform manual iteration... diff --git a/lib/node_modules/@stdlib/stats/base/dists/chi/README.md b/lib/node_modules/@stdlib/stats/base/dists/chi/README.md index 15972576c5a..7a194f7eaed 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chi/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/chi/README.md @@ -109,8 +109,10 @@ var filledarrayBy = require( '@stdlib/array/filled-by' ); var variance = require( '@stdlib/stats/base/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var rayleigh = require( '@stdlib/stats/base/dists/rayleigh' ); +var absdiff = require( '@stdlib/math/base/utils/absolute-difference' ); var mean = require( '@stdlib/stats/base/mean' ); var abs = require( '@stdlib/math/base/special/abs' ); +var max = require( '@stdlib/math/base/special/max' ); var chi = require( '@stdlib/stats/base/dists/chi' ); // Define the degrees of freedom parameter: @@ -128,9 +130,9 @@ var chiCDF = chi.cdf.factory( k ); var cdf = filledarrayBy( x.length, 'float64', chiCDF ); // Output the PDF and CDF values: -console.log( 'x values:', x ); -console.log( 'PDF values:', pdf ); -console.log( 'CDF values:', cdf ); +console.log( 'x values: ', x ); +console.log( 'PDF values: ', pdf ); +console.log( 'CDF values: ', cdf ); // Compute statistical properties: var theoreticalMean = chi.mean( k ); @@ -138,10 +140,10 @@ var theoreticalVariance = chi.variance( k ); var theoreticalSkewness = chi.skewness( k ); var theoreticalKurtosis = chi.kurtosis( k ); -console.log( 'Theoretical Mean:', theoreticalMean ); -console.log( 'Theoretical Variance:', theoreticalVariance ); -console.log( 'Skewness:', theoreticalSkewness ); -console.log( 'Kurtosis:', theoreticalKurtosis ); +console.log( 'Theoretical Mean: ', theoreticalMean ); +console.log( 'Theoretical Variance: ', theoreticalVariance ); +console.log( 'Skewness: ', theoreticalSkewness ); +console.log( 'Kurtosis: ', theoreticalKurtosis ); // Generate random samples from the Chi distribution: var rchi = chiRandomFactory( k ); @@ -152,12 +154,12 @@ var samples = filledarrayBy( n, 'float64', rchi ); var sampleMean = mean( n, samples, 1 ); var sampleVariance = variance( n, 1, samples, 1 ); -console.log( 'Sample Mean:', sampleMean ); -console.log( 'Sample Variance:', sampleVariance ); +console.log( 'Sample Mean: ', sampleMean ); +console.log( 'Sample Variance: ', sampleVariance ); // Compare sample statistics to theoretical values: -console.log( 'Difference in Mean:', abs( theoreticalMean - sampleMean ) ); -console.log( 'Difference in Variance:', abs( theoreticalVariance - sampleVariance ) ); +console.log( 'Difference in Mean: ', abs( theoreticalMean - sampleMean ) ); +console.log( 'Difference in Variance: ', abs( theoreticalVariance - sampleVariance ) ); // Demonstrate the relationship with the Rayleigh distribution when k=2: var rayleighPDF = rayleigh.pdf.factory( 1.0 ); @@ -175,17 +177,13 @@ var diffPDF; var diffCDF; var i; for ( i = 0; i < x.length; i++ ) { - diffPDF = abs( pdf[ i ] - rayleighPDFValues[ i ] ); - if ( diffPDF > maxDiffPDF ) { - maxDiffPDF = diffPDF; - } - diffCDF = abs( cdf[ i ] - rayleighCDFValues[ i ] ); - if ( diffCDF > maxDiffCDF ) { - maxDiffCDF = diffCDF; - } + diffPDF = absdiff( pdf[ i ], rayleighPDFValues[ i ] ); + maxDiffPDF = max( maxDiffPDF, diffPDF ); + diffCDF = absdiff( cdf[ i ], rayleighCDFValues[ i ] ); + maxDiffCDF = max( maxDiffCDF, diffCDF ); } -console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF:', maxDiffPDF ); -console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF:', maxDiffCDF ); +console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF: ', maxDiffPDF ); +console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF: ', maxDiffCDF ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js index 6857d460c06..dfb3ad3828e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js @@ -23,8 +23,10 @@ var filledarrayBy = require( '@stdlib/array/filled-by' ); var variance = require( '@stdlib/stats/base/variance' ); var linspace = require( '@stdlib/array/base/linspace' ); var rayleigh = require( '@stdlib/stats/base/dists/rayleigh' ); +var absdiff = require( '@stdlib/math/base/utils/absolute-difference' ); var mean = require( '@stdlib/stats/base/mean' ); var abs = require( '@stdlib/math/base/special/abs' ); +var max = require( '@stdlib/math/base/special/max' ); var chi = require( './../lib' ); // Define the degrees of freedom parameter: @@ -42,9 +44,9 @@ var chiCDF = chi.cdf.factory( k ); var cdf = filledarrayBy( x.length, 'float64', chiCDF ); // Output the PDF and CDF values: -console.log( 'x values:', x ); -console.log( 'PDF values:', pdf ); -console.log( 'CDF values:', cdf ); +console.log( 'x values: ', x ); +console.log( 'PDF values: ', pdf ); +console.log( 'CDF values: ', cdf ); // Compute statistical properties: var theoreticalMean = chi.mean( k ); @@ -52,10 +54,10 @@ var theoreticalVariance = chi.variance( k ); var theoreticalSkewness = chi.skewness( k ); var theoreticalKurtosis = chi.kurtosis( k ); -console.log( 'Theoretical Mean:', theoreticalMean ); -console.log( 'Theoretical Variance:', theoreticalVariance ); -console.log( 'Skewness:', theoreticalSkewness ); -console.log( 'Kurtosis:', theoreticalKurtosis ); +console.log( 'Theoretical Mean: ', theoreticalMean ); +console.log( 'Theoretical Variance: ', theoreticalVariance ); +console.log( 'Skewness: ', theoreticalSkewness ); +console.log( 'Kurtosis: ', theoreticalKurtosis ); // Generate random samples from the Chi distribution: var rchi = chiRandomFactory( k ); @@ -66,12 +68,12 @@ var samples = filledarrayBy( n, 'float64', rchi ); var sampleMean = mean( n, samples, 1 ); var sampleVariance = variance( n, 1, samples, 1 ); -console.log( 'Sample Mean:', sampleMean ); -console.log( 'Sample Variance:', sampleVariance ); +console.log( 'Sample Mean: ', sampleMean ); +console.log( 'Sample Variance: ', sampleVariance ); // Compare sample statistics to theoretical values: -console.log( 'Difference in Mean:', abs( theoreticalMean - sampleMean ) ); -console.log( 'Difference in Variance:', abs( theoreticalVariance - sampleVariance ) ); +console.log( 'Difference in Mean: ', abs( theoreticalMean - sampleMean ) ); +console.log( 'Difference in Variance: ', abs( theoreticalVariance - sampleVariance ) ); // Demonstrate the relationship with the Rayleigh distribution when k=2: var rayleighPDF = rayleigh.pdf.factory( 1.0 ); @@ -89,14 +91,10 @@ var diffPDF; var diffCDF; var i; for ( i = 0; i < x.length; i++ ) { - diffPDF = abs( pdf[ i ] - rayleighPDFValues[ i ] ); - if ( diffPDF > maxDiffPDF ) { - maxDiffPDF = diffPDF; - } - diffCDF = abs( cdf[ i ] - rayleighCDFValues[ i ] ); - if ( diffCDF > maxDiffCDF ) { - maxDiffCDF = diffCDF; - } + diffPDF = absdiff( pdf[ i ], rayleighPDFValues[ i ] ); + maxDiffPDF = max( maxDiffPDF, diffPDF ); + diffCDF = absdiff( cdf[ i ], rayleighCDFValues[ i ] ); + maxDiffCDF = max( maxDiffCDF, diffCDF ); } -console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF:', maxDiffPDF ); -console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF:', maxDiffCDF ); +console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF: ', maxDiffPDF ); +console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF: ', maxDiffCDF ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/exponential/README.md b/lib/node_modules/@stdlib/stats/base/dists/exponential/README.md index 6be2ae17e1f..5161e75cbd4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/exponential/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/exponential/README.md @@ -123,14 +123,14 @@ var interarrivalTimes = randomExponential( numCustomers, lambda, { 'dtype': 'float64' }); -console.log( 'Simulated interarrival times for ' + numCustomers + ' customers:' ); +console.log( 'Simulated interarrival times for ' + numCustomers + ' customers: ' ); console.log( interarrivalTimes ); // Calculate cumulative arrival times by computing the cumulative sum of interarrival times: var arrivalTimes = new Float64Array( interarrivalTimes.length ); dcusum( interarrivalTimes.length, 0.0, interarrivalTimes, 1, arrivalTimes, 1 ); -console.log( '\nCustomer arrival times:' ); +console.log( '\nCustomer arrival times: ' ); console.log( arrivalTimes ); // Probability that a customer arrives within two minutes: @@ -153,7 +153,7 @@ console.log( 'PDF at x = 1: ' + out.toFixed(4) ); // Evaluate the MGF at t = 0.1: out = dist.mgf( 0.1 ); -console.log( 'MGF at t = 0.5: ' + out.toFixed(4) ); +console.log( 'MGF at t = 0.1: ' + out.toFixed(4) ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/exponential/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/exponential/examples/index.js index ed12ae6c03e..1c3e016b1ba 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/exponential/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/exponential/examples/index.js @@ -32,14 +32,14 @@ var interarrivalTimes = randomExponential( numCustomers, lambda, { 'dtype': 'float64' }); -console.log( 'Simulated interarrival times for ' + numCustomers + ' customers:' ); +console.log( 'Simulated interarrival times for ' + numCustomers + ' customers: ' ); console.log( interarrivalTimes ); // Calculate cumulative arrival times by computing the cumulative sum of interarrival times: var arrivalTimes = new Float64Array( interarrivalTimes.length ); dcusum( interarrivalTimes.length, 0.0, interarrivalTimes, 1, arrivalTimes, 1 ); -console.log( '\nCustomer arrival times:' ); +console.log( '\nCustomer arrival times: ' ); console.log( arrivalTimes ); // Probability that a customer arrives within two minutes: @@ -62,4 +62,4 @@ console.log( 'PDF at x = 1: ' + out.toFixed(4) ); // Evaluate the MGF at t = 0.1: out = dist.mgf( 0.1 ); -console.log( 'MGF at t = 0.5: ' + out.toFixed(4) ); +console.log( 'MGF at t = 0.1: ' + out.toFixed(4) ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md b/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md index fd921a584bb..393445cb54f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/geometric/README.md @@ -136,9 +136,9 @@ var geometricCDF = geometric.cdf.factory( p ); var cdf = filledarrayBy( x.length, 'float64', geometricCDF ); // Output the PMF and CDF values: -console.log( 'x values:', x ); -console.log( 'PMF values:', pmf ); -console.log( 'CDF values:', cdf ); +console.log( 'x values: ', x ); +console.log( 'PMF values: ', pmf ); +console.log( 'CDF values: ', cdf ); // Compute statistical properties: var theoreticalMean = geometric.mean( p ); @@ -146,10 +146,10 @@ var theoreticalVariance = geometric.variance( p ); var theoreticalSkewness = geometric.skewness( p ); var theoreticalKurtosis = geometric.kurtosis( p ); -console.log( 'Theoretical Mean:', theoreticalMean ); -console.log( 'Theoretical Variance:', theoreticalVariance ); -console.log( 'Skewness:', theoreticalSkewness ); -console.log( 'Kurtosis:', theoreticalKurtosis ); +console.log( 'Theoretical Mean: ', theoreticalMean ); +console.log( 'Theoretical Variance: ', theoreticalVariance ); +console.log( 'Skewness: ', theoreticalSkewness ); +console.log( 'Kurtosis: ', theoreticalKurtosis ); // Generate random samples from the geometric distribution: var rgeom = geometricRandomFactory( p ); @@ -160,19 +160,19 @@ var samples = filledarrayBy( n, 'float64', rgeom ); var sampleMean = mean( n, samples, 1 ); var sampleVariance = variance( n, 1, samples, 1 ); -console.log( 'Sample Mean:', sampleMean ); -console.log( 'Sample Variance:', sampleVariance ); +console.log( 'Sample Mean: ', sampleMean ); +console.log( 'Sample Variance: ', sampleVariance ); // Demonstrate the memoryless property: var s = 2.0; var t = 3.0; var prob1 = ( 1.0 - geometric.cdf( s + t - 1.0, p ) ) / - ( 1.0 - geometric.cdf( s - 1.0, p )); + ( 1.0 - geometric.cdf( s - 1.0, p ) ); var prob2 = 1.0 - geometric.cdf( t - 1.0, p ); -console.log( 'P(X > s + t | X > s):', prob1 ); -console.log( 'P(X > t):', prob2 ); -console.log( 'Difference:', abs( prob1 - prob2 ) ); +console.log( 'P(X > s + t | X > s): ', prob1 ); +console.log( 'P(X > t): ', prob2 ); +console.log( 'Difference: ', abs( prob1 - prob2 ) ); // Demonstrate that the sum of k independent geometric random variables follows a negative binomial distribution: var k = 5; @@ -194,14 +194,14 @@ var sumSampleVariance = variance( n, 1, sumSamples, 1 ); var nbMean = negativeBinomial.mean( k, p ); var nbVariance = negativeBinomial.variance( k, p ); -console.log( 'Sum Sample Mean:', sumSampleMean ); -console.log( 'Sum Sample Variance:', sumSampleVariance ); -console.log( 'Negative Binomial Mean:', nbMean ); -console.log( 'Negative Binomial Variance:', nbVariance ); +console.log( 'Sum Sample Mean: ', sumSampleMean ); +console.log( 'Sum Sample Variance: ', sumSampleVariance ); +console.log( 'Negative Binomial Mean: ', nbMean ); +console.log( 'Negative Binomial Variance: ', nbVariance ); // Compare sample statistics to theoretical values: -console.log( 'Difference in Mean:', abs( nbMean - sumSampleMean ) ); -console.log( 'Difference in Variance:', abs( nbVariance - sumSampleVariance ) ); +console.log( 'Difference in Mean: ', abs( nbMean - sumSampleMean ) ); +console.log( 'Difference in Variance: ', abs( nbVariance - sumSampleVariance ) ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js index edf38c65b64..ad503990e48 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/geometric/examples/index.js @@ -42,9 +42,9 @@ var geometricCDF = geometric.cdf.factory( p ); var cdf = filledarrayBy( x.length, 'float64', geometricCDF ); // Output the PMF and CDF values: -console.log( 'x values:', x ); -console.log( 'PMF values:', pmf ); -console.log( 'CDF values:', cdf ); +console.log( 'x values: ', x ); +console.log( 'PMF values: ', pmf ); +console.log( 'CDF values: ', cdf ); // Compute statistical properties: var theoreticalMean = geometric.mean( p ); @@ -52,10 +52,10 @@ var theoreticalVariance = geometric.variance( p ); var theoreticalSkewness = geometric.skewness( p ); var theoreticalKurtosis = geometric.kurtosis( p ); -console.log( 'Theoretical Mean:', theoreticalMean ); -console.log( 'Theoretical Variance:', theoreticalVariance ); -console.log( 'Skewness:', theoreticalSkewness ); -console.log( 'Kurtosis:', theoreticalKurtosis ); +console.log( 'Theoretical Mean: ', theoreticalMean ); +console.log( 'Theoretical Variance: ', theoreticalVariance ); +console.log( 'Skewness: ', theoreticalSkewness ); +console.log( 'Kurtosis: ', theoreticalKurtosis ); // Generate random samples from the geometric distribution: var rgeom = geometricRandomFactory( p ); @@ -66,19 +66,19 @@ var samples = filledarrayBy( n, 'float64', rgeom ); var sampleMean = mean( n, samples, 1 ); var sampleVariance = variance( n, 1, samples, 1 ); -console.log( 'Sample Mean:', sampleMean ); -console.log( 'Sample Variance:', sampleVariance ); +console.log( 'Sample Mean: ', sampleMean ); +console.log( 'Sample Variance: ', sampleVariance ); // Demonstrate the memoryless property: var s = 2.0; var t = 3.0; var prob1 = ( 1.0 - geometric.cdf( s + t - 1.0, p ) ) / - ( 1.0 - geometric.cdf( s - 1.0, p )); + ( 1.0 - geometric.cdf( s - 1.0, p ) ); var prob2 = 1.0 - geometric.cdf( t - 1.0, p ); -console.log( 'P(X > s + t | X > s):', prob1 ); -console.log( 'P(X > t):', prob2 ); -console.log( 'Difference:', abs( prob1 - prob2 ) ); +console.log( 'P(X > s + t | X > s): ', prob1 ); +console.log( 'P(X > t): ', prob2 ); +console.log( 'Difference: ', abs( prob1 - prob2 ) ); // Demonstrate that the sum of k independent geometric random variables follows a negative binomial distribution: var k = 5; @@ -100,11 +100,11 @@ var sumSampleVariance = variance( n, 1, sumSamples, 1 ); var nbMean = negativeBinomial.mean( k, p ); var nbVariance = negativeBinomial.variance( k, p ); -console.log( 'Sum Sample Mean:', sumSampleMean ); -console.log( 'Sum Sample Variance:', sumSampleVariance ); -console.log( 'Negative Binomial Mean:', nbMean ); -console.log( 'Negative Binomial Variance:', nbVariance ); +console.log( 'Sum Sample Mean: ', sumSampleMean ); +console.log( 'Sum Sample Variance: ', sumSampleVariance ); +console.log( 'Negative Binomial Mean: ', nbMean ); +console.log( 'Negative Binomial Variance: ', nbVariance ); // Compare sample statistics to theoretical values: -console.log( 'Difference in Mean:', abs( nbMean - sumSampleMean ) ); -console.log( 'Difference in Variance:', abs( nbVariance - sumSampleVariance ) ); +console.log( 'Difference in Mean: ', abs( nbMean - sumSampleMean ) ); +console.log( 'Difference in Variance: ', abs( nbVariance - sumSampleVariance ) ); From c0a5dbe868b88f8bcf770e128833d5768c041919 Mon Sep 17 00:00:00 2001 From: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com> Date: Sat, 12 Oct 2024 23:12:13 +0530 Subject: [PATCH 23/50] test: achieve complete code coverage in `blas/base/dznrm2` and `blas/base/scnrm2` PR-URL: https://github.com/stdlib-js/stdlib/pull/2977 Closes: https://github.com/stdlib-js/stdlib/issues/2543 Reviewed-by: Philipp Burckhardt Reviewed-by: Athan Reines --- .../blas/base/dznrm2/test/test.ndarray.js | 80 +++++++++++++++++++ .../blas/base/scnrm2/test/test.ndarray.js | 80 +++++++++++++++++++ 2 files changed, 160 insertions(+) diff --git a/lib/node_modules/@stdlib/blas/base/dznrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dznrm2/test/test.ndarray.js index d1b7b4acd2c..2657e8fc721 100644 --- a/lib/node_modules/@stdlib/blas/base/dznrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/dznrm2/test/test.ndarray.js @@ -105,6 +105,86 @@ tape( 'the function computes the L2-norm', function test( t ) { actual = dznrm2( 3, zx, 1, 0 ); isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + zx = new Complex128Array([ + 1e150, // 1 + 1e150, // 1 + 1e150, // 2 + 1e150, // 2 + 1e150, // 3 + 1e150, // 3 + 1e150, // 4 + 1e150 // 4 + ]); + expected = 2.82842e+150; + + actual = dznrm2( 4, zx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + zx = new Complex128Array([ + 1e-155, // 1 + 1e-155, // 1 + 1e-155, // 2 + 1e-155, // 2 + 1e-155, // 3 + 1e-155, // 3 + 1e-155, // 4 + 1e-155 // 4 + ]); + expected = 2.82843e-155; + + actual = dznrm2( 4, zx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + zx = new Complex128Array([ + 1e150, // 1 + 1e50, // 1 + 1e150, // 2 + 1e50, // 2 + 1e150, // 3 + 1e50, // 3 + 1e150, // 4 + 1e50 // 4 + ]); + expected = 2.00000e150; + + actual = dznrm2( 4, zx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + zx = new Complex128Array([ + 1e-155, // 1 + 1e50, // 1 + 1e-155, // 2 + 1e50, // 2 + 1e-155, // 3 + 1e50, // 3 + 1e-155, // 4 + 1e50 // 4 + ]); + expected = 2.00000e50; + + actual = dznrm2( 4, zx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + zx = new Complex128Array([ + 1.4e-154, // 1 + 1.5e-154, // 1 + 1.4e-154, // 2 + 1.5e-154, // 2 + 1.4e-154, // 3 + 0, // 3 + 1.4e-154, // 4 + 0 // 4 + ]); + expected = 3.51283e-154; + + actual = dznrm2( 4, zx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js index 212ba463817..d864d9b3e8d 100644 --- a/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/scnrm2/test/test.ndarray.js @@ -105,6 +105,86 @@ tape( 'the function computes the L2-norm', function test( t ) { actual = scnrm2( 3, cx, 1, 0 ); isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + cx = new Complex64Array([ + 5e+15, // 1 + 5e+15, // 1 + 5e+15, // 2 + 5e+15, // 2 + 5e+15, // 3 + 5e+15, // 3 + 5e+15, // 4 + 5e+15 // 4 + ]); + expected = 14142135623730952; + + actual = scnrm2( 4, cx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + cx = new Complex64Array([ + 1e-20, // 1 + 1e-20, // 1 + 1e-20, // 2 + 1e-20, // 2 + 1e-20, // 3 + 1e-20, // 3 + 1e-20, // 4 + 1e-20 // 4 + ]); + expected = 2.82843e-20; + + actual = scnrm2( 4, cx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + cx = new Complex64Array([ + 1e20, // 1 + 1e10, // 1 + 1e20, // 2 + 1e10, // 2 + 1e20, // 3 + 1e10, // 3 + 1e20, // 4 + 1e10 // 4 + ]); + expected = 200000000000000000000; + + actual = scnrm2( 4, cx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + cx = new Complex64Array([ + 1e-20, // 1 + 1e10, // 1 + 1e-20, // 2 + 1e10, // 2 + 1e-20, // 3 + 1e10, // 3 + 1e-20, // 4 + 1e10 // 4 + ]); + expected = 20000000000; + + actual = scnrm2( 4, cx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); + + // Checked on Wolfram Alpha: + cx = new Complex64Array([ + 1e-19, // 1 + 1.08420217e-19, // 1 + 1e-19, // 2 + 1.08420217e-19, // 2 + 1e-19, // 3 + 0, // 3 + 1e-19, // 4 + 0 // 4 + ]); + expected = 2.52012e-19; + + actual = scnrm2( 4, cx, 1, 0 ); + isApprox( t, actual, expected, 2.0 ); t.end(); }); From 0c4f6564dbf72e0f029b3337879251c123e97209 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sun, 13 Oct 2024 07:57:04 -0700 Subject: [PATCH 24/50] chore: fix indentation PR-URL: #3003 Signed-off-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Reviewed-by: Philipp Burckhardt --- .../@stdlib/iter/cusome-by/package.json | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/iter/cusome-by/package.json b/lib/node_modules/@stdlib/iter/cusome-by/package.json index baddd3c9508..656f1e22ad4 100644 --- a/lib/node_modules/@stdlib/iter/cusome-by/package.json +++ b/lib/node_modules/@stdlib/iter/cusome-by/package.json @@ -50,24 +50,24 @@ ], "keywords": [ "stdlib", - "stdutils", - "stdutil", - "utilities", - "utility", - "utils", - "util", - "test", - "some", - "any", - "every", - "all", - "iterate", - "iterator", - "iter", - "validate", - "predicate", - "cumulative", - "cusome", - "transform" + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "test", + "some", + "any", + "every", + "all", + "iterate", + "iterator", + "iter", + "validate", + "predicate", + "cumulative", + "cusome", + "transform" ] } From e5b993a1b314d478be07dabc12a7b349872e4427 Mon Sep 17 00:00:00 2001 From: Kohantika Nath <145763549+kohantikanath@users.noreply.github.com> Date: Mon, 14 Oct 2024 02:36:01 +0530 Subject: [PATCH 25/50] docs: improve README examples of `stats/base/dists/cosine` namespace PR-URL: https://github.com/stdlib-js/stdlib/pull/2669 Closes: https://github.com/stdlib-js/stdlib/issues/1620 Co-authored-by: Kohantika Nath Co-authored-by: Philipp Burckhardt Reviewed-by: Philipp Burckhardt --- .../@stdlib/stats/base/dists/cosine/README.md | 38 ++++++++++++++++++- .../stats/base/dists/cosine/examples/index.js | 38 ++++++++++++++++++- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md b/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md index 0c3bbd1c508..279e9a5b9e7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md @@ -108,10 +108,44 @@ var y = dist.cdf( 0.5 ); ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); var cosine = require( '@stdlib/stats/base/dists/cosine' ); -console.log( objectKeys( cosine ) ); +// Create a raised cosine distribution: +var mu = 2.0; +var s = 1.5; +var dist = new cosine.Cosine( mu, s ); + +// Calculate various distribution properties: +console.log( 'Mean: %d', dist.mean ); +// => 'Mean: 2' + +console.log( 'Median: %d', dist.median ); +// => 'Median: 2' + +console.log( 'Mode: %d', dist.mode ); +// => 'Mode: 2' + +console.log( 'Standard Deviation: %d', dist.stdev ); +// => 'Standard Deviation: 0.5422680827869919' + +console.log( 'Variance: %d', dist.variance ); +// => 'Variance: 0.29405467360947996' + +// Evaluate the probability density function (PDF): +var x = 1.5; +console.log( 'PDF( %d ): %d', x, dist.pdf( x ) ); +// => 'PDF( 1.5 ): 0.5' + +// Evaluate the cumulative distribution function (CDF): +console.log( 'CDF( %d ): %d', x, dist.cdf( x ) ); +// => 'CDF( 1.5 ): 0.19550110947788535' + +// Calculate distribution moments: +console.log( 'Skewness: %d', cosine.skewness( mu, s ) ); +// => 'Skewness: 0' + +console.log( 'Excess Kurtosis: %d', cosine.kurtosis( mu, s ) ); +// => 'Excess Kurtosis: -0.5937628755982807' ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/cosine/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/cosine/examples/index.js index 28c2d1289c3..a6fc9e9d6ab 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/cosine/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/cosine/examples/index.js @@ -18,7 +18,41 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); var cosine = require( './../lib' ); -console.log( objectKeys( cosine ) ); +// Create a raised cosine distribution: +var mu = 2.0; +var s = 1.5; +var dist = new cosine.Cosine( mu, s ); + +// Calculate various distribution properties: +console.log( 'Mean: %d', dist.mean ); +// => 'Mean: 2' + +console.log( 'Median: %d', dist.median ); +// => 'Median: 2' + +console.log( 'Mode: %d', dist.mode ); +// => 'Mode: 2' + +console.log( 'Standard Deviation: %d', dist.stdev ); +// => 'Standard Deviation: 0.5422680827869919' + +console.log( 'Variance: %d', dist.variance ); +// => 'Variance: 0.29405467360947996' + +// Evaluate the probability density function (PDF): +var x = 1.5; +console.log( 'PDF( %d ): %d', x, dist.pdf( x ) ); +// => 'PDF( 1.5 ): 0.5' + +// Evaluate the cumulative distribution function (CDF): +console.log( 'CDF( %d ): %d', x, dist.cdf( x ) ); +// => 'CDF( 1.5 ): 0.19550110947788535' + +// Calculate distribution moments: +console.log( 'Skewness: %d', cosine.skewness( mu, s ) ); +// => 'Skewness: 0' + +console.log( 'Excess Kurtosis: %d', cosine.kurtosis( mu, s ) ); +// => 'Excess Kurtosis: -0.5937628755982807' From b74a08ae1dfc859ac8b9704af27e3c3399ad2da5 Mon Sep 17 00:00:00 2001 From: Prajwal Kulkarni Date: Mon, 14 Oct 2024 07:39:56 +0530 Subject: [PATCH 26/50] feat!: improve type declarations for `utils/map-arguments` This change significantly improves the type definition of the mapArguments function, transitioning from broad 'Function' types to specific, generic types and implementing conditional this context based on thisArg presence. BREAKING CHANGE: function signature and return type now more strictly typed The mapArguments function now uses generic types instead of 'Function', and its return type depends on thisArg presence. Users should review and update their usage of mapArguments, particularly: - Ensure provided functions match the new, stricter type requirements - Update any type assertions or checks where mapArguments is used - Pay special attention to contexts where this binding is significant PR-URL: https://github.com/stdlib-js/stdlib/pull/2050 Closes: https://github.com/stdlib-js/stdlib/issues/1087 Co-authored-by: Philipp Burckhardt Co-authored-by: Prajwal Kulkarni Reviewed-by: Philipp Burckhardt --- .../utils/map-arguments/docs/types/index.d.ts | 52 ++++++++++++++++++- .../utils/map-arguments/docs/types/test.ts | 32 ++++++++---- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/map-arguments/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/map-arguments/docs/types/index.d.ts index 8a7e22b54ab..85cfda99b29 100644 --- a/lib/node_modules/@stdlib/utils/map-arguments/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/map-arguments/docs/types/index.d.ts @@ -47,7 +47,57 @@ * var out = bar( 1, 2, 3 ); * // returns [ 2, 4, 6 ] */ -declare function mapArguments( fcn: Function, clbk: Function, thisArg?: any ): Function; +declare function mapArguments< + T extends ( ...args: Array ) => any, + C extends ( this: ThisParameterType, value: Parameters[number], index: number ) => any +>( + fcn: T, + clbk: C +): ( ...args: Parameters ) => ReturnType; + +/** +* Returns a function that applies arguments to a provided function after transforming arguments according to a callback function. +* +* ## Notes +* +* - The callback function is provided the following arguments: +* +* - **value**: argument value. +* - **index**: argument index. +* +* @param fcn - input function +* @param clbk - callback function +* @param thisArg - input function context +* @returns function wrapper +* +* @example +* function foo( a, b, c ) { +* return [ a, b, c ]; +* } +* +* function clbk( v ) { +* this.count += 1; +* return v * 2; +* } +* +* var thisArg = { 'count': 0 }; +* var bar = mapArguments( foo, clbk, thisArg ); +* +* var out = bar( 1, 2, 3 ); +* // returns [ 2, 4, 6 ] +* +* var count = thisArg.count; +* // returns 3 +*/ +declare function mapArguments< + T extends ( ...args: Array ) => any, + C extends ( this: ThisParameterType, value: Parameters[number], index: number ) => any, + ThisArg +>( + fcn: T, + clbk: C, + thisArg: ThisArg +): ( this: ThisArg, ...args: Parameters ) => ReturnType; // EXPORTS // diff --git a/lib/node_modules/@stdlib/utils/map-arguments/docs/types/test.ts b/lib/node_modules/@stdlib/utils/map-arguments/docs/types/test.ts index 12a72a6f1b1..f18a5cb7599 100644 --- a/lib/node_modules/@stdlib/utils/map-arguments/docs/types/test.ts +++ b/lib/node_modules/@stdlib/utils/map-arguments/docs/types/test.ts @@ -18,23 +18,37 @@ import mapArguments = require( './index' ); -/** -* Callback function. -* -* @param v - argument -* @returns result -*/ -function clbk( v: any ): any { +// FUNCTIONS // + +function clbk( v: T ): T { return v; } +function stringify( n: number ): string { + return n.toString(); +} + +function sum( ...numbers: Array ): number { + return numbers.reduce( ( a, b ) => a + b, 0 ); +} + +function greet( this: { name: string }, greeting: string ): string { + return `${greeting}, ${this.name}!`; // eslint-disable-line no-invalid-this +} + // TESTS // // The function returns a function... { - mapArguments( ( x: any, y: any, z: any ): Array => [ x, y, z ], clbk ); // $ExpectType Function - mapArguments( ( x: any, y: any, z: any ): Array => [ x, y, z ], clbk, {} ); // $ExpectType Function + mapArguments( ( x: number, y: number, z: number ): Array => [ x, y, z ], clbk ); // $ExpectType (x: number, y: number, z: number) => number[] + mapArguments( ( x: string, y: string, z: string ): Array => [ x, y, z ], clbk, {} ); // $ExpectType (this: {}, x: string, y: string, z: string) => string[] + mapArguments( ( x: number, y: number ): number => x + y, clbk ); // $ExpectType (x: number, y: number) => number + + mapArguments( stringify, ( x: number ) => x * 2 ); // $ExpectType (n: number) => string + mapArguments( sum, ( x: number ) => x * 2 ); // $ExpectType (...args: number[]) => number + + mapArguments( greet, ( s: string ) => s.toUpperCase(), { 'name': 'World' } ); // $ExpectType (this: { name: string; }, greeting: string) => string } // The compiler throws an error if the function is provided a first argument other than a function... From 3282bd009f0ab7539ab7f2ea5e671add106fa1c2 Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sun, 13 Oct 2024 19:52:25 -0700 Subject: [PATCH 27/50] docs: update list of contributors PR-URL: #3006 Signed-off-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Reviewed-by: Philipp Burckhardt --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index f1b00f3f813..9b6e69d177d 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -45,6 +45,7 @@ Justin Dennison Kaif Mohd Karthik Prakash <116057817+skoriop@users.noreply.github.com> Khaldon +Kohantika Nath <145763549+kohantikanath@users.noreply.github.com> Krishnendu Das <86651039+itskdhere@users.noreply.github.com> Lovelin <100030865+lovelindhoni@users.noreply.github.com> Manik Sharma From 03a4ad79edbde3654b67e84a4f8d19ad0f670003 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 14 Oct 2024 22:34:57 +0200 Subject: [PATCH 28/50] style: fix spacing --- lib/node_modules/@stdlib/math/base/special/log/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/log/src/main.c b/lib/node_modules/@stdlib/math/base/special/log/src/main.c index 8ec3fb31943..092be90fea6 100644 --- a/lib/node_modules/@stdlib/math/base/special/log/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/log/src/main.c @@ -31,5 +31,5 @@ * // returns 2.0 */ double stdlib_base_log( const double x, const double b ) { - return stdlib_base_ln ( x ) / stdlib_base_ln ( b ); + return stdlib_base_ln( x ) / stdlib_base_ln( b ); } From d71493e2f9ec53c9b7168ae0baf81731ebf15a9d Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 15 Oct 2024 10:57:55 +0200 Subject: [PATCH 29/50] build: add WebAssembly configuration --- .../math/base/special/floor/manifest.json | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/floor/manifest.json b/lib/node_modules/@stdlib/math/base/special/floor/manifest.json index 5d84b9cad1c..2de89c6ed63 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/floor/manifest.json @@ -1,6 +1,7 @@ { "options": { - "task": "build" + "task": "build", + "wasm": false }, "fields": [ { @@ -27,6 +28,7 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ "./src/floor.c" ], @@ -43,6 +45,7 @@ }, { "task": "benchmark", + "wasm": false, "src": [ "./src/floor.c" ], @@ -57,6 +60,7 @@ }, { "task": "examples", + "wasm": false, "src": [ "./src/floor.c" ], @@ -68,6 +72,21 @@ ], "libpath": [], "dependencies": [] - } + }, + { + "task": "build", + "wasm": true, + "src": [ + "./src/floor.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [] + } ] } From 2ce25ea8e857700287558847d93b108f3ca6b33d Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 15 Oct 2024 10:58:31 +0200 Subject: [PATCH 30/50] build: add WebAssembly configuration --- .../math/base/special/round/manifest.json | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/round/manifest.json b/lib/node_modules/@stdlib/math/base/special/round/manifest.json index fba97891a97..d52c3d1ec2b 100644 --- a/lib/node_modules/@stdlib/math/base/special/round/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/round/manifest.json @@ -1,6 +1,7 @@ { "options": { - "task": "build" + "task": "build", + "wasm": false }, "fields": [ { @@ -27,6 +28,7 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ "./src/main.c" ], @@ -44,6 +46,7 @@ }, { "task": "benchmark", + "wasm": false, "src": [ "./src/main.c" ], @@ -60,6 +63,24 @@ }, { "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/special/floor", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/assert/is-negative-zero" + ] + }, + { + "task": "build", + "wasm": true, "src": [ "./src/main.c" ], From 870f64561a7d90579bd92920c8733a205ed0a55c Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 15 Oct 2024 10:58:47 +0200 Subject: [PATCH 31/50] build: add WebAssembly configuration --- .../math/base/special/exp2/manifest.json | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/exp2/manifest.json b/lib/node_modules/@stdlib/math/base/special/exp2/manifest.json index 231455d84a5..a2adffecfdb 100644 --- a/lib/node_modules/@stdlib/math/base/special/exp2/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/exp2/manifest.json @@ -1,6 +1,7 @@ { "options": { - "task": "build" + "task": "build", + "wasm": false }, "fields": [ { @@ -27,6 +28,7 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ "./src/main.c" ], @@ -47,6 +49,7 @@ }, { "task": "benchmark", + "wasm": false, "src": [ "./src/main.c" ], @@ -66,6 +69,27 @@ }, { "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/constants/float64/max-base2-exponent", + "@stdlib/constants/float64/pinf", + "@stdlib/math/base/special/round", + "@stdlib/math/base/special/ldexp", + "@stdlib/constants/float64/min-base2-exponent" + ] + }, + { + "task": "build", + "wasm": true, "src": [ "./src/main.c" ], From 6c58a22b6f7e514fb358c3256b9573357e4baa65 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 15 Oct 2024 10:59:08 +0200 Subject: [PATCH 32/50] bench: refactor benchmarks --- .../@stdlib/math/base/special/erf/benchmark/c/benchmark.c | 8 +++++--- .../math/base/special/erf/benchmark/c/cephes/benchmark.c | 8 +++++--- .../math/base/special/erf/benchmark/c/native/benchmark.c | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/benchmark.c index 594df4612ec..be466a68258 100644 --- a/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/benchmark.c @@ -89,16 +89,18 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double values[ 10 ]; double elapsed; - double x; double y; double t; int i; + for ( i = 0; i < 10; i++ ) { + values[ i ] = ( 2.0*rand_double() ) - 1.0; + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 2.0*rand_double() ) - 1.0; - y = erf( x ); + y = erf( values[ i%10 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/cephes/benchmark.c index dc7e719ed8d..8b384e80285 100644 --- a/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/cephes/benchmark.c @@ -94,16 +94,18 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double values[ 10 ]; double elapsed; - double x; double y; double t; int i; + for ( i = 0; i < 10; i++ ) { + values[ i ] = ( 2.0*rand_double() ) - 1.0; + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 2.0*rand_double() ) - 1.0; - y = erf( x ); + y = erf( values[ i%10 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/native/benchmark.c index 9c0029ca465..beda7fc2bc1 100644 --- a/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/erf/benchmark/c/native/benchmark.c @@ -90,16 +90,18 @@ static double rand_double( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { + double values[ 10 ]; double elapsed; - double x; double y; double t; int i; + for ( i = 0; i < 10; i++ ) { + values[ i ] = ( 2.0*rand_double() ) - 1.0; + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 2.0*rand_double() ) - 1.0; - y = stdlib_base_erf( x ); + y = stdlib_base_erf( values[ i%10 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; From 33494b7c0d3bba12b17fc6f0b6990cdadc9c04aa Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 15 Oct 2024 11:11:23 +0200 Subject: [PATCH 33/50] build: add WebAssembly configuration --- .../math/base/special/ln/manifest.json | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/ln/manifest.json b/lib/node_modules/@stdlib/math/base/special/ln/manifest.json index 668bf4bb60c..dcc9a2c1a87 100644 --- a/lib/node_modules/@stdlib/math/base/special/ln/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/ln/manifest.json @@ -1,6 +1,7 @@ { "options": { - "task": "build" + "task": "build", + "wasm": false }, "fields": [ { @@ -27,6 +28,7 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ "./src/main.c" ], @@ -46,6 +48,7 @@ }, { "task": "benchmark", + "wasm": false, "src": [ "./src/main.c" ], @@ -64,6 +67,26 @@ }, { "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/number/float64/base/get-high-word", + "@stdlib/number/float64/base/set-high-word", + "@stdlib/math/base/assert/is-nan", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/exponent-bias" + ] + }, + { + "task": "build", + "wasm": true, "src": [ "./src/main.c" ], From 2b30eb7d91ebcad9919546040198fad15c54b2b8 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 15 Oct 2024 11:47:02 +0200 Subject: [PATCH 34/50] bench: refactor C benchmarks --- .../math/base/special/exp2/benchmark/c/benchmark.c | 8 +++++--- .../math/base/special/exp2/benchmark/c/cephes/benchmark.c | 8 +++++--- .../math/base/special/exp2/benchmark/c/native/benchmark.c | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/benchmark.c index f947193145e..c4228156179 100644 --- a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/benchmark.c @@ -90,15 +90,17 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 10 ]; double y; double t; int i; + for ( i = 0; i < 10; i++ ) { + x[ i ] = ( 2044.0 * rand_double() ) - 1022.0; + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 2044.0*rand_double() ) - 1022.0; - y = exp2( x ); + y = exp2( x[ i%10 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/cephes/benchmark.c index 15a21e7b499..46e978141b2 100644 --- a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/cephes/benchmark.c @@ -95,15 +95,17 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 10 ]; double y; double t; int i; + for ( i = 0; i < 10; i++ ) { + x[ i ] = ( 2044.0 * rand_double() ) - 1022.0; + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 2044.0*rand_double() ) - 1022.0; - y = exp2( x ); + y = exp2( x[ i%10 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/native/benchmark.c index 2af497d9f52..dacc50fa22e 100644 --- a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/c/native/benchmark.c @@ -91,15 +91,17 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 10 ]; double y; double t; int i; + for ( i = 0; i < 10; i++ ) { + x[ i ] = ( 2044.0 * rand_double() ) - 1022.0; + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 2044.0 * rand_double() ) - 1022.0; - y = stdlib_base_exp2( x ); + y = stdlib_base_exp2( x[ i%10 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; From 923a3553d58b3dac76c22d895bf0bf7c7c3bc75e Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 15 Oct 2024 11:49:56 +0200 Subject: [PATCH 35/50] bench: refactor C benchmarks --- .../@stdlib/math/base/special/ln/benchmark/c/benchmark.c | 8 +++++--- .../math/base/special/ln/benchmark/c/cephes/benchmark.c | 8 +++++--- .../math/base/special/ln/benchmark/c/native/benchmark.c | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/benchmark.c index 0037cee728a..ea654772415 100644 --- a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/benchmark.c @@ -90,15 +90,17 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 10 ]; double y; double t; int i; + for ( i = 0; i < 10; i++ ) { + x[ i ] = ( 10000.0*rand_double() ) - 0.0; + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 10000.0*rand_double() ) - 0.0; - y = log( x ); + y = log( x[ i%10 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/cephes/benchmark.c b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/cephes/benchmark.c index 31049cf759b..152f2c585b1 100644 --- a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/cephes/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/cephes/benchmark.c @@ -95,15 +95,17 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 10 ]; double y; double t; int i; + for ( i = 0; i < 10; i++ ) { + x[ i ] = ( 10000.0*rand_double() ) - 0.0; + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 10000.0*rand_double() ) - 0.0; - y = log( x ); + y = log( x[ i%10 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/native/benchmark.c index 2976f68c898..62cff627fac 100644 --- a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/c/native/benchmark.c @@ -91,15 +91,17 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 10 ]; double y; double t; int i; + for ( i = 0; i < 10; i++ ) { + x[ i ] = ( 10000.0*rand_double() ) - 0.0; + } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 10000.0*rand_double() ) - 0.0; - y = stdlib_base_ln( x ); + y = stdlib_base_ln( x[ i%10 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; From c6fe24f012b118f30347d075ce52169c8423fbf5 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 15 Oct 2024 11:52:54 +0200 Subject: [PATCH 36/50] bench: refactor benchmarks --- .../math/base/special/exp2/benchmark/benchmark.js | 9 ++++++--- .../math/base/special/exp2/benchmark/benchmark.native.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/benchmark.js index 5305b6d1a2a..e904f823ab0 100644 --- a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var exp2 = require( './../lib' ); @@ -34,10 +34,13 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 10, -1022.0, 1022.0, { + 'dtype': 'generic' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*2044.0 ) - 1022.0; - y = exp2( x ); + y = exp2( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/benchmark.native.js index 04501101c8a..523019b6f78 100644 --- a/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/exp2/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 10, -1022.0, 1022.0, { + 'dtype': 'generic' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu() * 2044.0 ) - 1022.0; - y = exp2( x ); + y = exp2( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } From 325ca074aa79d05fc6aa551d035d600b7bb66f2e Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Tue, 15 Oct 2024 11:56:43 +0200 Subject: [PATCH 37/50] bench: refactor benchmarks --- .../math/base/special/ln/benchmark/benchmark.js | 16 +++++++++++----- .../special/ln/benchmark/benchmark.native.js | 9 ++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/benchmark.js index 1788cb22d12..335d0a63e83 100644 --- a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/benchmark.js @@ -21,7 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var ln = require( './../lib' ); @@ -34,10 +34,13 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = uniform( 10, 0.0, 10000.0, { + 'dtype': 'generic' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*10000.0 ) - 0.0; - y = ln( x ); + y = ln( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } @@ -55,10 +58,13 @@ bench( pkg+'::built-in', function benchmark( b ) { var y; var i; + x = uniform( 10, 0.0, 10000.0, { + 'dtype': 'generic' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*10000.0 ) - 0.0; - y = Math.log( x ); // eslint-disable-line stdlib/no-builtin-math + y = Math.log( x[ i%x.length ] ); // eslint-disable-line stdlib/no-builtin-math if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/benchmark.native.js index 324b8371a0a..7f1f81df675 100644 --- a/lib/node_modules/@stdlib/math/base/special/ln/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/ln/benchmark/benchmark.native.js @@ -22,7 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -43,10 +43,13 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = uniform( 10, 0.0, 10000.0, { + 'dtype': 'generic' + }); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = ( randu()*10000.0 ) - 0.0; - y = ln( x ); + y = ln( x[ i%x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } From 1dbc4400622b58ad2a2ad73d3ebd2c4e5703a0e6 Mon Sep 17 00:00:00 2001 From: Gunj Joshi Date: Tue, 15 Oct 2024 21:36:46 +0530 Subject: [PATCH 38/50] feat: add `constants/float32/half-ln-two` PR-URL: https://github.com/stdlib-js/stdlib/pull/3010 Ref: https://github.com/stdlib-js/stdlib/issues/649 Reviewed-by: Philipp Burckhardt --- .../constants/float32/half-ln-two/README.md | 139 ++++++++++++++++++ .../float32/half-ln-two/docs/repl.txt | 13 ++ .../float32/half-ln-two/docs/types/index.d.ts | 33 +++++ .../float32/half-ln-two/docs/types/test.ts | 28 ++++ .../float32/half-ln-two/examples/index.js | 24 +++ .../stdlib/constants/float32/half_ln_two.h | 27 ++++ .../float32/half-ln-two/lib/index.js | 50 +++++++ .../float32/half-ln-two/manifest.json | 36 +++++ .../float32/half-ln-two/package.json | 71 +++++++++ .../float32/half-ln-two/test/test.js | 56 +++++++ 10 files changed, 477 insertions(+) create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/README.md create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/examples/index.js create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/include/stdlib/constants/float32/half_ln_two.h create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/lib/index.js create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/manifest.json create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/package.json create mode 100644 lib/node_modules/@stdlib/constants/float32/half-ln-two/test/test.js diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/README.md b/lib/node_modules/@stdlib/constants/float32/half-ln-two/README.md new file mode 100644 index 00000000000..da0b2675a26 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/README.md @@ -0,0 +1,139 @@ + + +# FLOAT32_HALF_LN2 + +> One half times the [natural logarithm][@stdlib/math/base/special/ln] of `2` as a single-precision floating-point number. + +
+ +## Usage + +```javascript +var FLOAT32_HALF_LN2 = require( '@stdlib/constants/float32/half-ln-two' ); +``` + +#### FLOAT32_HALF_LN2 + +One half times the [natural logarithm][@stdlib/math/base/special/ln] of `2` as a single-precision floating-point number. + +```javascript +var bool = ( FLOAT32_HALF_LN2 === 0.3465735912322998 ); +// returns true +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var FLOAT32_HALF_LN2 = require( '@stdlib/constants/float32/half-ln-two' ); + +console.log( FLOAT32_HALF_LN2 ); +// => 0.3465735912322998 +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/constants/float32/half_ln_two.h" +``` + +#### STDLIB_CONSTANT_FLOAT32_HALF_LN2 + +Macro for one half times the [natural logarithm][@stdlib/math/base/special/ln] of `2` as a single-precision floating-point number. + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/repl.txt b/lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/repl.txt new file mode 100644 index 00000000000..62f3ee71087 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/repl.txt @@ -0,0 +1,13 @@ + +{{alias}} + One half times the natural logarithm of 2 as a single-precision + floating-point number. + + Examples + -------- + > {{alias}} + 0.3465735912322998 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/types/index.d.ts b/lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/types/index.d.ts new file mode 100644 index 00000000000..82e7c2f8430 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/types/index.d.ts @@ -0,0 +1,33 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/** +* One half times the natural logarithm of 2 as a single-precision floating-point number. +* +* @example +* var val = FLOAT32_HALF_LN2; +* // returns 0.3465735912322998 +*/ +declare const FLOAT32_HALF_LN2: number; + + +// EXPORTS // + +export = FLOAT32_HALF_LN2; diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/types/test.ts b/lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/types/test.ts new file mode 100644 index 00000000000..15eb5399bc2 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/docs/types/test.ts @@ -0,0 +1,28 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +import FLOAT32_HALF_LN2 = require( './index' ); + + +// TESTS // + +// The export is a number... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + FLOAT32_HALF_LN2; // $ExpectType number +} diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/examples/index.js b/lib/node_modules/@stdlib/constants/float32/half-ln-two/examples/index.js new file mode 100644 index 00000000000..b1aa4667eba --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/examples/index.js @@ -0,0 +1,24 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var FLOAT32_HALF_LN2 = require( './../lib' ); + +console.log( FLOAT32_HALF_LN2 ); +// => 0.3465735912322998 diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/include/stdlib/constants/float32/half_ln_two.h b/lib/node_modules/@stdlib/constants/float32/half-ln-two/include/stdlib/constants/float32/half_ln_two.h new file mode 100644 index 00000000000..e98ad8096da --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/include/stdlib/constants/float32/half_ln_two.h @@ -0,0 +1,27 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +#ifndef STDLIB_CONSTANTS_FLOAT32_HALF_LN_TWO_H +#define STDLIB_CONSTANTS_FLOAT32_HALF_LN_TWO_H + +/** +* Macro for one half times the natural logarithm of 2 as a single-precision floating-point number. +*/ +#define STDLIB_CONSTANT_FLOAT32_HALF_LN_TWO 0.3465735912322998 + +#endif // !STDLIB_CONSTANTS_FLOAT32_HALF_LN_TWO_H diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/lib/index.js b/lib/node_modules/@stdlib/constants/float32/half-ln-two/lib/index.js new file mode 100644 index 00000000000..3f81ba02ded --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/lib/index.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* One half times the natural logarithm of 2 as a single-precision floating-point number. +* +* @module @stdlib/constants/float32/half-ln-two +* @type {number} +* +* @example +* var FLOAT32_HALF_LN2 = require( '@stdlib/constants/float32/half-ln-two' ); +* // returns 0.3465735912322998 +*/ + +// MAIN // + +/** +* One half times the natural logarithm of 2 as a single-precision floating-point number. +* +* ```tex +* \frac{\ln 2}{2} +* ``` +* +* @constant +* @type {number} +* @default 0.3465735912322998 +*/ +var FLOAT32_HALF_LN2 = 0.3465735912322998; // 0x3EB17218 + + +// EXPORTS // + +module.exports = FLOAT32_HALF_LN2; diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/manifest.json b/lib/node_modules/@stdlib/constants/float32/half-ln-two/manifest.json new file mode 100644 index 00000000000..844d692f643 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/package.json b/lib/node_modules/@stdlib/constants/float32/half-ln-two/package.json new file mode 100644 index 00000000000..3253d3ac8b4 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/constants/float32/half-ln-two", + "version": "0.0.0", + "description": "One half times the natural logarithm of 2 as a single-precision floating-point number.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "constant", + "const", + "mathematics", + "math", + "ln", + "ln2", + "half", + "natural", + "logarithm", + "log", + "ieee754", + "float", + "flt", + "precision", + "floating-point", + "float32" + ] +} diff --git a/lib/node_modules/@stdlib/constants/float32/half-ln-two/test/test.js b/lib/node_modules/@stdlib/constants/float32/half-ln-two/test/test.js new file mode 100644 index 00000000000..b6d6ca0ecc2 --- /dev/null +++ b/lib/node_modules/@stdlib/constants/float32/half-ln-two/test/test.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var lnf = require( '@stdlib/math/base/special/lnf' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var FLOAT32_HALF_LN2 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a number', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof FLOAT32_HALF_LN2, 'number', 'main export is a number' ); + t.end(); +}); + +tape( 'export is a single-precision floating-point number equal to `0.3465735912322998`', function test( t ) { + t.equal( FLOAT32_HALF_LN2, float64ToFloat32( 3.46573590279972654709e-01 ), 'equals 0.3465735912322998' ); + t.end(); +}); + +tape( 'export equals `0.5*lnf(2)`', function test( t ) { + var delta; + var tol; + var v; + + v = float64ToFloat32( 0.5 * lnf( 2.0 ) ); + delta = absf( float64ToFloat32( v - FLOAT32_HALF_LN2 ) ); + tol = EPS * FLOAT32_HALF_LN2; + + t.ok( delta <= tol, 'equals 0.5*lnf(2) within tolerance '+tol ); + + t.end(); +}); From 319da6e0ce59429ae75536d85dd242c4ab1348a4 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 15 Oct 2024 12:48:00 -0400 Subject: [PATCH 39/50] build: update cppcheck version --- deps/checksums/cppcheck_v2_15_0_tar_gz/sha256 | 1 + deps/checksums/cppcheck_v2_15_0_zip/sha256 | 1 + tools/make/common.mk | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 deps/checksums/cppcheck_v2_15_0_tar_gz/sha256 create mode 100644 deps/checksums/cppcheck_v2_15_0_zip/sha256 diff --git a/deps/checksums/cppcheck_v2_15_0_tar_gz/sha256 b/deps/checksums/cppcheck_v2_15_0_tar_gz/sha256 new file mode 100644 index 00000000000..b201736697e --- /dev/null +++ b/deps/checksums/cppcheck_v2_15_0_tar_gz/sha256 @@ -0,0 +1 @@ +98bcc40ac8062635b492fb096d7815376a176ae26749d6c708083f4637f7c0bb diff --git a/deps/checksums/cppcheck_v2_15_0_zip/sha256 b/deps/checksums/cppcheck_v2_15_0_zip/sha256 new file mode 100644 index 00000000000..2b530d9732f --- /dev/null +++ b/deps/checksums/cppcheck_v2_15_0_zip/sha256 @@ -0,0 +1 @@ +44f661e138065b7001afd544bffbe0e028a20e4c1de05d27daa658c99df2026b diff --git a/tools/make/common.mk b/tools/make/common.mk index 38e86b502ed..935af1dfab7 100644 --- a/tools/make/common.mk +++ b/tools/make/common.mk @@ -608,7 +608,7 @@ DEPS_SHELLCHECK_ARCH := $(shell command -v $(NODE) >/dev/null 2>&1 && $(NODE_HOS DEPS_SHELLCHECK_PLATFORM := $(shell command -v $(NODE) >/dev/null 2>&1 && $(NODE_HOST_PLATFORM)) # Define the cppcheck version: -DEPS_CPPCHECK_VERSION ?= 2.9 +DEPS_CPPCHECK_VERSION ?= 2.15.0 # Generate a version slug: deps_cppcheck_version_slug := $(subst .,_,$(DEPS_CPPCHECK_VERSION)) From 4f8bad3ec19d742b1f08481bbb08ee2406312080 Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Fri, 18 Oct 2024 01:43:27 +0530 Subject: [PATCH 40/50] feat: add `blas/base/dnrm2-wasm` PR-URL: https://github.com/stdlib-js/stdlib/pull/3014 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/blas/base/dnrm2-wasm/README.md | 297 +++++++++++ .../base/dnrm2-wasm/benchmark/benchmark.js | 106 ++++ .../dnrm2-wasm/benchmark/benchmark.module.js | 66 +++ .../benchmark/benchmark.module.main.js | 130 +++++ .../benchmark/benchmark.module.ndarray.js | 130 +++++ .../dnrm2-wasm/benchmark/benchmark.ndarray.js | 106 ++++ .../blas/base/dnrm2-wasm/docs/repl.txt | 496 ++++++++++++++++++ .../base/dnrm2-wasm/docs/types/index.d.ts | 316 +++++++++++ .../blas/base/dnrm2-wasm/docs/types/test.ts | 347 ++++++++++++ .../blas/base/dnrm2-wasm/examples/index.js | 43 ++ .../examples/little_endian_arrays.js | 65 +++ .../blas/base/dnrm2-wasm/examples/module.js | 63 +++ .../base/dnrm2-wasm/lib/binary.browser.js | 33 ++ .../blas/base/dnrm2-wasm/lib/binary.js | 34 ++ .../@stdlib/blas/base/dnrm2-wasm/lib/index.js | 99 ++++ .../@stdlib/blas/base/dnrm2-wasm/lib/main.js | 60 +++ .../blas/base/dnrm2-wasm/lib/module.js | 198 +++++++ .../blas/base/dnrm2-wasm/lib/routine.js | 166 ++++++ .../blas/base/dnrm2-wasm/manifest.json | 36 ++ .../@stdlib/blas/base/dnrm2-wasm/package.json | 85 +++ .../blas/base/dnrm2-wasm/scripts/build.js | 63 +++ .../blas/base/dnrm2-wasm/scripts/template.txt | 33 ++ .../@stdlib/blas/base/dnrm2-wasm/src/Makefile | 232 ++++++++ .../blas/base/dnrm2-wasm/src/main.wasm | Bin 0 -> 605 bytes .../@stdlib/blas/base/dnrm2-wasm/src/main.wat | 213 ++++++++ .../@stdlib/blas/base/dnrm2-wasm/test/test.js | 53 ++ .../blas/base/dnrm2-wasm/test/test.main.js | 139 +++++ .../blas/base/dnrm2-wasm/test/test.module.js | 154 ++++++ .../base/dnrm2-wasm/test/test.module.main.js | 167 ++++++ .../dnrm2-wasm/test/test.module.ndarray.js | 198 +++++++ .../blas/base/dnrm2-wasm/test/test.ndarray.js | 136 +++++ .../blas/base/dnrm2-wasm/test/test.routine.js | 71 +++ 32 files changed, 4335 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/little_endian_arrays.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/binary.browser.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/binary.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/routine.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/scripts/build.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/scripts/template.txt create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/Makefile create mode 100755 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/main.wasm create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/main.wat create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.routine.js diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/README.md b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/README.md new file mode 100644 index 00000000000..5c4b9ab24b2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/README.md @@ -0,0 +1,297 @@ + + +# dnrm2 + +> Calculate the L2-norm of a double-precision floating-point vector. + +
+ +## Usage + +```javascript +var dnrm2 = require( '@stdlib/blas/base/dnrm2-wasm' ); +``` + +#### dnrm2.main( N, x, strideX ) + +Calculates the L2-norm of a double-precision floating-point vector. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); + +var z = dnrm2.main( 3, x, 1 ); +// returns 3.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: index increment for `x`. + +The `N` and stride parameters determine which elements in the input strided array are accessed at runtime. For example, to compute the L2-norm of every other element in `x`, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); + +var z = dnrm2.main( 4, x, 2 ); +// returns 5.0 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); + +// Create a typed array view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var z = dnrm2.main( 4, x1, 2 ); +// returns 5.0 +``` + +#### dnrm2.ndarray( N, x, strideX, offsetX ) + +Calculates the L2-norm of a double-precision floating-point vector using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); + +var z = dnrm2.ndarray( 3, x, 1, 0 ); +// returns 3.0 +``` + +The function has the following additional parameters: + +- **offsetX**: 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 for every other value in `x` starting from the second value, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); + +var z = dnrm2.ndarray( 4, x, 2, 1 ); +// returns 5.0 +``` + +* * * + +### Module + +#### dnrm2.Module( memory ) + +Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new dnrm2.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); +``` + +#### dnrm2.Module.prototype.main( N, xp, sx ) + +Computes the L2-norm of a double-precision floating-point vector. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new dnrm2.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointer (i.e., byte offsets) for storing the input vector: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +var out = mod.main( N, xptr, 1 ); +// returns ~7.42 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sx**: index increment for `x`. + +#### dnrm2.Module.prototype.ndarray( N, xp, sx, ox ) + +Computes the L2-norm of a double-precision floating-point vector using alternative indexing semantics. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new dnrm2.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointer (i.e., byte offsets) for storing the input vector: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +var out = mod.ndarray( N, xptr, 1, 0 ); +// returns ~7.42 +``` + +The function has the following additional parameters: + +- **ox**: starting index for `x`. + +
+ + + +
+ +* * * + +## Notes + +- If `N <= 0`, both `main` and `ndarray` methods return `0.0`. +- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `dnrm2` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/blas/base/dnrm2`][@stdlib/blas/base/dnrm2]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/blas/base/dnrm2`][@stdlib/blas/base/dnrm2]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other. +- `dnrm2()` corresponds to the [BLAS][blas] level 1 function [`dnrm2`][dnrm2]. + +
+ + + +
+ +* * * + +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dnrm2 = require( '@stdlib/blas/base/dnrm2-wasm' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, 0, 100, opts ); +console.log( x ); + +var out = dnrm2.ndarray( x.length, x, 1, 0 ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.js new file mode 100644 index 00000000000..5cdbdb971e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dnrm2.main( x.length, x, 1 ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.js new file mode 100644 index 00000000000..5e8eabccb69 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var pkg = require( './../package.json' ).name; +var dnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; + + +// MAIN // + +bench( pkg+':Module:constructor', opts, function benchmark( b ) { + var values; + var o; + var v; + var i; + + o = { + 'initial': 0 + }; + values = [ + new Memory( o ), + new Memory( o ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new dnrm2.Module( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.main.js new file mode 100644 index 00000000000..d21691428e0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.main.js @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var xptr; + var mod; + var mem; + var out; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new dnrm2.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*nb ); + + // Define pointer (i.e., byte offsets) to the first vector elements: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = mod.main( len, xptr, 1 ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.ndarray.js new file mode 100644 index 00000000000..c54a3aea09a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.module.ndarray.js @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var xptr; + var mod; + var mem; + var out; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new dnrm2.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*nb ); + + // Define pointer (i.e., byte offsets) to the first vector elements: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = mod.ndarray( len, xptr, 1, 0 ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.ndarray.js new file mode 100644 index 00000000000..75b82219521 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/benchmark/benchmark.ndarray.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dnrm2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dnrm2.ndarray( x.length, x, 1, 0 ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/repl.txt new file mode 100644 index 00000000000..841b2d821fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/repl.txt @@ -0,0 +1,496 @@ + +{{alias}}.main( N, x, strideX ) + Computes the L2-norm of a double-precision floating-point vector. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0` the function returns `0.0`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + Returns + ------- + out: number + The L2-norm. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var out = {{alias}}.main( x.length, x, 1 ) + 3.0 + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); + > out = {{alias}}.main( 3, x, 2 ) + 3.0 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > out = {{alias}}.main( 3, x1, 2 ) + 3.0 + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Computes the L2-norm of a double-precision floating-point vector using + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + Returns + ------- + out: number + The L2-norm. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var out = {{alias}}.ndarray( x.length, x, 1, 0 ) + 3.0 + + // Using offset parameter: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > out = {{alias}}.ndarray( 3, x, 2, 1 ) + 3.0 + + +{{alias}}.Module( memory ) + Returns a new WebAssembly module wrapper which uses the provided WebAssembly + memory instance as its underlying memory. + + Parameters + ---------- + memory: Memory + WebAssembly memory instance. + + Returns + ------- + mod: Module + WebAssembly module wrapper. + + Examples + -------- + // Create a new memory instance: + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + + // Create a new routine: + > var mod = new {{alias}}.Module( mem ); + + // Initialize the routine: + > mod.initializeSync(); + + +{{alias}}.Module.prototype.binary + Read-only property which returns WebAssembly binary code. + + Returns + ------- + out: Uint8Array + WebAssembly binary code. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.binary + + + +{{alias}}.Module.prototype.memory + Read-only property which returns WebAssembly memory. + + Returns + ------- + mem: Memory|null + WebAssembly memory. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.memory + + + +{{alias}}.Module.prototype.buffer + Read-only property which returns a WebAssembly memory buffer as a + Uint8Array. + + Returns + ------- + buf: Uint8Array|null + WebAssembly memory buffer. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.buffer + + + +{{alias}}.Module.prototype.view + Read-only property which returns a WebAsssembly memory buffer as a DataView. + + Returns + ------- + view: DataView|null + WebAssembly memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.view + + + +{{alias}}.Module.prototype.exports + Read-only property which returns "raw" WebAssembly module exports. + + Returns + ------- + out: Object|null + WebAssembly module exports. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.exports + {...} + + +{{alias}}.Module.prototype.initialize() + Asynchronously initializes a WebAssembly module instance. + + Returns + ------- + p: Promise + Promise which resolves upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initialize(); + + +{{alias}}.Module.prototype.initializeAsync( clbk ) + Asynchronously initializes a WebAssembly module instance. + + Parameters + ---------- + clbk: Function + Callback to invoke upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > function clbk() { console.log( 'done' ) }; + > mod.initializeAsync( clbk ); + + +{{alias}}.Module.prototype.initializeSync() + Synchronously initializes a WebAssembly module instance. + + In web browsers, JavaScript engines may raise an exception when attempting + to synchronously compile large WebAssembly binaries due to concerns about + blocking the main thread. Hence, to initialize WebAssembly modules having + large binaries (e.g., >4KiB), consider using asynchronous initialization + methods in browser contexts. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + +{{alias}}.Module.prototype.realloc( nbytes ) + Reallocates the underlying WebAssembly memory instance to a specified number + of bytes. + + WebAssembly memory can only *grow*, not shrink. Hence, if provided a number + of bytes which is less than or equal to the size of the current memory, the + function does nothing. + + When non-shared memory is resized, the underlying the `ArrayBuffer` is + detached, consequently invalidating any associated typed array views. Before + resizing non-shared memory, ensure that associated typed array views no + longer need byte access and can be garbage collected. + + Parameters + ---------- + nbytes: integer + Memory size (in bytes). + + Returns + ------- + bool: boolean + Boolean indicating whether the resize operation was successful. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ) + + + +{{alias}}.Module.prototype.hasCapacity( byteOffset, values ) + Returns a boolean indicating whether the underlying WebAssembly memory + instance has the capacity to store a provided list of values starting from a + specified byte offset. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + bool: boolean + Boolean indicating whether the underlying WebAssembly memory instance + has enough capacity. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.hasCapacity( 0, [ 1, 2, 3, 4 ] ) + true + + +{{alias}}.Module.prototype.isView( values ) + Returns a boolean indicating whether a provided list of values is a view of + the underlying memory of the WebAssembly module. + + Parameters + ---------- + values: ArrayLikeObject + Input array. + + Returns + ------- + bool: boolean + Boolean indicating whether the list is a memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.isView( [ 1, 2, 3, 4 ] ) + false + + +{{alias}}.Module.prototype.write( byteOffset, values ) + Writes values to the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the input array. For example, if provided a Float32Array, + the function writes each element as a single-precision floating-point number + to the underlying WebAssembly memory instance. + + In order to write elements as a different data type, you need to perform an + explicit cast *before* calling this method. For example, in order to write + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must first convert the Float32Array to an + Int32Array before passing the values to this method. + + If provided an array having an unknown or "generic" data type, elements are + written as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + + +{{alias}}.Module.prototype.read( byteOffset, out ) + Reads values from the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the output array. For example, if provided a Float32Array, + the function reads each element as a single-precision floating-point number + from the underlying WebAssembly memory instance. + + In order to read elements as a different data type, you need to perform an + explicit cast *after* calling this method. For example, in order to read + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must convert the Float32Array to an Int32Array + after reading memory values using this method. + + If provided an output array having an unknown or "generic" data type, + elements are read as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start reading values. + + out: ArrayLikeObject + Output array for storing read values. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + > var out = [ 0, 0, 0, 0 ]; + > mod.read( 0, out ); + > out + [ 1, 2, 3, 4 ] + + +{{alias}}.Module.prototype.main( N, xp, sx ) + Computes the L2-norm of a double-precision floating-point vector. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + Returns + ------- + out: number + The L2-norm. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointer" (i.e., byte offsets) into module memory: + > var xptr = 0; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + + // Perform computation: + > var out = mod.main( 5, xptr, 1 ) + ~7.42 + + +{{alias}}.Module.prototype.ndarray( N, xp, sx, ox ) + Computes the L2-norm of a double-precision floating-point vector using + alternative indexing semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + Returns + ------- + out: number + The L2-norm. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointer" (i.e., byte offsets) into module memory: + > var xptr = 0; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + + // Perform computation: + > var out = mod.ndarray( 5, xptr, 1, 0 ) + ~7.42 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/index.d.ts new file mode 100644 index 00000000000..de0c7474365 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/index.d.ts @@ -0,0 +1,316 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ModuleWrapper, Memory } from '@stdlib/types/wasm'; + +/** +* Interface defining a module constructor which is both "newable" and "callable". +*/ +interface ModuleConstructor { + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns ~7.42 + */ + new( mem: Memory ): Module; // newable + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = dnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns ~7.42 + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing a `dnrm2` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Computes the L2-norm of a double-precision floating-point vector. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @returns L2-norm + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns ~7.42 + */ + main( N: number, xptr: number, strideX: number ): number; + + /** + * Computes the L2-norm of a double-precision floating-point vector using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns L2-norm + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.ndarray( N, xptr, 1, 0 ); + * // returns ~7.42 + */ + ndarray( N: number, xptr: number, strideX: number, offsetX: number ): number; +} + +/** +* Interface describing `dnrm2`. +*/ +interface Routine extends ModuleWrapper { + /** + * Computes the L2-norm of a double-precision floating-point vector. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - `x` stride length + * @returns L2-norm + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * var out = dnrm2.main( x.length, 5.0, x, 1, y, 1 ); + * // returns ~7.42 + */ + main( N: number, x: Float64Array, strideX: number ): number; + + /** + * Computes the L2-norm of a double-precision floating-point vector using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns L2-norm + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * var out = dnrm2.ndarray( x.length, x, 1, 0 ); + * // returns ~7.42 + */ + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number ): number; + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dnrm2.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.main( N, 5.0, xptr, 1, yptr, 1 ); + * // returns ~7.42 + */ + Module: ModuleConstructor; +} + +/** +* Computes the L2-norm of a double-precision floating-point vector. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - `x` stride length +* @returns L2-norm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* var out = dnrm2.main( x.length, x, 1 ); +* // returns ~7.42 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* var out = dnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~7.42 +*/ +declare var dnrm2: Routine; + + +// EXPORTS // + +export = dnrm2; diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/test.ts new file mode 100644 index 00000000000..78d0c2a1bac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/test.ts @@ -0,0 +1,347 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable space-in-parens */ + +import Memory = require( '@stdlib/wasm/memory' ); +import dnrm2 = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a number... +{ + const x = new Float64Array( 10 ); + + dnrm2.main( x.length, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnrm2.main( '10', x, 1 ); // $ExpectError + dnrm2.main( true, x, 1 ); // $ExpectError + dnrm2.main( false, x, 1 ); // $ExpectError + dnrm2.main( null, x, 1 ); // $ExpectError + dnrm2.main( undefined, x, 1 ); // $ExpectError + dnrm2.main( [], x, 1 ); // $ExpectError + dnrm2.main( {}, x, 1 ); // $ExpectError + dnrm2.main( ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dnrm2.main( x.length, 10, 1 ); // $ExpectError + dnrm2.main( x.length, '10', 1 ); // $ExpectError + dnrm2.main( x.length, true, 1 ); // $ExpectError + dnrm2.main( x.length, false, 1 ); // $ExpectError + dnrm2.main( x.length, null, 1 ); // $ExpectError + dnrm2.main( x.length, undefined, 1 ); // $ExpectError + dnrm2.main( x.length, [], 1 ); // $ExpectError + dnrm2.main( x.length, {}, 1 ); // $ExpectError + dnrm2.main( x.length, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnrm2.main( x.length, x, '10' ); // $ExpectError + dnrm2.main( x.length, x, true ); // $ExpectError + dnrm2.main( x.length, x, false ); // $ExpectError + dnrm2.main( x.length, x, null ); // $ExpectError + dnrm2.main( x.length, x, undefined ); // $ExpectError + dnrm2.main( x.length, x, [] ); // $ExpectError + dnrm2.main( x.length, x, {} ); // $ExpectError + dnrm2.main( x.length, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + dnrm2.main(); // $ExpectError + dnrm2.main( x.length ); // $ExpectError + dnrm2.main( x.length, x ); // $ExpectError + dnrm2.main( x.length, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + dnrm2.ndarray( x.length, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnrm2.ndarray( '10', x, 1, 0 ); // $ExpectError + dnrm2.ndarray( true, x, 1, 0 ); // $ExpectError + dnrm2.ndarray( false, x, 1, 0 ); // $ExpectError + dnrm2.ndarray( null, x, 1, 0 ); // $ExpectError + dnrm2.ndarray( undefined, x, 1, 0 ); // $ExpectError + dnrm2.ndarray( [], x, 1, 0 ); // $ExpectError + dnrm2.ndarray( {}, x, 1, 0 ); // $ExpectError + dnrm2.ndarray( ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dnrm2.ndarray( x.length, 10, 1, 0 ); // $ExpectError + dnrm2.ndarray( x.length, '10', 1, 0 ); // $ExpectError + dnrm2.ndarray( x.length, true, 1, 0 ); // $ExpectError + dnrm2.ndarray( x.length, false, 1, 0 ); // $ExpectError + dnrm2.ndarray( x.length, null, 1, 0 ); // $ExpectError + dnrm2.ndarray( x.length, undefined, 1, 0 ); // $ExpectError + dnrm2.ndarray( x.length, [], 1, 0 ); // $ExpectError + dnrm2.ndarray( x.length, {}, 1, 0 ); // $ExpectError + dnrm2.ndarray( x.length, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnrm2.ndarray( x.length, x, '10', 0 ); // $ExpectError + dnrm2.ndarray( x.length, x, true, 0 ); // $ExpectError + dnrm2.ndarray( x.length, x, false, 0 ); // $ExpectError + dnrm2.ndarray( x.length, x, null, 0 ); // $ExpectError + dnrm2.ndarray( x.length, x, undefined, 0 ); // $ExpectError + dnrm2.ndarray( x.length, x, [], 0 ); // $ExpectError + dnrm2.ndarray( x.length, x, {}, 0 ); // $ExpectError + dnrm2.ndarray( x.length, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dnrm2.ndarray( x.length, x, 1, '10' ); // $ExpectError + dnrm2.ndarray( x.length, x, 1, true ); // $ExpectError + dnrm2.ndarray( x.length, x, 1, false ); // $ExpectError + dnrm2.ndarray( x.length, x, 1, null ); // $ExpectError + dnrm2.ndarray( x.length, x, 1, undefined ); // $ExpectError + dnrm2.ndarray( x.length, x, 1, [] ); // $ExpectError + dnrm2.ndarray( x.length, x, 1, {} ); // $ExpectError + dnrm2.ndarray( x.length, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + dnrm2.ndarray(); // $ExpectError + dnrm2.ndarray( x.length ); // $ExpectError + dnrm2.ndarray( x.length, x ); // $ExpectError + dnrm2.ndarray( x.length, x, 1 ); // $ExpectError + dnrm2.ndarray( x.length, x, 1, 0, 10 ); // $ExpectError +} + +// Attached to the main export is a `Module` constructor which returns a module... +{ + const mem = new Memory({ + 'initial': 0 + }); + + dnrm2.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + dnrm2.Module( '10' ); // $ExpectError + dnrm2.Module( true ); // $ExpectError + dnrm2.Module( false ); // $ExpectError + dnrm2.Module( null ); // $ExpectError + dnrm2.Module( undefined ); // $ExpectError + dnrm2.Module( [] ); // $ExpectError + dnrm2.Module( {} ); // $ExpectError + dnrm2.Module( ( x: number ): number => x ); // $ExpectError +} + +// The `Module` constructor returns a module instance having a `main` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.main( 10, 0, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.main( '10', 0, 10 ); // $ExpectError + mod.main( true, 0, 10 ); // $ExpectError + mod.main( false, 0, 10 ); // $ExpectError + mod.main( null, 0, 10 ); // $ExpectError + mod.main( undefined, 0, 10 ); // $ExpectError + mod.main( [], 0, 10 ); // $ExpectError + mod.main( {}, 0, 10 ); // $ExpectError + mod.main( ( x: number ): number => x, 0, 10 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.main( 10, '10', 1 ); // $ExpectError + mod.main( 10, true, 1 ); // $ExpectError + mod.main( 10, false, 1 ); // $ExpectError + mod.main( 10, null, 1 ); // $ExpectError + mod.main( 10, undefined, 1 ); // $ExpectError + mod.main( 10, [], 1 ); // $ExpectError + mod.main( 10, {}, 1 ); // $ExpectError + mod.main( 10, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.main( 10, 0, '10' ); // $ExpectError + mod.main( 10, 0, true ); // $ExpectError + mod.main( 10, 0, false ); // $ExpectError + mod.main( 10, 0, null ); // $ExpectError + mod.main( 10, 0, undefined ); // $ExpectError + mod.main( 10, 0, [] ); // $ExpectError + mod.main( 10, 0, {} ); // $ExpectError + mod.main( 10, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 0 ); // $ExpectError + mod.main( 10, 0, 1, 10 ); // $ExpectError +} + +// The `Module` constructor returns a module instance having an `ndarray` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.ndarray( 10, 0, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.ndarray( '10', 0, 1, 0 ); // $ExpectError + mod.ndarray( true, 0, 1, 0 ); // $ExpectError + mod.ndarray( false, 0, 1, 0 ); // $ExpectError + mod.ndarray( null, 0, 1, 0 ); // $ExpectError + mod.ndarray( undefined, 0, 1, 0 ); // $ExpectError + mod.ndarray( [], 0, 1, 0 ); // $ExpectError + mod.ndarray( {}, 0, 1, 0 ); // $ExpectError + mod.ndarray( ( x: number ): number => x, 0, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.ndarray( 10, '10', 1, 0 ); // $ExpectError + mod.ndarray( 10, true, 1, 0 ); // $ExpectError + mod.ndarray( 10, false, 1, 0 ); // $ExpectError + mod.ndarray( 10, null, 1, 0 ); // $ExpectError + mod.ndarray( 10, undefined, 1, 0 ); // $ExpectError + mod.ndarray( 10, [], 1, 0 ); // $ExpectError + mod.ndarray( 10, {}, 1, 0 ); // $ExpectError + mod.ndarray( 10, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.ndarray( 10, 0, '10', 0 ); // $ExpectError + mod.ndarray( 10, 0, true, 0 ); // $ExpectError + mod.ndarray( 10, 0, false, 0 ); // $ExpectError + mod.ndarray( 10, 0, null, 0 ); // $ExpectError + mod.ndarray( 10, 0, undefined, 0 ); // $ExpectError + mod.ndarray( 10, 0, [], 0 ); // $ExpectError + mod.ndarray( 10, 0, {}, 0 ); // $ExpectError + mod.ndarray( 10, 0, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.ndarray( 10, 0, 1, '10' ); // $ExpectError + mod.ndarray( 10, 0, 1, true ); // $ExpectError + mod.ndarray( 10, 0, 1, false ); // $ExpectError + mod.ndarray( 10, 0, 1, null ); // $ExpectError + mod.ndarray( 10, 0, 1, undefined ); // $ExpectError + mod.ndarray( 10, 0, 1, [] ); // $ExpectError + mod.ndarray( 10, 0, 1, {} ); // $ExpectError + mod.ndarray( 10, 0, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dnrm2.Module( mem ); + + mod.ndarray(); // $ExpectError + mod.ndarray( 10 ); // $ExpectError + mod.ndarray( 10, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/index.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/index.js new file mode 100644 index 00000000000..ad4f3acde92 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var oneTo = require( '@stdlib/array/one-to' ); +var dnrm2 = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Specify a vector length: + var N = 5; + + // Create input array: + var x = oneTo( N, 'float64' ); + + // Perform computation: + var out = dnrm2.ndarray( N, x, 1, 0 ); + + // Print the result: + console.log( out ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/little_endian_arrays.js new file mode 100644 index 00000000000..0e0ff252f63 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/little_endian_arrays.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); +var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +var dnrm2 = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new dnrm2.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Specify a vector length: + var N = 5; + + // Define pointer (i.e., byte offsets) for storing the input vector: + var xptr = 0; + + // Create typed array views over module memory: + var x = new Float64ArrayLE( mod.memory.buffer, xptr, N ); + + // Write values to module memory: + gfillBy( N, x, 1, discreteUniform( -10.0, 10.0 ) ); + + // Perform computation: + var out = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( out ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/module.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/module.js new file mode 100644 index 00000000000..583ce9a13ac --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/examples/module.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var dnrm2 = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new dnrm2.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Define a vector data type: + var dtype = 'float64'; + + // Specify a vector length: + var N = 5; + + // Define pointer (i.e., byte offsets) for storing the input vector: + var xptr = 0; + + // Write vector values to module memory: + mod.write( xptr, oneTo( N, dtype ) ); + + // Perform computation: + var out = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( out ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/binary.browser.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/binary.browser.js new file mode 100644 index 00000000000..3a5d0a560a6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAETA2AAAGADf39/AXxgBH9/f38BfAIPAQNlbnYGbWVtb3J5AgAAAwQDAAECB0wEEV9fd2FzbV9jYWxsX2N0b3JzAAAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAHY19kbnJtMgABD2NfZG5ybTJfbmRhcnJheQACCscDAwMAAQshAQF+IAAgASACIAKsIgNCASAArH1+QgAgA0IAVxunEAILngMCBHwDf0EBIQggAEEASgR8A0ACQCABIANBA3RqKwMAmSIGRAAAAAAAAFBeZARAIAcgBkQAAAAAAABQHqIiBiAGoqAhB0EAIQgMAQsgBkQAAAAAAAAAIGMEQCAIIQlBACEIIAlFDQEgBSAGRAAAAAAAAIBhoiIFIAWioCEFQQEhCAwBCyAEIAYgBqKgIQQLIAIgA2ohAyAKQQFqIgogAEcNAAsCfCAHRAAAAAAAAAAAZARAIAREAAAAAAAAUB6iRAAAAAAAAFAeoiAHoCIFIAcgBET////////vf2QbIAUgBEQAAAAAAAAAAGUbIQREAAAAAAAAkGEMAQtEAAAAAAAA8D8gBUQAAAAAAAAAAGRFDQAaAkAgBCAEYg0AIAREAAAAAAAAAABkDQAgBET////////vf2QNACAFIQREAAAAAAAAYB4MAQsgBZ9EAAAAAAAAYB6iIgUgBJ8iBCAEIAVjIgAbIgYgBqIgBCAFIAAbIAajIgQgBKJEAAAAAAAA8D+goiEERAAAAAAAAPA/CyAEn6IFRAAAAAAAAAAACws=' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/binary.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/binary.js new file mode 100644 index 00000000000..6f02393f96e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/binary.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readWASM = require( '@stdlib/fs/read-wasm' ).sync; + + +// MAIN // + +var wasm = readWASM( resolve( __dirname, '..', 'src', 'main.wasm' ) ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/index.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/index.js new file mode 100644 index 00000000000..9da6a3960a5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/index.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* WebAssembly routine to calculate the L2-norm of a double-precision floating-point vector. +* +* @module @stdlib/blas/base/dnrm2-wasm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dnrm2 = require( '@stdlib/blas/base/dnrm2-wasm' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var out = dnrm2.main( x.length, x, 1 ); +* // returns ~7.42 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dnrm2 = require( '@stdlib/blas/base/dnrm2-wasm' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var out = dnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~7.42 +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var dnrm2 = require( '@stdlib/blas/base/dnrm2-wasm' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var mod = new dnrm2.Module( mem ); +* // returns +* +* // Initialize the routine: +* mod.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* mod.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var out = mod.main( N, xptr, 1 ); +* // returns ~7.42 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var Module = require( './module.js' ); + + +// MAIN // + +setReadOnly( main, 'Module', Module ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "Module": "main.Module" } diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/main.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/main.js new file mode 100644 index 00000000000..03daf61599e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/main.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var Routine = require( './routine.js' ); + + +// MAIN // + +/** +* WebAssembly module to calculate the L2-norm of a double-precision floating-point vector. +* +* @name dnrm2 +* @type {Routine} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var out = dnrm2.main( x.length, x, 1 ); +* // returns ~7.42 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var out = dnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~7.42 +*/ +var dnrm2 = new Routine(); +dnrm2.initializeSync(); // eslint-disable-line node/no-sync + + +// EXPORTS // + +module.exports = dnrm2; diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/module.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/module.js new file mode 100644 index 00000000000..504ccf37e72 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/module.js @@ -0,0 +1,198 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var WasmModule = require( '@stdlib/wasm/module-wrapper' ); +var format = require( '@stdlib/string/format' ); +var wasmBinary = require( './binary.js' ); + + +// MAIN // + +/** +* BLAS routine WebAssembly module wrapper constructor. +* +* @constructor +* @param {Object} memory - WebAssembly memory instance +* @throws {TypeError} must provide a WebAssembly memory instance +* @returns {Module} module instance +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var dnrm2 = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dnrm2.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dnrm2.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var out = dnrm2.main( N, xptr, 1 ); +* // returns ~7.42 +*/ +function Module( memory ) { + if ( !( this instanceof Module ) ) { + return new Module( memory ); + } + if ( !isWebAssemblyMemory( memory ) ) { + throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) ); + } + // Call the parent constructor: + WasmModule.call( this, wasmBinary, memory, { + 'env': { + 'memory': memory + } + }); + + return this; +} + +// Inherit from the parent constructor: +inherits( Module, WasmModule ); + +/** +* Calculates the L2-norm of a double-precision floating-point vector. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @returns {number} the L2-norm +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var dnrm2 = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dnrm2.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dnrm2.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var out = dnrm2.main( N, xptr, 1 ); +* // returns ~7.42 +*/ +setReadOnly( Module.prototype, 'main', function dnrm2( N, xptr, strideX ) { + return this._instance.exports.c_dnrm2( N, xptr, strideX ); +}); + +/** +* Calculates the L2-norm of a double-precision floating-point vector using alternative indexing semantics. +* +* @name ndarray +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @returns {number} the L2-norm +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var dnrm2 = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dnrm2.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dnrm2.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var out = dnrm2.ndarray( N, xptr, 1, 0 ); +* // returns ~7.42 +*/ +setReadOnly( Module.prototype, 'ndarray', function dnrm2( N, xptr, strideX, offsetX ) { + return this._instance.exports.c_dnrm2_ndarray( N, xptr, strideX, offsetX ); +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/routine.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/routine.js new file mode 100644 index 00000000000..ab71c83802e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/lib/routine.js @@ -0,0 +1,166 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var Memory = require( '@stdlib/wasm/memory' ); +var arrays2ptrs = require( '@stdlib/wasm/base/arrays2ptrs' ); +var strided2object = require( '@stdlib/wasm/base/strided2object' ); +var Module = require( './module.js' ); + + +// MAIN // + +/** +* Routine constructor. +* +* @private +* @constructor +* @returns {Routine} routine instance +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnrm2 = new Routine(); +* +* // Initialize the module: +* dnrm2.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var out = dnrm2.main( x.length, x, 1 ); +* // returns ~7.42 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnrm2 = new Routine(); +* +* // Initialize the module: +* dnrm2.initializeSync(); +* +* // Define strided arrays: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var out = dnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~7.42 +*/ +function Routine() { + if ( !( this instanceof Routine ) ) { + return new Routine(); + } + Module.call( this, new Memory({ + 'initial': 0 + })); + return this; +} + +// Inherit from the parent constructor: +inherits( Routine, Module ); + +/** +* Calculates the L2-norm of a double-precision floating-point vector. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - `x` stride length +* @returns {number} the L2-norm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnrm2 = new Routine(); +* +* // Initialize the module: +* dnrm2.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var out = dnrm2.main( x.length, x, 1 ); +* // returns ~7.42 +*/ +setReadOnly( Routine.prototype, 'main', function dnrm2( N, x, strideX ) { + return this.ndarray( N, x, strideX, stride2offset( N, strideX ) ); +}); + +/** +* Calculates the L2-norm of a double-precision floating-point vector using alternative indexing semantics. +* +* @name ndarray +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @returns {number} the L2-norm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dnrm2 = new Routine(); +* +* // Initialize the module: +* dnrm2.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var out = dnrm2.ndarray( x.length, x, 1, 0 ); +* // returns ~7.42 +*/ +setReadOnly( Routine.prototype, 'ndarray', function dnrm2( N, x, strideX, offsetX ) { + var ptrs; + var p0; + + // Convert the input array to "pointers" in the module's memory: + ptrs = arrays2ptrs( this, [ + strided2object( N, x, strideX, offsetX ) + ]); + p0 = ptrs[ 0 ]; + + // Perform computation by calling the corresponding parent method: + return Module.prototype.ndarray.call( this, N, p0.ptr, p0.stride, p0.offset ); // eslint-disable-line max-len +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/manifest.json b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/manifest.json new file mode 100644 index 00000000000..71408a07fde --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/dnrm2" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/package.json b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/package.json new file mode 100644 index 00000000000..d9996dafba8 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/package.json @@ -0,0 +1,85 @@ +{ + "name": "@stdlib/blas/base/dnrm2-wasm", + "version": "0.0.0", + "description": "Calculate the L2-norm of a double-precision floating-point vector.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": { + "./lib/binary.js": "./lib/binary.browser.js" + }, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "dnrm2", + "nrm2", + "euclidean", + "magnitude", + "2-norm", + "l2-norm", + "norm", + "linear", + "algebra", + "subroutines", + "vector", + "array", + "ndarray", + "float64", + "double", + "float64array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/scripts/build.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/scripts/build.js new file mode 100644 index 00000000000..348354d7029 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/scripts/build.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var replace = require( '@stdlib/string/replace' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/scripts/template.txt b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/scripts/template.txt new file mode 100644 index 00000000000..12996dd89e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( '{{WASM_BASE64}}' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/Makefile b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/Makefile new file mode 100644 index 00000000000..0c43d5df827 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/Makefile @@ -0,0 +1,232 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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. +#/ + +#/ +# To compile targets listed in this Makefile, use top-level project `make` +# commands rather than commands listed in this Makefile. The top-level project +# `make` commands will ensure that various environment variables and flags are +# appropriately set. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files to WebAssembly: +ifdef EMCC_COMPILER + EMCC := $(EMCC_COMPILER) +else + EMCC := emcc +endif + +# Define the program used for compiling WebAssembly files to the WebAssembly text format: +ifdef WASM2WAT + WASM_TO_WAT := $(WASM2WAT) +else + WASM_TO_WAT := wasm2wat +endif + +# Define the program used for compiling WebAssembly files to JavaScript: +ifdef WASM2JS + WASM_TO_JS := $(WASM2JS) +else + WASM_TO_JS := wasm2js +endif + +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic \ + -D CBLAS_INT=int32_t + +# Define the command-line options when compiling C files to WebAssembly and asm.js: +EMCCFLAGS ?= $(CFLAGS) + +# Define shared `emcc` flags: +EMCC_SHARED_FLAGS := \ + -s SIDE_MODULE=2 \ + -s WASM_BIGINT=0 \ + -s EXPORTED_FUNCTIONS="['_c_dnrm2','_c_dnrm2_ndarray']" + +# Define WebAssembly `emcc` flags: +EMCC_WASM_FLAGS := $(EMCC_SHARED_FLAGS) \ + -s WASM=1 + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of WebAssembly targets: +wasm_targets := main.wasm + +# List of WebAssembly WAT targets: +wat_targets := main.wat + +# List of WebAssembly JavaScript targets: +wasm_js_targets := main.wasm.js + +# List of other JavaScript targets: +browser_js_targets := ./../lib/binary.browser.js + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: wasm + +.PHONY: all + +#/ +# Compiles source files to WebAssembly. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make wasm +#/ +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) + +.PHONY: wasm + +#/ +# Compiles C source files to WebAssembly binaries. +# +# @private +# @param {string} EMCC - EMCC compiler (e.g., `emcc`) +# @param {string} EMCCFLAGS - EMCC compiler options +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(wasm_targets): + $(QUIET) $(EMCC) $(EMCCFLAGS) $(EMCC_WASM_FLAGS) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Compiles WebAssembly binary files to the WebAssembly text format. +# +# @private +# @param {string} WASM2WAT - WAT compiler (e.g., `wasm2wat`) +#/ +$(wat_targets): %.wat: %.wasm + $(QUIET) $(WASM_TO_WAT) -o $@ $(wasm_targets) + +#/ +# Compiles WebAssembly binary files to JavaScript. +# +# @private +# @param {string} WASM2JS - JavaScript compiler (e.g., `wasm2js`) +#/ +$(wasm_js_targets): %.wasm.js: %.wasm + $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) + +#/ +# Generates an inline WebAssembly build for use in bundlers. +# +# @private +# @param {string} NODE - Node.js executable +#/ +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + +#/ +# Removes generated WebAssembly files. +# +# @example +# make clean-wasm +#/ +clean-wasm: + $(QUIET) -rm -f *.wasm *.wat *.wasm.js + +.PHONY: clean-wasm + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-wasm + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/main.wasm b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/main.wasm new file mode 100755 index 0000000000000000000000000000000000000000..d6fa12537389216f1f7e90e09cb06900bbabfc58 GIT binary patch literal 605 zcmYjN%TB^j5S{yI3si!}jj;)tc57mcKL8~X6XU|2JKJl^LM)F|q9H-*C%APZq%Pd> zAAXMfflg~F&Svhp=bkg?4ycC#1FA+PoJM!U`{NTPGtBmd58#U=N!ZMn)Tr|Y6TRW1 zKIjcb@stAyDS&a~Qto-)6IpqIiXtzVjN%7?gW^t&$I;Xa)kJx5FB%0z8G#oLib?-Sz?-9=L0(rkp=_gpC2ppUj(WPZ4HxXn4l_#%FrcRuyP6SL?baD;CHbOK zM?;NtS~fP*N&GXCCM6YpTVTy)eW!+SUI&xU&?qthWEtcpQ8V41&{&eKLF7+f-$`iE z)XiIfo@H;qtD>oeblpO2>)x%yA^l&Xysg7OahRjhnUGex`OWMP+M;mrX)iQ);gAVx gfdf{)rVJohsDEU{CiuFwOiQD6i&n8nw{cAK7yHU^%>V!Z literal 0 HcmV?d00001 diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/main.wat b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/main.wat new file mode 100644 index 00000000000..8f7bd848b37 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/src/main.wat @@ -0,0 +1,213 @@ +;; @license Apache-2.0 +;; +;; Copyright (c) 2024 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. + +(module + (type (;0;) (func)) + (type (;1;) (func (param i32 i32 i32) (result f64))) + (type (;2;) (func (param i32 i32 i32 i32) (result f64))) + (import "env" "memory" (memory (;0;) 0)) + (func (;0;) (type 0) + nop) + (func (;1;) (type 1) (param i32 i32 i32) (result f64) + (local i64) + local.get 0 + local.get 1 + local.get 2 + local.get 2 + i64.extend_i32_s + local.tee 3 + i64.const 1 + local.get 0 + i64.extend_i32_s + i64.sub + i64.mul + i64.const 0 + local.get 3 + i64.const 0 + i64.le_s + select + i32.wrap_i64 + call 2) + (func (;2;) (type 2) (param i32 i32 i32 i32) (result f64) + (local f64 f64 f64 f64 i32 i32 i32) + i32.const 1 + local.set 8 + local.get 0 + i32.const 0 + i32.gt_s + if (result f64) ;; label = @1 + loop ;; label = @2 + block ;; label = @3 + local.get 1 + local.get 3 + i32.const 3 + i32.shl + i32.add + f64.load + f64.abs + local.tee 6 + f64.const 0x1p+486 (;=1.99792e+146;) + f64.gt + if ;; label = @4 + local.get 7 + local.get 6 + f64.const 0x1p-538 (;=1.11138e-162;) + f64.mul + local.tee 6 + local.get 6 + f64.mul + f64.add + local.set 7 + i32.const 0 + local.set 8 + br 1 (;@3;) + end + local.get 6 + f64.const 0x1p-511 (;=1.49167e-154;) + f64.lt + if ;; label = @4 + local.get 8 + local.set 9 + i32.const 0 + local.set 8 + local.get 9 + i32.eqz + br_if 1 (;@3;) + local.get 5 + local.get 6 + f64.const 0x1p+537 (;=4.49891e+161;) + f64.mul + local.tee 5 + local.get 5 + f64.mul + f64.add + local.set 5 + i32.const 1 + local.set 8 + br 1 (;@3;) + end + local.get 4 + local.get 6 + local.get 6 + f64.mul + f64.add + local.set 4 + end + local.get 2 + local.get 3 + i32.add + local.set 3 + local.get 10 + i32.const 1 + i32.add + local.tee 10 + local.get 0 + i32.ne + br_if 0 (;@2;) + end + block (result f64) ;; label = @2 + local.get 7 + f64.const 0x0p+0 (;=0;) + f64.gt + if ;; label = @3 + local.get 4 + f64.const 0x1p-538 (;=1.11138e-162;) + f64.mul + f64.const 0x1p-538 (;=1.11138e-162;) + f64.mul + local.get 7 + f64.add + local.tee 5 + local.get 7 + local.get 4 + f64.const 0x1.fffffffffffffp+1023 (;=1.79769e+308;) + f64.gt + select + local.get 5 + local.get 4 + f64.const 0x0p+0 (;=0;) + f64.le + select + local.set 4 + f64.const 0x1p+538 (;=8.99783e+161;) + br 1 (;@2;) + end + f64.const 0x1p+0 (;=1;) + local.get 5 + f64.const 0x0p+0 (;=0;) + f64.gt + i32.eqz + br_if 0 (;@2;) + drop + block ;; label = @3 + local.get 4 + local.get 4 + f64.ne + br_if 0 (;@3;) + local.get 4 + f64.const 0x0p+0 (;=0;) + f64.gt + br_if 0 (;@3;) + local.get 4 + f64.const 0x1.fffffffffffffp+1023 (;=1.79769e+308;) + f64.gt + br_if 0 (;@3;) + local.get 5 + local.set 4 + f64.const 0x1p-537 (;=2.22276e-162;) + br 1 (;@2;) + end + local.get 5 + f64.sqrt + f64.const 0x1p-537 (;=2.22276e-162;) + f64.mul + local.tee 5 + local.get 4 + f64.sqrt + local.tee 4 + local.get 4 + local.get 5 + f64.lt + local.tee 0 + select + local.tee 6 + local.get 6 + f64.mul + local.get 4 + local.get 5 + local.get 0 + select + local.get 6 + f64.div + local.tee 4 + local.get 4 + f64.mul + f64.const 0x1p+0 (;=1;) + f64.add + f64.mul + local.set 4 + f64.const 0x1p+0 (;=1;) + end + local.get 4 + f64.sqrt + f64.mul + else + f64.const 0x0p+0 (;=0;) + end) + (export "__wasm_call_ctors" (func 0)) + (export "__wasm_apply_data_relocs" (func 0)) + (export "c_dnrm2" (func 1)) + (export "c_dnrm2_ndarray" (func 2))) diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.js new file mode 100644 index 00000000000..823e9793620 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var dnrm2 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dnrm2, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `main` method', function test( t ) { + t.strictEqual( typeof dnrm2.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof dnrm2.ndarray, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `Module` constructor', function test( t ) { + t.strictEqual( typeof dnrm2.Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the main export is a `Module` instance', function test( t ) { + t.strictEqual( dnrm2 instanceof dnrm2.Module, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.main.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.main.js new file mode 100644 index 00000000000..290355b4a40 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.main.js @@ -0,0 +1,139 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dnrm2 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dnrm2, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `main` method has an arity of 3', function test( t ) { + t.strictEqual( dnrm2.main.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method calculates the L2-norm of a vector', function test( t ) { + var x; + var z; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + + z = dnrm2.main( x.length, x, 1 ); + t.strictEqual( z, sqrt( 55.0 ), 'returns expected value' ); + + x = new Float64Array( [ -4.0 ] ); + + z = dnrm2.main( x.length, x, 1 ); + t.strictEqual( z, 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports a `stride` parameter', function test( t ) { + var x; + var z; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + z = dnrm2.main( 4, x, 2 ); + + t.strictEqual( z, 5.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports a negative `stride` parameter', function test( t ) { + var x; + var z; + + x = new Float64Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + z = dnrm2.main( 4, x, -2 ); + + t.strictEqual( z, 5.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `main` method returns `0`', function test( t ) { + var x; + var z; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + z = dnrm2.main( 0, x, 1 ); + t.strictEqual( z, 0.0, 'returns expected value' ); + + z = dnrm2.main( -1, x, 1 ); + t.strictEqual( z, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports view offsets', function test( t ) { + var x0; + var x1; + var z; + + x0 = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0, // 3 + 6.0 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + + z = dnrm2.main( 4, x1, 2 ); + t.strictEqual( z, 5.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.js new file mode 100644 index 00000000000..9adcb07e22f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = Module( mem ); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Module( value ); + }; + } +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (no new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Module( value ); // eslint-disable-line new-cap + }; + } +}); + +tape( 'the module instance returned by the module constructor inherits from a module wrapper', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.main.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.main.js new file mode 100644 index 00000000000..367e781af8a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.main.js @@ -0,0 +1,167 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which has an arity of 3', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.main.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which calculates the L2-norm of a vector', function test( t ) { + var nrm2; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ) ); + + nrm2 = mod.main( 6, xp, 1 ); + t.strictEqual( nrm2, sqrt( 55.0 ), 'returns expected value' ); + + // Short datasets: + xp = 0; + + mod.write( xp, new Float64Array( [ -4.0 ] ) ); + + nrm2 = mod.main( 1, xp, 1 ); + t.strictEqual( nrm2, 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports a `stride` parameter', function test( t ) { + var nrm2; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ])); + + nrm2 = mod.main( 4, xp, 2 ); + t.strictEqual( nrm2, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports a negative `stride` parameter', function test( t ) { + var nrm2; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ])); + + nrm2 = mod.main( 4, xp, -2 ); + t.strictEqual( nrm2, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has a `main` method which returns `0`', function test( t ) { + var nrm2; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + nrm2 = mod.main( -1, xp, 1 ); + t.strictEqual( nrm2, 0.0, 'returns expected value' ); + + nrm2 = mod.main( 0, xp, 1 ); + t.strictEqual( nrm2, 0.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.ndarray.js new file mode 100644 index 00000000000..ac0e9026087 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.module.ndarray.js @@ -0,0 +1,198 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which has an arity of 4', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.ndarray.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which calculates the L2-norm of a vector', function test( t ) { + var nrm2; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ) ); + + nrm2 = mod.ndarray( 6, xp, 1, 0 ); + t.strictEqual( nrm2, sqrt( 55.0 ), 'returns expected value' ); + + // Short datasets: + xp = 0; + + mod.write( xp, new Float64Array( [ -4.0 ] ) ); + + nrm2 = mod.ndarray( 1, xp, 1, 0 ); + t.strictEqual( nrm2, 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports a `stride` parameter', function test( t ) { + var nrm2; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ])); + + nrm2 = mod.ndarray( 4, xp, 2, 0 ); + t.strictEqual( nrm2, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports a negative `stride`', function test( t ) { + var nrm2; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ])); + + nrm2 = mod.ndarray( 4, xp, -2, 6 ); + t.strictEqual( nrm2, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` offset', function test( t ) { + var nrm2; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ])); + + nrm2 = mod.ndarray( 4, xp, 2, 1 ); + t.strictEqual( nrm2, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has an `ndarray` method which returns `0`', function test( t ) { + var nrm2; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + nrm2 = mod.ndarray( -1, xp, 1, 0 ); + t.strictEqual( nrm2, 0.0, 'returns expected value' ); + + nrm2 = mod.ndarray( 0, xp, 1, 0 ); + t.strictEqual( nrm2, 0.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.ndarray.js new file mode 100644 index 00000000000..cac7757ae74 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.ndarray.js @@ -0,0 +1,136 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dnrm2 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dnrm2, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `ndarray` method has an arity of 4', function test( t ) { + t.strictEqual( dnrm2.ndarray.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method calculates the L2-norm of a vector', function test( t ) { + var x; + var z; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 0.0, 3.0 ] ); + + z = dnrm2.ndarray( x.length, x, 1, 0 ); + t.strictEqual( z, sqrt( 55.0 ), 'returns expected value' ); + + // Short datasets: + x = new Float64Array( [ -4.0 ] ); + + z = dnrm2.ndarray( x.length, x, 1, 0 ); + t.strictEqual( z, 4.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports a `stride` parameter', function test( t ) { + var x; + var z; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 2.0, // 1 + -7.0, + -2.0, // 2 + 3.0, + 4.0, // 3 + 2.0 + ]); + + z = dnrm2.ndarray( 4, x, 2, 0 ); + + t.strictEqual( z, 5.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports a negative stride parameter', function test( t ) { + var x; + var z; + + x = new Float64Array([ + 1.0, // 3 + 2.0, + 2.0, // 2 + -7.0, + -2.0, // 1 + 3.0, + 4.0, // 0 + 2.0 + ]); + + z = dnrm2.ndarray( 4, x, -2, x.length-2 ); + + t.strictEqual( z, 5.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports an `offset` parameter', function test( t ) { + var x; + var z; + + x = new Float64Array([ + 2.0, + 1.0, // 0 + 2.0, + -2.0, // 1 + -2.0, + 2.0, // 2 + 3.0, + 4.0 // 3 + ]); + + z = dnrm2.ndarray( 4, x, 2, 1 ); + t.strictEqual( z, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `ndarray` method returns `0`', function test( t ) { + var x; + var z; + + x = new Float64Array( [ 1.0, -2.0, -4.0, 5.0, 3.0 ] ); + + z = dnrm2.ndarray( 0, x, 1, 0 ); + t.strictEqual( z, 0.0, 'returns expected value' ); + + z = dnrm2.ndarray( -1, x, 1, 0 ); + t.strictEqual( z, 0.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.routine.js b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.routine.js new file mode 100644 index 00000000000..56a4b67daaf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/test/test.routine.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib/module.js' ); +var Routine = require( './../lib/routine.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Routine, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mod = Routine(); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a module wrapper', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a BLAS routine module', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); From 01e414bd9a03e578d44e2c284fcc77ce2fbcd825 Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:20:06 +0530 Subject: [PATCH 41/50] docs: fix examples in `blas/base/dnrm2-wasm` PR-URL: https://github.com/stdlib-js/stdlib/pull/3018 Ref: https://github.com/stdlib-js/stdlib/commit/4f8bad3ec19d742b1f08481bbb08ee2406312080 Ref: https://github.com/stdlib-js/stdlib/pull/3014 Reviewed-by: Athan Reines --- .../@stdlib/blas/base/dnrm2-wasm/docs/types/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/index.d.ts index de0c7474365..5ec0e7c13b8 100644 --- a/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/dnrm2-wasm/docs/types/index.d.ts @@ -218,7 +218,7 @@ interface Routine extends ModuleWrapper { * * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); * - * var out = dnrm2.main( x.length, 5.0, x, 1, y, 1 ); + * var out = dnrm2.main( x.length, x, 1 ); * // returns ~7.42 */ main( N: number, x: Float64Array, strideX: number ): number; @@ -278,7 +278,7 @@ interface Routine extends ModuleWrapper { * mod.write( xptr, oneTo( N, dtype ) ); * * // Perform computation: - * var out = mod.main( N, 5.0, xptr, 1, yptr, 1 ); + * var out = mod.main( N, xptr, 1 ); * // returns ~7.42 */ Module: ModuleConstructor; From bfcfb8907b096bb574c9dffba4cc256687a4f213 Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Fri, 18 Oct 2024 16:46:05 +0530 Subject: [PATCH 42/50] feat: add `blas/base/dscal-wasm` PR-URL: https://github.com/stdlib-js/stdlib/pull/2985 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/blas/base/dscal-wasm/README.md | 317 +++++++++++ .../base/dscal-wasm/benchmark/benchmark.js | 106 ++++ .../dscal-wasm/benchmark/benchmark.module.js | 66 +++ .../benchmark/benchmark.module.main.js | 135 +++++ .../benchmark/benchmark.module.ndarray.js | 135 +++++ .../dscal-wasm/benchmark/benchmark.ndarray.js | 106 ++++ .../blas/base/dscal-wasm/docs/repl.txt | 520 ++++++++++++++++++ .../base/dscal-wasm/docs/types/index.d.ts | 376 +++++++++++++ .../blas/base/dscal-wasm/docs/types/test.ts | 413 ++++++++++++++ .../blas/base/dscal-wasm/examples/index.js | 44 ++ .../examples/little_endian_arrays.js | 65 +++ .../blas/base/dscal-wasm/examples/module.js | 68 +++ .../base/dscal-wasm/lib/binary.browser.js | 33 ++ .../blas/base/dscal-wasm/lib/binary.js | 34 ++ .../@stdlib/blas/base/dscal-wasm/lib/index.js | 108 ++++ .../@stdlib/blas/base/dscal-wasm/lib/main.js | 60 ++ .../blas/base/dscal-wasm/lib/module.js | 235 ++++++++ .../blas/base/dscal-wasm/lib/routine.js | 175 ++++++ .../blas/base/dscal-wasm/manifest.json | 36 ++ .../@stdlib/blas/base/dscal-wasm/package.json | 80 +++ .../blas/base/dscal-wasm/scripts/build.js | 63 +++ .../blas/base/dscal-wasm/scripts/template.txt | 33 ++ .../@stdlib/blas/base/dscal-wasm/src/Makefile | 232 ++++++++ .../blas/base/dscal-wasm/src/main.wasm | Bin 0 -> 754 bytes .../@stdlib/blas/base/dscal-wasm/src/main.wat | 350 ++++++++++++ .../@stdlib/blas/base/dscal-wasm/test/test.js | 53 ++ .../blas/base/dscal-wasm/test/test.main.js | 186 +++++++ .../blas/base/dscal-wasm/test/test.module.js | 154 ++++++ .../base/dscal-wasm/test/test.module.main.js | 253 +++++++++ .../dscal-wasm/test/test.module.ndarray.js | 289 ++++++++++ .../blas/base/dscal-wasm/test/test.ndarray.js | 183 ++++++ .../blas/base/dscal-wasm/test/test.routine.js | 71 +++ 32 files changed, 4979 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/little_endian_arrays.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/binary.browser.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/binary.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/routine.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/scripts/build.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/scripts/template.txt create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/src/Makefile create mode 100755 lib/node_modules/@stdlib/blas/base/dscal-wasm/src/main.wasm create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/src/main.wat create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.routine.js diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/README.md b/lib/node_modules/@stdlib/blas/base/dscal-wasm/README.md new file mode 100644 index 00000000000..3008910bf4e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/README.md @@ -0,0 +1,317 @@ + + +# dscal + +> Multiply a vector `x` by a constant `alpha`. + +
+ +## Usage + +```javascript +var dscal = require( '@stdlib/blas/base/dscal-wasm' ); +``` + +#### dscal.main( N, alpha, x, strideX ) + +Multiplies a vector `x` by a constant `alpha`. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +dscal.main( x.length, 5.0, x, 1 ); +// x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **alpha**: scalar constant. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: index increment for `x`. + +The `N` and stride parameters determine which elements in the input strided array are accessed at runtime. For example, to multiply every other value in `x` by `alpha` in reverse order, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +dscal.main( 5, 5.0, x, -1 ); +// x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +// Create a typed array view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +dscal.main( 3, 5.0, x1, -2 ); +// x0 => [ 1.0, 10.0, 3.0, 20.0, 5.0, 30.0 ] +``` + +#### dscal.ndarray( N, alpha, x, strideX, offsetX ) + +Multiplies a vector `x` by a constant `alpha` using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +dscal.ndarray( x.length, 5.0, x, 1, 0 ); +// x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +``` + +The function has the following additional parameters: + +- **offsetX**: 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 multiply every other value in `x` by a constant `alpha` starting from the second element, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +dscal.ndarray( 3, 5.0, x, 2, 1 ); +// x => [ 1.0, 10.0, 3.0, 20.0, 5.0, 30.0 ] +``` + +* * * + +### Module + +#### dscal.Module( memory ) + +Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new dscal.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); +``` + +#### dscal.Module.prototype.main( N, α, xp, sx ) + +Multiplies a vector `x` by a constant `α`. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var ones = require( '@stdlib/array/ones' ); +var zeros = require( '@stdlib/array/zeros' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new dscal.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointer (i.e., byte offsets) for storing input vector: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +mod.main( N, 5.0, xptr, 1 ); + +// Read out the results: +var view = zeros( N, dtype ); +mod.read( xptr, view ); + +console.log( view ); +// => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **α**: scalar constant. +- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sx**: index increment for `x`. + +#### dscal.Module.prototype.ndarray( N, α, xp, sx, ox ) + +Multiplies a vector `x` by a constant `α` using alternative indexing semantics. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var ones = require( '@stdlib/array/ones' ); +var zeros = require( '@stdlib/array/zeros' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new dscal.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointer (i.e., byte offsets) for storing input vector: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +mod.ndarray( N, 5.0, xptr, 1, 0 ); + +// Read out the results: +var view = zeros( N, dtype ); +mod.read( xptr, view ); + +console.log( view ); +// => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +``` + +The function has the following additional parameters: + +- **ox**: starting index for `x`. + +
+ + + +
+ +* * * + +## Notes + +- If `N <= 0`, `x` is left unchanged. +- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `dscal` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/blas/base/dscal`][@stdlib/blas/base/dscal]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/blas/base/dscal`][@stdlib/blas/base/dscal]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other. +- `dscal()` corresponds to the [BLAS][blas] level 1 function [`dscal`][dscal]. + +
+ + + +
+ +* * * + +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dscal = require( '@stdlib/blas/base/dscal-wasm' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, 0, 100, opts ); +console.log( x ); + +dscal.ndarray( x.length, 5.0, x, 1, 0 ); +console.log( x ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.js new file mode 100644 index 00000000000..936a8033c3f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dscal = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dscal.main( x.length, 1.01, x, 1 ); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.js new file mode 100644 index 00000000000..71cae7896a5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var pkg = require( './../package.json' ).name; +var dscal = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; + + +// MAIN // + +bench( pkg+':Module:constructor', opts, function benchmark( b ) { + var values; + var o; + var v; + var i; + + o = { + 'initial': 0 + }; + values = [ + new Memory( o ), + new Memory( o ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new dscal.Module( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.main.js new file mode 100644 index 00000000000..da9c5755614 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.main.js @@ -0,0 +1,135 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dscal = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var byteOffset; + var view; + var xptr; + var mod; + var mem; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new dscal.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*nb ); + + // Define pointer (i.e., byte offsets) to the vector elements: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + + // Retrieve a DataView of module memory: + view = mod.view; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + mod.main( len, 5.0, xptr, 1 ); + byteOffset = xptr + ( (i%len)*nb ); + if ( isnan( view.getFloat64( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( view.getFloat64( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.ndarray.js new file mode 100644 index 00000000000..ec1dfd190af --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.module.ndarray.js @@ -0,0 +1,135 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dscal = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var byteOffset; + var view; + var xptr; + var mod; + var mem; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new dscal.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*nb ); + + // Define pointers (i.e., byte offsets) to the first vector elements: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + + // Retrieve a DataView of module memory: + view = mod.view; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + mod.ndarray( len, 5.0, xptr, 1, 0 ); + byteOffset = xptr + ( (i%len)*nb ); + if ( isnan( view.getFloat64( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( view.getFloat64( byteOffset, true ) ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.ndarray.js new file mode 100644 index 00000000000..37ec7b271c9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/benchmark/benchmark.ndarray.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dscal = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = dscal.ndarray( x.length, 5.0, x, 1, 0 ); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y[ i%x.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/repl.txt new file mode 100644 index 00000000000..380939be55b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/repl.txt @@ -0,0 +1,520 @@ + +{{alias}}.main( N, alpha, x, strideX ) + Multiplies a vector `x` by a constant `alpha`. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0`, the function returns `x` unchanged. + + Parameters + ---------- + N: integer + Number of indexed elements. + + alpha: number + Constant. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + Returns + ------- + x: Float64Array + Input array. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0 ] ); + > {{alias}}.main( x.length, 5.0, x, 1 ) + [ -10.0, 5.0, 15.0, -25.0 ] + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0 ] ); + > {{alias}}.main( 2, 5.0, x, 2 ) + [ -10.0, 1.0, 15.0, -5.0 ] + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > {{alias}}.main( 2, 5.0, x1, 2 ) + [ -10.0, 3.0, -20.0 ] + > x0 + [ 1.0, -10.0, 3.0, -20.0 ] + + +{{alias}}.ndarray( N, alpha, x, strideX, offsetX ) + Multiplies a vector `x` by a constant `alpha` using alternative indexing + semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + alpha: number + Constant. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + Returns + ------- + x: Float64Array + Input array. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0 ] ); + > {{alias}}.ndarray( x.length, 5.0, x, 1, 0 ) + [ -10.0, 5.0, 15.0, -25.0 ] + + // Using an index offset: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0 ] ); + > {{alias}}.ndarray( 2, 5.0, x, 2, 1 ) + [ 1.0, -10.0, 3.0, -20.0, 5.0 ] + + +{{alias}}.Module( memory ) + Returns a new WebAssembly module wrapper which uses the provided WebAssembly + memory instance as its underlying memory. + + Parameters + ---------- + memory: Memory + WebAssembly memory instance. + + Returns + ------- + mod: Module + WebAssembly module wrapper. + + Examples + -------- + // Create a new memory instance: + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + + // Create a new routine: + > var mod = new {{alias}}.Module( mem ); + + // Initialize the routine: + > mod.initializeSync(); + + +{{alias}}.Module.prototype.binary + Read-only property which returns WebAssembly binary code. + + Returns + ------- + out: Uint8Array + WebAssembly binary code. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.binary + + + +{{alias}}.Module.prototype.memory + Read-only property which returns WebAssembly memory. + + Returns + ------- + mem: Memory|null + WebAssembly memory. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.memory + + + +{{alias}}.Module.prototype.buffer + Read-only property which returns a WebAssembly memory buffer as a + Uint8Array. + + Returns + ------- + buf: Uint8Array|null + WebAssembly memory buffer. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.buffer + + + +{{alias}}.Module.prototype.view + Read-only property which returns a WebAsssembly memory buffer as a DataView. + + Returns + ------- + view: DataView|null + WebAssembly memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.view + + + +{{alias}}.Module.prototype.exports + Read-only property which returns "raw" WebAssembly module exports. + + Returns + ------- + out: Object|null + WebAssembly module exports. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.exports + {...} + + +{{alias}}.Module.prototype.initialize() + Asynchronously initializes a WebAssembly module instance. + + Returns + ------- + p: Promise + Promise which resolves upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initialize(); + + +{{alias}}.Module.prototype.initializeAsync( clbk ) + Asynchronously initializes a WebAssembly module instance. + + Parameters + ---------- + clbk: Function + Callback to invoke upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > function clbk() { console.log( 'done' ) }; + > mod.initializeAsync( clbk ); + + +{{alias}}.Module.prototype.initializeSync() + Synchronously initializes a WebAssembly module instance. + + In web browsers, JavaScript engines may raise an exception when attempting + to synchronously compile large WebAssembly binaries due to concerns about + blocking the main thread. Hence, to initialize WebAssembly modules having + large binaries (e.g., >4KiB), consider using asynchronous initialization + methods in browser contexts. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + +{{alias}}.Module.prototype.realloc( nbytes ) + Reallocates the underlying WebAssembly memory instance to a specified number + of bytes. + + WebAssembly memory can only *grow*, not shrink. Hence, if provided a number + of bytes which is less than or equal to the size of the current memory, the + function does nothing. + + When non-shared memory is resized, the underlying the `ArrayBuffer` is + detached, consequently invalidating any associated typed array views. Before + resizing non-shared memory, ensure that associated typed array views no + longer need byte access and can be garbage collected. + + Parameters + ---------- + nbytes: integer + Memory size (in bytes). + + Returns + ------- + bool: boolean + Boolean indicating whether the resize operation was successful. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ) + + + +{{alias}}.Module.prototype.hasCapacity( byteOffset, values ) + Returns a boolean indicating whether the underlying WebAssembly memory + instance has the capacity to store a provided list of values starting from a + specified byte offset. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + bool: boolean + Boolean indicating whether the underlying WebAssembly memory instance + has enough capacity. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.hasCapacity( 0, [ 1, 2, 3, 4 ] ) + true + + +{{alias}}.Module.prototype.isView( values ) + Returns a boolean indicating whether a provided list of values is a view of + the underlying memory of the WebAssembly module. + + Parameters + ---------- + values: ArrayLikeObject + Input array. + + Returns + ------- + bool: boolean + Boolean indicating whether the list is a memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.isView( [ 1, 2, 3, 4 ] ) + false + + +{{alias}}.Module.prototype.write( byteOffset, values ) + Writes values to the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the input array. For example, if provided a Float32Array, + the function writes each element as a single-precision floating-point number + to the underlying WebAssembly memory instance. + + In order to write elements as a different data type, you need to perform an + explicit cast *before* calling this method. For example, in order to write + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must first convert the Float32Array to an + Int32Array before passing the values to this method. + + If provided an array having an unknown or "generic" data type, elements are + written as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + + +{{alias}}.Module.prototype.read( byteOffset, out ) + Reads values from the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the output array. For example, if provided a Float32Array, + the function reads each element as a single-precision floating-point number + from the underlying WebAssembly memory instance. + + In order to read elements as a different data type, you need to perform an + explicit cast *after* calling this method. For example, in order to read + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must convert the Float32Array to an Int32Array + after reading memory values using this method. + + If provided an output array having an unknown or "generic" data type, + elements are read as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start reading values. + + out: ArrayLikeObject + Output array for storing read values. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + > var out = [ 0, 0, 0, 0 ]; + > mod.read( 0, out ); + > out + [ 1, 2, 3, 4 ] + + +{{alias}}.Module.prototype.main( N, α, xp, sx ) + Multiples a vector `x` by a constant `α`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + α: number + Constant. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + Returns + ------- + xp: integer + Input array pointer (i.e., byte offset). + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointer" (i.e., byte offsets) into module memory: + > var xptr = 0; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + + // Perform computation: + > mod.main( 5, 5.0, xptr, 1 ); + + // Extract results from module memory: + > var view = {{alias:@stdlib/array/zeros}}( 5, 'float64' ); + > mod.read( xptr, view ); + > view + [ 5.0, 10.0, 15.0, 20.0, 25.0 ] + + +{{alias}}.Module.prototype.ndarray( N, α, xp, sx, ox ) + Multiples a vector `x` by a constant `α` using alternative indexing + semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + α: number + Constant. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + Returns + ------- + ox: integer + Input array pointer (i.e., byte offset). + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointer" (i.e., byte offsets) into module memory: + > var xptr = 0; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + + // Perform computation: + > mod.ndarray( 5, 5.0, xptr, 1, 0 ); + + // Extract results from module memory: + > var view = {{alias:@stdlib/array/zeros}}( 5, 'float64' ); + > mod.read( xptr, view ); + > view + [ 5.0, 10.0, 15.0, 20.0, 25.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/types/index.d.ts new file mode 100644 index 00000000000..ee27a09cc1f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/types/index.d.ts @@ -0,0 +1,376 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ModuleWrapper, Memory } from '@stdlib/types/wasm'; + +/** +* Interface defining a module constructor which is both "newable" and "callable". +*/ +interface ModuleConstructor { + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dscal.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.main( N, 5.0, xptr, 1 ); + * // returns + * + * var bool = ( ptr === xptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * mod.read( xptr, view ); + * // view => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] + */ + new( mem: Memory ): Module; // newable + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = dscal.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing input vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.main( N, 5.0, xptr, 1 ); + * // returns + * + * var bool = ( ptr === xptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * mod.read( xptr, view ); + * // view => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing a `dscal` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Multiplies a vector `x` by a constant `alpha`. + * + * @param N - number of indexed elements + * @param alpha - constant + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @returns input array pointer (i.e., byte offset) + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dscal.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.main( N, 5.0, xptr, 1 ); + * // returns + * + * var bool = ( ptr === xptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * mod.read( xptr, view ); + * // view => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] + */ + main( N: number, alpha: number, xptr: number, strideX: number ): number; + + /** + * Multiplies a vector `x` by a constant `alpha` using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param alpha - constant + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns input array pointer (i.e., byte offset) + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dscal.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.ndarray( N, 5.0, xptr, 1, 0 ); + * // returns + * + * var bool = ( ptr === xptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * mod.read( xptr, view ); + * // view => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] + */ + ndarray( N: number, alpha: number, xptr: number, strideX: number, offsetX: number ): number; +} + +/** +* Interface describing `dscal`. +*/ +interface Routine extends ModuleWrapper { + /** + * Multiplies a vector `x` by a constant `alpha`. + * + * @param N - number of indexed elements + * @param alpha - constant + * @param x - input array + * @param strideX - `x` stride length + * @returns input array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * dscal.main( x.length, 5.0, x, 1 ); + * // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] + */ + main( N: number, alpha: number, x: Float64Array, strideX: number ): Float64Array; + + /** + * Multiplies a vector `x` by a constant `alpha` using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param alpha - constant + * @param x - input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns input array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * dscal.ndarray( x.length, 5.0, x, 1, 0 ); + * // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] + */ + ndarray( N: number, alpha: number, x: Float64Array, strideX: number, offsetX: number ): Float64Array; + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dscal.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var ptr = mod.main( N, 5.0, xptr, 1 ); + * // returns + * + * var bool = ( ptr === xptr ); + * // returns true + * + * // Read out the results: + * var view = zeros( N, dtype ); + * mod.read( xptr, view ); + * // view => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] + */ + Module: ModuleConstructor; +} + +/** +* Multiplies a vector `x` by a constant `alpha`. +* +* @param N - number of indexed elements +* @param alpha - constant +* @param x - input array +* @param strideX - `x` stride length +* @returns input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* dscal.main( x.length, 5.0, x, 1 ); +* // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* dscal.ndarray( x.length, 5.0, x, 1, 0 ); +* // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ +declare var dscal: Routine; + + +// EXPORTS // + +export = dscal; diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/types/test.ts new file mode 100644 index 00000000000..c6b95d6060c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/docs/types/test.ts @@ -0,0 +1,413 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable space-in-parens */ + +import Memory = require( '@stdlib/wasm/memory' ); +import dscal = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + + dscal.main( x.length, 5.0, x, 1 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `main` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dscal.main( '10', 5.0, x, 1 ); // $ExpectError + dscal.main( true, 5.0, x, 1 ); // $ExpectError + dscal.main( false, 5.0, x, 1 ); // $ExpectError + dscal.main( null, 5.0, x, 1 ); // $ExpectError + dscal.main( undefined, 5.0, x, 1 ); // $ExpectError + dscal.main( [], 5.0, x, 1 ); // $ExpectError + dscal.main( {}, 5.0, x, 1 ); // $ExpectError + dscal.main( ( x: number ): number => x, 5.0, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dscal.main( x.length, '10', x, 1 ); // $ExpectError + dscal.main( x.length, true, x, 1 ); // $ExpectError + dscal.main( x.length, false, x, 1 ); // $ExpectError + dscal.main( x.length, null, x, 1 ); // $ExpectError + dscal.main( x.length, undefined, x, 1 ); // $ExpectError + dscal.main( x.length, [], x, 1 ); // $ExpectError + dscal.main( x.length, {}, x, 1 ); // $ExpectError + dscal.main( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dscal.main( x.length, 5.0, 10, 1 ); // $ExpectError + dscal.main( x.length, 5.0, '10', 1 ); // $ExpectError + dscal.main( x.length, 5.0, true, 1 ); // $ExpectError + dscal.main( x.length, 5.0, false, 1 ); // $ExpectError + dscal.main( x.length, 5.0, null, 1 ); // $ExpectError + dscal.main( x.length, 5.0, undefined, 1 ); // $ExpectError + dscal.main( x.length, 5.0, [], 1 ); // $ExpectError + dscal.main( x.length, 5.0, {}, 1 ); // $ExpectError + dscal.main( x.length, 5.0, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dscal.main( x.length, 5.0, x, '10' ); // $ExpectError + dscal.main( x.length, 5.0, x, true ); // $ExpectError + dscal.main( x.length, 5.0, x, false ); // $ExpectError + dscal.main( x.length, 5.0, x, null ); // $ExpectError + dscal.main( x.length, 5.0, x, undefined ); // $ExpectError + dscal.main( x.length, 5.0, x, [] ); // $ExpectError + dscal.main( x.length, 5.0, x, {} ); // $ExpectError + dscal.main( x.length, 5.0, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + dscal.main(); // $ExpectError + dscal.main( x.length ); // $ExpectError + dscal.main( x.length, 5.0 ); // $ExpectError + dscal.main( x.length, 5.0, x ); // $ExpectError + dscal.main( x.length, 5.0, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const x = new Float64Array( 10 ); + + dscal.ndarray( x.length, 5.0, x, 1, 0 ); // $ExpectType Float64Array +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dscal.ndarray( '10', 5.0, x, 1, 0 ); // $ExpectError + dscal.ndarray( true, 5.0, x, 1, 0 ); // $ExpectError + dscal.ndarray( false, 5.0, x, 1, 0 ); // $ExpectError + dscal.ndarray( null, 5.0, x, 1, 0 ); // $ExpectError + dscal.ndarray( undefined, 5.0, x, 1, 0 ); // $ExpectError + dscal.ndarray( [], 5.0, x, 1, 0 ); // $ExpectError + dscal.ndarray( {}, 5.0, x, 1, 0 ); // $ExpectError + dscal.ndarray( ( x: number ): number => x, 5.0, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dscal.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, [], x, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dscal.ndarray( x.length, 5.0, 10, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, '10', 1, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, true, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, false, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, null, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, undefined, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, [], 1, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, {}, 1, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dscal.ndarray( x.length, 5.0, x, '10', 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, true, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, false, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, null, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, undefined, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, [], 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, {}, 0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dscal.ndarray( x.length, 5.0, x, 1, '10' ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, 1, true ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, 1, false ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, 1, null ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, 1, undefined ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, 1, [] ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, 1, {} ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + dscal.ndarray(); // $ExpectError + dscal.ndarray( x.length ); // $ExpectError + dscal.ndarray( x.length, 5.0 ); // $ExpectError + dscal.ndarray( x.length, 5.0, x ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, 1 ); // $ExpectError + dscal.ndarray( x.length, 5.0, x, 1, 0, 10 ); // $ExpectError +} + +// Attached to the main export is a `Module` constructor which returns a module... +{ + const mem = new Memory({ + 'initial': 0 + }); + + dscal.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + dscal.Module( '10' ); // $ExpectError + dscal.Module( true ); // $ExpectError + dscal.Module( false ); // $ExpectError + dscal.Module( null ); // $ExpectError + dscal.Module( undefined ); // $ExpectError + dscal.Module( [] ); // $ExpectError + dscal.Module( {} ); // $ExpectError + dscal.Module( ( x: number ): number => x ); // $ExpectError +} + +// The `Module` constructor returns a module instance having a `main` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.main( 10, 5.0, 0, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.main( '10', 5.0, 10, 1 ); // $ExpectError + mod.main( true, 5.0, 10, 1 ); // $ExpectError + mod.main( false, 5.0, 10, 1 ); // $ExpectError + mod.main( null, 5.0, 10, 1 ); // $ExpectError + mod.main( undefined, 5.0, 10, 1 ); // $ExpectError + mod.main( [], 5.0, 10, 1 ); // $ExpectError + mod.main( {}, 5.0, 10, 1 ); // $ExpectError + mod.main( ( x: number ): number => x, 5.0, 10, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.main( 10, '10', 0, 1 ); // $ExpectError + mod.main( 10, true, 0, 1 ); // $ExpectError + mod.main( 10, false, 0, 1 ); // $ExpectError + mod.main( 10, null, 0, 1 ); // $ExpectError + mod.main( 10, undefined, 0, 1 ); // $ExpectError + mod.main( 10, [], 0, 1 ); // $ExpectError + mod.main( 10, {}, 0, 1 ); // $ExpectError + mod.main( 10, ( x: number ): number => x, 0, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.main( 10, 5.0, '10', 1 ); // $ExpectError + mod.main( 10, 5.0, true, 1 ); // $ExpectError + mod.main( 10, 5.0, false, 1 ); // $ExpectError + mod.main( 10, 5.0, null, 1 ); // $ExpectError + mod.main( 10, 5.0, undefined, 1 ); // $ExpectError + mod.main( 10, 5.0, [], 1 ); // $ExpectError + mod.main( 10, 5.0, {}, 1 ); // $ExpectError + mod.main( 10, 5.0, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.main( 10, 5.0, 0, '10' ); // $ExpectError + mod.main( 10, 5.0, 0, true ); // $ExpectError + mod.main( 10, 5.0, 0, false ); // $ExpectError + mod.main( 10, 5.0, 0, null ); // $ExpectError + mod.main( 10, 5.0, 0, undefined ); // $ExpectError + mod.main( 10, 5.0, 0, [] ); // $ExpectError + mod.main( 10, 5.0, 0, {} ); // $ExpectError + mod.main( 10, 5.0, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 5.0 ); // $ExpectError + mod.main( 10, 5.0, 0 ); // $ExpectError + mod.main( 10, 5.0, 0, 1, 10 ); // $ExpectError +} + +// The `Module` constructor returns a module instance having an `ndarray` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.ndarray( 10, 5.0, 0, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.ndarray( '10', 5.0, 0, 1, 0 ); // $ExpectError + mod.ndarray( true, 5.0, 0, 1, 0 ); // $ExpectError + mod.ndarray( false, 5.0, 0, 1, 0 ); // $ExpectError + mod.ndarray( null, 5.0, 0, 1, 0 ); // $ExpectError + mod.ndarray( undefined, 5.0, 0, 1, 0 ); // $ExpectError + mod.ndarray( [], 5.0, 0, 1, 0 ); // $ExpectError + mod.ndarray( {}, 5.0, 0, 1, 0 ); // $ExpectError + mod.ndarray( ( x: number ): number => x, 5.0, 0, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.ndarray( 10, '10', 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, true, 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, false, 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, null, 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, undefined, 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, [], 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, {}, 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, ( x: number ): number => x, 0, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.ndarray( 10, 5.0, '10', 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, true, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, false, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, null, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, undefined, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, [], 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, {}, 1, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.ndarray( 10, 5.0, 0, '10', 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, true, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, false, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, null, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, undefined, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, [], 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, {}, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fifth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.ndarray( 10, 5.0, 0, 1, '10' ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, true ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, false ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, null ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, undefined ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, [] ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, {} ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dscal.Module( mem ); + + mod.ndarray(); // $ExpectError + mod.ndarray( 10 ); // $ExpectError + mod.ndarray( 10, 5.0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1 ); // $ExpectError + mod.ndarray( 10, 5.0, 0, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/index.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/index.js new file mode 100644 index 00000000000..9a71316de58 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var oneTo = require( '@stdlib/array/one-to' ); +var dscal = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Specify a vector length: + var N = 5; + + // Create input array: + var x = oneTo( N, 'float64' ); + + // Perform computation: + dscal.ndarray( N, 5.0, x, 1, 0 ); + + // Print the results: + console.log( x ); + // => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/little_endian_arrays.js new file mode 100644 index 00000000000..ed522f89ea4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/little_endian_arrays.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); +var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +var dscal = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new dscal.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Specify a vector length: + var N = 5; + + // Define pointer (i.e., byte offsets) for storing input vector: + var xptr = 0; + + // Create a typed array view over module memory: + var x = new Float64ArrayLE( mod.memory.buffer, xptr, N ); + + // Write values to module memory: + gfillBy( N, x, 1, discreteUniform( -10.0, 10.0 ) ); + + // Perform computation: + mod.ndarray( N, 5.0, xptr, 1, 0 ); + + // Print the result: + console.log( 'x[:] = [%s]', x.toString() ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/module.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/module.js new file mode 100644 index 00000000000..abc9ae3f2fd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/examples/module.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var zeros = require( '@stdlib/array/zeros' ); +var dscal = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new dscal.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Define a vector data type: + var dtype = 'float64'; + + // Specify a vector length: + var N = 5; + + // Define pointer (i.e., byte offsets) for storing input vector: + var xptr = 0; + + // Write vector values to module memory: + mod.write( xptr, oneTo( N, dtype ) ); + + // Perform computation: + mod.ndarray( N, 5.0, xptr, 1, 0 ); + + // Read out the results: + var view = zeros( N, dtype ); + mod.read( xptr, view ); + + console.log( view ); + // => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/binary.browser.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/binary.browser.js new file mode 100644 index 00000000000..f9b99fd093f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAETA2AAAGAEf3x/fwBgBX98f39/AAIPAQNlbnYGbWVtb3J5AgAAAwQDAAECB0wEEV9fd2FzbV9jYWxsX2N0b3JzAAAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAHY19kc2NhbAABD2NfZHNjYWxfbmRhcnJheQACCtwEAwMAAQsjAQF+IAAgASACIAMgA6wiBEIBIACsfX5CACAEQgBXG6cQAguxBAEHfwJAIABBAEwNACABRAAAAAAAAPA/YQ0AIANBAUcEQCAAQQFrQQNPBEAgAEH8////B3EhByADIANqIgggA2oiCiADaiELA0AgAiAEQQN0aiIGIAEgBisDAKI5AwAgAiADIARqQQN0aiIGIAEgBisDAKI5AwAgAiAEIAhqQQN0aiIGIAEgBisDAKI5AwAgAiAEIApqQQN0aiIGIAEgBisDAKI5AwAgBCALaiEEIAVBBGoiBSAHRw0ACwsgAEEDcSIARQ0BQQAhBQNAIAIgBEEDdGoiByABIAcrAwCiOQMAIAMgBGohBCAFQQFqIgUgAEcNAAsMAQsCQCAAQQVwIgMiBUUNACADQQFrQQNPBEAgAkEYaiEIIAJBEGohCiACQQhqIQsgBUEEcSEGA0AgAiAEQQN0IgNqIgkgASAJKwMAojkDACADIAtqIgkgASAJKwMAojkDACADIApqIgkgASAJKwMAojkDACADIAhqIgMgASADKwMAojkDACAEQQRqIQQgB0EEaiIHIAZHDQALCyAFQQNxIgdFDQBBACEDA0AgAiAEQQN0aiIIIAEgCCsDAKI5AwAgBEEBaiEEIANBAWoiAyAHRw0ACwsgAEEFSA0AA0AgAiAEQQN0aiIDIAEgAysDAKI5AwAgAyABIAMrAwiiOQMIIAMgASADKwMQojkDECADIAEgAysDGKI5AxggAyABIAMrAyCiOQMgIARBBWohBCAFQQVqIgUgAEgNAAsLCw==' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/binary.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/binary.js new file mode 100644 index 00000000000..6f02393f96e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/binary.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readWASM = require( '@stdlib/fs/read-wasm' ).sync; + + +// MAIN // + +var wasm = readWASM( resolve( __dirname, '..', 'src', 'main.wasm' ) ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/index.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/index.js new file mode 100644 index 00000000000..c4e53a6e56d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/index.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* WebAssembly routine to multiply a vector `x` by a constant `alpha`. +* +* @module @stdlib/blas/base/dscal-wasm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dscal = require( '@stdlib/blas/base/dscal-wasm' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* dscal.main( x.length, 5.0, x, 1 ); +* // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dscal = require( '@stdlib/blas/base/dscal-wasm' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* dscal.ndarray( x.length, 5.0, x, 1, 0 ); +* // y => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var ones = require( '@stdlib/array/ones' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +* var dscal = require( '@stdlib/blas/base/dscal-wasm' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var mod = new dscal.Module( mem ); +* // returns +* +* // Initialize the routine: +* mod.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing input vectors: +* var xptr = 0; +* +* // Write vector values to module memory: +* mod.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* mod.main( N, 5.0, xptr, 1 ); +* +* // Read out the results: +* var view = zeros( N, dtype ); +* mod.read( xptr, view ); +* +* console.log( view ); +* // => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var Module = require( './module.js' ); + + +// MAIN // + +setReadOnly( main, 'Module', Module ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "Module": "main.Module" } diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/main.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/main.js new file mode 100644 index 00000000000..1cdd04840c3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/main.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var Routine = require( './routine.js' ); + + +// MAIN // + +/** +* WebAssembly module to multiply a vector `x` by a constant `alpha`. +* +* @name dscal +* @type {Routine} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* dscal.main( x.length, 5.0, x, 1 ); +* // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* dscal.ndarray( x.length, 5.0, x, 1, 0 ); +* // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ +var dscal = new Routine(); +dscal.initializeSync(); // eslint-disable-line node/no-sync + + +// EXPORTS // + +module.exports = dscal; diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/module.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/module.js new file mode 100644 index 00000000000..6b31313e5fa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/module.js @@ -0,0 +1,235 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var WasmModule = require( '@stdlib/wasm/module-wrapper' ); +var format = require( '@stdlib/string/format' ); +var wasmBinary = require( './binary.js' ); + + +// MAIN // + +/** +* BLAS routine WebAssembly module wrapper constructor. +* +* @constructor +* @param {Object} memory - WebAssembly memory instance +* @throws {TypeError} must provide a WebAssembly memory instance +* @returns {Module} module instance +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var ones = require( '@stdlib/array/ones' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var dscal = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dscal.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dscal.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var ptr = dscal.main( N, 5.0, xptr, 1 ); +* // returns +* +* var bool = ( ptr === xptr ); +* // returns true +* +* // Read out the results: +* var view = zeros( N, dtype ); +* dscal.read( xptr, view ); +* // view => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ +function Module( memory ) { + if ( !( this instanceof Module ) ) { + return new Module( memory ); + } + if ( !isWebAssemblyMemory( memory ) ) { + throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) ); + } + // Call the parent constructor: + WasmModule.call( this, wasmBinary, memory, { + 'env': { + 'memory': memory + } + }); + + return this; +} + +// Inherit from the parent constructor: +inherits( Module, WasmModule ); + +/** +* Multiplies a vector `x` by a constant `alpha`. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - scalar +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @returns {NonNegativeInteger} input array pointer (i.e., byte offset) +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var ones = require( '@stdlib/array/ones' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var dscal = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dscal.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dscal.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var ptr = dscal.main( N, 5.0, xptr, 1 ); +* // returns +* +* var bool = ( ptr === xptr ); +* // returns true +* +* // Read out the results: +* var view = zeros( N, dtype ); +* dscal.read( xptr, view ); +* // view => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ +setReadOnly( Module.prototype, 'main', function dscal( N, alpha, xptr, strideX ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point + this._instance.exports.c_dscal( N, alpha, xptr, strideX ); + return xptr; +}); + +/** +* Multiplies a vector `x` by a constant `alpha` using alternative indexing semantics. +* +* @name ndarray +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - scalar +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @returns {NonNegativeInteger} input array pointer (i.e., byte offset) +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var ones = require( '@stdlib/array/ones' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var dscal = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dscal.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing input vectors: +* var xptr = 0; +* +* // Write vector values to module memory: +* dscal.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var ptr = dscal.ndarray( N, 5.0, xptr, 1, 0 ); +* // returns +* +* var bool = ( ptr === xptr ); +* // returns true +* +* // Read out the results: +* var view = zeros( N, dtype ); +* dscal.read( xptr, view ); +* // view => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ +setReadOnly( Module.prototype, 'ndarray', function dscal( N, alpha, xptr, strideX, offsetX ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point + this._instance.exports.c_dscal_ndarray( N, alpha, xptr, strideX, offsetX ); + return xptr; +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/routine.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/routine.js new file mode 100644 index 00000000000..8c81d5235ad --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/lib/routine.js @@ -0,0 +1,175 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var readDataView = require( '@stdlib/strided/base/read-dataview' ).ndarray; +var Memory = require( '@stdlib/wasm/memory' ); +var arrays2ptrs = require( '@stdlib/wasm/base/arrays2ptrs' ); +var strided2object = require( '@stdlib/wasm/base/strided2object' ); +var Module = require( './module.js' ); + + +// MAIN // + +/** +* Routine constructor. +* +* @private +* @constructor +* @returns {Routine} routine instance +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dscal = new Routine(); +* +* // Initialize the module: +* dscal.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* dscal.main( x.length, 5.0, x, 1 ); +* // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dscal = new Routine(); +* +* // Initialize the module: +* dscal.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* dscal.ndarray( x.length, 5.0, x, 1, 0 ); +* // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ +function Routine() { + if ( !( this instanceof Routine ) ) { + return new Routine(); + } + Module.call( this, new Memory({ + 'initial': 0 + })); + return this; +} + +// Inherit from the parent constructor: +inherits( Routine, Module ); + +/** +* Multiplies a vector `x` by a constant `alpha`. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - scalar +* @param {Float64Array} x - input array +* @param {integer} strideX - `x` stride length +* @returns {Float64Array} input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dscal = new Routine(); +* +* // Initialize the module: +* dscal.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* dscal.main( x.length, 5.0, x, 1 ); +* // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ +setReadOnly( Routine.prototype, 'main', function dscal( N, alpha, x, strideX ) { + return this.ndarray( N, alpha, x, strideX, stride2offset( N, strideX ) ); +}); + +/** +* Multiplies a vector `x` by a constant `alpha` using alternative indexing semantics. +* +* @name ndarray +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {number} alpha - scalar +* @param {Float64Array} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @returns {Float64Array} input array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dscal = new Routine(); +* +* // Initialize the module: +* dscal.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* dscal.ndarray( x.length, 5.0, x, 1, 0 ); +* // x => [ 5.0, 10.0, 15.0, 20.0, 25.0 ] +*/ +setReadOnly( Routine.prototype, 'ndarray', function dscal( N, alpha, x, strideX, offsetX ) { + var ptrs; + var p0; + + // Convert the input arrays to "pointers" in the module's memory: + ptrs = arrays2ptrs( this, [ + strided2object( N, x, strideX, offsetX ) + ]); + p0 = ptrs[0]; + + // Perform computation by calling the corresponding parent method: + Module.prototype.ndarray.call( this, N, alpha, p0.ptr, p0.stride, p0.offset ); // eslint-disable-line max-len + + // If the input array data had to be copied to module memory, copy the results to the provided input array... + if ( p0.copy ) { + readDataView( N, this.view, p0.stride*p0.BYTES_PER_ELEMENT, p0.ptr, x, strideX, offsetX, true ); // eslint-disable-line max-len + } + return x; +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/manifest.json b/lib/node_modules/@stdlib/blas/base/dscal-wasm/manifest.json new file mode 100644 index 00000000000..848e2505924 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/dscal" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/package.json b/lib/node_modules/@stdlib/blas/base/dscal-wasm/package.json new file mode 100644 index 00000000000..de247b938fe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/package.json @@ -0,0 +1,80 @@ +{ + "name": "@stdlib/blas/base/dscal-wasm", + "version": "0.0.0", + "description": "Multiply a vector `x` by a scalar `alpha`.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": { + "./lib/binary.js": "./lib/binary.browser.js" + }, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "dscal", + "linear", + "algebra", + "subroutines", + "alpha", + "vector", + "array", + "ndarray", + "float64", + "double", + "float64array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/scripts/build.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/scripts/build.js new file mode 100644 index 00000000000..348354d7029 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/scripts/build.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var replace = require( '@stdlib/string/replace' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/scripts/template.txt b/lib/node_modules/@stdlib/blas/base/dscal-wasm/scripts/template.txt new file mode 100644 index 00000000000..12996dd89e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( '{{WASM_BASE64}}' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/src/Makefile b/lib/node_modules/@stdlib/blas/base/dscal-wasm/src/Makefile new file mode 100644 index 00000000000..3930516cfaa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/src/Makefile @@ -0,0 +1,232 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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. +#/ + +#/ +# To compile targets listed in this Makefile, use top-level project `make` +# commands rather than commands listed in this Makefile. The top-level project +# `make` commands will ensure that various environment variables and flags are +# appropriately set. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files to WebAssembly: +ifdef EMCC_COMPILER + EMCC := $(EMCC_COMPILER) +else + EMCC := emcc +endif + +# Define the program used for compiling WebAssembly files to the WebAssembly text format: +ifdef WASM2WAT + WASM_TO_WAT := $(WASM2WAT) +else + WASM_TO_WAT := wasm2wat +endif + +# Define the program used for compiling WebAssembly files to JavaScript: +ifdef WASM2JS + WASM_TO_JS := $(WASM2JS) +else + WASM_TO_JS := wasm2js +endif + +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic \ + -D CBLAS_INT=int32_t + +# Define the command-line options when compiling C files to WebAssembly and asm.js: +EMCCFLAGS ?= $(CFLAGS) + +# Define shared `emcc` flags: +EMCC_SHARED_FLAGS := \ + -s SIDE_MODULE=2 \ + -s WASM_BIGINT=0 \ + -s EXPORTED_FUNCTIONS="['_c_dscal','_c_dscal_ndarray']" + +# Define WebAssembly `emcc` flags: +EMCC_WASM_FLAGS := $(EMCC_SHARED_FLAGS) \ + -s WASM=1 + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of WebAssembly targets: +wasm_targets := main.wasm + +# List of WebAssembly WAT targets: +wat_targets := main.wat + +# List of WebAssembly JavaScript targets: +wasm_js_targets := main.wasm.js + +# List of other JavaScript targets: +browser_js_targets := ./../lib/binary.browser.js + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: wasm + +.PHONY: all + +#/ +# Compiles source files to WebAssembly. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make wasm +#/ +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) + +.PHONY: wasm + +#/ +# Compiles C source files to WebAssembly binaries. +# +# @private +# @param {string} EMCC - EMCC compiler (e.g., `emcc`) +# @param {string} EMCCFLAGS - EMCC compiler options +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(wasm_targets): + $(QUIET) $(EMCC) $(EMCCFLAGS) $(EMCC_WASM_FLAGS) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Compiles WebAssembly binary files to the WebAssembly text format. +# +# @private +# @param {string} WASM2WAT - WAT compiler (e.g., `wasm2wat`) +#/ +$(wat_targets): %.wat: %.wasm + $(QUIET) $(WASM_TO_WAT) -o $@ $(wasm_targets) + +#/ +# Compiles WebAssembly binary files to JavaScript. +# +# @private +# @param {string} WASM2JS - JavaScript compiler (e.g., `wasm2js`) +#/ +$(wasm_js_targets): %.wasm.js: %.wasm + $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) + +#/ +# Generates an inline WebAssembly build for use in bundlers. +# +# @private +# @param {string} NODE - Node.js executable +#/ +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + +#/ +# Removes generated WebAssembly files. +# +# @example +# make clean-wasm +#/ +clean-wasm: + $(QUIET) -rm -f *.wasm *.wat *.wasm.js + +.PHONY: clean-wasm + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-wasm + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/src/main.wasm b/lib/node_modules/@stdlib/blas/base/dscal-wasm/src/main.wasm new file mode 100755 index 0000000000000000000000000000000000000000..81f50294979c0847e225cf2ac2b65f5d229cfbdd GIT binary patch literal 754 zcmZ`$O^?$s5S{VZaW4sv04r*apagrZ4YGAue1VHg3W*7!euY~ zAASTs0I7_Vw!3H-A8fy|-@JJ2V0=bnfU$1AHVuqTI2urW zq}k$gG@s3v^-ckhCO~Dc^wT{5BB}C8QC0b5yR0_=!$YiCt*Tu2 zS3UXr4%+qmZ6Sy8~CqjQnb8Es1+iDdMW;QJeb zR$G^k#WlzOi6@W5HM=s^Y%*PX!}hWV&Pipo_Hfa|3{rEi0xK2RV+F*zV`5-JU_L?D zdNwOh-duE64<1!EEYp}(HYn3Xj#$hE*>xJ76uj6z6OFSw4fi0DJcz`lCt=Z%rNxYR zvcZ$(sPklkCo46HCpsyHUL(hMObkpJP)K>|hI!wEdz62~4j`7P$k@6v1_B00FcdI6 S0v5nBPt&!|w5^lu&bhzPR(!7j literal 0 HcmV?d00001 diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/src/main.wat b/lib/node_modules/@stdlib/blas/base/dscal-wasm/src/main.wat new file mode 100644 index 00000000000..3f8a006dbbd --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/src/main.wat @@ -0,0 +1,350 @@ +;; @license Apache-2.0 +;; +;; Copyright (c) 2024 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. + +(module + (type (;0;) (func)) + (type (;1;) (func (param i32 f64 i32 i32))) + (type (;2;) (func (param i32 f64 i32 i32 i32))) + (import "env" "memory" (memory (;0;) 0)) + (func (;0;) (type 0) + nop) + (func (;1;) (type 1) (param i32 f64 i32 i32) + (local i64) + local.get 0 + local.get 1 + local.get 2 + local.get 3 + local.get 3 + i64.extend_i32_s + local.tee 4 + i64.const 1 + local.get 0 + i64.extend_i32_s + i64.sub + i64.mul + i64.const 0 + local.get 4 + i64.const 0 + i64.le_s + select + i32.wrap_i64 + call 2) + (func (;2;) (type 2) (param i32 f64 i32 i32 i32) + (local i32 i32 i32 i32 i32 i32 i32) + block ;; label = @1 + local.get 0 + i32.const 0 + i32.le_s + br_if 0 (;@1;) + local.get 1 + f64.const 0x1p+0 (;=1;) + f64.eq + br_if 0 (;@1;) + local.get 3 + i32.const 1 + i32.ne + if ;; label = @2 + local.get 0 + i32.const 1 + i32.sub + i32.const 3 + i32.ge_u + if ;; label = @3 + local.get 0 + i32.const 2147483644 + i32.and + local.set 7 + local.get 3 + local.get 3 + i32.add + local.tee 8 + local.get 3 + i32.add + local.tee 10 + local.get 3 + i32.add + local.set 11 + loop ;; label = @4 + local.get 2 + local.get 4 + i32.const 3 + i32.shl + i32.add + local.tee 6 + local.get 1 + local.get 6 + f64.load + f64.mul + f64.store + local.get 2 + local.get 3 + local.get 4 + i32.add + i32.const 3 + i32.shl + i32.add + local.tee 6 + local.get 1 + local.get 6 + f64.load + f64.mul + f64.store + local.get 2 + local.get 4 + local.get 8 + i32.add + i32.const 3 + i32.shl + i32.add + local.tee 6 + local.get 1 + local.get 6 + f64.load + f64.mul + f64.store + local.get 2 + local.get 4 + local.get 10 + i32.add + i32.const 3 + i32.shl + i32.add + local.tee 6 + local.get 1 + local.get 6 + f64.load + f64.mul + f64.store + local.get 4 + local.get 11 + i32.add + local.set 4 + local.get 5 + i32.const 4 + i32.add + local.tee 5 + local.get 7 + i32.ne + br_if 0 (;@4;) + end + end + local.get 0 + i32.const 3 + i32.and + local.tee 0 + i32.eqz + br_if 1 (;@1;) + i32.const 0 + local.set 5 + loop ;; label = @3 + local.get 2 + local.get 4 + i32.const 3 + i32.shl + i32.add + local.tee 7 + local.get 1 + local.get 7 + f64.load + f64.mul + f64.store + local.get 3 + local.get 4 + i32.add + local.set 4 + local.get 5 + i32.const 1 + i32.add + local.tee 5 + local.get 0 + i32.ne + br_if 0 (;@3;) + end + br 1 (;@1;) + end + block ;; label = @2 + local.get 0 + i32.const 5 + i32.rem_u + local.tee 3 + local.tee 5 + i32.eqz + br_if 0 (;@2;) + local.get 3 + i32.const 1 + i32.sub + i32.const 3 + i32.ge_u + if ;; label = @3 + local.get 2 + i32.const 24 + i32.add + local.set 8 + local.get 2 + i32.const 16 + i32.add + local.set 10 + local.get 2 + i32.const 8 + i32.add + local.set 11 + local.get 5 + i32.const 4 + i32.and + local.set 6 + loop ;; label = @4 + local.get 2 + local.get 4 + i32.const 3 + i32.shl + local.tee 3 + i32.add + local.tee 9 + local.get 1 + local.get 9 + f64.load + f64.mul + f64.store + local.get 3 + local.get 11 + i32.add + local.tee 9 + local.get 1 + local.get 9 + f64.load + f64.mul + f64.store + local.get 3 + local.get 10 + i32.add + local.tee 9 + local.get 1 + local.get 9 + f64.load + f64.mul + f64.store + local.get 3 + local.get 8 + i32.add + local.tee 3 + local.get 1 + local.get 3 + f64.load + f64.mul + f64.store + local.get 4 + i32.const 4 + i32.add + local.set 4 + local.get 7 + i32.const 4 + i32.add + local.tee 7 + local.get 6 + i32.ne + br_if 0 (;@4;) + end + end + local.get 5 + i32.const 3 + i32.and + local.tee 7 + i32.eqz + br_if 0 (;@2;) + i32.const 0 + local.set 3 + loop ;; label = @3 + local.get 2 + local.get 4 + i32.const 3 + i32.shl + i32.add + local.tee 8 + local.get 1 + local.get 8 + f64.load + f64.mul + f64.store + local.get 4 + i32.const 1 + i32.add + local.set 4 + local.get 3 + i32.const 1 + i32.add + local.tee 3 + local.get 7 + i32.ne + br_if 0 (;@3;) + end + end + local.get 0 + i32.const 5 + i32.lt_s + br_if 0 (;@1;) + loop ;; label = @2 + local.get 2 + local.get 4 + i32.const 3 + i32.shl + i32.add + local.tee 3 + local.get 1 + local.get 3 + f64.load + f64.mul + f64.store + local.get 3 + local.get 1 + local.get 3 + f64.load offset=8 + f64.mul + f64.store offset=8 + local.get 3 + local.get 1 + local.get 3 + f64.load offset=16 + f64.mul + f64.store offset=16 + local.get 3 + local.get 1 + local.get 3 + f64.load offset=24 + f64.mul + f64.store offset=24 + local.get 3 + local.get 1 + local.get 3 + f64.load offset=32 + f64.mul + f64.store offset=32 + local.get 4 + i32.const 5 + i32.add + local.set 4 + local.get 5 + i32.const 5 + i32.add + local.tee 5 + local.get 0 + i32.lt_s + br_if 0 (;@2;) + end + end) + (export "__wasm_call_ctors" (func 0)) + (export "__wasm_apply_data_relocs" (func 0)) + (export "c_dscal" (func 1)) + (export "c_dscal_ndarray" (func 2))) diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.js new file mode 100644 index 00000000000..f058cbd959d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var dscal = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dscal, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `main` method', function test( t ) { + t.strictEqual( typeof dscal.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof dscal.ndarray, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `Module` constructor', function test( t ) { + t.strictEqual( typeof dscal.Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the main export is a `Module` instance', function test( t ) { + t.strictEqual( dscal instanceof dscal.Module, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.main.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.main.js new file mode 100644 index 00000000000..b76dcbbe730 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.main.js @@ -0,0 +1,186 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dscal = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dscal, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `main` method has an arity of 4', function test( t ) { + t.strictEqual( dscal.main.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method multiplies `x` by a constant `alpha`', function test( t ) { + var expected; + var alpha; + var x; + + alpha = 2.0; + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + expected = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + + dscal.main( x.length, alpha, x, 1 ); + + t.deepEqual( x, expected, 'returns expected value' ); + + // Short datasets: + x = new Float64Array( [ 1.0, 2.0 ] ); + + expected = new Float64Array( [ 2.0, 4.0 ] ); + + dscal.main( x.length, alpha, x, 1 ); + + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports an `x` stride', function test( t ) { + var expected; + var x; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + N = 3; + + dscal.main( N, 2.0, x, 2 ); + + expected = new Float64Array( [ 2.0, 2.0, 6.0, 4.0, 10.0 ] ); + + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method returns a reference to the output array', function test( t ) { + var out; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + out = dscal.main( x.length, 3.0, x, 1 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `main` method returns the input array unchanged', function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + dscal.main( -1, 3.0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + dscal.main( 0, 3.0, x, 1 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports specifying a negative stride', function test( t ) { + var expected; + var x; + var N; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + N = 3; + + dscal.main( N, 3.0, x, -2 ); + + expected = new Float64Array( [ 3.0, 2.0, 9.0, 4.0, 15.0 ] ); + + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports complex access patterns', function test( t ) { + var expected; + var x; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ]); + N = 3; + + dscal.main( N, 3.0, x, 2 ); + + expected = new Float64Array( [ 3.0, 2.0, 9.0, 4.0, 15.0, 6.0 ] ); + + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports view offsets', function test( t ) { + var expected; + var x0; + var x1; + + // Initial array: + x0 = new Float64Array([ + 1.0, + 2.0, // 2 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 0 + ]); + + // Create offset view: + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + + dscal.main( 3, 3.0, x1, -2 ); + expected = new Float64Array( [ 1.0, 6.0, 3.0, 12.0, 5.0, 18.0 ] ); + + t.deepEqual( x0, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.js new file mode 100644 index 00000000000..9adcb07e22f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = Module( mem ); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Module( value ); + }; + } +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (no new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Module( value ); // eslint-disable-line new-cap + }; + } +}); + +tape( 'the module instance returned by the module constructor inherits from a module wrapper', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.main.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.main.js new file mode 100644 index 00000000000..236ab30f37a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.main.js @@ -0,0 +1,253 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which has an arity of 4', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.main.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which multiplies `x` by a constant `alpha`', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + expected = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + + mod.main( 5, 2.0, xp, 1 ); + + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + // Short datasets: + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0 ] ) ); + + expected = new Float64Array( [ 2.0, 4.0 ] ); + + mod.main( 2, 2.0, xp, 1 ); + + actual = new Float64Array( 2 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports an `x` stride', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ])); + N = 3; + + mod.main( N, 2.0, xp, 2 ); + + expected = new Float64Array( [ 2.0, 2.0, 6.0, 4.0, 10.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which returns a pointer to the input array', function test( t ) { + var out; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + out = mod.main( 5, 3.0, xp, 1 ); + + t.strictEqual( out, xp, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has a `main` method which leaves the input array unchanged', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + mod.main( -1, 3.0, xp, 1 ); + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mod.main( 0, 3.0, xp, 1 ); + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports specifying a negative stride', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + N = 3; + + mod.main( N, 3.0, xp, -2 ); + + expected = new Float64Array( [ 3.0, 2.0, 9.0, 4.0, 15.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports complex access patterns', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ])); + N = 3; + + mod.main( N, 3.0, xp, 2 ); + + expected = new Float64Array( [ 3.0, 2.0, 9.0, 4.0, 15.0, 6.0 ] ); + + actual = new Float64Array( 6 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.ndarray.js new file mode 100644 index 00000000000..b3490020b16 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.module.ndarray.js @@ -0,0 +1,289 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which has an arity of 5', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.ndarray.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which multiplies `x` by a constant `alpha`', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + expected = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + + mod.ndarray( 5, 2.0, xp, 1, 0 ); + + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + // Short datasets: + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0 ] ) ); + + expected = new Float64Array( [ 2.0, 4.0 ] ); + + mod.ndarray( 2, 2.0, xp, 1, 0 ); + + actual = new Float64Array( 2 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` stride', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ])); + N = 3; + + mod.ndarray( N, 2.0, xp, 2, 0 ); + + expected = new Float64Array( [ 2.0, 2.0, 6.0, 4.0, 10.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` offset', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 1 + 5.0 // 2 + ])); + N = 3; + + mod.ndarray( N, 3.0, xp, 1, 2 ); + + expected = new Float64Array( [ 1.0, 2.0, 9.0, 12.0, 15.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which returns a pointer to the input array', function test( t ) { + var out; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + out = mod.ndarray( 5, 3.0, xp, 1, 0 ); + + t.strictEqual( out, xp, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has an `ndarray` method which leaves the input array unchanged', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + mod.ndarray( -1, 3.0, xp, 1, 0 ); + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + mod.ndarray( 0, 3.0, xp, 1, 0 ); + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports negative strides', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + N = 3; + + mod.ndarray( N, 3.0, xp, -2, 4 ); + + expected = new Float64Array( [ 3.0, 2.0, 9.0, 4.0, 15.0 ] ); + + actual = new Float64Array( 5 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports complex access patterns', function test( t ) { + var expected; + var actual; + var mem; + var mod; + var xp; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 0 + 6.0 + ])); + N = 3; + + mod.ndarray( N, 3.0, xp, -2, 4 ); + + expected = new Float64Array( [ 3.0, 2.0, 9.0, 4.0, 15.0, 6.0 ] ); + + actual = new Float64Array( 6 ); + mod.read( xp, actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.ndarray.js new file mode 100644 index 00000000000..3465293b009 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.ndarray.js @@ -0,0 +1,183 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dscal = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dscal, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `ndarray` method has an arity of 5', function test( t ) { + t.strictEqual( dscal.ndarray.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method multiplies `x` by a constant `alpha`', function test( t ) { + var expected; + var alpha; + var x; + + alpha = 2.0; + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + expected = new Float64Array( [ 2.0, 4.0, 6.0, 8.0, 10.0 ] ); + + dscal.ndarray( x.length, alpha, x, 1, 0 ); + + t.deepEqual( x, expected, 'returns expected value' ); + + // Short datasets: + x = new Float64Array( [ 1.0, 2.0 ] ); + + expected = new Float64Array( [ 2.0, 4.0 ] ); + + dscal.ndarray( x.length, alpha, x, 1, 0 ); + + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports an `x` stride', function test( t ) { + var expected; + var x; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + N = 3; + + dscal.ndarray( N, 2.0, x, 2, 0 ); + + expected = new Float64Array( [ 2.0, 2.0, 6.0, 4.0, 10.0 ] ); + + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports an `x` offset', function test( t ) { + var expected; + var x; + var N; + + x = new Float64Array([ + 1.0, + 2.0, + 3.0, // 0 + 4.0, // 1 + 5.0 // 2 + ]); + N = 3; + + dscal.ndarray( N, 3.0, x, 1, 2 ); + + expected = new Float64Array( [ 1.0, 2.0, 9.0, 12.0, 15.0 ] ); + + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method returns a reference to the input array', function test( t ) { + var out; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + out = dscal.ndarray( x.length, 3.0, x, 1, 0 ); + + t.strictEqual( out, x, 'same reference' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `ndarray` method returns the input array unchanged', function test( t ) { + var expected; + var x; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + dscal.ndarray( -1, 3.0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + dscal.ndarray( 0, 3.0, x, 1, 0 ); + t.deepEqual( x, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports specifying a negative stride', function test( t ) { + var expected; + var x; + var N; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + N = 3; + + dscal.ndarray( N, 3.0, x, -2, x.length-1 ); + + expected = new Float64Array( [ 3.0, 2.0, 9.0, 4.0, 15.0 ] ); + + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports complex access patterns', function test( t ) { + var expected; + var x; + var N; + + x = new Float64Array([ + 1.0, + 2.0, // 2 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 0 + ]); + N = 3; + + dscal.ndarray( N, 3.0, x, -2, 5 ); + + expected = new Float64Array( [ 1.0, 6.0, 3.0, 12.0, 5.0, 18.0 ] ); + + t.deepEqual( x, expected, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.routine.js b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.routine.js new file mode 100644 index 00000000000..56a4b67daaf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dscal-wasm/test/test.routine.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib/module.js' ); +var Routine = require( './../lib/routine.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Routine, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mod = Routine(); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a module wrapper', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a BLAS routine module', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); From 200e78af939661bb4f435dc4f523cb57594c003e Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Fri, 18 Oct 2024 13:18:32 +0200 Subject: [PATCH 43/50] docs: add missing comma --- lib/node_modules/@stdlib/blas/base/dscal/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/dscal/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/dscal/docs/repl.txt index 611b788f461..c862df078f7 100644 --- a/lib/node_modules/@stdlib/blas/base/dscal/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/dscal/docs/repl.txt @@ -9,7 +9,7 @@ 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 `x` unchanged. Parameters ---------- From 1594f0f4dc6ff16c5b44a7ae6428784ff76f2b75 Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Fri, 18 Oct 2024 17:56:14 +0530 Subject: [PATCH 44/50] feat: add `blas/base/ddot-wasm` PR-URL: https://github.com/stdlib-js/stdlib/pull/2986 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/blas/base/ddot-wasm/README.md | 324 +++++++++++ .../base/ddot-wasm/benchmark/benchmark.js | 107 ++++ .../ddot-wasm/benchmark/benchmark.module.js | 66 +++ .../benchmark/benchmark.module.main.js | 133 +++++ .../benchmark/benchmark.module.ndarray.js | 133 +++++ .../ddot-wasm/benchmark/benchmark.ndarray.js | 107 ++++ .../@stdlib/blas/base/ddot-wasm/docs/repl.txt | 543 ++++++++++++++++++ .../blas/base/ddot-wasm/docs/types/index.d.ts | 357 ++++++++++++ .../blas/base/ddot-wasm/docs/types/test.ts | 528 +++++++++++++++++ .../blas/base/ddot-wasm/examples/index.js | 45 ++ .../examples/little_endian_arrays.js | 73 +++ .../blas/base/ddot-wasm/examples/module.js | 67 +++ .../blas/base/ddot-wasm/lib/binary.browser.js | 33 ++ .../@stdlib/blas/base/ddot-wasm/lib/binary.js | 34 ++ .../@stdlib/blas/base/ddot-wasm/lib/index.js | 108 ++++ .../@stdlib/blas/base/ddot-wasm/lib/main.js | 62 ++ .../@stdlib/blas/base/ddot-wasm/lib/module.js | 218 +++++++ .../blas/base/ddot-wasm/lib/routine.js | 178 ++++++ .../@stdlib/blas/base/ddot-wasm/manifest.json | 36 ++ .../@stdlib/blas/base/ddot-wasm/package.json | 80 +++ .../blas/base/ddot-wasm/scripts/build.js | 63 ++ .../blas/base/ddot-wasm/scripts/template.txt | 33 ++ .../@stdlib/blas/base/ddot-wasm/src/Makefile | 232 ++++++++ .../@stdlib/blas/base/ddot-wasm/src/main.wasm | Bin 0 -> 764 bytes .../@stdlib/blas/base/ddot-wasm/src/main.wat | 368 ++++++++++++ .../@stdlib/blas/base/ddot-wasm/test/test.js | 53 ++ .../blas/base/ddot-wasm/test/test.main.js | 209 +++++++ .../blas/base/ddot-wasm/test/test.module.js | 154 +++++ .../base/ddot-wasm/test/test.module.main.js | 252 ++++++++ .../ddot-wasm/test/test.module.ndarray.js | 329 +++++++++++ .../blas/base/ddot-wasm/test/test.ndarray.js | 231 ++++++++ .../blas/base/ddot-wasm/test/test.routine.js | 71 +++ 32 files changed, 5227 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/little_endian_arrays.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/binary.browser.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/binary.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/routine.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/scripts/build.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/scripts/template.txt create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/src/Makefile create mode 100755 lib/node_modules/@stdlib/blas/base/ddot-wasm/src/main.wasm create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/src/main.wat create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.routine.js diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/README.md b/lib/node_modules/@stdlib/blas/base/ddot-wasm/README.md new file mode 100644 index 00000000000..f13388eea67 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/README.md @@ -0,0 +1,324 @@ + + +# ddot + +> Compute the dot product of `x` and `y`. + +
+ +## Usage + +```javascript +var ddot = require( '@stdlib/blas/base/ddot-wasm' ); +``` + +#### ddot.main( N, x, strideX, y, strideY ) + +Computes the dot product of `x` and `y`. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); +var y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + +var z = ddot.main( x.length, x, 1, y, 1 ); +// returns -5.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: first input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: index increment for `x`. +- **y**: second input [`Float64Array`][@stdlib/array/float64]. +- **strideY**: index increment for `y`. + +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 Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + +var z = ddot.main( 3, x, 2, y, -1 ); +// returns 9.0 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial arrays... +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +// Create offset views... +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element + +var z = ddot.main( 3, x1, -2, y1, 1 ); +// returns 128.0 +``` + +#### ddot.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + +Computes the dot product of `x` and `y` using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); +var y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + +var z = ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); +// returns -5.0 +``` + +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 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 Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + +var z = ddot.ndarray( 3, x, 2, 1, y, -1, y.length-1 ); +// returns 128.0 +``` + +* * * + +### Module + +#### ddot.Module( memory ) + +Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new ddot.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); +``` + +#### ddot.Module.prototype.main( N, xp, sx, yp, sy ) + +Computes the dot product of `x` and `y`. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var ones = require( '@stdlib/array/ones' ); +var zeros = require( '@stdlib/array/zeros' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new ddot.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointers (i.e., byte offsets) for storing two vectors: +var xptr = 0; +var yptr = N * bytesPerElement( dtype ); + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); +mod.write( yptr, ones( N, dtype ) ); + +// Perform computation: +var z = mod.main( N, xptr, 1, yptr, 1 ); + +console.log( z ); +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **xp**: first input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sx**: index increment for `x`. +- **yp**: second input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sy**: index increment for `y`. + +#### ddot.Module.prototype.ndarray( N, xp, sx, ox, yp, sy, oy ) + +Computes the dot product of `x` and `y` using alternative indexing semantics. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var ones = require( '@stdlib/array/ones' ); +var zeros = require( '@stdlib/array/zeros' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new ddot.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointers (i.e., byte offsets) for storing two vectors: +var xptr = 0; +var yptr = N * bytesPerElement( dtype ); + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); +mod.write( yptr, ones( N, dtype ) ); + +// Perform computation: +var z = mod.ndarray( N, xptr, 1, 0, yptr, 1, 0 ); + +console.log( z ); +``` + +The function has the following additional parameters: + +- **ox**: starting index for `x`. +- **oy**: starting index for `y`. + +
+ + + +
+ +* * * + +## Notes + +- If `N <= 0`, both `main` and `ndarray` methods return `0.0`. +- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `ddot` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/blas/base/ddot`][@stdlib/blas/base/ddot]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/blas/base/ddot`][@stdlib/blas/base/ddot]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other. +- `ddot()` corresponds to the [BLAS][blas] level 1 function [`ddot`][ddot]. + +
+ + + +
+ +* * * + +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ddot = require( '@stdlib/blas/base/ddot-wasm' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, 0, 100, opts ); +console.log( x ); + +var y = discreteUniform( x.length, 0, 10, opts ); +console.log( y ); + +var z = ddot.ndarray( x.length, x, 1, 0, y, -1, y.length-1 ); +console.log( z ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.js new file mode 100644 index 00000000000..799c80bc20e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var ddot = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = ddot.main( x.length, x, 1, y, 1 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.js new file mode 100644 index 00000000000..74b2ee05b84 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var pkg = require( './../package.json' ).name; +var ddot = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; + + +// MAIN // + +bench( pkg+':Module:constructor', opts, function benchmark( b ) { + var values; + var o; + var v; + var i; + + o = { + 'initial': 0 + }; + values = [ + new Memory( o ), + new Memory( o ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new ddot.Module( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.main.js new file mode 100644 index 00000000000..236dfef3e49 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.main.js @@ -0,0 +1,133 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var ddot = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var xptr; + var yptr; + var mod; + var mem; + var nb; + var d; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new ddot.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*2*nb ); + + // Define pointers (i.e., byte offsets) to the first vector elements: + xptr = 0; + yptr = len * nb; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + mod.write( yptr, uniform( len, -100.0, 100.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = mod.main( len, xptr, 1, yptr, 1 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.ndarray.js new file mode 100644 index 00000000000..ec01a05ccb0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.module.ndarray.js @@ -0,0 +1,133 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var ddot = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var xptr; + var yptr; + var mod; + var mem; + var nb; + var d; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new ddot.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*2*nb ); + + // Define pointers (i.e., byte offsets) to the first vector elements: + xptr = 0; + yptr = len * nb; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + mod.write( yptr, uniform( len, -100.0, 100.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = mod.ndarray( len, xptr, 1, 0, yptr, 1, 0 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.ndarray.js new file mode 100644 index 00000000000..c9f2a875429 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/benchmark/benchmark.ndarray.js @@ -0,0 +1,107 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var ddot = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + var y = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/repl.txt new file mode 100644 index 00000000000..df861a9da5d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/repl.txt @@ -0,0 +1,543 @@ + +{{alias}}.main( N, x, strideX, y, strideY ) + Computes the dot product of `x` and `y`. + + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + If `N <= 0`, both the functions return `0`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + First input array. + + strideX: integer + Index increment for `x`. + + y: Float64Array + Second input array. + + strideY: integer + Index increment for `y`. + + Returns + ------- + out: number + Dot product. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + > var out = {{alias}}.main( x.length, x, 1, y, 1 ) + -5.0 + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > out = {{alias}}.main( 3, x, 2, y, -1 ) + 9.0 + + // Using view offsets: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x.buffer, x.BYTES_PER_ELEMENT*1 ); + > var y1 = new {{alias:@stdlib/array/float64}}( y.buffer, y.BYTES_PER_ELEMENT*3 ); + > out = {{alias}}.main( 3, x1, -2, y1, 1 ) + 128.0 + + +{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY ) + Computes the dot product of `x` and `y` using alternative indexing + semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + First input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + y: Float64Array + Second input array. + + strideY: integer + Index increment for `y`. + + offsetY: integer + Starting index for `y`. + + Returns + ------- + out: number + Dot product. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ); + > var y = new {{alias:@stdlib/array/float64}}( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ); + > var out = {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 ) + -5.0 + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + > out = {{alias}}.ndarray( 3, x, 2, 0, y, 2, 0 ) + 9.0 + + // Using offset indices: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); + > out = {{alias}}.ndarray( 3, x, -2, x.length-1, y, 1, 3 ) + 128.0 + + +{{alias}}.Module( memory ) + Returns a new WebAssembly module wrapper which uses the provided WebAssembly + memory instance as its underlying memory. + + Parameters + ---------- + memory: Memory + WebAssembly memory instance. + + Returns + ------- + mod: Module + WebAssembly module wrapper. + + Examples + -------- + // Create a new memory instance: + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + + // Create a new routine: + > var mod = new {{alias}}.Module( mem ); + + // Initialize the routine: + > mod.initializeSync(); + + +{{alias}}.Module.prototype.binary + Read-only property which returns WebAssembly binary code. + + Returns + ------- + out: Uint8Array + WebAssembly binary code. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.binary + + + +{{alias}}.Module.prototype.memory + Read-only property which returns WebAssembly memory. + + Returns + ------- + mem: Memory|null + WebAssembly memory. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.memory + + + +{{alias}}.Module.prototype.buffer + Read-only property which returns a WebAssembly memory buffer as a + Uint8Array. + + Returns + ------- + buf: Uint8Array|null + WebAssembly memory buffer. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.buffer + + + +{{alias}}.Module.prototype.view + Read-only property which returns a WebAsssembly memory buffer as a DataView. + + Returns + ------- + view: DataView|null + WebAssembly memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.view + + + +{{alias}}.Module.prototype.exports + Read-only property which returns "raw" WebAssembly module exports. + + Returns + ------- + out: Object|null + WebAssembly module exports. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.exports + {...} + + +{{alias}}.Module.prototype.initialize() + Asynchronously initializes a WebAssembly module instance. + + Returns + ------- + p: Promise + Promise which resolves upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initialize(); + + +{{alias}}.Module.prototype.initializeAsync( clbk ) + Asynchronously initializes a WebAssembly module instance. + + Parameters + ---------- + clbk: Function + Callback to invoke upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > function clbk() { console.log( 'done' ) }; + > mod.initializeAsync( clbk ); + + +{{alias}}.Module.prototype.initializeSync() + Synchronously initializes a WebAssembly module instance. + + In web browsers, JavaScript engines may raise an exception when attempting + to synchronously compile large WebAssembly binaries due to concerns about + blocking the main thread. Hence, to initialize WebAssembly modules having + large binaries (e.g., >4KiB), consider using asynchronous initialization + methods in browser contexts. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + +{{alias}}.Module.prototype.realloc( nbytes ) + Reallocates the underlying WebAssembly memory instance to a specified number + of bytes. + + WebAssembly memory can only *grow*, not shrink. Hence, if provided a number + of bytes which is less than or equal to the size of the current memory, the + function does nothing. + + When non-shared memory is resized, the underlying the `ArrayBuffer` is + detached, consequently invalidating any associated typed array views. Before + resizing non-shared memory, ensure that associated typed array views no + longer need byte access and can be garbage collected. + + Parameters + ---------- + nbytes: integer + Memory size (in bytes). + + Returns + ------- + bool: boolean + Boolean indicating whether the resize operation was successful. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ) + + + +{{alias}}.Module.prototype.hasCapacity( byteOffset, values ) + Returns a boolean indicating whether the underlying WebAssembly memory + instance has the capacity to store a provided list of values starting from a + specified byte offset. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + bool: boolean + Boolean indicating whether the underlying WebAssembly memory instance + has enough capacity. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.hasCapacity( 0, [ 1, 2, 3, 4 ] ) + true + + +{{alias}}.Module.prototype.isView( values ) + Returns a boolean indicating whether a provided list of values is a view of + the underlying memory of the WebAssembly module. + + Parameters + ---------- + values: ArrayLikeObject + Input array. + + Returns + ------- + bool: boolean + Boolean indicating whether the list is a memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.isView( [ 1, 2, 3, 4 ] ) + false + + +{{alias}}.Module.prototype.write( byteOffset, values ) + Writes values to the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the input array. For example, if provided a Float32Array, + the function writes each element as a single-precision floating-point number + to the underlying WebAssembly memory instance. + + In order to write elements as a different data type, you need to perform an + explicit cast *before* calling this method. For example, in order to write + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must first convert the Float32Array to an + Int32Array before passing the values to this method. + + If provided an array having an unknown or "generic" data type, elements are + written as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + + +{{alias}}.Module.prototype.read( byteOffset, out ) + Reads values from the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the output array. For example, if provided a Float32Array, + the function reads each element as a single-precision floating-point number + from the underlying WebAssembly memory instance. + + In order to read elements as a different data type, you need to perform an + explicit cast *after* calling this method. For example, in order to read + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must convert the Float32Array to an Int32Array + after reading memory values using this method. + + If provided an output array having an unknown or "generic" data type, + elements are read as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start reading values. + + out: ArrayLikeObject + Output array for storing read values. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + > var out = [ 0, 0, 0, 0 ]; + > mod.read( 0, out ); + > out + [ 1, 2, 3, 4 ] + + +{{alias}}.Module.prototype.main( N, xp, sx, yp, sy ) + Computes the dot product of `x` and `y`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + First input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + yp: integer + Second input array pointer (i.e., byte offset). + + sy: integer + Index increment for `y`. + + Returns + ------- + out: number + Dot product. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointers" (i.e., byte offsets) into module memory: + > var xptr = 0; + > var yptr = 40; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + > mod.write( yptr, {{alias:@stdlib/array/ones}}( 5, 'float64' ) ); + + // Perform computation: + > var out = mod.main( 5, xptr, 1, yptr, 1 ) + 15.0 + + +{{alias}}.Module.prototype.ndarray( N, xp, sx, ox, yp, sy, oy ) + Computes the dot product of `x` and `y`, using alternative indexing + semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + First input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + yp: integer + Second input array pointer (i.e., byte offset). + + sy: integer + Index increment for `y`. + + oy: integer + Starting index for `y`. + + Returns + ------- + out: number + Dot product. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointers" (i.e., byte offsets) into module memory: + > var xptr = 0; + > var yptr = 40; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + > mod.write( yptr, {{alias:@stdlib/array/ones}}( 5, 'float64' ) ); + + // Perform computation: + > var out = mod.ndarray( 5, xptr, 1, 0, yptr, 1, 0 ) + 15.0 + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/types/index.d.ts new file mode 100644 index 00000000000..65dab9ebec2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/types/index.d.ts @@ -0,0 +1,357 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ModuleWrapper, Memory } from '@stdlib/types/wasm'; + +/** +* Interface defining a module constructor which is both "newable" and "callable". +*/ +interface ModuleConstructor { + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new ddot.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var dot = mod.main( N, xptr, 1, yptr, 1 ); + * // returns 15.0 + */ + new( mem: Memory ): Module; // newable + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = ddot.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var dot = mod.main( N, xptr, 1, yptr, 1 ); + * // returns 15.0 + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing a `ddot` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Computes the dot product of `x` and `y`. + * + * @param N - number of indexed elements + * @param xptr - first input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param yptr - second input array pointer (i.e., byte offset) + * @param strideY - `y` stride length + * @returns dot product + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new ddot.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var dot = mod.main( N, 5.0, xptr, 1, yptr, 1 ); + * // returns 15.0 + */ + main( N: number, xptr: number, strideX: number, yptr: number, strideY: number ): number; + + /** + * Computes the dot product of `x` and `y` using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param xptr - first input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param yptr - second input array pointer (i.e., byte offset) + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns dot product + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new ddot.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var dot = mod.ndarray( N, 5.0, xptr, 1, 0, yptr, 1, 0 ); + * // returns 15.0 + */ + ndarray( N: number, xptr: number, strideX: number, offsetX: number, yptr: number, strideY: number, offsetY: number ): number; +} + +/** +* Interface describing `ddot`. +*/ +interface Routine extends ModuleWrapper { + /** + * Computes the dot product of `x` and `y`. + * + * @param N - number of indexed elements + * @param x - first input array + * @param strideX - `x` stride length + * @param y - second input array + * @param strideY - `y` stride length + * @returns dot product + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + * + * var dot = ddot.main( x.length, x, 1, y, 1 ); + * // returns 15.0 + */ + main( N: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number ): number; + + /** + * Computes the dot product of `x` and `y` using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - first input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @param y - second input array + * @param strideY - `y` stride length + * @param offsetY - starting index for `y` + * @returns dot product + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + * + * ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); + * // returns 15.0 + */ + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number, y: Float64Array, strideY: number, offsetY: number ): number; + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * var ones = require( '@stdlib/array/ones' ); + * var zeros = require( '@stdlib/array/zeros' ); + * var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new ddot.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointers (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * var yptr = N * bytesPerElement( dtype ); + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * mod.write( yptr, ones( N, dtype ) ); + * + * // Perform computation: + * var dot = mod.main( N, xptr, 1, yptr, 1 ); + * // returns 15.0 + */ + Module: ModuleConstructor; +} + +/** +* Computes the dot product of `x` and `y`. +* +* @param N - number of indexed elements +* @param x - first input array +* @param strideX - `x` stride length +* @param y - second input array +* @param strideY - `y` stride length +* @returns dot product +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* var dot = ddot.main( x.length, x, 1, y, 1 ); +* // returns 15.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* var dot = ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns 15.0 +*/ +declare var ddot: Routine; + + +// EXPORTS // + +export = ddot; diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/types/test.ts new file mode 100644 index 00000000000..29889263520 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/docs/types/test.ts @@ -0,0 +1,528 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable space-in-parens */ + +import Memory = require( '@stdlib/wasm/memory' ); +import ddot = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.main( x.length, x, 1, y, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.main( '10', x, 1, y, 1 ); // $ExpectError + ddot.main( true, x, 1, y, 1 ); // $ExpectError + ddot.main( false, x, 1, y, 1 ); // $ExpectError + ddot.main( null, x, 1, y, 1 ); // $ExpectError + ddot.main( undefined, x, 1, y, 1 ); // $ExpectError + ddot.main( [], x, 1, y, 1 ); // $ExpectError + ddot.main( {}, x, 1, y, 1 ); // $ExpectError + ddot.main( ( x: number ): number => x, x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.main( x.length, 10, 1, y, 1 ); // $ExpectError + ddot.main( x.length, '10', 1, y, 1 ); // $ExpectError + ddot.main( x.length, true, 1, y, 1 ); // $ExpectError + ddot.main( x.length, false, 1, y, 1 ); // $ExpectError + ddot.main( x.length, null, 1, y, 1 ); // $ExpectError + ddot.main( x.length, undefined, 1, y, 1 ); // $ExpectError + ddot.main( x.length, [], 1, y, 1 ); // $ExpectError + ddot.main( x.length, {}, 1, y, 1 ); // $ExpectError + ddot.main( x.length, ( x: number ): number => x, 1, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.main( x.length, x, '10', y, 1 ); // $ExpectError + ddot.main( x.length, x, true, y, 1 ); // $ExpectError + ddot.main( x.length, x, false, y, 1 ); // $ExpectError + ddot.main( x.length, x, null, y, 1 ); // $ExpectError + ddot.main( x.length, x, undefined, y, 1 ); // $ExpectError + ddot.main( x.length, x, [], y, 1 ); // $ExpectError + ddot.main( x.length, x, {}, y, 1 ); // $ExpectError + ddot.main( x.length, x, ( x: number ): number => x, y, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a fourth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + ddot.main( x.length, x, 1, 10, 1 ); // $ExpectError + ddot.main( x.length, x, 1, '10', 1 ); // $ExpectError + ddot.main( x.length, x, 1, true, 1 ); // $ExpectError + ddot.main( x.length, x, 1, false, 1 ); // $ExpectError + ddot.main( x.length, x, 1, null, 1 ); // $ExpectError + ddot.main( x.length, x, 1, undefined, 1 ); // $ExpectError + ddot.main( x.length, x, 1, [], 1 ); // $ExpectError + ddot.main( x.length, x, 1, {}, 1 ); // $ExpectError + ddot.main( x.length, x, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a fifth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.main( x.length, x, 1, y, '10' ); // $ExpectError + ddot.main( x.length, x, 1, y, true ); // $ExpectError + ddot.main( x.length, x, 1, y, false ); // $ExpectError + ddot.main( x.length, x, 1, y, null ); // $ExpectError + ddot.main( x.length, x, 1, y, undefined ); // $ExpectError + ddot.main( x.length, x, 1, y, [] ); // $ExpectError + ddot.main( x.length, x, 1, y, {} ); // $ExpectError + ddot.main( x.length, x, 1, y, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.main(); // $ExpectError + ddot.main( x.length ); // $ExpectError + ddot.main( x.length, x ); // $ExpectError + ddot.main( x.length, x, 1 ); // $ExpectError + ddot.main( x.length, x, 1, y ); // $ExpectError + ddot.main( x.length, x, 1, y, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.ndarray( '10', x, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( true, x, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( false, x, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( null, x, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( undefined, x, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( [], x, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( {}, x, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( ( x: number ): number => x, x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.ndarray( x.length, 10, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, '10', 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, true, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, false, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, null, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, undefined, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, [], 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, {}, 1, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, ( x: number ): number => x, 1, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.ndarray( x.length, x, '10', 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, true, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, false, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, null, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, undefined, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, [], 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, {}, 0, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, ( x: number ): number => x, 0, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.ndarray( x.length, x, 1, '10', y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, true, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, false, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, null, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, undefined, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, [], y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, {}, y, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, ( x: number ): number => x, y, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + ddot.ndarray( x.length, x, 1, 0, 10, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, '10', 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, true, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, false, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, null, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, undefined, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, [], 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, {}, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.ndarray( x.length, x, 1, 0, y, '10', 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, true, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, false, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, null, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, undefined, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, [], 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, {}, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.ndarray( x.length, x, 1, 0, y, 1, '10' ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, 1, true ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, 1, false ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, 1, null ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, 1, undefined ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, 1, [] ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, 1, {} ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + const y = new Float64Array( 10 ); + + ddot.ndarray(); // $ExpectError + ddot.ndarray( x.length ); // $ExpectError + ddot.ndarray( x.length, x ); // $ExpectError + ddot.ndarray( x.length, x, 1 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, 1 ); // $ExpectError + ddot.ndarray( x.length, x, 1, 0, y, 1, 0, 10 ); // $ExpectError +} + +// Attached to the main export is a `Module` constructor which returns a module... +{ + const mem = new Memory({ + 'initial': 0 + }); + + ddot.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + ddot.Module( '10' ); // $ExpectError + ddot.Module( true ); // $ExpectError + ddot.Module( false ); // $ExpectError + ddot.Module( null ); // $ExpectError + ddot.Module( undefined ); // $ExpectError + ddot.Module( [] ); // $ExpectError + ddot.Module( {} ); // $ExpectError + ddot.Module( ( x: number ): number => x ); // $ExpectError +} + +// The `Module` constructor returns a module instance having a `main` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.main( 10, 0, 1, 80, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.main( '10', 10, 1, 80, 1 ); // $ExpectError + mod.main( true, 10, 1, 80, 1 ); // $ExpectError + mod.main( false, 10, 1, 80, 1 ); // $ExpectError + mod.main( null, 10, 1, 80, 1 ); // $ExpectError + mod.main( undefined, 10, 1, 80, 1 ); // $ExpectError + mod.main( [], 10, 1, 80, 1 ); // $ExpectError + mod.main( {}, 10, 1, 80, 1 ); // $ExpectError + mod.main( ( x: number ): number => x, 10, 1, 80, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.main( 10, '10', 1, 80, 1 ); // $ExpectError + mod.main( 10, true, 1, 80, 1 ); // $ExpectError + mod.main( 10, false, 1, 80, 1 ); // $ExpectError + mod.main( 10, null, 1, 80, 1 ); // $ExpectError + mod.main( 10, undefined, 1, 80, 1 ); // $ExpectError + mod.main( 10, [], 1, 80, 1 ); // $ExpectError + mod.main( 10, {}, 1, 80, 1 ); // $ExpectError + mod.main( 10, ( x: number ): number => x, 1, 80, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.main( 10, 0, '10', 80, 1 ); // $ExpectError + mod.main( 10, 0, true, 80, 1 ); // $ExpectError + mod.main( 10, 0, false, 80, 1 ); // $ExpectError + mod.main( 10, 0, null, 80, 1 ); // $ExpectError + mod.main( 10, 0, undefined, 80, 1 ); // $ExpectError + mod.main( 10, 0, [], 80, 1 ); // $ExpectError + mod.main( 10, 0, {}, 80, 1 ); // $ExpectError + mod.main( 10, 0, ( x: number ): number => x, 80, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.main( 10, 0, 1, '10', 1 ); // $ExpectError + mod.main( 10, 0, 1, true, 1 ); // $ExpectError + mod.main( 10, 0, 1, false, 1 ); // $ExpectError + mod.main( 10, 0, 1, null, 1 ); // $ExpectError + mod.main( 10, 0, 1, undefined, 1 ); // $ExpectError + mod.main( 10, 0, 1, [], 1 ); // $ExpectError + mod.main( 10, 0, 1, {}, 1 ); // $ExpectError + mod.main( 10, 0, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a fifth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.main( 10, 0, 1, 80, '10' ); // $ExpectError + mod.main( 10, 0, 1, 80, true ); // $ExpectError + mod.main( 10, 0, 1, 80, false ); // $ExpectError + mod.main( 10, 0, 1, 80, null ); // $ExpectError + mod.main( 10, 0, 1, 80, undefined ); // $ExpectError + mod.main( 10, 0, 1, 80, [] ); // $ExpectError + mod.main( 10, 0, 1, 80, {} ); // $ExpectError + mod.main( 10, 0, 1, 80, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 0 ); // $ExpectError + mod.main( 10, 0, 1 ); // $ExpectError + mod.main( 10, 0, 1, 80 ); // $ExpectError + mod.main( 10, 0, 1, 80, 1, 10 ); // $ExpectError +} + +// The `Module` constructor returns a module instance having an `ndarray` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.ndarray( 10, 0, 1, 0, 80, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.ndarray( '10', 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( true, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( false, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( null, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( undefined, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( [], 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( {}, 0, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( ( x: number ): number => x, 0, 1, 0, 80, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.ndarray( 10, '10', 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, true, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, false, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, null, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, undefined, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, [], 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, {}, 1, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, ( x: number ): number => x, 1, 0, 80, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.ndarray( 10, 0, '10', 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, true, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, false, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, null, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, undefined, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, [], 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, {}, 0, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, ( x: number ): number => x, 0, 80, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.ndarray( 10, 0, 1, '10', 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, true, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, false, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, null, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, undefined, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, [], 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, {}, 80, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, ( x: number ): number => x, 80, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fifth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.ndarray( 10, 0, 1, 0, '10', 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, true, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, false, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, null, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, undefined, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, [], 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, {}, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a sixth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.ndarray( 10, 0, 1, 0, 80, '10', 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, true, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, false, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, null, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, undefined, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, [], 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, {}, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a seventh argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.ndarray( 10, 0, 1, 0, 80, 1, '10' ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, true ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, false ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, null ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, undefined ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, [] ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, {} ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = ddot.Module( mem ); + + mod.ndarray(); // $ExpectError + mod.ndarray( 10 ); // $ExpectError + mod.ndarray( 10, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 80, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/index.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/index.js new file mode 100644 index 00000000000..e5b89b84db9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/index.js @@ -0,0 +1,45 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var oneTo = require( '@stdlib/array/one-to' ); +var ones = require( '@stdlib/array/ones' ); +var ddot = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Specify a vector length: + var N = 5; + + // Create two arrays: + var x = oneTo( N, 'float64' ); + var y = ones( N, 'float64' ); + + // Perform computation: + var dot = ddot.ndarray( N, x, 1, 0, y, 1, 0 ); + + // Print the result: + console.log( dot ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/little_endian_arrays.js new file mode 100644 index 00000000000..3504d2e4633 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/little_endian_arrays.js @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var gfill = require( '@stdlib/blas/ext/base/gfill' ); +var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +var ddot = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new ddot.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Define a vector data type: + var dtype = 'float64'; + + // Specify a vector length: + var N = 5; + + // Define pointers (i.e., byte offsets) for storing two vectors: + var xptr = 0; + var yptr = N * bytesPerElement( dtype ); + + // Create typed array views over module memory: + var x = new Float64ArrayLE( mod.memory.buffer, xptr, N ); + var y = new Float64ArrayLE( mod.memory.buffer, yptr, N ); + + // Write values to module memory: + gfillBy( N, x, 1, discreteUniform( -10.0, 10.0 ) ); + gfill( N, 1.0, y, 1 ); + + // Perform computation: + var dot = mod.ndarray( N, xptr, 1, 0, yptr, 1, 0 ); + + // Print the result: + console.log( dot ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/module.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/module.js new file mode 100644 index 00000000000..fcc482f2114 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/examples/module.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var ones = require( '@stdlib/array/ones' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var ddot = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new ddot.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Define a vector data type: + var dtype = 'float64'; + + // Specify a vector length: + var N = 5; + + // Define pointers (i.e., byte offsets) for storing two vectors: + var xptr = 0; + var yptr = N * bytesPerElement( dtype ); + + // Write vector values to module memory: + mod.write( xptr, oneTo( N, dtype ) ); + mod.write( yptr, ones( N, dtype ) ); + + // Perform computation: + var dot = mod.ndarray( N, xptr, 1, 0, yptr, 1, 0 ); + + // Print the result: + console.log( dot ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/binary.browser.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/binary.browser.js new file mode 100644 index 00000000000..e5d16b22ad4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAEYA2AAAGAFf39/f38BfGAHf39/f39/fwF8Ag8BA2VudgZtZW1vcnkCAAADBAMAAQIHSgQRX193YXNtX2NhbGxfY3RvcnMAABhfX3dhc21fYXBwbHlfZGF0YV9yZWxvY3MAAAZjX2Rkb3QAAQ5jX2Rkb3RfbmRhcnJheQACCuMEAwMAAQs7AQJ+IAAgASACIAKsIgVCASAArCIGfX5CACAFQgBXG6cgAyAEIASsIgVCASAGfX5CACAFQgBXG6cQAgugBAIBfAl/IABBAEwEQEQAAAAAAAAAAA8LAkACQAJAIAJBAUYgBUEBRnFFBEAgAEEBcSEJIABBAUcNAQwCCwJAIABBBXAiBUUEQAwBCyAFQQFxIQoCQCAAQQVwIgtBAUYEQCAGIQggAyECDAELIARBCGohDCABQQhqIQ0gBUEGcSEOIAYhCCADIQIDQCANIAJBA3QiD2orAwAgDCAIQQN0IhBqKwMAoiABIA9qKwMAIAQgEGorAwCiIAegoCEHIAhBAmohCCACQQJqIQIgCUECaiIJIA5HDQALCyAKBEAgASACQQN0aisDACAEIAhBA3RqKwMAoiAHoCEHCyAAIAZqIAAgC2siAmshBiAAIANqIAJrIQMLIABBBUgNAgNAIAcgASADQQN0aiICKwMgIAQgBkEDdGoiCCsDIKIgAisDGCAIKwMYoiACKwMQIAgrAxCiIAIrAwAgCCsDAKIgAisDCCAIKwMIoqCgoKCgIQcgBkEFaiEGIANBBWohAyAFQQVqIgUgAEgNAAsMAgsgAEH+////B3EhACAFIAVqIQogAiACaiELA0AgASACIANqQQN0aisDACAEIAUgBmpBA3RqKwMAoiABIANBA3RqKwMAIAQgBkEDdGorAwCiIAegoCEHIAYgCmohBiADIAtqIQMgCEECaiIIIABHDQALCyAJRQ0AIAEgA0EDdGorAwAgBCAGQQN0aisDAKIgB6AhBwsgBws=' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/binary.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/binary.js new file mode 100644 index 00000000000..6f02393f96e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/binary.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readWASM = require( '@stdlib/fs/read-wasm' ).sync; + + +// MAIN // + +var wasm = readWASM( resolve( __dirname, '..', 'src', 'main.wasm' ) ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/index.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/index.js new file mode 100644 index 00000000000..61ca31aeaa0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/index.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* WebAssembly routine to compute the dot product of `x` and `y`. +* +* @module @stdlib/blas/base/ddot-wasm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ddot = require( '@stdlib/blas/base/ddot-wasm' ); +* +* // Define strided arrays: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* var dot = ddot.main( x.length, x, 1, y, 1 ); +* // returns 15.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ddot = require( '@stdlib/blas/base/ddot-wasm' ); +* +* // Define strided arrays: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* var dot = ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns 15.0 +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var ones = require( '@stdlib/array/ones' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +* var ddot = require( '@stdlib/blas/base/ddot-wasm' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var mod = new ddot.Module( mem ); +* // returns +* +* // Initialize the routine: +* mod.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointers (i.e., byte offsets) for storing two vectors: +* var xptr = 0; +* var yptr = N * bytesPerElement( dtype ); +* +* // Write vector values to module memory: +* mod.write( xptr, oneTo( N, dtype ) ); +* mod.write( yptr, ones( N, dtype ) ); +* +* // Perform computation: +* var dot = mod.main( N, xptr, 1, yptr, 1 ); +* +* console.log( dot ); +* // returns 15.0 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var Module = require( './module.js' ); + + +// MAIN // + +setReadOnly( main, 'Module', Module ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "Module": "main.Module" } diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/main.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/main.js new file mode 100644 index 00000000000..29a7738657d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/main.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var Routine = require( './routine.js' ); + + +// MAIN // + +/** +* WebAssembly module to compute the dot product of `x` and `y`. +* +* @name ddot +* @type {Routine} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define strided arrays: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* var dot = ddot.main( x.length, x, 1, y, 1 ); +* // returns 15.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define strided arrays: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* var dot = ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns 15.0 +*/ +var ddot = new Routine(); +ddot.initializeSync(); // eslint-disable-line node/no-sync + + +// EXPORTS // + +module.exports = ddot; diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/module.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/module.js new file mode 100644 index 00000000000..09c32bc4347 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/module.js @@ -0,0 +1,218 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var WasmModule = require( '@stdlib/wasm/module-wrapper' ); +var format = require( '@stdlib/string/format' ); +var wasmBinary = require( './binary.js' ); + + +// MAIN // + +/** +* BLAS routine WebAssembly module wrapper constructor. +* +* @constructor +* @param {Object} memory - WebAssembly memory instance +* @throws {TypeError} must provide a WebAssembly memory instance +* @returns {Module} module instance +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var ones = require( '@stdlib/array/ones' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var ddot = new Module( mem ); +* // returns +* +* // Initialize the routine: +* ddot.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointers (i.e., byte offsets) for storing two vectors: +* var xptr = 0; +* var yptr = N * bytesPerElement( dtype ); +* +* // Write vector values to module memory: +* ddot.write( xptr, oneTo( N, dtype ) ); +* ddot.write( yptr, ones( N, dtype ) ); +* +* // Perform computation: +* var dot = ddot.main( N, xptr, 1, yptr, 1 ); +* // returns 15.0 +*/ +function Module( memory ) { + if ( !( this instanceof Module ) ) { + return new Module( memory ); + } + if ( !isWebAssemblyMemory( memory ) ) { + throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) ); + } + // Call the parent constructor: + WasmModule.call( this, wasmBinary, memory, { + 'env': { + 'memory': memory + } + }); + + return this; +} + +// Inherit from the parent constructor: +inherits( Module, WasmModule ); + +/** +* Computes the dot product of `x` and `y`. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - first input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} yptr - second input array pointer (i.e., byte offset) +* @param {integer} strideY - `y` stride length +* @returns {number} dot product +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var ones = require( '@stdlib/array/ones' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var ddot = new Module( mem ); +* // returns +* +* // Initialize the routine: +* ddot.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointers (i.e., byte offsets) for storing two vectors: +* var xptr = 0; +* var yptr = N * bytesPerElement( dtype ); +* +* // Write vector values to module memory: +* ddot.write( xptr, oneTo( N, dtype ) ); +* ddot.write( yptr, ones( N, dtype ) ); +* +* // Perform computation: +* var dot = ddot.main( N, xptr, 1, yptr, 1 ); +* // returns 15.0 +*/ +setReadOnly( Module.prototype, 'main', function ddot( N, xptr, strideX, yptr, strideY ) { + return this._instance.exports.c_ddot( N, xptr, strideX, yptr, strideY ); +}); + +/** +* Computes the dot product of `x` and `y` using alternative indexing semantics. +* +* @name ndarray +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - first input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {NonNegativeInteger} yptr - second input array pointer (i.e., byte offset) +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @returns {number} dot product +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var ones = require( '@stdlib/array/ones' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var ddot = new Module( mem ); +* // returns +* +* // Initialize the routine: +* ddot.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointers (i.e., byte offsets) for storing two vectors: +* var xptr = 0; +* var yptr = N * bytesPerElement( dtype ); +* +* // Write vector values to module memory: +* ddot.write( xptr, oneTo( N, dtype ) ); +* ddot.write( yptr, ones( N, dtype ) ); +* +* // Perform computation: +* var ddot = ddot.ndarray( N, xptr, 1, 0, yptr, 1, 0 ); +* // returns 15.0 +*/ +setReadOnly( Module.prototype, 'ndarray', function ddot( N, xptr, strideX, offsetX, yptr, strideY, offsetY ) { + return this._instance.exports.c_ddot_ndarray( N, xptr, strideX, offsetX, yptr, strideY, offsetY ); // eslint-disable-line max-len +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/routine.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/routine.js new file mode 100644 index 00000000000..73fc999c7e2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/lib/routine.js @@ -0,0 +1,178 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var Memory = require( '@stdlib/wasm/memory' ); +var arrays2ptrs = require( '@stdlib/wasm/base/arrays2ptrs' ); +var strided2object = require( '@stdlib/wasm/base/strided2object' ); +var Module = require( './module.js' ); + + +// MAIN // + +/** +* Routine constructor. +* +* @private +* @constructor +* @returns {Routine} routine instance +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var ddot = new Routine(); +* +* // Initialize the module: +* ddot.initializeSync(); +* +* // Define strided arrays: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* var dot = ddot.main( x.length, x, 1, y, 1 ); +* // returns 15.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var ddot = new Routine(); +* +* // Initialize the module: +* ddot.initializeSync(); +* +* // Define strided arrays: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* var dot = ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns 15.0 +*/ +function Routine() { + if ( !( this instanceof Routine ) ) { + return new Routine(); + } + Module.call( this, new Memory({ + 'initial': 0 + })); + return this; +} + +// Inherit from the parent constructor: +inherits( Routine, Module ); + +/** +* Computes the dot product of `x` and `y`. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` stride length +* @returns {number} dot product +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var ddot = new Routine(); +* +* // Initialize the module: +* ddot.initializeSync(); +* +* // Define strided arrays: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* var dot = ddot.main( x.length, x, 1, y, 1 ); +* // returns 15.0 +*/ +setReadOnly( Routine.prototype, 'main', function ddot( N, x, strideX, y, strideY ) { + return this.ndarray( N, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); // eslint-disable-line max-len +}); + +/** +* Computes the dot product of `x` and `y` using alternative indexing semantics. +* +* @name ndarray +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - first input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @param {Float64Array} y - second input array +* @param {integer} strideY - `y` stride length +* @param {NonNegativeInteger} offsetY - starting `y` index +* @returns {number} dot product +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var ddot = new Routine(); +* +* // Initialize the module: +* ddot.initializeSync(); +* +* // Define strided arrays: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* var y = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* +* // Perform operation: +* var dot = ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); +* // returns 15.0 +*/ +setReadOnly( Routine.prototype, 'ndarray', function ddot( N, x, strideX, offsetX, y, strideY, offsetY ) { + var ptrs; + var p0; + var p1; + + // Convert the input arrays to "pointers" in the module's memory: + ptrs = arrays2ptrs( this, [ + strided2object( N, x, strideX, offsetX ), + strided2object( N, y, strideY, offsetY ) + ]); + p0 = ptrs[ 0 ]; + p1 = ptrs[ 1 ]; + + // Perform computation by calling the corresponding parent method: + return Module.prototype.ndarray.call( this, N, p0.ptr, p0.stride, p0.offset, p1.ptr, p1.stride, p1.offset ); // eslint-disable-line max-len +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/manifest.json b/lib/node_modules/@stdlib/blas/base/ddot-wasm/manifest.json new file mode 100644 index 00000000000..d5b6aa8d273 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/ddot" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/package.json b/lib/node_modules/@stdlib/blas/base/ddot-wasm/package.json new file mode 100644 index 00000000000..f17b7a0b15b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/package.json @@ -0,0 +1,80 @@ +{ + "name": "@stdlib/blas/base/ddot-wasm", + "version": "0.0.0", + "description": "Compute the dot product of `x` and `y`.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": { + "./lib/binary.js": "./lib/binary.browser.js" + }, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "ddot", + "linear", + "algebra", + "subroutines", + "dot", + "vector", + "array", + "ndarray", + "float64", + "double", + "float64array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/scripts/build.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/scripts/build.js new file mode 100644 index 00000000000..348354d7029 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/scripts/build.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var replace = require( '@stdlib/string/replace' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/scripts/template.txt b/lib/node_modules/@stdlib/blas/base/ddot-wasm/scripts/template.txt new file mode 100644 index 00000000000..12996dd89e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( '{{WASM_BASE64}}' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/src/Makefile b/lib/node_modules/@stdlib/blas/base/ddot-wasm/src/Makefile new file mode 100644 index 00000000000..bd2f30dc5f0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/src/Makefile @@ -0,0 +1,232 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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. +#/ + +#/ +# To compile targets listed in this Makefile, use top-level project `make` +# commands rather than commands listed in this Makefile. The top-level project +# `make` commands will ensure that various environment variables and flags are +# appropriately set. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files to WebAssembly: +ifdef EMCC_COMPILER + EMCC := $(EMCC_COMPILER) +else + EMCC := emcc +endif + +# Define the program used for compiling WebAssembly files to the WebAssembly text format: +ifdef WASM2WAT + WASM_TO_WAT := $(WASM2WAT) +else + WASM_TO_WAT := wasm2wat +endif + +# Define the program used for compiling WebAssembly files to JavaScript: +ifdef WASM2JS + WASM_TO_JS := $(WASM2JS) +else + WASM_TO_JS := wasm2js +endif + +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic \ + -D CBLAS_INT=int32_t + +# Define the command-line options when compiling C files to WebAssembly and asm.js: +EMCCFLAGS ?= $(CFLAGS) + +# Define shared `emcc` flags: +EMCC_SHARED_FLAGS := \ + -s SIDE_MODULE=2 \ + -s WASM_BIGINT=0 \ + -s EXPORTED_FUNCTIONS="['_c_ddot','_c_ddot_ndarray']" + +# Define WebAssembly `emcc` flags: +EMCC_WASM_FLAGS := $(EMCC_SHARED_FLAGS) \ + -s WASM=1 + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of WebAssembly targets: +wasm_targets := main.wasm + +# List of WebAssembly WAT targets: +wat_targets := main.wat + +# List of WebAssembly JavaScript targets: +wasm_js_targets := main.wasm.js + +# List of other JavaScript targets: +browser_js_targets := ./../lib/binary.browser.js + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: wasm + +.PHONY: all + +#/ +# Compiles source files to WebAssembly. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make wasm +#/ +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) + +.PHONY: wasm + +#/ +# Compiles C source files to WebAssembly binaries. +# +# @private +# @param {string} EMCC - EMCC compiler (e.g., `emcc`) +# @param {string} EMCCFLAGS - EMCC compiler options +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(wasm_targets): + $(QUIET) $(EMCC) $(EMCCFLAGS) $(EMCC_WASM_FLAGS) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Compiles WebAssembly binary files to the WebAssembly text format. +# +# @private +# @param {string} WASM2WAT - WAT compiler (e.g., `wasm2wat`) +#/ +$(wat_targets): %.wat: %.wasm + $(QUIET) $(WASM_TO_WAT) -o $@ $(wasm_targets) + +#/ +# Compiles WebAssembly binary files to JavaScript. +# +# @private +# @param {string} WASM2JS - JavaScript compiler (e.g., `wasm2js`) +#/ +$(wasm_js_targets): %.wasm.js: %.wasm + $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) + +#/ +# Generates an inline WebAssembly build for use in bundlers. +# +# @private +# @param {string} NODE - Node.js executable +#/ +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + +#/ +# Removes generated WebAssembly files. +# +# @example +# make clean-wasm +#/ +clean-wasm: + $(QUIET) -rm -f *.wasm *.wat *.wasm.js + +.PHONY: clean-wasm + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-wasm + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/src/main.wasm b/lib/node_modules/@stdlib/blas/base/ddot-wasm/src/main.wasm new file mode 100755 index 0000000000000000000000000000000000000000..403fd9d8cf4f652baea185fbde2469733750f8de GIT binary patch literal 764 zcmZ`%xo+D)5S_hvXhlis1f&_VH4vmvBMEVA817S2gs39aEei<*IQFjyYTWp*@*h#& zkTjAeOMvs{dNX`WDjrsfaQabsTz*?GK73SGd^I#vqN#h9qaLSW4Fu}GGV}HKU^QQD z_D4-*tRbbtJNqure}FHa70YElJ8bq3M8h^#Y`4o}UKWQU-_Mtu8B)P4FU!q=RIdT~ zx-9nl;z+vl%NlU{Pf9;Av0}~oHFFci^qK`fpC-g^LSNs%uwl!#N&OoiXn(R=J;u*W zW4gDa&(xm2*CTmYkJT4;c>d}U#AdT3h zTJm-rRcV)%m;}|qF73VL&4?3>Gl#5ST^ZsoN8${`IkVy>YPk)Br&AiDL|35KVl>Av zSCbjDY~I${f=z_Jx`l`}=aagu4_M z$EfJYjaI40B67K=`ui;oySJW*Q|~CMwHwys8;Jt$)Fau;ND(ZHm>P-V>qP#W|8$E+ Gq5lIjG>3Ko literal 0 HcmV?d00001 diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/src/main.wat b/lib/node_modules/@stdlib/blas/base/ddot-wasm/src/main.wat new file mode 100644 index 00000000000..3aed2b72c24 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/src/main.wat @@ -0,0 +1,368 @@ +;; @license Apache-2.0 +;; +;; Copyright (c) 2024 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. + +(module + (type (;0;) (func)) + (type (;1;) (func (param i32 i32 i32 i32 i32) (result f64))) + (type (;2;) (func (param i32 i32 i32 i32 i32 i32 i32) (result f64))) + (import "env" "memory" (memory (;0;) 0)) + (func (;0;) (type 0) + nop) + (func (;1;) (type 1) (param i32 i32 i32 i32 i32) (result f64) + (local i64 i64) + local.get 0 + local.get 1 + local.get 2 + local.get 2 + i64.extend_i32_s + local.tee 5 + i64.const 1 + local.get 0 + i64.extend_i32_s + local.tee 6 + i64.sub + i64.mul + i64.const 0 + local.get 5 + i64.const 0 + i64.le_s + select + i32.wrap_i64 + local.get 3 + local.get 4 + local.get 4 + i64.extend_i32_s + local.tee 5 + i64.const 1 + local.get 6 + i64.sub + i64.mul + i64.const 0 + local.get 5 + i64.const 0 + i64.le_s + select + i32.wrap_i64 + call 2) + (func (;2;) (type 2) (param i32 i32 i32 i32 i32 i32 i32) (result f64) + (local f64 i32 i32 i32 i32 i32 i32 i32 i32 i32) + local.get 0 + i32.const 0 + i32.le_s + if ;; label = @1 + f64.const 0x0p+0 (;=0;) + return + end + block ;; label = @1 + block ;; label = @2 + block ;; label = @3 + local.get 2 + i32.const 1 + i32.eq + local.get 5 + i32.const 1 + i32.eq + i32.and + i32.eqz + if ;; label = @4 + local.get 0 + i32.const 1 + i32.and + local.set 9 + local.get 0 + i32.const 1 + i32.ne + br_if 1 (;@3;) + br 2 (;@2;) + end + block ;; label = @4 + local.get 0 + i32.const 5 + i32.rem_u + local.tee 5 + i32.eqz + if ;; label = @5 + br 1 (;@4;) + end + local.get 5 + i32.const 1 + i32.and + local.set 10 + block ;; label = @5 + local.get 0 + i32.const 5 + i32.rem_u + local.tee 11 + i32.const 1 + i32.eq + if ;; label = @6 + local.get 6 + local.set 8 + local.get 3 + local.set 2 + br 1 (;@5;) + end + local.get 4 + i32.const 8 + i32.add + local.set 12 + local.get 1 + i32.const 8 + i32.add + local.set 13 + local.get 5 + i32.const 6 + i32.and + local.set 14 + local.get 6 + local.set 8 + local.get 3 + local.set 2 + loop ;; label = @6 + local.get 13 + local.get 2 + i32.const 3 + i32.shl + local.tee 15 + i32.add + f64.load + local.get 12 + local.get 8 + i32.const 3 + i32.shl + local.tee 16 + i32.add + f64.load + f64.mul + local.get 1 + local.get 15 + i32.add + f64.load + local.get 4 + local.get 16 + i32.add + f64.load + f64.mul + local.get 7 + f64.add + f64.add + local.set 7 + local.get 8 + i32.const 2 + i32.add + local.set 8 + local.get 2 + i32.const 2 + i32.add + local.set 2 + local.get 9 + i32.const 2 + i32.add + local.tee 9 + local.get 14 + i32.ne + br_if 0 (;@6;) + end + end + local.get 10 + if ;; label = @5 + local.get 1 + local.get 2 + i32.const 3 + i32.shl + i32.add + f64.load + local.get 4 + local.get 8 + i32.const 3 + i32.shl + i32.add + f64.load + f64.mul + local.get 7 + f64.add + local.set 7 + end + local.get 0 + local.get 6 + i32.add + local.get 0 + local.get 11 + i32.sub + local.tee 2 + i32.sub + local.set 6 + local.get 0 + local.get 3 + i32.add + local.get 2 + i32.sub + local.set 3 + end + local.get 0 + i32.const 5 + i32.lt_s + br_if 2 (;@1;) + loop ;; label = @4 + local.get 7 + local.get 1 + local.get 3 + i32.const 3 + i32.shl + i32.add + local.tee 2 + f64.load offset=32 + local.get 4 + local.get 6 + i32.const 3 + i32.shl + i32.add + local.tee 8 + f64.load offset=32 + f64.mul + local.get 2 + f64.load offset=24 + local.get 8 + f64.load offset=24 + f64.mul + local.get 2 + f64.load offset=16 + local.get 8 + f64.load offset=16 + f64.mul + local.get 2 + f64.load + local.get 8 + f64.load + f64.mul + local.get 2 + f64.load offset=8 + local.get 8 + f64.load offset=8 + f64.mul + f64.add + f64.add + f64.add + f64.add + f64.add + local.set 7 + local.get 6 + i32.const 5 + i32.add + local.set 6 + local.get 3 + i32.const 5 + i32.add + local.set 3 + local.get 5 + i32.const 5 + i32.add + local.tee 5 + local.get 0 + i32.lt_s + br_if 0 (;@4;) + end + br 2 (;@1;) + end + local.get 0 + i32.const 2147483646 + i32.and + local.set 0 + local.get 5 + local.get 5 + i32.add + local.set 10 + local.get 2 + local.get 2 + i32.add + local.set 11 + loop ;; label = @3 + local.get 1 + local.get 2 + local.get 3 + i32.add + i32.const 3 + i32.shl + i32.add + f64.load + local.get 4 + local.get 5 + local.get 6 + i32.add + i32.const 3 + i32.shl + i32.add + f64.load + f64.mul + local.get 1 + local.get 3 + i32.const 3 + i32.shl + i32.add + f64.load + local.get 4 + local.get 6 + i32.const 3 + i32.shl + i32.add + f64.load + f64.mul + local.get 7 + f64.add + f64.add + local.set 7 + local.get 6 + local.get 10 + i32.add + local.set 6 + local.get 3 + local.get 11 + i32.add + local.set 3 + local.get 8 + i32.const 2 + i32.add + local.tee 8 + local.get 0 + i32.ne + br_if 0 (;@3;) + end + end + local.get 9 + i32.eqz + br_if 0 (;@1;) + local.get 1 + local.get 3 + i32.const 3 + i32.shl + i32.add + f64.load + local.get 4 + local.get 6 + i32.const 3 + i32.shl + i32.add + f64.load + f64.mul + local.get 7 + f64.add + local.set 7 + end + local.get 7) + (export "__wasm_call_ctors" (func 0)) + (export "__wasm_apply_data_relocs" (func 0)) + (export "c_ddot" (func 1)) + (export "c_ddot_ndarray" (func 2))) diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.js new file mode 100644 index 00000000000..fcbd4b67fd5 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ddot = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ddot, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `main` method', function test( t ) { + t.strictEqual( typeof ddot.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof ddot.ndarray, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `Module` constructor', function test( t ) { + t.strictEqual( typeof ddot.Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the main export is a `Module` instance', function test( t ) { + t.strictEqual( ddot instanceof ddot.Module, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.main.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.main.js new file mode 100644 index 00000000000..de10dc3f944 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.main.js @@ -0,0 +1,209 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ddot = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ddot, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `main` method has an arity of 5', function test( t ) { + t.strictEqual( ddot.main.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method computes the dot product of `x` and `y`', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + dot = ddot.main( x.length, x, 1, y, 1 ); + t.strictEqual( dot, -17.0, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + dot = ddot.main( x.length, x, 1, y, 1 ); + t.strictEqual( dot, 14.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports an `x` stride', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, // 1 + -3.0, // 2 + 3.0, + -4.0, + 1.0 + ]); + + dot = ddot.main( 3, x, 2, y, 1 ); + t.strictEqual( dot, -12.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports a `y` stride', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, // 1 + -5.0, // 2 + 7.0, + 6.0 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, + -3.0, // 1 + 3.0, + -4.0, // 2 + 1.0 + ]); + + dot = ddot.main( 3, x, 1, y, 2 ); + t.strictEqual( dot, 45.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `main` method returns `0.0`', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + dot = ddot.main( 0, x, 1, y, 1 ); + t.strictEqual( dot, 0.0, 'returns expected value' ); + + dot = ddot.main( -4, x, 1, y, 1 ); + t.strictEqual( dot, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports negative strides', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + + dot = ddot.main( 3, x, -2, y, -1 ); + t.strictEqual( dot, 67.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports complex access patterns', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + + dot = ddot.main( 3, x, 2, y, -1 ); + t.strictEqual( dot, 59.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports view offsets', function test( t ) { + var dot; + var x0; + var y0; + var x1; + var y1; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + y0 = new Float64Array([ + 6.0, + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 1 + 11.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); + + dot = ddot.main( 3, x1, 2, y1, 1 ); + t.strictEqual( dot, 124.0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.js new file mode 100644 index 00000000000..9adcb07e22f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = Module( mem ); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Module( value ); + }; + } +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (no new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Module( value ); // eslint-disable-line new-cap + }; + } +}); + +tape( 'the module instance returned by the module constructor inherits from a module wrapper', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.main.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.main.js new file mode 100644 index 00000000000..27e5613ade1 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.main.js @@ -0,0 +1,252 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which has an arity of 5', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.main.length, 5, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which computes the dot product of `x` and `y`', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 64; + + mod.write( xp, new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ) ); // eslint-disable-line max-len + mod.write( yp, new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ) ); // eslint-disable-line max-len + + dot = mod.main( 8, xp, 1, yp, 1 ); + t.strictEqual( dot, -17.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports an `x` stride', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ])); + mod.write( yp, new Float64Array([ + 8.0, // 0 + 2.0, // 1 + -3.0, // 2 + 3.0, + -4.0, + 1.0 + ])); + + dot = mod.main( 3, xp, 2, yp, 1 ); + t.strictEqual( dot, -12.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports a `y` stride', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 2.0, // 0 + -3.0, // 1 + -5.0, // 2 + 7.0, + 6.0 + ])); + mod.write( yp, new Float64Array([ + 8.0, // 0 + 2.0, + -3.0, // 1 + 3.0, + -4.0, // 2 + 1.0 + ])); + + dot = mod.main( 3, xp, 1, yp, 2 ); + t.strictEqual( dot, 45.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has a `main` method which returns `0.0`', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + dot = mod.main( -1, xp, 1, yp, 1 ); + t.strictEqual( dot, 0.0, 'returns expected value' ); + + dot = mod.main( 0, xp, 1, yp, 1 ); + t.strictEqual( dot, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports negative strides', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + mod.write( yp, new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ])); + + dot = mod.main( 3, xp, -2, yp, -1 ); + t.strictEqual( dot, 67.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports complex access patterns', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ])); + mod.write( yp, new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ])); + + dot = mod.main( 3, xp, 2, yp, -1 ); + t.strictEqual( dot, 59.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.ndarray.js new file mode 100644 index 00000000000..54ae75b8c0d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.module.ndarray.js @@ -0,0 +1,329 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which has an arity of 7', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.ndarray.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which computes the dot product of `x` and `y`', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ) ); + + dot = mod.ndarray( 5, xp, 1, 0, yp, 1, 0 ); + t.strictEqual( dot, 15.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` stride', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ])); + mod.write( yp, new Float64Array([ + 8.0, // 0 + 2.0, // 1 + -3.0, // 2 + 3.0, + -4.0, + 1.0 + ])); + + dot = mod.ndarray( 3, xp, 2, 0, yp, 1, 0 ); + t.strictEqual( dot, -12.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` offset', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 2.0, + -3.0, // 0 + -5.0, // 1 + 7.0, // 2 + 6.0 + ])); + mod.write( yp, new Float64Array([ + 8.0, // 0 + 2.0, // 1 + -3.0, // 2 + 3.0, + -4.0, + 1.0 + ])); + + dot = mod.ndarray( 3, xp, 1, 1, yp, 1, 0 ); + t.strictEqual( dot, -55.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports a `y` stride', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 2.0, // 0 + -3.0, // 1 + -5.0, // 2 + 7.0, + 6.0 + ])); + mod.write( yp, new Float64Array([ + 8.0, // 0 + 2.0, + -3.0, // 1 + 3.0, + -4.0, // 2 + 1.0 + ])); + + dot = mod.ndarray( 3, xp, 1, 0, yp, 2, 0 ); + t.strictEqual( dot, 45.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports a `y` offset', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 48; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, // 1 + 3.0, // 2 + 4.0, + 5.0, + 6.0 + ])); + mod.write( yp, new Float64Array([ + 6.0, + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 1 + 11.0 // 2 + ])); + + dot = mod.ndarray( 3, xp, 1, 0, yp, 1, 3 ); + t.strictEqual( dot, 62.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has an `ndarray` method which returns `0.0`', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + mod.write( yp, new Float64Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ) ); + + dot = mod.ndarray( -1, 3.0, xp, 1, 0, yp, 1, 0 ); + t.strictEqual( dot, 0.0, 'returns expected value' ); + + dot = mod.ndarray( 0, 3.0, xp, 1, 0, yp, 1, 0 ); + t.strictEqual( dot, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports negative strides', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + mod.write( yp, new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ])); + + dot = mod.ndarray( 3, xp, -2, 4, yp, -1, 2 ); + t.strictEqual( dot, 67.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports complex access patterns', function test( t ) { + var dot; + var mem; + var mod; + var xp; + var yp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + yp = 40; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ])); + mod.write( yp, new Float64Array([ + 6.0, + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0 + ])); + + dot = mod.ndarray( 3, xp, 2, 0, yp, -1, 3 ); + t.strictEqual( dot, 68.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.ndarray.js new file mode 100644 index 00000000000..6c455fd80c4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.ndarray.js @@ -0,0 +1,231 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var ddot = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof ddot, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `ndarray` method has an arity of 7', function test( t ) { + t.strictEqual( ddot.ndarray.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method computes the dot product of `x` and `y`', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] ); + y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] ); + + dot = ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual( dot, -17.0, 'returns expected value' ); + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + dot = ddot.ndarray( x.length, x, 1, 0, y, 1, 0 ); + t.strictEqual( dot, 14.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports an `x` stride', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, + -5.0, // 1 + 7.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, // 1 + -3.0, // 2 + 3.0, + -4.0, + 1.0 + ]); + + dot = ddot.ndarray( 3, x, 2, 0, y, 1, 0 ); + t.strictEqual( dot, -12.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports an `x` offset', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + y = new Float64Array([ + 6.0, // 0 + 7.0, // 1 + 8.0, // 2 + 9.0, + 10.0, + 11.0 + ]); + + dot = ddot.ndarray( 3, x, 2, 1, y, 1, 0 ); + t.strictEqual( dot, 88.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports a `y` stride', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 2.0, // 0 + -3.0, // 1 + -5.0, // 2 + 7.0, + 6.0 + ]); + y = new Float64Array([ + 8.0, // 0 + 2.0, + -3.0, // 1 + 3.0, + -4.0, // 2 + 1.0 + ]); + + dot = ddot.ndarray( 3, x, 1, 0, y, 2, 0 ); + t.strictEqual( dot, 45.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports a `y` offset', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ]); + y = new Float64Array([ + 6.0, + 7.0, + 8.0, + 9.0, // 0 + 10.0, // 1 + 11.0 // 2 + ]); + + dot = ddot.ndarray( 3, x, 2, 0, y, 1, 3 ); + t.strictEqual( dot, 94.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `ndarray` method returns `0.0`', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array( [ 3.0, -4.0, 1.0 ] ); + y = new Float64Array( [ 1.0, -2.0, 3.0 ] ); + + dot = ddot.ndarray( 0, x, 1, 0, y, 1, 0 ); + t.strictEqual( dot, 0.0, 'returns expected value' ); + + dot = ddot.ndarray( -4, x, 1, 0, y, 1, 0 ); + t.strictEqual( dot, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports negative strides', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ]); + y = new Float64Array([ + 6.0, // 2 + 7.0, // 1 + 8.0, // 0 + 9.0, + 10.0 + ]); + + dot = ddot.ndarray( 3, x, -2, x.length-1, y, -1, 2 ); + t.strictEqual( dot, 67.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports complex access patterns', function test( t ) { + var dot; + var x; + var y; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 2 + ]); + y = new Float64Array([ + 6.0, + 7.0, // 2 + 8.0, // 1 + 9.0, // 0 + 10.0 + ]); + + dot = ddot.ndarray( 3, x, 2, 0, y, -1, y.length-2 ); + t.strictEqual( dot, 68.0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.routine.js b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.routine.js new file mode 100644 index 00000000000..56a4b67daaf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/ddot-wasm/test/test.routine.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib/module.js' ); +var Routine = require( './../lib/routine.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Routine, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mod = Routine(); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a module wrapper', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a BLAS routine module', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); From 3ab82210f8241550f61dfc491345ee1ebd9bcf2f Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 19 Oct 2024 01:05:48 +0200 Subject: [PATCH 45/50] docs: fix note --- lib/node_modules/@stdlib/blas/base/idamax/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/idamax/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/idamax/docs/repl.txt index 5b82171255c..f179ffadd94 100644 --- a/lib/node_modules/@stdlib/blas/base/idamax/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/idamax/docs/repl.txt @@ -8,7 +8,7 @@ Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N < 1`, both functions return `-1`. + If `N < 1`, the function returns `-1`. Parameters ---------- From 6c9018cb081c3e9e0510bd5609995bf38449e6d1 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 19 Oct 2024 01:06:05 +0200 Subject: [PATCH 46/50] docs: fix note --- lib/node_modules/@stdlib/blas/base/isamax/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/blas/base/isamax/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/isamax/docs/repl.txt index 2b19fedb391..6326e1c94b4 100644 --- a/lib/node_modules/@stdlib/blas/base/isamax/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/isamax/docs/repl.txt @@ -8,7 +8,7 @@ Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N < 1`, both functions return `-1`. + If `N < 1`, the function returns `-1`. Parameters ---------- From 8f8b6497126fee0256de7be78a9501edd37c70fb Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Sat, 19 Oct 2024 04:41:01 +0530 Subject: [PATCH 47/50] feat: add `blas/base/idamax-wasm` PR-URL: https://github.com/stdlib-js/stdlib/pull/3016 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/blas/base/idamax-wasm/README.md | 298 +++++++++++ .../base/idamax-wasm/benchmark/benchmark.js | 106 ++++ .../idamax-wasm/benchmark/benchmark.module.js | 66 +++ .../benchmark/benchmark.module.main.js | 130 +++++ .../benchmark/benchmark.module.ndarray.js | 130 +++++ .../benchmark/benchmark.ndarray.js | 106 ++++ .../blas/base/idamax-wasm/docs/repl.txt | 496 ++++++++++++++++++ .../base/idamax-wasm/docs/types/index.d.ts | 316 +++++++++++ .../blas/base/idamax-wasm/docs/types/test.ts | 347 ++++++++++++ .../blas/base/idamax-wasm/examples/index.js | 43 ++ .../examples/little_endian_arrays.js | 65 +++ .../blas/base/idamax-wasm/examples/module.js | 63 +++ .../base/idamax-wasm/lib/binary.browser.js | 33 ++ .../blas/base/idamax-wasm/lib/binary.js | 34 ++ .../blas/base/idamax-wasm/lib/index.js | 99 ++++ .../@stdlib/blas/base/idamax-wasm/lib/main.js | 60 +++ .../blas/base/idamax-wasm/lib/module.js | 198 +++++++ .../blas/base/idamax-wasm/lib/routine.js | 166 ++++++ .../blas/base/idamax-wasm/manifest.json | 36 ++ .../blas/base/idamax-wasm/package.json | 84 +++ .../blas/base/idamax-wasm/scripts/build.js | 63 +++ .../base/idamax-wasm/scripts/template.txt | 33 ++ .../blas/base/idamax-wasm/src/Makefile | 232 ++++++++ .../blas/base/idamax-wasm/src/main.wasm | Bin 0 -> 295 bytes .../blas/base/idamax-wasm/src/main.wat | 106 ++++ .../blas/base/idamax-wasm/test/test.js | 53 ++ .../blas/base/idamax-wasm/test/test.main.js | 163 ++++++ .../blas/base/idamax-wasm/test/test.module.js | 154 ++++++ .../base/idamax-wasm/test/test.module.main.js | 184 +++++++ .../idamax-wasm/test/test.module.ndarray.js | 243 +++++++++ .../base/idamax-wasm/test/test.ndarray.js | 185 +++++++ .../base/idamax-wasm/test/test.routine.js | 71 +++ 32 files changed, 4363 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/little_endian_arrays.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/binary.browser.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/binary.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/routine.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/scripts/build.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/scripts/template.txt create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/src/Makefile create mode 100755 lib/node_modules/@stdlib/blas/base/idamax-wasm/src/main.wasm create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/src/main.wat create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.routine.js diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/README.md b/lib/node_modules/@stdlib/blas/base/idamax-wasm/README.md new file mode 100644 index 00000000000..c7d292df4a7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/README.md @@ -0,0 +1,298 @@ + + +# idamax + +> Find the index of the first element having the maximum absolute value. + +
+ +## Usage + +```javascript +var idamax = require( '@stdlib/blas/base/idamax-wasm' ); +``` + +#### idamax.main( N, x, strideX ) + +Finds the index of the first element having the maximum absolute value. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); + +var idx = idamax.main( 3, x, 1 ); +// returns 1 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: index increment for `x`. + +The `N` and stride parameters determine which elements in the input strided array are accessed at runtime. For example, to traverse every other value, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var idx = idamax.main( 4, x, 2 ); +// returns 2 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +// Create an offset view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Find index of element having the maximum absolute value: +var idx = idamax.main( 3, x1, 2 ); +// returns 2 +``` + +#### idamax.ndarray( N, x, strideX, offsetX ) + +Finds the index of the first element having the maximum absolute value using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, 2.0 ] ); + +var idx = idamax.ndarray( 3, x, 1, 0 ); +// returns 1 +``` + +The function has the following additional parameters: + +- **offsetX**: 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 start from the second index, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +var idx = idamax.ndarray( 5, x, 1, 1 ); +// returns 4 +``` + +* * * + +### Module + +#### idamax.Module( memory ) + +Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new idamax.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); +``` + +#### idamax.Module.prototype.main( N, xp, sx ) + +Finds the index of the first element having the maximum absolute value. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new idamax.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointer (i.e., byte offsets) for storing the input vector: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +var idx = mod.main( N, xptr, 1 ); +// returns 4 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sx**: index increment for `x`. + +#### idamax.Module.prototype.ndarray( N, xp, sx, ox ) + +Finds the index of the first element having the maximum absolute value using alternative indexing semantics. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new idamax.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointer (i.e., byte offsets) for storing the input vector: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +var idx = mod.ndarray( N, xptr, 1, 0 ); +// returns 4 +``` + +The function has the following additional parameters: + +- **ox**: starting index for `x`. + +
+ + + +
+ +* * * + +## Notes + +- If `N < 1`, both `main` and `ndarray` methods return `-1`. +- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `idamax` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/blas/base/idamax`][@stdlib/blas/base/idamax]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/blas/base/idamax`][@stdlib/blas/base/idamax]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other. +- `idamax()` corresponds to the [BLAS][blas] level 1 function [`idamax`][idamax]. + +
+ + + +
+ +* * * + +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var idamax = require( '@stdlib/blas/base/idamax-wasm' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, 0, 100, opts ); +console.log( x ); + +var idx = idamax.ndarray( x.length, x, 1, 0 ); +console.log( idx ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.js new file mode 100644 index 00000000000..afc46d660be --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var idamax = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var idx; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = idamax.main( x.length, x, 1 ); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.js new file mode 100644 index 00000000000..f2b3bd4880a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var pkg = require( './../package.json' ).name; +var idamax = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; + + +// MAIN // + +bench( pkg+':Module:constructor', opts, function benchmark( b ) { + var values; + var o; + var v; + var i; + + o = { + 'initial': 0 + }; + values = [ + new Memory( o ), + new Memory( o ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new idamax.Module( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.main.js new file mode 100644 index 00000000000..728c214689a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.main.js @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var idamax = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var xptr; + var idx; + var mod; + var mem; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new idamax.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*nb ); + + // Define pointer (i.e., byte offsets) to the first vector elements: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = mod.main( len, xptr, 1 ); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.ndarray.js new file mode 100644 index 00000000000..ee48e7a8b34 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.module.ndarray.js @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var idamax = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var xptr; + var idx; + var mod; + var mem; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new idamax.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*nb ); + + // Define pointer (i.e., byte offsets) to the first vector elements: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = mod.ndarray( len, xptr, 1, 0 ); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.ndarray.js new file mode 100644 index 00000000000..6704dc34298 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/benchmark/benchmark.ndarray.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var idamax = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var idx; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + idx = idamax.ndarray( x.length, x, 1, 0 ); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( idx ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/repl.txt new file mode 100644 index 00000000000..fda0a2a5da2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/repl.txt @@ -0,0 +1,496 @@ + +{{alias}}.main( N, x, strideX ) + Finds the index of the first element having the maximum absolute value. + + 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 + array views. + + If `N < 1`, the function returns `-1`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + Returns + ------- + idx: integer + Index value. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var idx = {{alias}}.main( x.length, x, 1 ) + 1 + + // Using `N` and stride parameters: + > x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); + > idx = {{alias}}.main( 6, x, -1 ) + 2 + + // Using view offsets: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > idx = {{alias}}.main( 3, x1, 2 ) + 0 + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Finds the index of the first element having the maximum absolute value using + alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + Returns + ------- + idx: integer + Index value. + + Examples + -------- + // Standard Usage: + > var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] ); + > var idx = {{alias}}.ndarray( x.length, x, 1, 0 ) + 1 + + // Using offset parameter: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); + > idx = {{alias}}.ndarray( 4, x, 1, 1 ) + 3 + + +{{alias}}.Module( memory ) + Returns a new WebAssembly module wrapper which uses the provided WebAssembly + memory instance as its underlying memory. + + Parameters + ---------- + memory: Memory + WebAssembly memory instance. + + Returns + ------- + mod: Module + WebAssembly module wrapper. + + Examples + -------- + // Create a new memory instance: + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + + // Create a new routine: + > var mod = new {{alias}}.Module( mem ); + + // Initialize the routine: + > mod.initializeSync(); + + +{{alias}}.Module.prototype.binary + Read-only property which returns WebAssembly binary code. + + Returns + ------- + out: Uint8Array + WebAssembly binary code. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.binary + + + +{{alias}}.Module.prototype.memory + Read-only property which returns WebAssembly memory. + + Returns + ------- + mem: Memory|null + WebAssembly memory. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.memory + + + +{{alias}}.Module.prototype.buffer + Read-only property which returns a WebAssembly memory buffer as a + Uint8Array. + + Returns + ------- + buf: Uint8Array|null + WebAssembly memory buffer. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.buffer + + + +{{alias}}.Module.prototype.view + Read-only property which returns a WebAsssembly memory buffer as a DataView. + + Returns + ------- + view: DataView|null + WebAssembly memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.view + + + +{{alias}}.Module.prototype.exports + Read-only property which returns "raw" WebAssembly module exports. + + Returns + ------- + out: Object|null + WebAssembly module exports. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.exports + {...} + + +{{alias}}.Module.prototype.initialize() + Asynchronously initializes a WebAssembly module instance. + + Returns + ------- + p: Promise + Promise which resolves upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initialize(); + + +{{alias}}.Module.prototype.initializeAsync( clbk ) + Asynchronously initializes a WebAssembly module instance. + + Parameters + ---------- + clbk: Function + Callback to invoke upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > function clbk() { console.log( 'done' ) }; + > mod.initializeAsync( clbk ); + + +{{alias}}.Module.prototype.initializeSync() + Synchronously initializes a WebAssembly module instance. + + In web browsers, JavaScript engines may raise an exception when attempting + to synchronously compile large WebAssembly binaries due to concerns about + blocking the main thread. Hence, to initialize WebAssembly modules having + large binaries (e.g., >4KiB), consider using asynchronous initialization + methods in browser contexts. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + +{{alias}}.Module.prototype.realloc( nbytes ) + Reallocates the underlying WebAssembly memory instance to a specified number + of bytes. + + WebAssembly memory can only *grow*, not shrink. Hence, if provided a number + of bytes which is less than or equal to the size of the current memory, the + function does nothing. + + When non-shared memory is resized, the underlying the `ArrayBuffer` is + detached, consequently invalidating any associated typed array views. Before + resizing non-shared memory, ensure that associated typed array views no + longer need byte access and can be garbage collected. + + Parameters + ---------- + nbytes: integer + Memory size (in bytes). + + Returns + ------- + bool: boolean + Boolean indicating whether the resize operation was successful. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ) + + + +{{alias}}.Module.prototype.hasCapacity( byteOffset, values ) + Returns a boolean indicating whether the underlying WebAssembly memory + instance has the capacity to store a provided list of values starting from a + specified byte offset. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + bool: boolean + Boolean indicating whether the underlying WebAssembly memory instance + has enough capacity. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.hasCapacity( 0, [ 1, 2, 3, 4 ] ) + true + + +{{alias}}.Module.prototype.isView( values ) + Returns a boolean indicating whether a provided list of values is a view of + the underlying memory of the WebAssembly module. + + Parameters + ---------- + values: ArrayLikeObject + Input array. + + Returns + ------- + bool: boolean + Boolean indicating whether the list is a memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.isView( [ 1, 2, 3, 4 ] ) + false + + +{{alias}}.Module.prototype.write( byteOffset, values ) + Writes values to the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the input array. For example, if provided a Float32Array, + the function writes each element as a single-precision floating-point number + to the underlying WebAssembly memory instance. + + In order to write elements as a different data type, you need to perform an + explicit cast *before* calling this method. For example, in order to write + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must first convert the Float32Array to an + Int32Array before passing the values to this method. + + If provided an array having an unknown or "generic" data type, elements are + written as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + + +{{alias}}.Module.prototype.read( byteOffset, out ) + Reads values from the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the output array. For example, if provided a Float32Array, + the function reads each element as a single-precision floating-point number + from the underlying WebAssembly memory instance. + + In order to read elements as a different data type, you need to perform an + explicit cast *after* calling this method. For example, in order to read + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must convert the Float32Array to an Int32Array + after reading memory values using this method. + + If provided an output array having an unknown or "generic" data type, + elements are read as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start reading values. + + out: ArrayLikeObject + Output array for storing read values. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + > var out = [ 0, 0, 0, 0 ]; + > mod.read( 0, out ); + > out + [ 1, 2, 3, 4 ] + + +{{alias}}.Module.prototype.main( N, xp, sx ) + Finds the index of the first element having the maximum absolute value. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + Returns + ------- + idx: integer + Index value. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointer" (i.e., byte offsets) into module memory: + > var xptr = 0; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + + // Perform computation: + > var idx = mod.main( 5, xptr, 1 ) + 4 + + +{{alias}}.Module.prototype.ndarray( N, xp, sx, ox ) + Finds the index of the first element having the maximum absolute value using + alternative indexing semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + Returns + ------- + idx: integer + Index value. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointer" (i.e., byte offsets) into module memory: + > var xptr = 0; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + + // Perform computation: + > var out = mod.ndarray( 5, xptr, 1, 0 ) + 4 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/types/index.d.ts new file mode 100644 index 00000000000..3765db1f5b9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/types/index.d.ts @@ -0,0 +1,316 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ModuleWrapper, Memory } from '@stdlib/types/wasm'; + +/** +* Interface defining a module constructor which is both "newable" and "callable". +*/ +interface ModuleConstructor { + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new idamax.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var idx = mod.main( N, xptr, 1 ); + * // returns 4 + */ + new( mem: Memory ): Module; // newable + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = idamax.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var idx = mod.main( N, xptr, 1 ); + * // returns 4 + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing an `idamax` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Finds the index of the first element having the maximum absolute value. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @returns index value + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new idamax.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var idx = mod.main( N, xptr, 1 ); + * // returns 4 + */ + main( N: number, xptr: number, strideX: number ): number; + + /** + * Finds the index of the first element having the maximum absolute value using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns index value + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new idamax.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var idx = mod.ndarray( N, xptr, 1, 0 ); + * // returns 4 + */ + ndarray( N: number, xptr: number, strideX: number, offsetX: number ): number; +} + +/** +* Interface describing `idamax`. +*/ +interface Routine extends ModuleWrapper { + /** + * Finds the index of the first element having the maximum absolute value. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - `x` stride length + * @returns index value + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, -5.0 ] ); + * + * var idx = idamax.main( x.length, x, 1 ); + * // returns 4 + */ + main( N: number, x: Float64Array, strideX: number ): number; + + /** + * Finds the index of the first element having the maximum absolute value using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns index value + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, -5.0 ] ); + * + * var idx = idamax.ndarray( x.length, x, 1, 0 ); + * // returns 4 + */ + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number ): number; + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new idamax.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var idx = mod.main( N, xptr, 1 ); + * // returns 4 + */ + Module: ModuleConstructor; +} + +/** +* Finds the index of the first element having the maximum absolute value. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - `x` stride length +* @returns index value +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, -5.0, 4.0 ] ); +* +* var idx = idamax.main( x.length, x, 1 ); +* // returns 3 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* var idx = idamax.ndarray( x.length, x, -1, 4 ); +* // returns 0 +*/ +declare var idamax: Routine; + + +// EXPORTS // + +export = idamax; diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/types/test.ts new file mode 100644 index 00000000000..e26bc3d7839 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/docs/types/test.ts @@ -0,0 +1,347 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable space-in-parens */ + +import Memory = require( '@stdlib/wasm/memory' ); +import idamax = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a number... +{ + const x = new Float64Array( 10 ); + + idamax.main( x.length, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + idamax.main( '10', x, 1 ); // $ExpectError + idamax.main( true, x, 1 ); // $ExpectError + idamax.main( false, x, 1 ); // $ExpectError + idamax.main( null, x, 1 ); // $ExpectError + idamax.main( undefined, x, 1 ); // $ExpectError + idamax.main( [], x, 1 ); // $ExpectError + idamax.main( {}, x, 1 ); // $ExpectError + idamax.main( ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + idamax.main( x.length, 10, 1 ); // $ExpectError + idamax.main( x.length, '10', 1 ); // $ExpectError + idamax.main( x.length, true, 1 ); // $ExpectError + idamax.main( x.length, false, 1 ); // $ExpectError + idamax.main( x.length, null, 1 ); // $ExpectError + idamax.main( x.length, undefined, 1 ); // $ExpectError + idamax.main( x.length, [], 1 ); // $ExpectError + idamax.main( x.length, {}, 1 ); // $ExpectError + idamax.main( x.length, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + idamax.main( x.length, x, '10' ); // $ExpectError + idamax.main( x.length, x, true ); // $ExpectError + idamax.main( x.length, x, false ); // $ExpectError + idamax.main( x.length, x, null ); // $ExpectError + idamax.main( x.length, x, undefined ); // $ExpectError + idamax.main( x.length, x, [] ); // $ExpectError + idamax.main( x.length, x, {} ); // $ExpectError + idamax.main( x.length, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + idamax.main(); // $ExpectError + idamax.main( x.length ); // $ExpectError + idamax.main( x.length, x ); // $ExpectError + idamax.main( x.length, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + idamax.ndarray( x.length, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + idamax.ndarray( '10', x, 1, 0 ); // $ExpectError + idamax.ndarray( true, x, 1, 0 ); // $ExpectError + idamax.ndarray( false, x, 1, 0 ); // $ExpectError + idamax.ndarray( null, x, 1, 0 ); // $ExpectError + idamax.ndarray( undefined, x, 1, 0 ); // $ExpectError + idamax.ndarray( [], x, 1, 0 ); // $ExpectError + idamax.ndarray( {}, x, 1, 0 ); // $ExpectError + idamax.ndarray( ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + idamax.ndarray( x.length, 10, 1, 0 ); // $ExpectError + idamax.ndarray( x.length, '10', 1, 0 ); // $ExpectError + idamax.ndarray( x.length, true, 1, 0 ); // $ExpectError + idamax.ndarray( x.length, false, 1, 0 ); // $ExpectError + idamax.ndarray( x.length, null, 1, 0 ); // $ExpectError + idamax.ndarray( x.length, undefined, 1, 0 ); // $ExpectError + idamax.ndarray( x.length, [], 1, 0 ); // $ExpectError + idamax.ndarray( x.length, {}, 1, 0 ); // $ExpectError + idamax.ndarray( x.length, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + idamax.ndarray( x.length, x, '10', 0 ); // $ExpectError + idamax.ndarray( x.length, x, true, 0 ); // $ExpectError + idamax.ndarray( x.length, x, false, 0 ); // $ExpectError + idamax.ndarray( x.length, x, null, 0 ); // $ExpectError + idamax.ndarray( x.length, x, undefined, 0 ); // $ExpectError + idamax.ndarray( x.length, x, [], 0 ); // $ExpectError + idamax.ndarray( x.length, x, {}, 0 ); // $ExpectError + idamax.ndarray( x.length, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + idamax.ndarray( x.length, x, 1, '10' ); // $ExpectError + idamax.ndarray( x.length, x, 1, true ); // $ExpectError + idamax.ndarray( x.length, x, 1, false ); // $ExpectError + idamax.ndarray( x.length, x, 1, null ); // $ExpectError + idamax.ndarray( x.length, x, 1, undefined ); // $ExpectError + idamax.ndarray( x.length, x, 1, [] ); // $ExpectError + idamax.ndarray( x.length, x, 1, {} ); // $ExpectError + idamax.ndarray( x.length, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + idamax.ndarray(); // $ExpectError + idamax.ndarray( x.length ); // $ExpectError + idamax.ndarray( x.length, x ); // $ExpectError + idamax.ndarray( x.length, x, 1 ); // $ExpectError + idamax.ndarray( x.length, x, 1, 0, 10 ); // $ExpectError +} + +// Attached to the main export is a `Module` constructor which returns a module... +{ + const mem = new Memory({ + 'initial': 0 + }); + + idamax.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + idamax.Module( '10' ); // $ExpectError + idamax.Module( true ); // $ExpectError + idamax.Module( false ); // $ExpectError + idamax.Module( null ); // $ExpectError + idamax.Module( undefined ); // $ExpectError + idamax.Module( [] ); // $ExpectError + idamax.Module( {} ); // $ExpectError + idamax.Module( ( x: number ): number => x ); // $ExpectError +} + +// The `Module` constructor returns a module instance having a `main` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.main( 10, 0, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.main( '10', 0, 10 ); // $ExpectError + mod.main( true, 0, 10 ); // $ExpectError + mod.main( false, 0, 10 ); // $ExpectError + mod.main( null, 0, 10 ); // $ExpectError + mod.main( undefined, 0, 10 ); // $ExpectError + mod.main( [], 0, 10 ); // $ExpectError + mod.main( {}, 0, 10 ); // $ExpectError + mod.main( ( x: number ): number => x, 0, 10 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.main( 10, '10', 1 ); // $ExpectError + mod.main( 10, true, 1 ); // $ExpectError + mod.main( 10, false, 1 ); // $ExpectError + mod.main( 10, null, 1 ); // $ExpectError + mod.main( 10, undefined, 1 ); // $ExpectError + mod.main( 10, [], 1 ); // $ExpectError + mod.main( 10, {}, 1 ); // $ExpectError + mod.main( 10, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.main( 10, 0, '10' ); // $ExpectError + mod.main( 10, 0, true ); // $ExpectError + mod.main( 10, 0, false ); // $ExpectError + mod.main( 10, 0, null ); // $ExpectError + mod.main( 10, 0, undefined ); // $ExpectError + mod.main( 10, 0, [] ); // $ExpectError + mod.main( 10, 0, {} ); // $ExpectError + mod.main( 10, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 0 ); // $ExpectError + mod.main( 10, 0, 1, 10 ); // $ExpectError +} + +// The `Module` constructor returns a module instance having an `ndarray` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.ndarray( 10, 0, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.ndarray( '10', 0, 1, 0 ); // $ExpectError + mod.ndarray( true, 0, 1, 0 ); // $ExpectError + mod.ndarray( false, 0, 1, 0 ); // $ExpectError + mod.ndarray( null, 0, 1, 0 ); // $ExpectError + mod.ndarray( undefined, 0, 1, 0 ); // $ExpectError + mod.ndarray( [], 0, 1, 0 ); // $ExpectError + mod.ndarray( {}, 0, 1, 0 ); // $ExpectError + mod.ndarray( ( x: number ): number => x, 0, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.ndarray( 10, '10', 1, 0 ); // $ExpectError + mod.ndarray( 10, true, 1, 0 ); // $ExpectError + mod.ndarray( 10, false, 1, 0 ); // $ExpectError + mod.ndarray( 10, null, 1, 0 ); // $ExpectError + mod.ndarray( 10, undefined, 1, 0 ); // $ExpectError + mod.ndarray( 10, [], 1, 0 ); // $ExpectError + mod.ndarray( 10, {}, 1, 0 ); // $ExpectError + mod.ndarray( 10, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.ndarray( 10, 0, '10', 0 ); // $ExpectError + mod.ndarray( 10, 0, true, 0 ); // $ExpectError + mod.ndarray( 10, 0, false, 0 ); // $ExpectError + mod.ndarray( 10, 0, null, 0 ); // $ExpectError + mod.ndarray( 10, 0, undefined, 0 ); // $ExpectError + mod.ndarray( 10, 0, [], 0 ); // $ExpectError + mod.ndarray( 10, 0, {}, 0 ); // $ExpectError + mod.ndarray( 10, 0, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.ndarray( 10, 0, 1, '10' ); // $ExpectError + mod.ndarray( 10, 0, 1, true ); // $ExpectError + mod.ndarray( 10, 0, 1, false ); // $ExpectError + mod.ndarray( 10, 0, 1, null ); // $ExpectError + mod.ndarray( 10, 0, 1, undefined ); // $ExpectError + mod.ndarray( 10, 0, 1, [] ); // $ExpectError + mod.ndarray( 10, 0, 1, {} ); // $ExpectError + mod.ndarray( 10, 0, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = idamax.Module( mem ); + + mod.ndarray(); // $ExpectError + mod.ndarray( 10 ); // $ExpectError + mod.ndarray( 10, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/index.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/index.js new file mode 100644 index 00000000000..db6b2618b85 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var oneTo = require( '@stdlib/array/one-to' ); +var idamax = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Specify a vector length: + var N = 5; + + // Create input array: + var x = oneTo( N, 'float64' ); + + // Perform computation: + var idx = idamax.ndarray( N, x, 1, 0 ); + + // Print the result: + console.log( idx ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/little_endian_arrays.js new file mode 100644 index 00000000000..e7a585cadfe --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/little_endian_arrays.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); +var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +var idamax = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new idamax.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Specify a vector length: + var N = 5; + + // Define pointer (i.e., byte offsets) for storing the input vector: + var xptr = 0; + + // Create typed array views over module memory: + var x = new Float64ArrayLE( mod.memory.buffer, xptr, N ); + + // Write values to module memory: + gfillBy( N, x, 1, discreteUniform( -10.0, 10.0 ) ); + + // Perform computation: + var idx = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( idx ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/module.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/module.js new file mode 100644 index 00000000000..4618c639516 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/examples/module.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var idamax = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new idamax.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Define a vector data type: + var dtype = 'float64'; + + // Specify a vector length: + var N = 5; + + // Define pointer (i.e., byte offsets) for storing the input vector: + var xptr = 0; + + // Write vector values to module memory: + mod.write( xptr, oneTo( N, dtype ) ); + + // Perform computation: + var idx = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( idx ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/binary.browser.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/binary.browser.js new file mode 100644 index 00000000000..919693bd1ba --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAETA2AAAGADf39/AX9gBH9/f38BfwIPAQNlbnYGbWVtb3J5AgAAAwQDAAECB04EEV9fd2FzbV9jYWxsX2N0b3JzAAAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAIY19pZGFtYXgAARBjX2lkYW1heF9uZGFycmF5AAIKjwEDAwABCyEBAX4gACABIAIgAqwiA0IBIACsfX5CACADQgBXG6cQAgtnAgJ8A38gAEEATARAQX8PCyAAQQFGBEBBAA8LIAEgA0EDdGorAwCZIQRBASEGA0AgASACIANqIgNBA3RqKwMAmSIFIAQgBCAFYyIIGyEEIAYgByAIGyEHIAZBAWoiBiAARw0ACyAHCw==' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/binary.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/binary.js new file mode 100644 index 00000000000..6f02393f96e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/binary.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readWASM = require( '@stdlib/fs/read-wasm' ).sync; + + +// MAIN // + +var wasm = readWASM( resolve( __dirname, '..', 'src', 'main.wasm' ) ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/index.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/index.js new file mode 100644 index 00000000000..684904f47b6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/index.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* WebAssembly routine to find the index of the first element having the maximum absolute value. +* +* @module @stdlib/blas/base/idamax-wasm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var idamax = require( '@stdlib/blas/base/idamax-wasm' ); +* +* // Define a strided array: +* var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* // Perform operation: +* var idx = idamax.main( x.length, x, 1 ); +* // returns 3 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var idamax = require( '@stdlib/blas/base/idamax-wasm' ); +* +* // Define a strided array: +* var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); +* +* // Perform operation: +* var idx = idamax.ndarray( x.length, x, 1, 0 ); +* // returns 3 +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var idamax = require( '@stdlib/blas/base/idamax-wasm' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var mod = new idamax.Module( mem ); +* // returns +* +* // Initialize the routine: +* mod.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* mod.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var idx = mod.main( N, xptr, 1 ); +* // returns 4 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var Module = require( './module.js' ); + + +// MAIN // + +setReadOnly( main, 'Module', Module ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "Module": "main.Module" } diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/main.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/main.js new file mode 100644 index 00000000000..5edb94c1317 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/main.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var Routine = require( './routine.js' ); + + +// MAIN // + +/** +* WebAssembly module to find the index of the first element having the maximum absolute value. +* +* @name idamax +* @type {Routine} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var idx = idamax.main( x.length, x, 1 ); +* // returns 4 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var idx = idamax.ndarray( x.length, x, 1, 0 ); +* // returns 4 +*/ +var idamax = new Routine(); +idamax.initializeSync(); // eslint-disable-line node/no-sync + + +// EXPORTS // + +module.exports = idamax; diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/module.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/module.js new file mode 100644 index 00000000000..301e0ec1640 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/module.js @@ -0,0 +1,198 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var WasmModule = require( '@stdlib/wasm/module-wrapper' ); +var format = require( '@stdlib/string/format' ); +var wasmBinary = require( './binary.js' ); + + +// MAIN // + +/** +* BLAS routine WebAssembly module wrapper constructor. +* +* @constructor +* @param {Object} memory - WebAssembly memory instance +* @throws {TypeError} must provide a WebAssembly memory instance +* @returns {Module} module instance +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var idamax = new Module( mem ); +* // returns +* +* // Initialize the routine: +* idamax.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* idamax.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var idx = idamax.main( N, xptr, 1 ); +* // returns 4 +*/ +function Module( memory ) { + if ( !( this instanceof Module ) ) { + return new Module( memory ); + } + if ( !isWebAssemblyMemory( memory ) ) { + throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) ); + } + // Call the parent constructor: + WasmModule.call( this, wasmBinary, memory, { + 'env': { + 'memory': memory + } + }); + + return this; +} + +// Inherit from the parent constructor: +inherits( Module, WasmModule ); + +/** +* Finds the index of the first element having the maximum absolute value. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @returns {integer} index value +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var idamax = new Module( mem ); +* // returns +* +* // Initialize the routine: +* idamax.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* idamax.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var idx = idamax.main( N, xptr, 1 ); +* // returns 4 +*/ +setReadOnly( Module.prototype, 'main', function idamax( N, xptr, strideX ) { + return this._instance.exports.c_idamax( N, xptr, strideX ); +}); + +/** +* Finds the index of the first element having the maximum absolute value using alternative indexing semantics. +* +* @name ndarray +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @returns {integer} index value +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var idamax = new Module( mem ); +* // returns +* +* // Initialize the routine: +* idamax.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* idamax.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var idx = idamax.ndarray( N, xptr, 1, 0 ); +* // returns 4 +*/ +setReadOnly( Module.prototype, 'ndarray', function idamax( N, xptr, strideX, offsetX ) { + return this._instance.exports.c_idamax_ndarray( N, xptr, strideX, offsetX ); +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/routine.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/routine.js new file mode 100644 index 00000000000..0923588bc87 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/lib/routine.js @@ -0,0 +1,166 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var Memory = require( '@stdlib/wasm/memory' ); +var arrays2ptrs = require( '@stdlib/wasm/base/arrays2ptrs' ); +var strided2object = require( '@stdlib/wasm/base/strided2object' ); +var Module = require( './module.js' ); + + +// MAIN // + +/** +* Routine constructor. +* +* @private +* @constructor +* @returns {Routine} routine instance +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var idamax = new Routine(); +* +* // Initialize the module: +* idamax.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, -5.0 ] ); +* +* // Perform operation: +* var idx = idamax.main( x.length, x, 1 ); +* // returns 4 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var idamax = new Routine(); +* +* // Initialize the module: +* idamax.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, -5.0 ] ); +* +* // Perform operation: +* var idx = idamax.ndarray( x.length, x, 1, 0 ); +* // returns 4 +*/ +function Routine() { + if ( !( this instanceof Routine ) ) { + return new Routine(); + } + Module.call( this, new Memory({ + 'initial': 0 + })); + return this; +} + +// Inherit from the parent constructor: +inherits( Routine, Module ); + +/** +* Finds the index of the first element having the maximum absolute value. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - `x` stride length +* @returns {integer} index value +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var idamax = new Routine(); +* +* // Initialize the module: +* idamax.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, -5.0 ] ); +* +* // Perform operation: +* var idx = idamax.main( x.length, x, 1 ); +* // returns 4 +*/ +setReadOnly( Routine.prototype, 'main', function idamax( N, x, strideX ) { + return this.ndarray( N, x, strideX, stride2offset( N, strideX ) ); +}); + +/** +* Finds the index of the first element having the maximum absolute value using alternative indexing semantics. +* +* @name ndarray +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @returns {integer} index value +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var idamax = new Routine(); +* +* // Initialize the module: +* idamax.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0 ] ); +* +* // Perform operation: +* var idx = idamax.ndarray( x.length, x, 1, 0 ); +* // returns 4 +*/ +setReadOnly( Routine.prototype, 'ndarray', function idamax( N, x, strideX, offsetX ) { + var ptrs; + var p0; + + // Convert the input array to "pointers" in the module's memory: + ptrs = arrays2ptrs( this, [ + strided2object( N, x, strideX, offsetX ) + ]); + p0 = ptrs[ 0 ]; + + // Perform computation by calling the corresponding parent method: + return Module.prototype.ndarray.call( this, N, p0.ptr, p0.stride, p0.offset ); // eslint-disable-line max-len +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/manifest.json b/lib/node_modules/@stdlib/blas/base/idamax-wasm/manifest.json new file mode 100644 index 00000000000..23abf67de81 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/idamax" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/package.json b/lib/node_modules/@stdlib/blas/base/idamax-wasm/package.json new file mode 100644 index 00000000000..6dd2b73e19d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/package.json @@ -0,0 +1,84 @@ +{ + "name": "@stdlib/blas/base/idamax-wasm", + "version": "0.0.0", + "description": "Find the index of the first element having the maximum absolute value.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": { + "./lib/binary.js": "./lib/binary.browser.js" + }, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "idamax", + "maximum", + "abs", + "absolute", + "find", + "index", + "linear", + "algebra", + "subroutines", + "vector", + "array", + "ndarray", + "float64", + "double", + "float64array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/scripts/build.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/scripts/build.js new file mode 100644 index 00000000000..348354d7029 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/scripts/build.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var replace = require( '@stdlib/string/replace' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/scripts/template.txt b/lib/node_modules/@stdlib/blas/base/idamax-wasm/scripts/template.txt new file mode 100644 index 00000000000..12996dd89e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( '{{WASM_BASE64}}' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/src/Makefile b/lib/node_modules/@stdlib/blas/base/idamax-wasm/src/Makefile new file mode 100644 index 00000000000..6feaf79e4c6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/src/Makefile @@ -0,0 +1,232 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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. +#/ + +#/ +# To compile targets listed in this Makefile, use top-level project `make` +# commands rather than commands listed in this Makefile. The top-level project +# `make` commands will ensure that various environment variables and flags are +# appropriately set. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files to WebAssembly: +ifdef EMCC_COMPILER + EMCC := $(EMCC_COMPILER) +else + EMCC := emcc +endif + +# Define the program used for compiling WebAssembly files to the WebAssembly text format: +ifdef WASM2WAT + WASM_TO_WAT := $(WASM2WAT) +else + WASM_TO_WAT := wasm2wat +endif + +# Define the program used for compiling WebAssembly files to JavaScript: +ifdef WASM2JS + WASM_TO_JS := $(WASM2JS) +else + WASM_TO_JS := wasm2js +endif + +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic \ + -D CBLAS_INT=int32_t + +# Define the command-line options when compiling C files to WebAssembly and asm.js: +EMCCFLAGS ?= $(CFLAGS) + +# Define shared `emcc` flags: +EMCC_SHARED_FLAGS := \ + -s SIDE_MODULE=2 \ + -s WASM_BIGINT=0 \ + -s EXPORTED_FUNCTIONS="['_c_idamax','_c_idamax_ndarray']" + +# Define WebAssembly `emcc` flags: +EMCC_WASM_FLAGS := $(EMCC_SHARED_FLAGS) \ + -s WASM=1 + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of WebAssembly targets: +wasm_targets := main.wasm + +# List of WebAssembly WAT targets: +wat_targets := main.wat + +# List of WebAssembly JavaScript targets: +wasm_js_targets := main.wasm.js + +# List of other JavaScript targets: +browser_js_targets := ./../lib/binary.browser.js + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: wasm + +.PHONY: all + +#/ +# Compiles source files to WebAssembly. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make wasm +#/ +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) + +.PHONY: wasm + +#/ +# Compiles C source files to WebAssembly binaries. +# +# @private +# @param {string} EMCC - EMCC compiler (e.g., `emcc`) +# @param {string} EMCCFLAGS - EMCC compiler options +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(wasm_targets): + $(QUIET) $(EMCC) $(EMCCFLAGS) $(EMCC_WASM_FLAGS) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Compiles WebAssembly binary files to the WebAssembly text format. +# +# @private +# @param {string} WASM2WAT - WAT compiler (e.g., `wasm2wat`) +#/ +$(wat_targets): %.wat: %.wasm + $(QUIET) $(WASM_TO_WAT) -o $@ $(wasm_targets) + +#/ +# Compiles WebAssembly binary files to JavaScript. +# +# @private +# @param {string} WASM2JS - JavaScript compiler (e.g., `wasm2js`) +#/ +$(wasm_js_targets): %.wasm.js: %.wasm + $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) + +#/ +# Generates an inline WebAssembly build for use in bundlers. +# +# @private +# @param {string} NODE - Node.js executable +#/ +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + +#/ +# Removes generated WebAssembly files. +# +# @example +# make clean-wasm +#/ +clean-wasm: + $(QUIET) -rm -f *.wasm *.wat *.wasm.js + +.PHONY: clean-wasm + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-wasm + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/src/main.wasm b/lib/node_modules/@stdlib/blas/base/idamax-wasm/src/main.wasm new file mode 100755 index 0000000000000000000000000000000000000000..75ff5f70ff878c2df4900bfd1e04b2fd1197713e GIT binary patch literal 295 zcmX|(ze>bF5Qk@W_L5+boY)B0OwtPCBV1BwBeqv=mQ9e0`E%rg8qnKEu=WXT?japT zohg3b%nv@W`wl@SiK@BX_K#QBsK0MKrxKtf?>+ibOGv5&sqUYGuI`3$Rsf_4P=)vU z%$R3U8E4zpxM>*o02jYMyW6$1sqAFUShs_dDspC9+0MQIF8|Q`WvB?64+f#@+jK2VNqCMXL literal 0 HcmV?d00001 diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/src/main.wat b/lib/node_modules/@stdlib/blas/base/idamax-wasm/src/main.wat new file mode 100644 index 00000000000..26c6144a642 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/src/main.wat @@ -0,0 +1,106 @@ +;; @license Apache-2.0 +;; +;; Copyright (c) 2024 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. + +(module + (type (;0;) (func)) + (type (;1;) (func (param i32 i32 i32) (result i32))) + (type (;2;) (func (param i32 i32 i32 i32) (result i32))) + (import "env" "memory" (memory (;0;) 0)) + (func (;0;) (type 0) + nop) + (func (;1;) (type 1) (param i32 i32 i32) (result i32) + (local i64) + local.get 0 + local.get 1 + local.get 2 + local.get 2 + i64.extend_i32_s + local.tee 3 + i64.const 1 + local.get 0 + i64.extend_i32_s + i64.sub + i64.mul + i64.const 0 + local.get 3 + i64.const 0 + i64.le_s + select + i32.wrap_i64 + call 2) + (func (;2;) (type 2) (param i32 i32 i32 i32) (result i32) + (local f64 f64 i32 i32 i32) + local.get 0 + i32.const 0 + i32.le_s + if ;; label = @1 + i32.const -1 + return + end + local.get 0 + i32.const 1 + i32.eq + if ;; label = @1 + i32.const 0 + return + end + local.get 1 + local.get 3 + i32.const 3 + i32.shl + i32.add + f64.load + f64.abs + local.set 4 + i32.const 1 + local.set 6 + loop ;; label = @1 + local.get 1 + local.get 2 + local.get 3 + i32.add + local.tee 3 + i32.const 3 + i32.shl + i32.add + f64.load + f64.abs + local.tee 5 + local.get 4 + local.get 4 + local.get 5 + f64.lt + local.tee 8 + select + local.set 4 + local.get 6 + local.get 7 + local.get 8 + select + local.set 7 + local.get 6 + i32.const 1 + i32.add + local.tee 6 + local.get 0 + i32.ne + br_if 0 (;@1;) + end + local.get 7) + (export "__wasm_call_ctors" (func 0)) + (export "__wasm_apply_data_relocs" (func 0)) + (export "c_idamax" (func 1)) + (export "c_idamax_ndarray" (func 2))) diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.js new file mode 100644 index 00000000000..8e71929460e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var idamax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof idamax, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `main` method', function test( t ) { + t.strictEqual( typeof idamax.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof idamax.ndarray, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `Module` constructor', function test( t ) { + t.strictEqual( typeof idamax.Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the main export is a `Module` instance', function test( t ) { + t.strictEqual( idamax instanceof idamax.Module, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.main.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.main.js new file mode 100644 index 00000000000..49a08ca6709 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.main.js @@ -0,0 +1,163 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var idamax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof idamax, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `main` method has an arity of 3', function test( t ) { + t.strictEqual( idamax.main.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method finds the index of the element with the maximum absolute value', function test( t ) { + var idx; + var x; + + x = new Float64Array([ + 0.1, // 1 + -0.3, // 2 + 0.5, // 3 + -0.1, // 4 + 6.0, + 6.0, + 6.0 + ]); + + idx = idamax.main( 4, x, 1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + // Short datasets: + x = new Float64Array( [ + 0.2, // 1 + -0.6, // 2 + 0.3, // 3 + 5.0, + 5.0 + ] ); + + idx = idamax.main( 3, x, 1 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports a `stride` parameter', function test( t ) { + var idx; + var x; + + x = new Float64Array([ + 0.1, // 1 + 4.0, + -0.3, // 2 + 6.0, + -0.5, // 3 + 7.0, + -0.1, // 4 + 3.0 + ]); + + idx = idamax.main( 4, x, 2 ); + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, the `main` method returns `-1`', function test( t ) { + var idx; + var x; + + x = new Float64Array( [ + 1.0, + 2.0, + 3.0 + ] ); + + idx = idamax.main( 0, x, 1 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + idx = idamax.main( -1, x, 1 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the `main` method returns `0`', function test( t ) { + var idx; + var x; + + x = new Float64Array( [ + 1.0, + 2.0, + 3.0 + ] ); + + idx = idamax.main( 1, x, 1 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports a negative `stride` parameter', function test( t ) { + var idx; + var x; + + x = new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ); + + idx = idamax.main( x.length, x, -1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + x = new Float64Array( [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ] ); // eslint-disable-line max-len + idx = idamax.main( 6, x, -3 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports view offsets', function test( t ) { + var idx; + var x0; + var x1; + + x0 = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ]); + + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + + idx = idamax.main( 3, x1, 2 ); + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.js new file mode 100644 index 00000000000..9adcb07e22f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = Module( mem ); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Module( value ); + }; + } +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (no new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Module( value ); // eslint-disable-line new-cap + }; + } +}); + +tape( 'the module instance returned by the module constructor inherits from a module wrapper', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.main.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.main.js new file mode 100644 index 00000000000..1776c31a40a --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.main.js @@ -0,0 +1,184 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which has an arity of 3', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.main.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which finds the index of the element with the maximum absolute value', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, -3.0, 4.0, -5.0 ] ) ); + + idx = mod.main( 5, xp, 1 ); + t.strictEqual( idx, 4, 'returns expected value' ); + + // Short datasets: + xp = 0; + + mod.write( xp, new Float64Array( [ -1.0, -2.0 ] ) ); + + idx = mod.main( 2, xp, 1 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports an `x` stride', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 0.1, // 1 + 4.0, + -0.3, // 2 + 6.0, + -0.5, // 3 + 7.0, + -0.1, // 4 + 3.0 + ])); + + idx = mod.main( 4, xp, 2 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports a negative `stride` parameter', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 3.0, -4.0, 1.0, 15.0, 4.0, 3.0 ] ) ); + + idx = mod.main( 6, xp, -1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + mod.write( xp, new Float64Array( [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ] ) ); // eslint-disable-line max-len + + idx = mod.main( 6, xp, -3 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, a module instance has a `main` method which returns `-1`', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + idx = mod.main( -1, xp, 1 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + idx = mod.main( 0, xp, 1 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, a module instance has a `main` method which returns `0`', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0 ] ) ); + + idx = mod.main( 1, xp, 1 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.ndarray.js new file mode 100644 index 00000000000..452ec4a7daa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.module.ndarray.js @@ -0,0 +1,243 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which has an arity of 4', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.ndarray.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which finds the index of the element with the maximum absolute value', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + idx = mod.ndarray( 5, xp, 1, 0 ); + t.strictEqual( idx, 4, 'returns expected value' ); + + // Short datasets: + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0 ] ) ); + + idx = mod.ndarray( 2, xp, 1, 0 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` stride', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 0.1, // 1 + 4.0, + -0.3, // 2 + 6.0, + -0.5, // 3 + 7.0, + -0.1, // 4 + 3.0 + ])); + + idx = mod.ndarray( 4, xp, 2, 0 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports a negative `stride` parameter', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + + idx = mod.ndarray( 3, xp, -2, 4 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` offset', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0, // 3 + 6.0 // 4 + ])); + + idx = mod.ndarray( 5, xp, 1, 1 ); + t.strictEqual( idx, 4, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, a module instance has an `ndarray` method which returns `-1`', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + idx = mod.ndarray( -1, xp, 1, 0 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + idx = mod.ndarray( 0, xp, 1, 0 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, a module instance has an `ndarray` method which returns `0`', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0 ] ) ); + + idx = mod.ndarray( 1, xp, 1, 0 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports complex access patterns', function test( t ) { + var idx; + var mem; + var mod; + var xp; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 2 + ])); + + idx = mod.ndarray( 3, xp, 2, 1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.ndarray.js new file mode 100644 index 00000000000..fa54bc2c52f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.ndarray.js @@ -0,0 +1,185 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var idamax = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof idamax, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `ndarray` method has an arity of 4', function test( t ) { + t.strictEqual( idamax.ndarray.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method finds the index of the element with the maximum absolute value', function test( t ) { + var idx; + var x; + + x = new Float64Array([ + 0.1, // 1 + -0.3, // 2 + 0.5, // 3 + -0.1, // 4 + 6.0, + 6.0, + 6.0 + ]); + + idx = idamax.ndarray( 4, x, 1, 0 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + // Short datasets: + x = new Float64Array( [ + 0.2, // 1 + -0.6, // 2 + 0.3, // 3 + 5.0, + 5.0 + ] ); + + idx = idamax.ndarray( 3, x, 1, 0 ); + t.strictEqual( idx, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports a `stride` parameter', function test( t ) { + var idx; + var x; + + x = new Float64Array([ + 0.1, // 1 + 4.0, + -0.3, // 2 + 6.0, + -0.5, // 3 + 7.0, + -0.1, // 4 + 3.0 + ]); + + idx = idamax.ndarray( 4, x, 2, 0 ); + t.strictEqual( idx, 2, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports a negative `stride` parameter', function test( t ) { + var idx; + var x; + + x = new Float64Array([ + 3.0, // 5 + -4.0, // 4 + 1.0, // 3 + 15.0, // 2 + 4.0, // 1 + 3.0 // 0 + ]); + + idx = idamax.ndarray( x.length, x, -1, x.length-1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + x = new Float64Array( [ 3.0, 999.9, 999.9, -4.0, 999.9, 999.9, 1.0, 999.9, 999.9, 15.0, 999.9, 999.9, 4.0, 999.9, 999.9, 3.0 ] ); // eslint-disable-line max-len + idx = idamax.ndarray( 6, x, -3, x.length-1 ); + t.strictEqual( idx, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports an `x` offset', function test( t ) { + var idx; + var x; + + x = new Float64Array([ + 1.0, + 2.0, // 0 + 3.0, // 1 + 4.0, // 2 + 5.0, // 3 + 6.0 // 4 + ]); + + idx = idamax.ndarray( 5, x, 1, 1 ); + t.strictEqual( idx, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than `1`, the `ndarray` method returns `-1`', function test( t ) { + var idx; + var x; + + x = new Float64Array( [ + 1.0, + 2.0, + 3.0 + ] ); + + idx = idamax.ndarray( 0, x, 1, 0 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + idx = idamax.ndarray( -1, x, 1, 0 ); + t.strictEqual( idx, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter equal to `1`, the `ndarray` method returns `0`', function test( t ) { + var idx; + var x; + + x = new Float64Array( [ + 1.0, + 2.0, + 3.0 + ] ); + + idx = idamax.ndarray( 1, x, 1, 1 ); + t.strictEqual( idx, 0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports complex access patterns', function test( t ) { + var idx; + var x; + + x = new Float64Array([ + 1.0, + 2.0, // 2 + 3.0, + 4.0, // 1 + 5.0, + 6.0 // 0 + ]); + + idx = idamax.ndarray( 3, x, 2, -1 ); + t.strictEqual( idx, 0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.routine.js b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.routine.js new file mode 100644 index 00000000000..56a4b67daaf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/idamax-wasm/test/test.routine.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib/module.js' ); +var Routine = require( './../lib/routine.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Routine, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mod = Routine(); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a module wrapper', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a BLAS routine module', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); From e3512fca3391a238a1f40a030406c9354cb7cc25 Mon Sep 17 00:00:00 2001 From: Aman Bhansali <92033532+aman-095@users.noreply.github.com> Date: Sat, 19 Oct 2024 13:30:30 +0530 Subject: [PATCH 48/50] feat: add `blas/base/dasum-wasm` PR-URL: https://github.com/stdlib-js/stdlib/pull/2987 Ref: https://github.com/stdlib-js/stdlib/issues/2039 Co-authored-by: Athan Reines Reviewed-by: Athan Reines --- .../@stdlib/blas/base/dasum-wasm/README.md | 303 +++++++++++ .../base/dasum-wasm/benchmark/benchmark.js | 106 ++++ .../dasum-wasm/benchmark/benchmark.module.js | 66 +++ .../benchmark/benchmark.module.main.js | 130 +++++ .../benchmark/benchmark.module.ndarray.js | 130 +++++ .../dasum-wasm/benchmark/benchmark.ndarray.js | 106 ++++ .../blas/base/dasum-wasm/docs/repl.txt | 493 ++++++++++++++++++ .../base/dasum-wasm/docs/types/index.d.ts | 316 +++++++++++ .../blas/base/dasum-wasm/docs/types/test.ts | 347 ++++++++++++ .../blas/base/dasum-wasm/examples/index.js | 43 ++ .../examples/little_endian_arrays.js | 65 +++ .../blas/base/dasum-wasm/examples/module.js | 63 +++ .../base/dasum-wasm/lib/binary.browser.js | 33 ++ .../blas/base/dasum-wasm/lib/binary.js | 34 ++ .../@stdlib/blas/base/dasum-wasm/lib/index.js | 100 ++++ .../@stdlib/blas/base/dasum-wasm/lib/main.js | 60 +++ .../blas/base/dasum-wasm/lib/module.js | 198 +++++++ .../blas/base/dasum-wasm/lib/routine.js | 166 ++++++ .../blas/base/dasum-wasm/manifest.json | 36 ++ .../@stdlib/blas/base/dasum-wasm/package.json | 80 +++ .../blas/base/dasum-wasm/scripts/build.js | 63 +++ .../blas/base/dasum-wasm/scripts/template.txt | 33 ++ .../@stdlib/blas/base/dasum-wasm/src/Makefile | 232 +++++++++ .../blas/base/dasum-wasm/src/main.wasm | Bin 0 -> 413 bytes .../@stdlib/blas/base/dasum-wasm/src/main.wat | 172 ++++++ .../@stdlib/blas/base/dasum-wasm/test/test.js | 53 ++ .../blas/base/dasum-wasm/test/test.main.js | 152 ++++++ .../blas/base/dasum-wasm/test/test.module.js | 154 ++++++ .../base/dasum-wasm/test/test.module.main.js | 156 ++++++ .../dasum-wasm/test/test.module.ndarray.js | 218 ++++++++ .../blas/base/dasum-wasm/test/test.ndarray.js | 145 ++++++ .../blas/base/dasum-wasm/test/test.routine.js | 71 +++ 32 files changed, 4324 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/README.md create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/little_endian_arrays.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/binary.browser.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/binary.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/routine.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/manifest.json create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/package.json create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/scripts/build.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/scripts/template.txt create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/src/Makefile create mode 100755 lib/node_modules/@stdlib/blas/base/dasum-wasm/src/main.wasm create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/src/main.wat create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.main.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.routine.js diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/README.md b/lib/node_modules/@stdlib/blas/base/dasum-wasm/README.md new file mode 100644 index 00000000000..d52bdf5a75c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/README.md @@ -0,0 +1,303 @@ + + +# dasum + +> Compute the sum of absolute values. + +
+ +## Usage + +```javascript +var dasum = require( '@stdlib/blas/base/dasum-wasm' ); +``` + +#### dasum.main( N, x, stride ) + +Computes the sum of absolute values. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + +var sum = dasum.main( x.length, x, 1 ); +// returns 15.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **x**: input [`Float64Array`][@stdlib/array/float64]. +- **strideX**: index increment for `x`. + +The `N` and stride parameters determine which elements in the input strided array are accessed at runtime. For example, to compute the sum of every other value, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var sum = dasum.main( 4, x, 2 ); +// returns 10.0 +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +// Create a typed array view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +var sum = dasum.main( 3, x1, 2 ); +// returns 12.0 +``` + +#### dasum.ndarray( N, x, strideX, offsetX ) + +Computes the sum of absolute values using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ] ); + +var sum = dasum.ndarray( x.length, x, 1, 0 ); +// returns 19.0 +``` + +The function has the following additional parameters: + +- **offsetX**: 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 compute the sum of last three elements, + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + +var sum = dasum.ndarray( 3, x, 1, x.length-3 ); +// returns 15.0 + +// Using a negative stride to sum from the last element: +sum = dasum.ndarray( 3, x, -1, x.length-1 ); +// returns 15.0 +``` + +* * * + +### Module + +#### dasum.Module( memory ) + +Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new dasum.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); +``` + +#### dasum.Module.prototype.main( N, xp, sx ) + +Computes the sum of absolute values. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var zeros = require( '@stdlib/array/zeros' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new dasum.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointer (i.e., byte offsets) for storing the input vectors: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +var sum = mod.main( N, xptr, 1 ); +// returns 15.0 +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset). +- **sx**: index increment for `x`. + +#### dasum.Module.prototype.ndarray( N, xp, sx, ox ) + +Computes the sum of absolute values using alternative indexing semantics. + + + +```javascript +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var zeros = require( '@stdlib/array/zeros' ); + +// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +var mem = new Memory({ + 'initial': 10, + 'maximum': 100 +}); + +// Create a BLAS routine: +var mod = new dasum.Module( mem ); +// returns + +// Initialize the routine: +mod.initializeSync(); + +// Define a vector data type: +var dtype = 'float64'; + +// Specify a vector length: +var N = 5; + +// Define pointer (i.e., byte offsets) for storing the input vector: +var xptr = 0; + +// Write vector values to module memory: +mod.write( xptr, oneTo( N, dtype ) ); + +// Perform computation: +var sum = mod.ndarray( N, xptr, 1, 0 ); +// returns 15.0 +``` + +The function has the following additional parameters: + +- **ox**: starting index for `x`. + +
+ + + +
+ +* * * + +## Notes + +- If `N <= 0`, both `main` and `ndarray` methods return `0.0`. +- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `dasum` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/blas/base/dasum`][@stdlib/blas/base/dasum]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/blas/base/dasum`][@stdlib/blas/base/dasum]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other. +- `dasum()` corresponds to the [BLAS][blas] level 1 function [`dasum`][dasum]. + +
+ + + +
+ +* * * + +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dasum = require( '@stdlib/blas/base/dasum-wasm' ); + +var opts = { + 'dtype': 'float64' +}; +var x = discreteUniform( 10, 0, 100, opts ); +console.log( x ); + +var sum = dasum.ndarray( x.length, x, 1, 0 ); +console.log( sum ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.js new file mode 100644 index 00000000000..e26c3c94b28 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dasum = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var sum; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sum = dasum.main( x.length, x, 1 ); + if ( isnan( sum ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( sum ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.js new file mode 100644 index 00000000000..be06f746838 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var pkg = require( './../package.json' ).name; +var dasum = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; + + +// MAIN // + +bench( pkg+':Module:constructor', opts, function benchmark( b ) { + var values; + var o; + var v; + var i; + + o = { + 'initial': 0 + }; + values = [ + new Memory( o ), + new Memory( o ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = new dasum.Module( values[ i%values.length ] ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof v !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.main.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.main.js new file mode 100644 index 00000000000..786d8712fa7 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.main.js @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dasum = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var xptr; + var mod; + var mem; + var sum; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new dasum.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*nb ); + + // Define pointer (i.e., byte offsets) to the first vector elements: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sum = mod.main( len, xptr, 1 ); + if ( isnan( sum ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( sum ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.ndarray.js new file mode 100644 index 00000000000..816a46322a4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.module.ndarray.js @@ -0,0 +1,130 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dasum = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var xptr; + var mod; + var mem; + var sum; + var nb; + var i; + + // Create a new BLAS routine interface: + mem = new Memory({ + 'initial': 0 + }); + mod = new dasum.Module( mem ); + + // Initialize the module: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Reallocate the underlying memory to allow storing two vectors: + nb = bytesPerElement( options.dtype ); + mod.realloc( len*nb ); + + // Define pointers (i.e., byte offsets) to the first vector elements: + xptr = 0; + + // Write random values to module memory: + mod.write( xptr, uniform( len, -100.0, 100.0, options ) ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sum = mod.ndarray( len, xptr, 1, 0 ); + if ( isnan( sum ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( sum ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+'::module,pointers:ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.ndarray.js new file mode 100644 index 00000000000..8f49d887069 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/benchmark/benchmark.ndarray.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dasum = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasWebAssemblySupport() +}; +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = uniform( len, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var sum; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + sum = dasum.ndarray( x.length, x, 1, 0 ); + if ( isnan( sum ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( sum ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, opts, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/repl.txt new file mode 100644 index 00000000000..de0570052ca --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/repl.txt @@ -0,0 +1,493 @@ + +{{alias}}.main( N, x, strideX ) + Computes the sum of absolute values. + + 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 + array views. + + If `N <= 0`, the function returns `0`. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + Returns + ------- + sum: number + Sum of absolute values. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0 ] ); + > var s = {{alias}}.main( x.length, x, 1 ) + 15.0 + + // Using `N` and stride parameters: + > s = {{alias}}.main( 3, x, 2 ) + 9.0 + + // Use view offset; e.g., starting at 2nd element: + > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > s = {{alias}}.main( 3, x1, 2 ) + 12.0 + + +{{alias}}.ndarray( N, x, strideX, offsetX ) + Computes the sum of absolute values using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of indexed elements. + + x: Float64Array + Input array. + + strideX: integer + Index increment for `x`. + + offsetX: integer + Starting index for `x`. + + Returns + ------- + out: number + Sum of absolute values. + + Examples + -------- + // Standard usage: + > var x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0 ] ); + > var s = {{alias}}.ndarray( x.length, x, 1, 0 ) + 15.0 + + // Using offset parameter: + > x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); + > s = {{alias}}.ndarray( 3, x, -1, x.length-1 ) + 15.0 + + +{{alias}}.Module( memory ) + Returns a new WebAssembly module wrapper which uses the provided WebAssembly + memory instance as its underlying memory. + + Parameters + ---------- + memory: Memory + WebAssembly memory instance. + + Returns + ------- + mod: Module + WebAssembly module wrapper. + + Examples + -------- + // Create a new memory instance: + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + + // Create a new routine: + > var mod = new {{alias}}.Module( mem ); + + // Initialize the routine: + > mod.initializeSync(); + + +{{alias}}.Module.prototype.binary + Read-only property which returns WebAssembly binary code. + + Returns + ------- + out: Uint8Array + WebAssembly binary code. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.binary + + + +{{alias}}.Module.prototype.memory + Read-only property which returns WebAssembly memory. + + Returns + ------- + mem: Memory|null + WebAssembly memory. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.memory + + + +{{alias}}.Module.prototype.buffer + Read-only property which returns a WebAssembly memory buffer as a + Uint8Array. + + Returns + ------- + buf: Uint8Array|null + WebAssembly memory buffer. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.buffer + + + +{{alias}}.Module.prototype.view + Read-only property which returns a WebAsssembly memory buffer as a DataView. + + Returns + ------- + view: DataView|null + WebAssembly memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.view + + + +{{alias}}.Module.prototype.exports + Read-only property which returns "raw" WebAssembly module exports. + + Returns + ------- + out: Object|null + WebAssembly module exports. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.exports + {...} + + +{{alias}}.Module.prototype.initialize() + Asynchronously initializes a WebAssembly module instance. + + Returns + ------- + p: Promise + Promise which resolves upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initialize(); + + +{{alias}}.Module.prototype.initializeAsync( clbk ) + Asynchronously initializes a WebAssembly module instance. + + Parameters + ---------- + clbk: Function + Callback to invoke upon initializing a WebAssembly module instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > function clbk() { console.log( 'done' ) }; + > mod.initializeAsync( clbk ); + + +{{alias}}.Module.prototype.initializeSync() + Synchronously initializes a WebAssembly module instance. + + In web browsers, JavaScript engines may raise an exception when attempting + to synchronously compile large WebAssembly binaries due to concerns about + blocking the main thread. Hence, to initialize WebAssembly modules having + large binaries (e.g., >4KiB), consider using asynchronous initialization + methods in browser contexts. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + +{{alias}}.Module.prototype.realloc( nbytes ) + Reallocates the underlying WebAssembly memory instance to a specified number + of bytes. + + WebAssembly memory can only *grow*, not shrink. Hence, if provided a number + of bytes which is less than or equal to the size of the current memory, the + function does nothing. + + When non-shared memory is resized, the underlying the `ArrayBuffer` is + detached, consequently invalidating any associated typed array views. Before + resizing non-shared memory, ensure that associated typed array views no + longer need byte access and can be garbage collected. + + Parameters + ---------- + nbytes: integer + Memory size (in bytes). + + Returns + ------- + bool: boolean + Boolean indicating whether the resize operation was successful. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ) + + + +{{alias}}.Module.prototype.hasCapacity( byteOffset, values ) + Returns a boolean indicating whether the underlying WebAssembly memory + instance has the capacity to store a provided list of values starting from a + specified byte offset. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + bool: boolean + Boolean indicating whether the underlying WebAssembly memory instance + has enough capacity. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.hasCapacity( 0, [ 1, 2, 3, 4 ] ) + true + + +{{alias}}.Module.prototype.isView( values ) + Returns a boolean indicating whether a provided list of values is a view of + the underlying memory of the WebAssembly module. + + Parameters + ---------- + values: ArrayLikeObject + Input array. + + Returns + ------- + bool: boolean + Boolean indicating whether the list is a memory view. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.isView( [ 1, 2, 3, 4 ] ) + false + + +{{alias}}.Module.prototype.write( byteOffset, values ) + Writes values to the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the input array. For example, if provided a Float32Array, + the function writes each element as a single-precision floating-point number + to the underlying WebAssembly memory instance. + + In order to write elements as a different data type, you need to perform an + explicit cast *before* calling this method. For example, in order to write + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must first convert the Float32Array to an + Int32Array before passing the values to this method. + + If provided an array having an unknown or "generic" data type, elements are + written as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start writing values. + + values: ArrayLikeObject + Input array containing values to write. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + + +{{alias}}.Module.prototype.read( byteOffset, out ) + Reads values from the underlying WebAssembly memory instance. + + The function infers element size (i.e., number of bytes per element) from + the data type of the output array. For example, if provided a Float32Array, + the function reads each element as a single-precision floating-point number + from the underlying WebAssembly memory instance. + + In order to read elements as a different data type, you need to perform an + explicit cast *after* calling this method. For example, in order to read + single-precision floating-point numbers contained in a Float32Array as + signed 32-bit integers, you must convert the Float32Array to an Int32Array + after reading memory values using this method. + + If provided an output array having an unknown or "generic" data type, + elements are read as double-precision floating-point numbers. + + Parameters + ---------- + byteOffset: integer + Byte offset at which to start reading values. + + out: ArrayLikeObject + Output array for storing read values. + + Returns + ------- + mod: Module + Module wrapper instance. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 0 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + > mod.realloc( 100 ); + > mod.write( 0, [ 1, 2, 3, 4 ] ); + > var out = [ 0, 0, 0, 0 ]; + > mod.read( 0, out ); + > out + [ 1, 2, 3, 4 ] + + +{{alias}}.Module.prototype.main( N, xp, sx ) + Computes the sum of absolute values. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + Returns + ------- + sum: number + Sum of absolute values. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointer" (i.e., byte offsets) into module memory: + > var xptr = 0; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + + // Perform computation: + > var s = mod.main( 5, xptr, 1 ) + 15.0 + + +{{alias}}.Module.prototype.ndarray( N, xp, sx, ox ) + Computes the sum of absolute values using alternative indexing semantics. + + Parameters + ---------- + N: integer + Number of indexed elements. + + xp: integer + Input array pointer (i.e., byte offset). + + sx: integer + Index increment for `x`. + + ox: integer + Starting index for `x`. + + Returns + ------- + sum: number + Sum of absolute values. + + Examples + -------- + > var mem = new {{alias:@stdlib/wasm/memory}}( { 'initial': 1 } ); + > var mod = new {{alias}}.Module( mem ); + > mod.initializeSync(); + + // Define "pointer" (i.e., byte offsets) into module memory: + > var xptr = 0; + + // Write data to module memory: + > mod.write( xptr, {{alias:@stdlib/array/one-to}}( 5, 'float64' ) ); + + // Perform computation: + > var s = mod.ndarray( 5, xptr, 1, 0 ) + 15.0 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/types/index.d.ts new file mode 100644 index 00000000000..888ff40e1db --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/types/index.d.ts @@ -0,0 +1,316 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ModuleWrapper, Memory } from '@stdlib/types/wasm'; + +/** +* Interface defining a module constructor which is both "newable" and "callable". +*/ +interface ModuleConstructor { + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dasum.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns 15.0 + */ + new( mem: Memory ): Module; // newable + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = dasum.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing two vectors: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns 15.0 + */ + ( mem: Memory ): Module; // callable +} + +/** +* Interface describing a `dasum` WebAssembly module. +*/ +interface Module extends ModuleWrapper { + /** + * Computes the sum of absolute values. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @returns sum of absolute values + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dasum.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns 15.0 + */ + main( N: number, xptr: number, strideX: number ): number; + + /** + * Computes the sum of absolute values using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param xptr - input array pointer (i.e., byte offset) + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns sum of absolute values + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dasum.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.ndarray( N, xptr, 1, 0 ); + * // returns 15.0 + */ + ndarray( N: number, xptr: number, strideX: number, offsetX: number ): number; +} + +/** +* Interface describing `dasum`. +*/ +interface Routine extends ModuleWrapper { + /** + * Computes the sum of absolute values. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - `x` stride length + * @returns sum of absolute values + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * var out = dasum.main( x.length, 5.0, x, 1, y, 1 ); + * // returns 15.0 + */ + main( N: number, x: Float64Array, strideX: number ): number; + + /** + * Computes the sum of absolute values using alternative indexing semantics. + * + * @param N - number of indexed elements + * @param x - input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` + * @returns sum of absolute values + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + * + * var out = dasum.ndarray( x.length, x, 1, 0 ); + * // returns 15.0 + */ + ndarray( N: number, x: Float64Array, strideX: number, offsetX: number ): number; + + /** + * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory. + * + * @param mem - WebAssembly memory instance + * @returns module wrapper instance + * + * @example + * var Memory = require( '@stdlib/wasm/memory' ); + * var oneTo = require( '@stdlib/array/one-to' ); + * + * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + * var mem = new Memory({ + * 'initial': 10, + * 'maximum': 100 + * }); + * + * // Create a BLAS routine: + * var mod = new dasum.Module( mem ); + * // returns + * + * // Initialize the routine: + * mod.initializeSync(); + * + * // Define a vector data type: + * var dtype = 'float64'; + * + * // Specify a vector length: + * var N = 5; + * + * // Define pointer (i.e., byte offsets) for storing the input vector: + * var xptr = 0; + * + * // Write vector values to module memory: + * mod.write( xptr, oneTo( N, dtype ) ); + * + * // Perform computation: + * var out = mod.main( N, xptr, 1 ); + * // returns 15.0 + */ + Module: ModuleConstructor; +} + +/** +* Computes the sum of absolute values. +* +* @param N - number of indexed elements +* @param x - input array +* @param strideX - `x` stride length +* @returns sum of absolute values +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* var out = dasum.main( x.length, x, 1 ); +* // returns 15.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* var out = dasum.ndarray( x.length, x, 1, 0 ); +* // returns 15.0 +*/ +declare var dasum: Routine; + + +// EXPORTS // + +export = dasum; diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/types/test.ts new file mode 100644 index 00000000000..03588d11b46 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/docs/types/test.ts @@ -0,0 +1,347 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable space-in-parens */ + +import Memory = require( '@stdlib/wasm/memory' ); +import dasum = require( './index' ); + + +// TESTS // + +// Attached to the main export is a `main` method which returns a number... +{ + const x = new Float64Array( 10 ); + + dasum.main( x.length, x, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dasum.main( '10', x, 1 ); // $ExpectError + dasum.main( true, x, 1 ); // $ExpectError + dasum.main( false, x, 1 ); // $ExpectError + dasum.main( null, x, 1 ); // $ExpectError + dasum.main( undefined, x, 1 ); // $ExpectError + dasum.main( [], x, 1 ); // $ExpectError + dasum.main( {}, x, 1 ); // $ExpectError + dasum.main( ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dasum.main( x.length, 10, 1 ); // $ExpectError + dasum.main( x.length, '10', 1 ); // $ExpectError + dasum.main( x.length, true, 1 ); // $ExpectError + dasum.main( x.length, false, 1 ); // $ExpectError + dasum.main( x.length, null, 1 ); // $ExpectError + dasum.main( x.length, undefined, 1 ); // $ExpectError + dasum.main( x.length, [], 1 ); // $ExpectError + dasum.main( x.length, {}, 1 ); // $ExpectError + dasum.main( x.length, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dasum.main( x.length, x, '10' ); // $ExpectError + dasum.main( x.length, x, true ); // $ExpectError + dasum.main( x.length, x, false ); // $ExpectError + dasum.main( x.length, x, null ); // $ExpectError + dasum.main( x.length, x, undefined ); // $ExpectError + dasum.main( x.length, x, [] ); // $ExpectError + dasum.main( x.length, x, {} ); // $ExpectError + dasum.main( x.length, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + dasum.main(); // $ExpectError + dasum.main( x.length ); // $ExpectError + dasum.main( x.length, x ); // $ExpectError + dasum.main( x.length, x, 1, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const x = new Float64Array( 10 ); + + dasum.ndarray( x.length, x, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dasum.ndarray( '10', x, 1, 0 ); // $ExpectError + dasum.ndarray( true, x, 1, 0 ); // $ExpectError + dasum.ndarray( false, x, 1, 0 ); // $ExpectError + dasum.ndarray( null, x, 1, 0 ); // $ExpectError + dasum.ndarray( undefined, x, 1, 0 ); // $ExpectError + dasum.ndarray( [], x, 1, 0 ); // $ExpectError + dasum.ndarray( {}, x, 1, 0 ); // $ExpectError + dasum.ndarray( ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a Float64Array... +{ + const x = new Float64Array( 10 ); + + dasum.ndarray( x.length, 10, 1, 0 ); // $ExpectError + dasum.ndarray( x.length, '10', 1, 0 ); // $ExpectError + dasum.ndarray( x.length, true, 1, 0 ); // $ExpectError + dasum.ndarray( x.length, false, 1, 0 ); // $ExpectError + dasum.ndarray( x.length, null, 1, 0 ); // $ExpectError + dasum.ndarray( x.length, undefined, 1, 0 ); // $ExpectError + dasum.ndarray( x.length, [], 1, 0 ); // $ExpectError + dasum.ndarray( x.length, {}, 1, 0 ); // $ExpectError + dasum.ndarray( x.length, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dasum.ndarray( x.length, x, '10', 0 ); // $ExpectError + dasum.ndarray( x.length, x, true, 0 ); // $ExpectError + dasum.ndarray( x.length, x, false, 0 ); // $ExpectError + dasum.ndarray( x.length, x, null, 0 ); // $ExpectError + dasum.ndarray( x.length, x, undefined, 0 ); // $ExpectError + dasum.ndarray( x.length, x, [], 0 ); // $ExpectError + dasum.ndarray( x.length, x, {}, 0 ); // $ExpectError + dasum.ndarray( x.length, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const x = new Float64Array( 10 ); + + dasum.ndarray( x.length, x, 1, '10' ); // $ExpectError + dasum.ndarray( x.length, x, 1, true ); // $ExpectError + dasum.ndarray( x.length, x, 1, false ); // $ExpectError + dasum.ndarray( x.length, x, 1, null ); // $ExpectError + dasum.ndarray( x.length, x, 1, undefined ); // $ExpectError + dasum.ndarray( x.length, x, 1, [] ); // $ExpectError + dasum.ndarray( x.length, x, 1, {} ); // $ExpectError + dasum.ndarray( x.length, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const x = new Float64Array( 10 ); + + dasum.ndarray(); // $ExpectError + dasum.ndarray( x.length ); // $ExpectError + dasum.ndarray( x.length, x ); // $ExpectError + dasum.ndarray( x.length, x, 1 ); // $ExpectError + dasum.ndarray( x.length, x, 1, 0, 10 ); // $ExpectError +} + +// Attached to the main export is a `Module` constructor which returns a module... +{ + const mem = new Memory({ + 'initial': 0 + }); + + dasum.Module( mem ); // $ExpectType Module +} + +// The compiler throws an error if the `Module` constructor is not provided a WebAssembly memory instance... +{ + dasum.Module( '10' ); // $ExpectError + dasum.Module( true ); // $ExpectError + dasum.Module( false ); // $ExpectError + dasum.Module( null ); // $ExpectError + dasum.Module( undefined ); // $ExpectError + dasum.Module( [] ); // $ExpectError + dasum.Module( {} ); // $ExpectError + dasum.Module( ( x: number ): number => x ); // $ExpectError +} + +// The `Module` constructor returns a module instance having a `main` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.main( 10, 0, 1 ); // $ExpectType number +} + +// The compiler throws an error if the `main` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.main( '10', 0, 1 ); // $ExpectError + mod.main( true, 0, 1 ); // $ExpectError + mod.main( false, 0, 1 ); // $ExpectError + mod.main( null, 0, 1 ); // $ExpectError + mod.main( undefined, 0, 1 ); // $ExpectError + mod.main( [], 0, 1 ); // $ExpectError + mod.main( {}, 0, 1 ); // $ExpectError + mod.main( ( x: number ): number => x, 0, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.main( 10, '10', 1 ); // $ExpectError + mod.main( 10, true, 1 ); // $ExpectError + mod.main( 10, false, 1 ); // $ExpectError + mod.main( 10, null, 1 ); // $ExpectError + mod.main( 10, undefined, 1 ); // $ExpectError + mod.main( 10, [], 1 ); // $ExpectError + mod.main( 10, {}, 1 ); // $ExpectError + mod.main( 10, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.main( 10, 0, '10' ); // $ExpectError + mod.main( 10, 0, true ); // $ExpectError + mod.main( 10, 0, false ); // $ExpectError + mod.main( 10, 0, null ); // $ExpectError + mod.main( 10, 0, undefined ); // $ExpectError + mod.main( 10, 0, [] ); // $ExpectError + mod.main( 10, 0, {} ); // $ExpectError + mod.main( 10, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `main` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.main(); // $ExpectError + mod.main( 10 ); // $ExpectError + mod.main( 10, 0 ); // $ExpectError + mod.main( 10, 0, 1, 10 ); // $ExpectError +} + +// The `Module` constructor returns a module instance having an `ndarray` method which returns a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.ndarray( 10, 0, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a first argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.ndarray( '10', 0, 1, 0 ); // $ExpectError + mod.ndarray( true, 0, 1, 0 ); // $ExpectError + mod.ndarray( false, 0, 1, 0 ); // $ExpectError + mod.ndarray( null, 0, 1, 0 ); // $ExpectError + mod.ndarray( undefined, 0, 1, 0 ); // $ExpectError + mod.ndarray( [], 0, 1, 0 ); // $ExpectError + mod.ndarray( {}, 0, 1, 0 ); // $ExpectError + mod.ndarray( ( x: number ): number => x, 0, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a second argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.ndarray( 10, '10', 1, 0 ); // $ExpectError + mod.ndarray( 10, true, 1, 0 ); // $ExpectError + mod.ndarray( 10, false, 1, 0 ); // $ExpectError + mod.ndarray( 10, null, 1, 0 ); // $ExpectError + mod.ndarray( 10, undefined, 1, 0 ); // $ExpectError + mod.ndarray( 10, [], 1, 0 ); // $ExpectError + mod.ndarray( 10, {}, 1, 0 ); // $ExpectError + mod.ndarray( 10, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a third argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.ndarray( 10, 0, '10', 0 ); // $ExpectError + mod.ndarray( 10, 0, true, 0 ); // $ExpectError + mod.ndarray( 10, 0, false, 0 ); // $ExpectError + mod.ndarray( 10, 0, null, 0 ); // $ExpectError + mod.ndarray( 10, 0, undefined, 0 ); // $ExpectError + mod.ndarray( 10, 0, [], 0 ); // $ExpectError + mod.ndarray( 10, 0, {}, 0 ); // $ExpectError + mod.ndarray( 10, 0, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided a fourth argument which is not a number... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.ndarray( 10, 0, 1, '10' ); // $ExpectError + mod.ndarray( 10, 0, 1, true ); // $ExpectError + mod.ndarray( 10, 0, 1, false ); // $ExpectError + mod.ndarray( 10, 0, 1, null ); // $ExpectError + mod.ndarray( 10, 0, 1, undefined ); // $ExpectError + mod.ndarray( 10, 0, 1, [] ); // $ExpectError + mod.ndarray( 10, 0, 1, {} ); // $ExpectError + mod.ndarray( 10, 0, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method of a module instance is provided an unsupported number of arguments... +{ + const mem = new Memory({ + 'initial': 1 + }); + const mod = dasum.Module( mem ); + + mod.ndarray(); // $ExpectError + mod.ndarray( 10 ); // $ExpectError + mod.ndarray( 10, 0 ); // $ExpectError + mod.ndarray( 10, 0, 1 ); // $ExpectError + mod.ndarray( 10, 0, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/index.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/index.js new file mode 100644 index 00000000000..5e43a30f4ec --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var oneTo = require( '@stdlib/array/one-to' ); +var dasum = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Specify a vector length: + var N = 5; + + // Create an input array: + var x = oneTo( N, 'float64' ); + + // Perform computation: + var sum = dasum.ndarray( N, x, 1, 0 ); + + // Print the result: + console.log( sum ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/little_endian_arrays.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/little_endian_arrays.js new file mode 100644 index 00000000000..635d270563e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/little_endian_arrays.js @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); +var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' ); +var dasum = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new dasum.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Specify a vector length: + var N = 5; + + // Define pointer (i.e., byte offsets) for storing the input vector: + var xptr = 0; + + // Create typed array views over module memory: + var x = new Float64ArrayLE( mod.memory.buffer, xptr, N ); + + // Write values to module memory: + gfillBy( N, x, 1, discreteUniform( -10.0, 10.0 ) ); + + // Perform computation: + var sum = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( sum ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/module.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/module.js new file mode 100644 index 00000000000..9f06633fa87 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/examples/module.js @@ -0,0 +1,63 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' ); +var Memory = require( '@stdlib/wasm/memory' ); +var oneTo = require( '@stdlib/array/one-to' ); +var dasum = require( './../lib' ); + +function main() { + if ( !hasWebAssemblySupport() ) { + console.error( 'Environment does not support WebAssembly.' ); + return; + } + // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): + var mem = new Memory({ + 'initial': 10, + 'maximum': 100 + }); + + // Create a BLAS routine: + var mod = new dasum.Module( mem ); + // returns + + // Initialize the routine: + mod.initializeSync(); // eslint-disable-line node/no-sync + + // Define a vector data type: + var dtype = 'float64'; + + // Specify a vector length: + var N = 5; + + // Define pointer (i.e., byte offsets) for storing the input vectors: + var xptr = 0; + + // Write vector values to module memory: + mod.write( xptr, oneTo( N, dtype ) ); + + // Perform computation: + var sum = mod.ndarray( N, xptr, 1, 0 ); + + // Print the result: + console.log( sum ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/binary.browser.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/binary.browser.js new file mode 100644 index 00000000000..d85226505e4 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/binary.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAETA2AAAGADf39/AXxgBH9/f38BfAIPAQNlbnYGbWVtb3J5AgAAAwQDAAECB0wEEV9fd2FzbV9jYWxsX2N0b3JzAAAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAHY19kYXN1bQABD2NfZGFzdW1fbmRhcnJheQACCocCAwMAAQshAQF+IAAgASACIAKsIgNCASAArH1+QgAgA0IAVxunEAIL3gECAXwCfyAAQQBMBEBEAAAAAAAAAAAPCwJAIAJBAUcEQANAIAQgASADQQN0aisDAJmgIQQgAiADaiEDIAVBAWoiBSAARw0ACwwBCwJAIABBBnAiAkUEQCADIQUMAQsDQCAEIAEgA0EDdGorAwCZoCEEIANBAWoiBSEDIAZBAWoiBiACRw0ACwsgAEEGSA0AA0AgBCABIAVBA3RqIgMrAwCZIAMrAwiZoCADKwMQmaAgAysDGJmgIAMrAyCZoCADKwMomaCgIQQgBUEGaiEFIAJBBmoiAiAASA0ACwsgBAs=' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/binary.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/binary.js new file mode 100644 index 00000000000..6f02393f96e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/binary.js @@ -0,0 +1,34 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readWASM = require( '@stdlib/fs/read-wasm' ).sync; + + +// MAIN // + +var wasm = readWASM( resolve( __dirname, '..', 'src', 'main.wasm' ) ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/index.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/index.js new file mode 100644 index 00000000000..f06bc51e662 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/index.js @@ -0,0 +1,100 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +/** +* WebAssembly routine to compute the sum of absolute values. +* +* @module @stdlib/blas/base/dasum-wasm +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dasum = require( '@stdlib/blas/base/dasum-wasm' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var sum = dasum.main( x.length, x, 1 ); +* // returns 15.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dasum = require( '@stdlib/blas/base/dasum-wasm' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var sum = dasum.ndarray( x.length, x, 1, 0 ); +* // returns 15.0 +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* var zeros = require( '@stdlib/array/zeros' ); +* var dasum = require( '@stdlib/blas/base/dasum-wasm' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var mod = new dasum.Module( mem ); +* // returns +* +* // Initialize the routine: +* mod.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* mod.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var sum = mod.main( N, xptr, 1 ); +* // returns 15.0 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var Module = require( './module.js' ); + + +// MAIN // + +setReadOnly( main, 'Module', Module ); + + +// EXPORTS // + +module.exports = main; + +// exports: { "Module": "main.Module" } diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/main.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/main.js new file mode 100644 index 00000000000..4b332108ccb --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/main.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var Routine = require( './routine.js' ); + + +// MAIN // + +/** +* WebAssembly module to compute the sum of absolute values. +* +* @name dasum +* @type {Routine} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var sum = dasum.main( x.length, x, 1 ); +* // returns 15.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var sum = dasum.ndarray( x.length, x, 1, 0 ); +* // returns 15.0 +*/ +var dasum = new Routine(); +dasum.initializeSync(); // eslint-disable-line node/no-sync + + +// EXPORTS // + +module.exports = dasum; diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/module.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/module.js new file mode 100644 index 00000000000..e7c33cad717 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/module.js @@ -0,0 +1,198 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var isWebAssemblyMemory = require( '@stdlib/assert/is-wasm-memory' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var WasmModule = require( '@stdlib/wasm/module-wrapper' ); +var format = require( '@stdlib/string/format' ); +var wasmBinary = require( './binary.js' ); + + +// MAIN // + +/** +* BLAS routine WebAssembly module wrapper constructor. +* +* @constructor +* @param {Object} memory - WebAssembly memory instance +* @throws {TypeError} must provide a WebAssembly memory instance +* @returns {Module} module instance +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var dasum = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dasum.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dasum.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var sum = dasum.main( N, xptr, 1 ); +* // returns 15.0 +*/ +function Module( memory ) { + if ( !( this instanceof Module ) ) { + return new Module( memory ); + } + if ( !isWebAssemblyMemory( memory ) ) { + throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) ); + } + // Call the parent constructor: + WasmModule.call( this, wasmBinary, memory, { + 'env': { + 'memory': memory + } + }); + + return this; +} + +// Inherit from the parent constructor: +inherits( Module, WasmModule ); + +/** +* Computes the sum of absolute values. +* +* @name main +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @returns {number} sum of absolute values +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var dasum = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dasum.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dasum.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var sum = dasum.main( N, xptr, 1 ); +* // returns 15.0 +*/ +setReadOnly( Module.prototype, 'main', function dasum( N, xptr, strideX ) { + return this._instance.exports.c_dasum( N, xptr, strideX ); +}); + +/** +* Computes the sum of absolute values using alternative indexing semantics. +* +* @name ndarray +* @memberof Module.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset) +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` +* @returns {number} sum of absolute values +* +* @example +* var Memory = require( '@stdlib/wasm/memory' ); +* var oneTo = require( '@stdlib/array/one-to' ); +* +* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB): +* var mem = new Memory({ +* 'initial': 10, +* 'maximum': 100 +* }); +* +* // Create a BLAS routine: +* var dasum = new Module( mem ); +* // returns +* +* // Initialize the routine: +* dasum.initializeSync(); +* +* // Define a vector data type: +* var dtype = 'float64'; +* +* // Specify a vector length: +* var N = 5; +* +* // Define pointer (i.e., byte offsets) for storing the input vector: +* var xptr = 0; +* +* // Write vector values to module memory: +* dasum.write( xptr, oneTo( N, dtype ) ); +* +* // Perform computation: +* var sum = dasum.ndarray( N, xptr, 1, 0 ); +* // returns 15.0 +*/ +setReadOnly( Module.prototype, 'ndarray', function dasum( N, xptr, strideX, offsetX ) { + return this._instance.exports.c_dasum_ndarray( N, xptr, strideX, offsetX ); +}); + + +// EXPORTS // + +module.exports = Module; diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/routine.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/routine.js new file mode 100644 index 00000000000..feb08e7f0af --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/lib/routine.js @@ -0,0 +1,166 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable max-len, no-restricted-syntax, no-invalid-this */ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var inherits = require( '@stdlib/utils/inherit' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var Memory = require( '@stdlib/wasm/memory' ); +var arrays2ptrs = require( '@stdlib/wasm/base/arrays2ptrs' ); +var strided2object = require( '@stdlib/wasm/base/strided2object' ); +var Module = require( './module.js' ); + + +// MAIN // + +/** +* Routine constructor. +* +* @private +* @constructor +* @returns {Routine} routine instance +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dasum = new Routine(); +* +* // Initialize the module: +* dasum.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var sum = dasum.main( x.length, x, 1 ); +* // returns 15.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dasum = new Routine(); +* +* // Initialize the module: +* dasum.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var sum = dasum.ndarray( x.length, x, 1, 0 ); +* // returns 15.0 +*/ +function Routine() { + if ( !( this instanceof Routine ) ) { + return new Routine(); + } + Module.call( this, new Memory({ + 'initial': 0 + })); + return this; +} + +// Inherit from the parent constructor: +inherits( Routine, Module ); + +/** +* Computes the sum of absolute values. +* +* @name main +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - `x` stride length +* @returns {number} sum of absolute values +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dasum = new Routine(); +* +* // Initialize the module: +* dasum.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var sum = dasum.main( x.length, x, 1 ); +* // returns 15.0 +*/ +setReadOnly( Routine.prototype, 'main', function dasum( N, x, strideX ) { + return this.ndarray( N, x, strideX, stride2offset( N, strideX ) ); +}); + +/** +* Computes the sum of absolute values using alternative indexing semantics. +* +* @name ndarray +* @memberof Routine.prototype +* @readonly +* @type {Function} +* @param {PositiveInteger} N - number of indexed elements +* @param {Float64Array} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index +* @returns {number} sum of absolute values +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* // Create a new routine: +* var dasum = new Routine(); +* +* // Initialize the module: +* dasum.initializeSync(); +* +* // Define a strided array: +* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); +* +* // Perform operation: +* var sum = dasum.ndarray( x.length, x, 1, 0 ); +* // returns 15.0 +*/ +setReadOnly( Routine.prototype, 'ndarray', function dasum( N, x, strideX, offsetX ) { + var ptrs; + var p0; + + // Convert the input arrays to "pointers" in the module's memory: + ptrs = arrays2ptrs( this, [ + strided2object( N, x, strideX, offsetX ) + ]); + p0 = ptrs[ 0 ]; + + // Perform computation by calling the corresponding parent method: + return Module.prototype.ndarray.call( this, N, p0.ptr, p0.stride, p0.offset ); +}); + + +// EXPORTS // + +module.exports = Routine; diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/manifest.json b/lib/node_modules/@stdlib/blas/base/dasum-wasm/manifest.json new file mode 100644 index 00000000000..a83fdd46fe6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/dasum" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/package.json b/lib/node_modules/@stdlib/blas/base/dasum-wasm/package.json new file mode 100644 index 00000000000..2c7608866a2 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/package.json @@ -0,0 +1,80 @@ +{ + "name": "@stdlib/blas/base/dasum-wasm", + "version": "0.0.0", + "description": "Compute the sum of absolute values.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": { + "./lib/binary.js": "./lib/binary.browser.js" + }, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "scripts": "./scripts", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "level 1", + "dasum", + "linear", + "algebra", + "subroutines", + "sum", + "vector", + "array", + "ndarray", + "float64", + "double", + "float64array", + "webassembly", + "wasm" + ], + "__stdlib__": { + "wasm": true + } +} diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/scripts/build.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/scripts/build.js new file mode 100644 index 00000000000..348354d7029 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/scripts/build.js @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFile = require( '@stdlib/fs/read-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ).sync; +var replace = require( '@stdlib/string/replace' ); + + +// VARIABLES // + +var wpath = resolve( __dirname, '..', 'src', 'main.wasm' ); +var tpath = resolve( __dirname, 'template.txt' ); +var opath = resolve( __dirname, '..', 'lib', 'binary.browser.js' ); + +var opts = { + 'encoding': 'utf8' +}; + +var PLACEHOLDER = '{{WASM_BASE64}}'; + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var wasm; + var tmpl; + + wasm = readFile( wpath ); + tmpl = readFile( tpath, opts ); + + tmpl = replace( tmpl, PLACEHOLDER, wasm.toString( 'base64' ) ); + + writeFile( opath, tmpl, opts ); +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/scripts/template.txt b/lib/node_modules/@stdlib/blas/base/dasum-wasm/scripts/template.txt new file mode 100644 index 00000000000..12996dd89e3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/scripts/template.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var base64ToUint8Array = require( '@stdlib/string/base/base64-to-uint8array' ); + + +// MAIN // + +var wasm = base64ToUint8Array( '{{WASM_BASE64}}' ); + + +// EXPORTS // + +module.exports = wasm; diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/src/Makefile b/lib/node_modules/@stdlib/blas/base/dasum-wasm/src/Makefile new file mode 100644 index 00000000000..bc21e14c7b3 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/src/Makefile @@ -0,0 +1,232 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2024 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. +#/ + +#/ +# To compile targets listed in this Makefile, use top-level project `make` +# commands rather than commands listed in this Makefile. The top-level project +# `make` commands will ensure that various environment variables and flags are +# appropriately set. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files to WebAssembly: +ifdef EMCC_COMPILER + EMCC := $(EMCC_COMPILER) +else + EMCC := emcc +endif + +# Define the program used for compiling WebAssembly files to the WebAssembly text format: +ifdef WASM2WAT + WASM_TO_WAT := $(WASM2WAT) +else + WASM_TO_WAT := wasm2wat +endif + +# Define the program used for compiling WebAssembly files to JavaScript: +ifdef WASM2JS + WASM_TO_JS := $(WASM2JS) +else + WASM_TO_JS := wasm2js +endif + +# Define the path to the Node.js executable: +ifdef NODE + NODEJS := $(NODE) +else + NODEJS := node +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic \ + -D CBLAS_INT=int32_t + +# Define the command-line options when compiling C files to WebAssembly and asm.js: +EMCCFLAGS ?= $(CFLAGS) + +# Define shared `emcc` flags: +EMCC_SHARED_FLAGS := \ + -s SIDE_MODULE=2 \ + -s WASM_BIGINT=0 \ + -s EXPORTED_FUNCTIONS="['_c_dasum','_c_dasum_ndarray']" + +# Define WebAssembly `emcc` flags: +EMCC_WASM_FLAGS := $(EMCC_SHARED_FLAGS) \ + -s WASM=1 + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of WebAssembly targets: +wasm_targets := main.wasm + +# List of WebAssembly WAT targets: +wat_targets := main.wat + +# List of WebAssembly JavaScript targets: +wasm_js_targets := main.wasm.js + +# List of other JavaScript targets: +browser_js_targets := ./../lib/binary.browser.js + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: wasm + +.PHONY: all + +#/ +# Compiles source files to WebAssembly. +# +# @param {string} [EMCC_COMPILER] - EMCC compiler (e.g., `emcc`) +# @param {string} [EMCCFLAGS] - EMCC compiler options +# @param {string} [WASM2WAT] - WebAssembly text format compiler (e.g., `wasm2wat`) +# @param {string} [WASM2JS] - WebAssembly JavaScript compiler (e.g., `wasm2js`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make wasm +#/ +wasm: $(wasm_targets) $(wat_targets) $(browser_js_targets) + +.PHONY: wasm + +#/ +# Compiles C source files to WebAssembly binaries. +# +# @private +# @param {string} EMCC - EMCC compiler (e.g., `emcc`) +# @param {string} EMCCFLAGS - EMCC compiler options +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(wasm_targets): + $(QUIET) $(EMCC) $(EMCCFLAGS) $(EMCC_WASM_FLAGS) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) $(LIBRARIES) + +#/ +# Compiles WebAssembly binary files to the WebAssembly text format. +# +# @private +# @param {string} WASM2WAT - WAT compiler (e.g., `wasm2wat`) +#/ +$(wat_targets): %.wat: %.wasm + $(QUIET) $(WASM_TO_WAT) -o $@ $(wasm_targets) + +#/ +# Compiles WebAssembly binary files to JavaScript. +# +# @private +# @param {string} WASM2JS - JavaScript compiler (e.g., `wasm2js`) +#/ +$(wasm_js_targets): %.wasm.js: %.wasm + $(QUIET) $(WASM_TO_JS) -o $@ $(wasm_targets) + +#/ +# Generates an inline WebAssembly build for use in bundlers. +# +# @private +# @param {string} NODE - Node.js executable +#/ +$(browser_js_targets): $(wasm_targets) + $(QUIET) $(NODEJS) ./../scripts/build.js + +#/ +# Removes generated WebAssembly files. +# +# @example +# make clean-wasm +#/ +clean-wasm: + $(QUIET) -rm -f *.wasm *.wat *.wasm.js + +.PHONY: clean-wasm + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-wasm + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/src/main.wasm b/lib/node_modules/@stdlib/blas/base/dasum-wasm/src/main.wasm new file mode 100755 index 0000000000000000000000000000000000000000..cab460d8fabc8cb6af0869c8dbd0b690b039ce39 GIT binary patch literal 413 zcmZvWJx;?w5QXPw?L?T!K{SzQ#;%Z%5J#{hP$<$&9)a~qgT{hX=Zf#aC%2lpkyU&7R50YkT1yY!rT14@KaoS1|YG3vl6 zZ;Km-{UI`H$3?{ArC7wCz+?cyIXVPVe;w0R#usvU;Lyhbbb#ls m#q92hzWx2d$?znjlgLS~_XiirOZ_79G_zmCB%oI6X@Xx*_fSj# literal 0 HcmV?d00001 diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/src/main.wat b/lib/node_modules/@stdlib/blas/base/dasum-wasm/src/main.wat new file mode 100644 index 00000000000..32cbfdc227f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/src/main.wat @@ -0,0 +1,172 @@ +;; @license Apache-2.0 +;; +;; Copyright (c) 2024 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. + +(module + (type (;0;) (func)) + (type (;1;) (func (param i32 i32 i32) (result f64))) + (type (;2;) (func (param i32 i32 i32 i32) (result f64))) + (import "env" "memory" (memory (;0;) 0)) + (func (;0;) (type 0) + nop) + (func (;1;) (type 1) (param i32 i32 i32) (result f64) + (local i64) + local.get 0 + local.get 1 + local.get 2 + local.get 2 + i64.extend_i32_s + local.tee 3 + i64.const 1 + local.get 0 + i64.extend_i32_s + i64.sub + i64.mul + i64.const 0 + local.get 3 + i64.const 0 + i64.le_s + select + i32.wrap_i64 + call 2) + (func (;2;) (type 2) (param i32 i32 i32 i32) (result f64) + (local f64 i32 i32) + local.get 0 + i32.const 0 + i32.le_s + if ;; label = @1 + f64.const 0x0p+0 (;=0;) + return + end + block ;; label = @1 + local.get 2 + i32.const 1 + i32.ne + if ;; label = @2 + loop ;; label = @3 + local.get 4 + local.get 1 + local.get 3 + i32.const 3 + i32.shl + i32.add + f64.load + f64.abs + f64.add + local.set 4 + local.get 2 + local.get 3 + i32.add + local.set 3 + local.get 5 + i32.const 1 + i32.add + local.tee 5 + local.get 0 + i32.ne + br_if 0 (;@3;) + end + br 1 (;@1;) + end + block ;; label = @2 + local.get 0 + i32.const 6 + i32.rem_u + local.tee 2 + i32.eqz + if ;; label = @3 + local.get 3 + local.set 5 + br 1 (;@2;) + end + loop ;; label = @3 + local.get 4 + local.get 1 + local.get 3 + i32.const 3 + i32.shl + i32.add + f64.load + f64.abs + f64.add + local.set 4 + local.get 3 + i32.const 1 + i32.add + local.tee 5 + local.set 3 + local.get 6 + i32.const 1 + i32.add + local.tee 6 + local.get 2 + i32.ne + br_if 0 (;@3;) + end + end + local.get 0 + i32.const 6 + i32.lt_s + br_if 0 (;@1;) + loop ;; label = @2 + local.get 4 + local.get 1 + local.get 5 + i32.const 3 + i32.shl + i32.add + local.tee 3 + f64.load + f64.abs + local.get 3 + f64.load offset=8 + f64.abs + f64.add + local.get 3 + f64.load offset=16 + f64.abs + f64.add + local.get 3 + f64.load offset=24 + f64.abs + f64.add + local.get 3 + f64.load offset=32 + f64.abs + f64.add + local.get 3 + f64.load offset=40 + f64.abs + f64.add + f64.add + local.set 4 + local.get 5 + i32.const 6 + i32.add + local.set 5 + local.get 2 + i32.const 6 + i32.add + local.tee 2 + local.get 0 + i32.lt_s + br_if 0 (;@2;) + end + end + local.get 4) + (export "__wasm_call_ctors" (func 0)) + (export "__wasm_apply_data_relocs" (func 0)) + (export "c_dasum" (func 1)) + (export "c_dasum_ndarray" (func 2))) diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.js new file mode 100644 index 00000000000..51aa3de8284 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var dasum = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dasum, 'object', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `main` method', function test( t ) { + t.strictEqual( typeof dasum.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is an `ndarray` method', function test( t ) { + t.strictEqual( typeof dasum.ndarray, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main export is a `Module` constructor', function test( t ) { + t.strictEqual( typeof dasum.Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the main export is a `Module` instance', function test( t ) { + t.strictEqual( dasum instanceof dasum.Module, true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.main.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.main.js new file mode 100644 index 00000000000..925d69dff5e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.main.js @@ -0,0 +1,152 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dasum = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dasum, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `main` method has an arity of 3', function test( t ) { + t.strictEqual( dasum.main.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method computes the sum of absolute values', function test( t ) { + var x; + var y; + + x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0 ] ); + y = dasum.main( x.length, x, 1 ); + + t.strictEqual( y, 15.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports an `x` stride', function test( t ) { + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 1 + -2.0, + 3.0, // 2 + -4.0, + 5.0 // 3 + ]); + N = 3; + + y = dasum.main( N, x, 2 ); + + t.strictEqual( y, 9.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `main` method returns `0.0`', function test( t ) { + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + y = dasum.main( -1, x, 1 ); + t.deepEqual( y, 0.0, 'returns expected value' ); + + y = dasum.main( 0, x, 1 ); + t.deepEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports negative strides', function test( t ) { + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 2 + -2.0, + 3.0, // 1 + -4.0, + 5.0 + ]); + N = 2; + + y = dasum.main( N, x, -2 ); + + t.strictEqual( y, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports complex access patterns', function test( t ) { + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 2 + 6.0 + ]); + N = 3; + + y = dasum.main( N, x, 2 ); + + t.strictEqual( y, 9.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports view offsets', function test( t ) { + var x0; + var x1; + var y; + var N; + + // Initial array... + x0 = new Float64Array([ + 1.0, + -2.0, // 1 + 3.0, + -4.0, // 2 + 5.0, + -6.0 // 3 + ]); + + // Create an offset view... + x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // begin at 2nd element + + N = 3; + y = dasum.main( N, x1, 2 ); + + t.strictEqual( y, 12.0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.js new file mode 100644 index 00000000000..9adcb07e22f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.js @@ -0,0 +1,154 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = Module( mem ); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Module( value ); + }; + } +}); + +tape( 'the module constructor throws an error if provided a first argument which is not a WebAssembly memory instance (no new)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return Module( value ); // eslint-disable-line new-cap + }; + } +}); + +tape( 'the module instance returned by the module constructor inherits from a module wrapper', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.main.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.main.js new file mode 100644 index 00000000000..396fe557670 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.main.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which has an arity of 3', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.main.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has a `main` method which computes the sum of absolute values', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + y = mod.main( 5, xp, 1 ); + t.strictEqual( y, 15.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports an `x` stride', function test( t ) { + var mem; + var mod; + var xp; + var y; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + -3.0, // 1 + 4.0, + -5.0 // 2 + ])); + N = 3; + + y = mod.main( N, xp, 2 ); + t.strictEqual( y, 9.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has a `main` method which returns `0.0`', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + y = mod.main( -1, xp, 1 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = mod.main( 0, xp, 1 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has a `main` method which supports negative strides', function test( t ) { + var mem; + var mod; + var xp; + var y; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + N = 3; + + y = mod.main( N, xp, -2 ); + t.strictEqual( y, 9.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.ndarray.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.ndarray.js new file mode 100644 index 00000000000..567a6ded624 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.module.ndarray.js @@ -0,0 +1,218 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +/* eslint-disable node/no-sync */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Memory = require( '@stdlib/wasm/memory' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Module = require( './../lib' ).Module; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Module, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which has an arity of 4', function test( t ) { + var mem; + var mod; + + mem = new Memory({ + 'initial': 0 + }); + mod = new Module( mem ); + t.strictEqual( mod.ndarray.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which computes the sum of absolute values', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0 ] ) ); + + y = mod.ndarray( 5, xp, 1, 0 ); + t.strictEqual( y, 15.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` stride', function test( t ) { + var mem; + var mod; + var xp; + var y; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 0 + 2.0, + 3.0, // 1 + 4.0, + -5.0 // 2 + ])); + N = 3; + + y = mod.ndarray( N, xp, 2, 0 ); + t.strictEqual( y, 9.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports an `x` offset', function test( t ) { + var mem; + var mod; + var xp; + var y; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, + 2.0, + 3.0, // 0 + -4.0, // 1 + 5.0 // 2 + ])); + N = 3; + + y = mod.ndarray( N, xp, 1, 2 ); + t.strictEqual( y, 12.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, a module instance has an `ndarray` method which returns `0.0`', function test( t ) { + var mem; + var mod; + var xp; + var y; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ) ); + + y = mod.ndarray( -1, 3.0, xp, 1, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = mod.ndarray( 0, 3.0, xp, 1, 0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports negative strides', function test( t ) { + var mem; + var mod; + var xp; + var y; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0 // 0 + ])); + N = 3; + + y = mod.ndarray( N, xp, -2, 4 ); + t.strictEqual( y, 9.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'a module instance has an `ndarray` method which supports complex access patterns', function test( t ) { + var mem; + var mod; + var xp; + var y; + var N; + + mem = new Memory({ + 'initial': 1 + }); + mod = new Module( mem ); + mod.initializeSync(); + + xp = 0; + + mod.write( xp, new Float64Array([ + 0.0, + 1.0, // 2 + 2.0, + 3.0, // 1 + 4.0, + 5.0, // 0 + 6.0 + ])); + N = 3; + + y = mod.ndarray( N, xp, -2, 5 ); + t.strictEqual( y, 9.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.ndarray.js new file mode 100644 index 00000000000..258ce3832e9 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.ndarray.js @@ -0,0 +1,145 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dasum = require( './../lib' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dasum, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the `ndarray` method has an arity of 4', function test( t ) { + t.strictEqual( dasum.ndarray.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method computes the sum of absolute values', function test( t ) { + var x; + var y; + + x = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0 ] ); + y = dasum.ndarray( x.length, x, 1, 0 ); + + t.strictEqual( y, 15.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports an `x` stride', function test( t ) { + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 1 + -2.0, + 3.0, // 2 + -4.0, + 5.0 // 3 + ]); + N = 3; + + y = dasum.ndarray( N, x, 2, 0 ); + + t.strictEqual( y, 9.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `main` method supports an `x` offset', function test( t ) { + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, + -2.0, + 3.0, // 1 + -4.0, // 2 + 5.0 // 3 + ]); + N = 3; + + y = dasum.ndarray( N, x, 1, 2 ); + + t.strictEqual( y, 12.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided an `N` parameter less than or equal to `0`, the `main` method returns `0.0`', function test( t ) { + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); + + y = dasum.ndarray( -1, x, 1, 0 ); + t.deepEqual( y, 0.0, 'returns expected value' ); + + y = dasum.ndarray( 0, x, 1, 0 ); + t.deepEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `main` method supports negative strides', function test( t ) { + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, // 2 + -2.0, + 3.0, // 1 + -4.0, + 5.0 + ]); + N = 2; + + y = dasum.ndarray( N, x, -2, 2 ); + + t.strictEqual( y, 4.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method supports complex access patterns', function test( t ) { + var x; + var y; + var N; + + x = new Float64Array([ + 1.0, + -2.0, // 2 + 3.0, + -4.0, // 1 + 5.0 + ]); + N = 2; + + y = dasum.ndarray( N, x, -2, 3 ); + + t.strictEqual( y, 6.0, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.routine.js b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.routine.js new file mode 100644 index 00000000000..56a4b67daaf --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/dasum-wasm/test/test.routine.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ModuleWrapper = require( '@stdlib/wasm/module-wrapper' ); +var Module = require( './../lib/module.js' ); +var Routine = require( './../lib/routine.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Routine, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function is a constructor which does not require `new`', function test( t ) { + var mod = Routine(); // eslint-disable-line new-cap + t.strictEqual( mod instanceof Routine, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a module wrapper', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof ModuleWrapper, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the module instance returned by the constructor inherits from a BLAS routine module', function test( t ) { + var mod = new Routine(); + t.strictEqual( mod instanceof Module, true, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is a `main` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.main, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'attached to a module instance is an `ndarray` method', function test( t ) { + var mod = new Routine(); + t.strictEqual( typeof mod.ndarray, 'function', 'returns expected value' ); + t.end(); +}); From 04b72af273ca022bd8295379edc5ff04a03d23e7 Mon Sep 17 00:00:00 2001 From: Gunj Joshi Date: Sat, 19 Oct 2024 14:21:12 +0530 Subject: [PATCH 49/50] feat: add C implementation for `math/base/special/nanmin` PR-URL: https://github.com/stdlib-js/stdlib/pull/3004 Ref: https://github.com/stdlib-js/stdlib/issues/649 Co-authored-by: Athan Reines Reviewed-by: Athan Reines Signed-off-by: Athan Reines Signed-off-by: Gunj Joshi --- .../math/base/special/nanmin/README.md | 124 +++++++++++++ .../nanmin/benchmark/benchmark.native.js | 64 +++++++ .../nanmin/benchmark/c/native/Makefile | 146 +++++++++++++++ .../nanmin/benchmark/c/native/benchmark.c | 138 ++++++++++++++ .../math/base/special/nanmin/binding.gyp | 170 ++++++++++++++++++ .../base/special/nanmin/examples/c/Makefile | 146 +++++++++++++++ .../base/special/nanmin/examples/c/example.c | 32 ++++ .../math/base/special/nanmin/include.gypi | 53 ++++++ .../include/stdlib/math/base/special/nanmin.h | 38 ++++ .../math/base/special/nanmin/lib/native.js | 55 ++++++ .../math/base/special/nanmin/manifest.json | 75 ++++++++ .../math/base/special/nanmin/src/Makefile | 70 ++++++++ .../math/base/special/nanmin/src/addon.c | 22 +++ .../math/base/special/nanmin/src/main.c | 43 +++++ .../math/base/special/nanmin/test/test.js | 10 +- .../base/special/nanmin/test/test.native.js | 75 ++++++++ 16 files changed, 1256 insertions(+), 5 deletions(-) create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/benchmark/c/native/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/benchmark/c/native/benchmark.c create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/binding.gyp create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/include.gypi create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/include/stdlib/math/base/special/nanmin.h create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/lib/native.js create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/manifest.json create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/src/Makefile create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/src/addon.c create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/src/main.c create mode 100644 lib/node_modules/@stdlib/math/base/special/nanmin/test/test.native.js diff --git a/lib/node_modules/@stdlib/math/base/special/nanmin/README.md b/lib/node_modules/@stdlib/math/base/special/nanmin/README.md index 8ed7694c32e..ff1dfafce3c 100644 --- a/lib/node_modules/@stdlib/math/base/special/nanmin/README.md +++ b/lib/node_modules/@stdlib/math/base/special/nanmin/README.md @@ -79,6 +79,130 @@ var v = nanmin( NaN, NaN ); + + + + +
+ +## Examples + + + +```javascript +var nanmin = require( '@stdlib/math/base/special/nanmin' ); + +var m = nanmin( 3.0, 4.0 ); +console.log( m ); +// => 3.0 + +m = nanmin( NaN, 4.0 ); +console.log( m ); +// => 4.0 + +m = nanmin( 4.0, NaN ); +console.log( m ); +// => 4.0 + +m = nanmin( NaN, NaN ); +console.log( m ); +// => NaN +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/math/base/special/nanmin.h" +``` + +#### stdlib_base_nanmin( x, y ) + +Returns the minimum value, ignoring NaN. + +```c +double out = stdlib_base_nanmin( 4.2, 3.14 ); +// returns 3.14 + +out = stdlib_base_nanmin( 4.14, 0.0 / 0.0 ); +// returns 4.14 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **y**: `[in] double` input value. + +```c +double stdlib_base_nanmin( const double x, const double y ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/math/base/special/nanmin.h" +#include + +int main( void ) { + const double x[] = { 1.0, 0.45, -0.89, 0.0 / 0.0, -0.78, -0.22, 0.66, 0.11, -0.55, 0.0 }; + const double y[] = { -0.22, 0.66, 0.0, -0.55, 0.33, 1.0, 0.0 / 0.0, 0.11, 0.45, -0.78 }; + + double v; + int i; + for ( i = 0; i < 10; i++ ) { + v = stdlib_base_nanmin( x[i], y[i] ); + printf( "x[ %d ]: %f, y[ %d ]: %f, nanmin( x[ %d ], y[ %d ] ): %f\n", i, x[ i ], i, y[ i ], i, i, v ); + } +} +``` + +
+ + + +
+ + +