diff --git a/lib/node_modules/@stdlib/blas/base/zscal/README.md b/lib/node_modules/@stdlib/blas/base/zscal/README.md index eb70f3fbf13e..eea0460061fe 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/README.md +++ b/lib/node_modules/@stdlib/blas/base/zscal/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2024 The Stdlib Authors. +Copyright (c) 2025 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. @@ -30,39 +30,39 @@ limitations under the License. var zscal = require( '@stdlib/blas/base/zscal' ); ``` -#### zscal( N, za, zx, strideX ) +#### zscal( N, alpha, x, strideX ) -Scales values from `zx` by `za`. +Scales values from `x` by `alpha`. ```javascript var Complex128Array = require( '@stdlib/array/complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var zx = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); -var za = new Complex128( 2.0, 0.0 ); +var x = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var alpha = new Complex128( 2.0, 0.0 ); -zscal( 3, za, zx, 1 ); -// zx => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] +zscal( 3, alpha, x, 1 ); +// x => [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ``` The function has the following parameters: - **N**: number of indexed elements. -- **za**: scalar [`Complex128`][@stdlib/complex/float64/ctor] constant. -- **zx**: input [`Complex128Array`][@stdlib/array/complex128]. -- **strideX**: index increment for `zx`. +- **alpha**: scalar [`Complex128`][@stdlib/complex/float64/ctor] constant. +- **x**: input [`Complex128Array`][@stdlib/array/complex128]. +- **strideX**: index increment for `x`. -The `N` and stride parameters determine how values from `zx` are scaled by `za`. For example, to scale every other value in `zx` by `za`, +The `N` and stride parameters determine how values from `x` are scaled by `alpha`. For example, to scale every other value in `x` by `alpha`, ```javascript var Complex128Array = require( '@stdlib/array/complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -var za = new Complex128( 2.0, 0.0 ); +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var alpha = new Complex128( 2.0, 0.0 ); -zscal( 2, za, zx, 2 ); -// zx => [ 2.0, 4.0, 3.0, 4.0, 10.0, 12.0, 7.0, 8.0 ] +zscal( 2, alpha, x, 2 ); +// x => [ 2.0, 4.0, 3.0, 4.0, 10.0, 12.0, 7.0, 8.0 ] ``` Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. @@ -74,37 +74,37 @@ var Complex128Array = require( '@stdlib/array/complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); // Initial array: -var zx0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var x0 = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); // Define a scalar constant: -var za = new Complex128( 2.0, 2.0 ); +var alpha = new Complex128( 2.0, 2.0 ); // Create an offset view: -var zx1 = new Complex128Array( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element // Scales every other value from `zx1` by `za`... -zscal( 3, za, zx1, 1 ); -// zx0 => [ 1.0, 2.0, -2.0, 14.0, -2.0, 22.0, -2.0, 30.0 ] +zscal( 3, alpha, x1, 1 ); +// x0 => [ 1.0, 2.0, -2.0, 14.0, -2.0, 22.0, -2.0, 30.0 ] ``` -#### zscal.ndarray( N, za, zx, strideX, offsetX ) +#### zscal.ndarray( N, alpha, x, strideX, offsetX ) -Scales values from `zx` by `za` using alternative indexing semantics. +Scales values from `x` by `alpha` using alternative indexing semantics. ```javascript var Complex128Array = require( '@stdlib/array/complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -var za = new Complex128( 2.0, 2.0 ); +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var alpha = new Complex128( 2.0, 2.0 ); -zscal.ndarray( 3, za, zx, 1, 0 ); -// zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] +zscal.ndarray( 3, alpha, x, 1, 0 ); +// x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] ``` The function has the following additional parameters: -- **offsetX**: starting index for `zx`. +- **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 scale every other value in the input strided array starting from the second element, @@ -112,11 +112,11 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the var Complex128Array = require( '@stdlib/array/complex128' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); -var za = new Complex128( 2.0, 2.0 ); +var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); +var alpha = new Complex128( 2.0, 2.0 ); -zscal.ndarray( 2, za, zx, 2, 1 ); -// zx => [ 1.0, 2.0, -2.0, 14.0, 5.0, 6.0, -2.0, 30.0 ] +zscal.ndarray( 2, alpha, x, 2, 1 ); +// x => [ 1.0, 2.0, -2.0, 14.0, 5.0, 6.0, -2.0, 30.0 ] ``` @@ -127,7 +127,7 @@ zscal.ndarray( 2, za, zx, 2, 1 ); ## Notes -- If `N <= 0` or `strideX <= 0` , both functions return `zx` unchanged. +- If `N <= 0` , both functions return `x` unchanged. - `zscal()` corresponds to the [BLAS][blas] level 1 function [`zscal`][zscal]. @@ -150,15 +150,15 @@ function rand() { return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); } -var zx = filledarrayBy( 10, 'complex128', rand ); -console.log( zx.toString() ); +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); -var za = new Complex128( 2.0, 2.0 ); -console.log( za.toString() ); +var alpha = new Complex128( 2.0, 2.0 ); +console.log( alpha.toString() ); -// Scales elements from `zx` by `za`: -zscal( zx.length, za, zx, 1 ); -console.log( zx.get( zx.length-1 ).toString() ); +// Scales elements from `x` by `alpha`: +zscal( x.length, alpha, x, 1 ); +console.log( x.get( x.length-1 ).toString() ); ``` @@ -191,28 +191,53 @@ console.log( zx.get( zx.length-1 ).toString() ); #include "stdlib/blas/base/zscal.h" ``` -#### c_zscal( N, za, \*ZX, strideX ) +#### c_zscal( N, alpha, \*X, strideX ) -Scales values from `ZX` by `za`. +Scales values from `X` by `alpha`. ```c #include "stdlib/complex/float64/ctor.h" -double zx[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; -const stdlib_complex128_t za = stdlib_complex128( 2.0, 2.0 ); +double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; +const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 ); -c_zscal( 4, za, (void *)zx, 1 ); +c_zscal( 4, alpha, (void *)x, 1 ); ``` The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. -- **za**: `[in] stdlib_complex128_t` scalar constant. -- **ZX**: `[inout] void*` input array. -- **strideX**: `[in] CBLAS_INT` index increment for `ZX`. +- **alpha**: `[in] stdlib_complex128_t` scalar constant. +- **X**: `[inout] void*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. ```c -void c_zscal( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX ); +void c_zscal( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX ); +``` + +#### c_zscal_ndarray( N, alpha, \*X, strideX, offsetX ) + +Scales values from `X` by `alpha` using alternative indexing semantics. + +```c +#include "stdlib/complex/float64/ctor.h" + +double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; +const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 ); + +c_zscal_ndarray( 4, alpha, (void *)x, 1, 0 ); +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **alpha**: `[in] stdlib_complex128_t` scalar constant. +- **X**: `[inout] void*` input array. +- **strideX**: `[in] CBLAS_INT` index increment for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +void c_zscal_ndarray( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); ``` @@ -240,10 +265,10 @@ void c_zscal( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const C int main( void ) { // Create a strided array of interleaved real and imaginary components: - double zx[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; // Create a complex scalar: - const stdlib_complex128_t ca = stdlib_complex128( 2.0, 2.0 ); + const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 ); // Specify the number of elements: const int N = 4; @@ -252,11 +277,19 @@ int main( void ) { const int strideX = 1; // Scale the elements of the array: - c_zscal( N, za, (void *)zx, strideX ); + c_zscal( N, alpha, (void *)x, strideX ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "x[ %i ] = %lf + %lfj\n", i, x[ i*2 ], x[ (i*2)+1 ] ); + } + + // Scale the elements of the array using alternative indexing semantics: + c_zscal_ndarray( N, alpha, (void *)x, -strideX, N-1 ); // Print the result: for ( int i = 0; i < N; i++ ) { - printf( "zx[ %i ] = %f + %fj\n", i, zx[ i*2 ], zx[ (i*2)+1 ] ); + printf( "x[ %i ] = %lf + %lfj\n", i, x[ i*2 ], x[ (i*2)+1 ] ); } } ``` diff --git a/lib/node_modules/@stdlib/blas/base/zscal/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/blas/base/zscal/benchmark/c/benchmark.length.c index 531a2df4e87b..6055f7f10712 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/blas/base/zscal/benchmark/c/benchmark.length.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. @@ -95,7 +95,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 ) { stdlib_complex128_t za; double zx[ len*2 ]; double elapsed; @@ -122,6 +122,40 @@ 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 ) { + stdlib_complex128_t za; + double zx[ len*2 ]; + double elapsed; + double t; + int i; + + za = stdlib_complex128( 1.0, 0.0 ); + for ( i = 0; i < len*2; i+=2 ) { + zx[ i ] = ( rand_double()*2.0 ) - 1.0; + zx[ i+1 ] = ( rand_double()*2.0 ) - 1.0; + } + t = tic(); + for ( i = 0; i < iterations; i++ ) { + c_zscal_ndarray( len, za, (void *)zx, 1, 0 ); + if ( zx[ 0 ] != zx[ 0 ] ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( zx[ 0 ] != zx[ 0 ] ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -144,7 +178,14 @@ 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 ( 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/base/zscal/docs/repl.txt b/lib/node_modules/@stdlib/blas/base/zscal/docs/repl.txt index 8bac937e8183..d57f9910443e 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/base/zscal/docs/repl.txt @@ -1,16 +1,15 @@ -{{alias}}( N, za, zx, strideX ) +{{alias}}( N, alpha, x, strideX ) Scales a double-precision complex floating-point vector by a double- precision complex floating-point constant. - The `N` and stride parameters determine how values from `zx` are scaled by - `za`. + The `N` and stride parameters determine which values from `x` are scaled by + `alpha`. Indexing is relative to the first index. To introduce an offset, use typed array views. - If `N` or `strideX` is less than or equal to `0`, the function returns `zx` - unchanged. + If `N` is less than or equal to `0`, the function returns `x` unchanged. Parameters @@ -18,45 +17,45 @@ N: integer Number of indexed elements. - za: Complex128 + alpha: Complex128 Complex constant. - zx: Complex128Array + x: Complex128Array Input array. strideX: integer - Index increment for `zx`. + Index increment for `x`. Returns ------- - zx: Complex128Array + x: Complex128Array Input array. Examples -------- // Standard usage: - > var zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var za = new {{alias:@stdlib/complex/float64/ctor}}( 1.0, 2.0 ); - > {{alias}}( 2, za, zx, 1 ) + > var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var alpha = new {{alias:@stdlib/complex/float64/ctor}}( 1.0, 2.0 ); + > {{alias}}( 2, alpha, x, 1 ) [ -3.0, 4.0, -5.0, 10.0 ] // Advanced indexing: - > zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - > za = new {{alias:@stdlib/complex/float64/ctor}}( 1.0, 1.0 ); - > {{alias}}( 2, za, zx, 2 ) + > x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > alpha = new {{alias:@stdlib/complex/float64/ctor}}( 1.0, 1.0 ); + > {{alias}}( 2, alpha, x, 2 ) [ -1.0, 3.0, 3.0, 4.0, -1.0, 11.0 ] // Using typed array views: - > var zx0 = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - > var zx1 = new {{alias:@stdlib/array/complex128}}( zx0.buffer, zx0.BYTES_PER_ELEMENT*1 ); - > var za = new {{alias:@stdlib/complex/float64/ctor}}( 2.0, 2.0 ); - > {{alias}}( 2, za, zx1, 1 ) + > var x0 = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + > var x1 = new {{alias:@stdlib/array/complex128}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); + > alpha = new {{alias:@stdlib/complex/float64/ctor}}( 2.0, 2.0 ); + > {{alias}}( 2, alpha, x1, 1 ) [ -2.0, 14.0, -2.0, 22.0 ] - > zx0 + > x0 [ 1.0, 2.0, -2.0, 14.0, -2.0, 22.0 ] -{{alias}}.ndarray( N, za, zx, strideX, offsetX ) +{{alias}}.ndarray( N, alpha, x, strideX, offsetX ) Scales a double-precision complex floating-point vector by a double- precision complex floating-point constant using alternative indexing semantics. @@ -70,35 +69,35 @@ N: integer Number of indexed elements. - za: Complex128 + alpha: Complex128 Complex constant. - zx: Complex128Array + x: Complex128Array Input array. strideX: integer - Index increment for `zx`. + Index increment for `x`. offsetX: integer - Starting index for `zx`. + Starting index for `x`. Returns ------- - zx: Complex128Array + x: Complex128Array Input array. Examples -------- // Standard usage: - > var zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var za = new {{alias:@stdlib/complex/float64/ctor}}( 2.0, 2.0 ); - > {{alias}}.ndarray( 2, za, zx, 1, 0 ) + > var x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var alpha = new {{alias:@stdlib/complex/float64/ctor}}( 2.0, 2.0 ); + > {{alias}}.ndarray( 2, alpha, x, 1, 0 ) [ -2.0, 6.0, -2.0, 14.0 ] // Advanced indexing: - > zx = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - > za = new {{alias:@stdlib/complex/float64/ctor}}( 1.0, 2.0 ); - > {{alias}}.ndarray( 2, za, zx, 1, 2 ) + > x = new {{alias:@stdlib/array/complex128}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); + > alpha = new {{alias:@stdlib/complex/float64/ctor}}( 1.0, 2.0 ); + > {{alias}}.ndarray( 2, alpha, x, 1, 2 ) [ 1.0, 2.0, 3.0, 4.0, -7.0, 16.0, -9.0, 22.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/base/zscal/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/base/zscal/docs/types/index.d.ts index c0d469193fa3..550e7bf98228 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/base/zscal/docs/types/index.d.ts @@ -31,74 +31,74 @@ interface Routine { * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param N - number of indexed elements - * @param za - scalar constant - * @param zx - input array - * @param strideX - `zx` stride length + * @param alpha - scalar constant + * @param x - input array + * @param strideX - `x` stride length * @returns input array * * @example * var Complex128Array = require( '@stdlib/array/complex128' ); * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * - * var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - * var za = new Complex128( 2.0, 2.0 ); + * var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var alpha = new Complex128( 2.0, 2.0 ); * - * zscal( 3, za, zx, 1 ); - * // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] + * zscal( 3, alpha, x, 1 ); + * // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] */ - ( N: number, za: Complex128, zx: Complex128Array, strideX: number ): Complex128Array; + ( N: number, alpha: Complex128, x: Complex128Array, strideX: number ): Complex128Array; /** * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param N - number of indexed elements - * @param za - scalar constant - * @param zx - input array - * @param strideX - `zx` stride length - * @param offsetX - starting index for `zx` + * @param alpha - scalar constant + * @param x - input array + * @param strideX - `x` stride length + * @param offsetX - starting index for `x` * @returns input array * * @example * var Complex128Array = require( '@stdlib/array/complex128' ); * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * - * var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - * var za = new Complex128( 2.0, 2.0 ); + * var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + * var alpha = new Complex128( 2.0, 2.0 ); * - * zscal.ndarray( 3, za, zx, 1, 0 ); - * // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] + * zscal.ndarray( 3, alpha, x, 1, 0 ); + * // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] */ - ndarray( N: number, za: Complex128, zx: Complex128Array, strideX: number, offsetX: number ): Complex128Array; + ndarray( N: number, alpha: Complex128, x: Complex128Array, strideX: number, offsetX: number ): Complex128Array; } /** * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param N - number of indexed elements -* @param za - scalar constant -* @param zx - input array -* @param strideX - `zx` stride length +* @param alpha - scalar constant +* @param x - input array +* @param strideX - `x` stride length * @returns input array * * @example * var Complex128Array = require( '@stdlib/array/complex128' ); * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * -* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var za = new Complex128( 2.0, 2.0 ); +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var alpha = new Complex128( 2.0, 2.0 ); * -* zscal( 3, za, zx, 1 ); -* // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] +* zscal( 3, alpha, x, 1 ); +* // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] * * @example * var Complex128Array = require( '@stdlib/array/complex128' ); * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * -* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var za = new Complex128( 2.0, 2.0 ); +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var alpha = new Complex128( 2.0, 2.0 ); * -* zscal.ndarray( 2, za, zx, 1, 1 ); -* // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] +* zscal.ndarray( 2, alpha, x, 1, 1 ); +* // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] */ declare var zscal: Routine; diff --git a/lib/node_modules/@stdlib/blas/base/zscal/docs/types/test.ts b/lib/node_modules/@stdlib/blas/base/zscal/docs/types/test.ts index 3a8aced11a20..f86107ce5547 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/docs/types/test.ts +++ b/lib/node_modules/@stdlib/blas/base/zscal/docs/types/test.ts @@ -25,178 +25,178 @@ import zscal = require( './index' ); // The function returns a Complex128Array... { - const zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); - zscal( zx.length, za, zx, 1 ); // $ExpectType Complex128Array + zscal( x.length, alpha, x, 1 ); // $ExpectType Complex128Array } // The compiler throws an error if the function is provided a first argument which is not a number... { - const zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); - - zscal( '10', za, zx, 1 ); // $EzxpectError - zscal( true, za, zx, 1 ); // $ExpectError - zscal( false, za, zx, 1 ); // $ExpectError - zscal( null, za, zx, 1 ); // $ExpectError - zscal( undefined, za, zx, 1 ); // $ExpectError - zscal( [], za, zx, 1 ); // $ExpectError - zscal( {}, za, zx, 1 ); // $ExpectError - zscal( ( zx: number ): number => zx, za, zx, 1 ); // $ExpectError + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); + + zscal( '10', alpha, x, 1 ); // $ExpectError + zscal( true, alpha, x, 1 ); // $ExpectError + zscal( false, alpha, x, 1 ); // $ExpectError + zscal( null, alpha, x, 1 ); // $ExpectError + zscal( undefined, alpha, x, 1 ); // $ExpectError + zscal( [], alpha, x, 1 ); // $ExpectError + zscal( {}, alpha, x, 1 ); // $ExpectError + zscal( ( x: number ): number => x, alpha, x, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not a complex number... { - const zx = new Complex128Array( 10 ); - - zscal( zx.length, 10, zx, 1 ); // $ExpectError - zscal( zx.length, '10', zx, 1 ); // $ExpectError - zscal( zx.length, true, zx, 1 ); // $ExpectError - zscal( zx.length, false, zx, 1 ); // $ExpectError - zscal( zx.length, null, zx, 1 ); // $ExpectError - zscal( zx.length, undefined, zx, 1 ); // $ExpectError - zscal( zx.length, [ '1' ], zx, 1 ); // $ExpectError - zscal( zx.length, {}, zx, 1 ); // $ExpectError - zscal( zx.length, ( zx: number ): number => zx, zx, 1 ); // $ExpectError + const x = new Complex128Array( 10 ); + + zscal( x.length, 10, x, 1 ); // $ExpectError + zscal( x.length, '10', x, 1 ); // $ExpectError + zscal( x.length, true, x, 1 ); // $ExpectError + zscal( x.length, false, x, 1 ); // $ExpectError + zscal( x.length, null, x, 1 ); // $ExpectError + zscal( x.length, undefined, x, 1 ); // $ExpectError + zscal( x.length, [ '1' ], x, 1 ); // $ExpectError + zscal( x.length, {}, x, 1 ); // $ExpectError + zscal( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a third argument which is not a Complex128Array... { - const zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); - - zscal( zx.length, za, 10, 1 ); // $ExpectError - zscal( zx.length, za, '10', 1 ); // $ExpectError - zscal( zx.length, za, true, 1 ); // $ExpectError - zscal( zx.length, za, false, 1 ); // $ExpectError - zscal( zx.length, za, null, 1 ); // $ExpectError - zscal( zx.length, za, undefined, 1 ); // $ExpectError - zscal( zx.length, za, [ '1' ], 1 ); // $ExpectError - zscal( zx.length, za, {}, 1 ); // $ExpectError - zscal( zx.length, za, ( zx: number ): number => zx, 1 ); // $ExpectError + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); + + zscal( x.length, alpha, 10, 1 ); // $ExpectError + zscal( x.length, alpha, '10', 1 ); // $ExpectError + zscal( x.length, alpha, true, 1 ); // $ExpectError + zscal( x.length, alpha, false, 1 ); // $ExpectError + zscal( x.length, alpha, null, 1 ); // $ExpectError + zscal( x.length, alpha, undefined, 1 ); // $ExpectError + zscal( x.length, alpha, [ '1' ], 1 ); // $ExpectError + zscal( x.length, alpha, {}, 1 ); // $ExpectError + zscal( x.length, alpha, ( x: number ): number => x, 1 ); // $ExpectError } // The compiler throws an error if the function is provided a fourth argument which is not a number... { - const zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); - - zscal( zx.length, za, zx, '10' ); // $ExpectError - zscal( zx.length, za, zx, true ); // $ExpectError - zscal( zx.length, za, zx, false ); // $ExpectError - zscal( zx.length, za, zx, null ); // $ExpectError - zscal( zx.length, za, zx, undefined ); // $ExpectError - zscal( zx.length, za, zx, [] ); // $ExpectError - zscal( zx.length, za, zx, {} ); // $ExpectError - zscal( zx.length, za, zx, ( zx: number ): number => zx ); // $ExpectError + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); + + zscal( x.length, alpha, x, '10' ); // $ExpectError + zscal( x.length, alpha, x, true ); // $ExpectError + zscal( x.length, alpha, x, false ); // $ExpectError + zscal( x.length, alpha, x, null ); // $ExpectError + zscal( x.length, alpha, x, undefined ); // $ExpectError + zscal( x.length, alpha, x, [] ); // $ExpectError + zscal( x.length, alpha, x, {} ); // $ExpectError + zscal( x.length, alpha, x, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... { - const zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); zscal(); // $ExpectError - zscal( zx.length ); // $ExpectError - zscal( zx.length, za ); // $ExpectError - zscal( zx.length, za, zx ); // $ExpectError - zscal( zx.length, za, zx, 1, 10 ); // $ExpectError + zscal( x.length ); // $ExpectError + zscal( x.length, alpha ); // $ExpectError + zscal( x.length, alpha, x ); // $ExpectError + zscal( x.length, alpha, x, 1, 10 ); // $ExpectError } // Attached to main export is an `ndarray` method which returns a Complex128Array... { - const zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); - zscal.ndarray( zx.length, za, zx, 1, 0 ); // $ExpectType Complex128Array + zscal.ndarray( x.length, alpha, x, 1, 0 ); // $ExpectType Complex128Array } // The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... { - const zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); - - zscal.ndarray( '10', za, zx, 1, 0 ); // $ExpectError - zscal.ndarray( true, za, zx, 1, 0 ); // $ExpectError - zscal.ndarray( false, za, zx, 1, 0 ); // $ExpectError - zscal.ndarray( null, za, zx, 1, 0 ); // $ExpectError - zscal.ndarray( undefined, za, zx, 1, 0 ); // $ExpectError - zscal.ndarray( [], za, zx, 1, 0 ); // $ExpectError - zscal.ndarray( {}, za, zx, 1, 0 ); // $ExpectError - zscal.ndarray( ( zx: number ): number => zx, za, zx, 1, 0 ); // $ExpectError + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); + + zscal.ndarray( '10', alpha, x, 1, 0 ); // $ExpectError + zscal.ndarray( true, alpha, x, 1, 0 ); // $ExpectError + zscal.ndarray( false, alpha, x, 1, 0 ); // $ExpectError + zscal.ndarray( null, alpha, x, 1, 0 ); // $ExpectError + zscal.ndarray( undefined, alpha, x, 1, 0 ); // $ExpectError + zscal.ndarray( [], alpha, x, 1, 0 ); // $ExpectError + zscal.ndarray( {}, alpha, x, 1, 0 ); // $ExpectError + zscal.ndarray( ( x: number ): number => x, alpha, x, 1, 0 ); // $ExpectError } // The compiler throws an error if the `ndarray` method is provided a second argument which is not a complex number... { - const zx = new Complex128Array( 10 ); - - zscal.ndarray( zx.length, 10, zx, 1, 0 ); // $ExpectError - zscal.ndarray( zx.length, '10', zx, 1, 0 ); // $ExpectError - zscal.ndarray( zx.length, true, zx, 1, 0 ); // $ExpectError - zscal.ndarray( zx.length, false, zx, 1, 0 ); // $ExpectError - zscal.ndarray( zx.length, null, zx, 1, 0 ); // $ExpectError - zscal.ndarray( zx.length, undefined, zx, 1, 0 ); // $ExpectError - zscal.ndarray( zx.length, [ '1' ], zx, 1, 0 ); // $ExpectError - zscal.ndarray( zx.length, {}, zx, 1, 0 ); // $ExpectError - zscal.ndarray( zx.length, ( zx: number ): number => zx, zx, 1, 0 ); // $ExpectError + const x = new Complex128Array( 10 ); + + zscal.ndarray( x.length, 10, x, 1, 0 ); // $ExpectError + zscal.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError + zscal.ndarray( x.length, true, x, 1, 0 ); // $ExpectError + zscal.ndarray( x.length, false, x, 1, 0 ); // $ExpectError + zscal.ndarray( x.length, null, x, 1, 0 ); // $ExpectError + zscal.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError + zscal.ndarray( x.length, [ '1' ], x, 1, 0 ); // $ExpectError + zscal.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError + zscal.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 Complex128Array... { - const zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); - - zscal( zx.length, za, 10, 1, 0 ); // $ExpectError - zscal( zx.length, za, '10', 1, 0 ); // $ExpectError - zscal( zx.length, za, true, 1, 0 ); // $ExpectError - zscal( zx.length, za, false, 1, 0 ); // $ExpectError - zscal( zx.length, za, null, 1, 0 ); // $ExpectError - zscal( zx.length, za, undefined, 1, 0 ); // $ExpectError - zscal( zx.length, za, [ '1' ], 1, 0 ); // $ExpectError - zscal( zx.length, za, {}, 1, 0 ); // $ExpectError - zscal( zx.length, za, ( zx: number ): number => zx, 1, 0 ); // $ExpectError + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); + + zscal( x.length, alpha, 10, 1, 0 ); // $ExpectError + zscal( x.length, alpha, '10', 1, 0 ); // $ExpectError + zscal( x.length, alpha, true, 1, 0 ); // $ExpectError + zscal( x.length, alpha, false, 1, 0 ); // $ExpectError + zscal( x.length, alpha, null, 1, 0 ); // $ExpectError + zscal( x.length, alpha, undefined, 1, 0 ); // $ExpectError + zscal( x.length, alpha, [ '1' ], 1, 0 ); // $ExpectError + zscal( x.length, alpha, {}, 1, 0 ); // $ExpectError + zscal( x.length, alpha, ( 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 zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); - - zscal.ndarray( zx.length, za, zx, '10', 0 ); // $ExpectError - zscal.ndarray( zx.length, za, zx, true, 0 ); // $ExpectError - zscal.ndarray( zx.length, za, zx, false, 0 ); // $ExpectError - zscal.ndarray( zx.length, za, zx, null, 0 ); // $ExpectError - zscal.ndarray( zx.length, za, zx, undefined, 0 ); // $ExpectError - zscal.ndarray( zx.length, za, zx, [], 0 ); // $ExpectError - zscal.ndarray( zx.length, za, zx, {}, 0 ); // $ExpectError - zscal.ndarray( zx.length, za, zx, ( zx: number ): number => zx, 0 ); // $ExpectError + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); + + zscal.ndarray( x.length, alpha, x, '10', 0 ); // $ExpectError + zscal.ndarray( x.length, alpha, x, true, 0 ); // $ExpectError + zscal.ndarray( x.length, alpha, x, false, 0 ); // $ExpectError + zscal.ndarray( x.length, alpha, x, null, 0 ); // $ExpectError + zscal.ndarray( x.length, alpha, x, undefined, 0 ); // $ExpectError + zscal.ndarray( x.length, alpha, x, [], 0 ); // $ExpectError + zscal.ndarray( x.length, alpha, x, {}, 0 ); // $ExpectError + zscal.ndarray( x.length, alpha, 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 zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); - - zscal.ndarray( zx.length, za, zx, 1, '10' ); // $ExpectError - zscal.ndarray( zx.length, za, zx, 1, true ); // $ExpectError - zscal.ndarray( zx.length, za, zx, 1, false ); // $ExpectError - zscal.ndarray( zx.length, za, zx, 1, null ); // $ExpectError - zscal.ndarray( zx.length, za, zx, 1, undefined ); // $ExpectError - zscal.ndarray( zx.length, za, zx, 1, [] ); // $ExpectError - zscal.ndarray( zx.length, za, zx, 1, {} ); // $ExpectError - zscal.ndarray( zx.length, za, zx, 1, ( zx: number ): number => zx ); // $ExpectError + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); + + zscal.ndarray( x.length, alpha, x, 1, '10' ); // $ExpectError + zscal.ndarray( x.length, alpha, x, 1, true ); // $ExpectError + zscal.ndarray( x.length, alpha, x, 1, false ); // $ExpectError + zscal.ndarray( x.length, alpha, x, 1, null ); // $ExpectError + zscal.ndarray( x.length, alpha, x, 1, undefined ); // $ExpectError + zscal.ndarray( x.length, alpha, x, 1, [] ); // $ExpectError + zscal.ndarray( x.length, alpha, x, 1, {} ); // $ExpectError + zscal.ndarray( x.length, alpha, x, 1, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... { - const zx = new Complex128Array( 10 ); - const za = new Complex128( 2.0, 2.0 ); + const x = new Complex128Array( 10 ); + const alpha = new Complex128( 2.0, 2.0 ); zscal.ndarray(); // $ExpectError - zscal.ndarray( zx.length ); // $ExpectError - zscal.ndarray( zx.length, za ); // $ExpectError - zscal.ndarray( zx.length, za, zx ); // $ExpectError - zscal.ndarray( zx.length, za, zx, 1 ); // $ExpectError - zscal.ndarray( zx.length, za, zx, 1, 0, 10 ); // $ExpectError + zscal.ndarray( x.length ); // $ExpectError + zscal.ndarray( x.length, alpha ); // $ExpectError + zscal.ndarray( x.length, alpha, x ); // $ExpectError + zscal.ndarray( x.length, alpha, x, 1 ); // $ExpectError + zscal.ndarray( x.length, alpha, x, 1, 0, 10 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/examples/c/example.c b/lib/node_modules/@stdlib/blas/base/zscal/examples/c/example.c index 3ff3c69a730c..bd25d9b15ec1 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/examples/c/example.c +++ b/lib/node_modules/@stdlib/blas/base/zscal/examples/c/example.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,10 @@ int main( void ) { // Create a strided array of interleaved real and imaginary components: - double zx[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; // Create a complex scalar: - const stdlib_complex128_t za = stdlib_complex128( 2.0, 2.0 ); + const stdlib_complex128_t alpha = stdlib_complex128( 2.0, 2.0 ); // Specify the number of elements: const int N = 4; @@ -34,10 +34,18 @@ int main( void ) { const int strideX = 1; // Scale the elements of the array: - c_zscal( N, za, (void *)zx, strideX ); + c_zscal( N, alpha, (void *)x, strideX ); // Print the result: for ( int i = 0; i < N; i++ ) { - printf( "zx[ %i ] = %lf + %lfj\n", i, zx[ i*2 ], zx[ (i*2)+1 ] ); + printf( "x[ %i ] = %lf + %lfj\n", i, x[ i*2 ], x[ (i*2)+1 ] ); + } + + // Scale the elements of the array using alternative indexing semantics: + c_zscal_ndarray( N, alpha, (void *)x, -strideX, N-1 ); + + // Print the result: + for ( int i = 0; i < N; i++ ) { + printf( "x[ %i ] = %lf + %lfj\n", i, x[ i*2 ], x[ (i*2)+1 ] ); } } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/examples/index.js b/lib/node_modules/@stdlib/blas/base/zscal/examples/index.js index 9c138caf4327..36f1debbba83 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/examples/index.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/examples/index.js @@ -27,12 +27,12 @@ function rand() { return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) ); } -var zx = filledarrayBy( 10, 'complex128', rand ); -console.log( zx.toString() ); +var x = filledarrayBy( 10, 'complex128', rand ); +console.log( x.toString() ); -var za = new Complex128( 2.0, 2.0 ); -console.log( za.toString() ); +var alpha = new Complex128( 2.0, 2.0 ); +console.log( alpha.toString() ); -// Scale elements from `zx` by `za`: -zscal( zx.length, za, zx, 1 ); -console.log( zx.get( zx.length-1 ).toString() ); +// Scale elements from `x` by `alpha`: +zscal( x.length, alpha, x, 1 ); +console.log( x.get( x.length-1 ).toString() ); diff --git a/lib/node_modules/@stdlib/blas/base/zscal/include/stdlib/blas/base/zscal.h b/lib/node_modules/@stdlib/blas/base/zscal/include/stdlib/blas/base/zscal.h index 98bc1f5a1dce..c698445dfcaf 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/include/stdlib/blas/base/zscal.h +++ b/lib/node_modules/@stdlib/blas/base/zscal/include/stdlib/blas/base/zscal.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. @@ -35,7 +35,12 @@ extern "C" { /** * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. */ -void API_SUFFIX(c_zscal)( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX ); +void API_SUFFIX(c_zscal)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX ); + +/** +* Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant using alternative indexing semantics. +*/ +void API_SUFFIX(c_zscal_ndarray)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/include/stdlib/blas/base/zscal_cblas.h b/lib/node_modules/@stdlib/blas/base/zscal/include/stdlib/blas/base/zscal_cblas.h index c80d88d58980..baf490d2b00a 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/include/stdlib/blas/base/zscal_cblas.h +++ b/lib/node_modules/@stdlib/blas/base/zscal/include/stdlib/blas/base/zscal_cblas.h @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. @@ -35,7 +35,7 @@ extern "C" { /** * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. */ -void API_SUFFIX(cblas_zscal)( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX ); +void API_SUFFIX(cblas_zscal)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/lib/index.js b/lib/node_modules/@stdlib/blas/base/zscal/lib/index.js index f7ec1520f674..a7d589d1f776 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/lib/index.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/lib/index.js @@ -28,22 +28,22 @@ * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * var zscal = require( '@stdlib/blas/base/zscal' ); * -* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var za = new Complex128( 2.0, 2.0 ); +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var alpha = new Complex128( 2.0, 2.0 ); * -* zscal( 3, za, zx, 1 ); -* // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] +* zscal( 3, alpha, x, 1 ); +* // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] * * @example * var Complex128Array = require( '@stdlib/array/complex128' ); * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * var zscal = require( '@stdlib/blas/base/zscal' ); * -* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var za = new Complex128( 2.0, 2.0 ); +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var alpha = new Complex128( 2.0, 2.0 ); * -* zscal.ndarray( 3, za, zx, 1 ); -* // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] +* zscal.ndarray( 3, alpha, x, 1 ); +* // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.js b/lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.js index e5c140e5fa7d..a9e0a2db57b9 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.js @@ -32,23 +32,23 @@ var imag = require( '@stdlib/complex/float64/imag' ); * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param {PositiveInteger} N - number of indexed elements -* @param {Complex128} za - constant -* @param {Complex128Array} zx - input array -* @param {integer} strideZX - `zx` stride length -* @param {NonNegativeInteger} offsetZX - starting `zx` index +* @param {Complex128} alpha - constant +* @param {Complex128Array} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting `x` index * @returns {Complex128Array} input array * * @example * var Complex128Array = require( '@stdlib/array/complex128' ); * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * -* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var za = new Complex128( 2.0, 2.0 ); +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var alpha = new Complex128( 2.0, 2.0 ); * -* zscal( 3, za, zx, 1, 0 ); -* // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] +* zscal( 3, alpha, x, 1, 0 ); +* // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] */ -function zscal( N, za, zx, strideZX, offsetZX ) { +function zscal( N, alpha, x, strideX, offsetX ) { var view; var re1; var im1; @@ -59,18 +59,18 @@ function zscal( N, za, zx, strideZX, offsetZX ) { var i; if ( N <= 0 ) { - return zx; + return x; } // Reinterpret the input array as a real-valued array of interleaved real and imaginary components: - view = reinterpret( zx, 0 ); + view = reinterpret( x, 0 ); // Adjust the stride and offset: - sx = strideZX * 2; - ix = offsetZX * 2; + sx = strideX * 2; + ix = offsetX * 2; // Decompose the input scalar to real and imaginary components: - re1 = real( za ); - im1 = imag( za ); + re1 = real( alpha ); + im1 = imag( alpha ); for ( i = 0; i < N; i++ ) { re2 = view[ ix ]; @@ -78,7 +78,7 @@ function zscal( N, za, zx, strideZX, offsetZX ) { cmul( re1, im1, re2, im2, view, 1, ix ); ix += sx; } - return zx; + return x; } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.native.js b/lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.native.js index 811a84f96deb..f3c26a77d2d4 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/lib/ndarray.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ // MODULES // var reinterpret = require( '@stdlib/strided/base/reinterpret-complex128' ); -var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' ); var addon = require( './../src/addon.node' ); @@ -31,28 +30,26 @@ var addon = require( './../src/addon.node' ); * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param {PositiveInteger} N - number of indexed elements -* @param {Complex128} za - scalar constant -* @param {Complex128Array} zx - input array -* @param {integer} strideZX - `zx` stride length -* @param {NonNegativeInteger} offsetZX - starting `zx` index +* @param {Complex128} alpha - scalar constant +* @param {Complex128Array} x - input array +* @param {integer} strideX - `x` stride length +* @param {NonNegativeInteger} offsetX - starting index for `x` * @returns {Complex128Array} input array * * @example * var Complex128Array = require( '@stdlib/array/complex128' ); * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * -* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var za = new Complex128( 2.0, 2.0 ); +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var alpha = new Complex128( 2.0, 2.0 ); * -* zscal( 3, za, zx, 1, 0 ); -* // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] +* zscal( 3, alpha, x, 1, 0 ); +* // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] */ -function zscal( N, za, zx, strideZX, offsetZX ) { - var viewZX; - offsetZX = minViewBufferIndex( N, strideZX, offsetZX ); - viewZX = reinterpret( zx, offsetZX ); - addon( N, za, viewZX, strideZX ); - return zx; +function zscal( N, alpha, x, strideX, offsetX ) { + var viewZX = reinterpret( x, 0 ); + addon.ndarray( N, alpha, viewZX, strideX, offsetX ); + return x; } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.js b/lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.js index 0d6e54585b70..4dc501610438 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. @@ -30,23 +30,24 @@ var ndarray = require( './ndarray.js' ); * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param {PositiveInteger} N - number of indexed elements -* @param {Complex128} za - constant -* @param {Complex128Array} zx - input array -* @param {integer} strideZX - `zx` stride length +* @param {Complex128} alpha - constant +* @param {Complex128Array} x - input array +* @param {integer} strideX - `x` stride length * @returns {Complex128Array} input array * * @example * var Complex128Array = require( '@stdlib/array/complex128' ); * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * -* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var za = new Complex128( 2.0, 2.0 ); +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var alpha = new Complex128( 2.0, 2.0 ); * -* zscal( 3, za, zx, 1 ); -* // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] +* zscal( 3, alpha, x, 1 ); +* // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] */ -function zscal( N, za, zx, strideZX ) { - return ndarray( N, za, zx, strideZX, stride2offset( N, strideZX ) ); +function zscal( N, alpha, x, strideX ) { + var ox = stride2offset( N, strideX ); + return ndarray( N, alpha, x, strideX, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.native.js b/lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.native.js index bce55a6e0eef..67bd2abec939 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.native.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/lib/zscal.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. @@ -30,25 +30,25 @@ var addon = require( './../src/addon.node' ); * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param {PositiveInteger} N - number of indexed elements -* @param {Complex128} za - scalar constant -* @param {Complex128Array} zx - input array -* @param {integer} strideZX - `zx` stride length +* @param {Complex128} alpha - scalar constant +* @param {Complex128Array} x - input array +* @param {integer} strideX - `x` stride length * @returns {Complex128Array} input array * * @example * var Complex128Array = require( '@stdlib/array/complex128' ); * var Complex128 = require( '@stdlib/complex/float64/ctor' ); * -* var zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); -* var za = new Complex128( 2.0, 2.0 ); +* var x = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var alpha = new Complex128( 2.0, 2.0 ); * -* zscal( 3, za, zx, 1 ); -* // zx => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] +* zscal( 3, alpha, x, 1 ); +* // x => [ -2.0, 6.0, -2.0, 14.0, -2.0, 22.0 ] */ -function zscal( N, za, zx, strideZX ) { - var viewZX = reinterpret( zx, 0 ); - addon( N, za, viewZX, strideZX ); - return zx; +function zscal( N, alpha, x, strideX ) { + var viewZX = reinterpret( x, 0 ); + addon( N, alpha, viewZX, strideX ); + return x; } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/manifest.json b/lib/node_modules/@stdlib/blas/base/zscal/manifest.json index 506fbaac331d..c70e11170c14 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/manifest.json +++ b/lib/node_modules/@stdlib/blas/base/zscal/manifest.json @@ -45,11 +45,13 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex128array", "@stdlib/napi/argv-complex128", - "@stdlib/complex/float64/ctor" + "@stdlib/complex/float64/ctor", + "@stdlib/complex/float64/base/mul" ] }, { @@ -58,7 +60,8 @@ "blas": "", "wasm": false, "src": [ - "./src/zscal.c" + "./src/zscal.c", + "./src/zscal_ndarray.c" ], "include": [ "./include" @@ -67,6 +70,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float64/base/mul", "@stdlib/complex/float64/ctor" ] @@ -77,7 +81,8 @@ "blas": "", "wasm": false, "src": [ - "./src/zscal.c" + "./src/zscal.c", + "./src/zscal_ndarray.c" ], "include": [ "./include" @@ -86,6 +91,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float64/base/mul", "@stdlib/complex/float64/ctor" ] @@ -110,6 +116,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex128array", @@ -135,6 +142,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float32/ctor" ] }, @@ -156,6 +164,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float32/ctor" ] }, @@ -177,6 +186,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex128array", @@ -190,7 +200,8 @@ "blas": "", "wasm": false, "src": [ - "./src/zscal.c" + "./src/zscal.c", + "./src/zscal_ndarray.c" ], "include": [ "./include" @@ -199,6 +210,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float64/base/mul", "@stdlib/complex/float64/ctor" ] @@ -209,7 +221,8 @@ "blas": "", "wasm": false, "src": [ - "./src/zscal.c" + "./src/zscal.c", + "./src/zscal_ndarray.c" ], "include": [ "./include" @@ -218,6 +231,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float64/base/mul", "@stdlib/complex/float64/ctor" ] @@ -241,6 +255,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex128array", @@ -265,6 +280,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float64/ctor" ] }, @@ -285,6 +301,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float64/ctor" ] }, @@ -308,6 +325,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex128array", @@ -333,6 +351,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float64/ctor" ] }, @@ -354,6 +373,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/min-view-buffer-index", "@stdlib/complex/float64/ctor" ] }, @@ -364,7 +384,8 @@ "blas": "", "wasm": false, "src": [ - "./src/zscal.c" + "./src/zscal.c", + "./src/zscal_ndarray.c" ], "include": [ "./include" @@ -374,6 +395,7 @@ "dependencies": [ "@stdlib/blas/base/shared", "@stdlib/napi/export", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", "@stdlib/napi/argv-strided-complex128array", @@ -388,7 +410,8 @@ "blas": "", "wasm": false, "src": [ - "./src/zscal.c" + "./src/zscal.c", + "./src/zscal_ndarray.c" ], "include": [ "./include" @@ -397,6 +420,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float64/base/mul", "@stdlib/complex/float64/ctor" ] @@ -407,7 +431,8 @@ "blas": "", "wasm": false, "src": [ - "./src/zscal.c" + "./src/zscal.c", + "./src/zscal_ndarray.c" ], "include": [ "./include" @@ -416,6 +441,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float64/base/mul", "@stdlib/complex/float64/ctor" ] @@ -427,7 +453,8 @@ "blas": "", "wasm": true, "src": [ - "./src/zscal.c" + "./src/zscal.c", + "./src/zscal_ndarray.c" ], "include": [ "./include" @@ -436,6 +463,7 @@ "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/complex/float64/base/mul", "@stdlib/complex/float64/ctor" ] diff --git a/lib/node_modules/@stdlib/blas/base/zscal/src/addon.c b/lib/node_modules/@stdlib/blas/base/zscal/src/addon.c index be50a5375b39..2fe06654fee0 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/src/addon.c +++ b/lib/node_modules/@stdlib/blas/base/zscal/src/addon.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. @@ -17,6 +17,7 @@ */ #include "stdlib/blas/base/zscal.h" +#include "stdlib/blas/base/shared.h" #include "stdlib/napi/export.h" #include "stdlib/napi/argv.h" #include "stdlib/napi/argv_int64.h" @@ -35,10 +36,28 @@ static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); - STDLIB_NAPI_ARGV_COMPLEX128( env, za, argv, 1 ); - STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, ZX, N, strideX, argv, 2 ); - c_zscal( N, za, (void *)ZX, strideX ); + STDLIB_NAPI_ARGV_COMPLEX128( env, alpha, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(c_zscal)( N, alpha, (void *)X, strideX ); return NULL; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* 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, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_ARGV_COMPLEX128( env, alpha, argv, 1 ); + STDLIB_NAPI_ARGV_STRIDED_COMPLEX128ARRAY( env, X, N, strideX, argv, 2 ); + API_SUFFIX(c_zscal_ndarray)( N, alpha, (void *)X, strideX, offsetX ); + return NULL; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/blas/base/zscal/src/zscal.c b/lib/node_modules/@stdlib/blas/base/zscal/src/zscal.c index 1e76ed849b12..81ee73be4a0e 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/src/zscal.c +++ b/lib/node_modules/@stdlib/blas/base/zscal/src/zscal.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,29 +20,17 @@ #include "stdlib/blas/base/shared.h" #include "stdlib/complex/float64/ctor.h" #include "stdlib/complex/float64/base/mul.h" -#include +#include "stdlib/strided/base/stride2offset.h" /** * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param N number of indexed elements -* @param za scalar constant -* @param ZX input array -* @param strideX ZX stride length +* @param alpha scalar constant +* @param X input array +* @param strideX X stride length */ -void API_SUFFIX(c_zscal)( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX ) { - stdlib_complex128_t z; - CBLAS_INT i; - - uint8_t *ip1 = (uint8_t *)ZX; - int64_t is1 = 16 * strideX; - - if ( N <= 0 || strideX <= 0 ) { - return; - } - for ( i = 0; i < N; i++, ip1 += is1 ) { - z = *(stdlib_complex128_t *)ip1; - *(stdlib_complex128_t *)ip1 = stdlib_base_complex128_mul( za, z ); - } - return; +void API_SUFFIX(c_zscal)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX ) { + CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + API_SUFFIX(c_zscal_ndarray)( N, alpha, X, strideX, ox ); } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_cblas.c b/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_cblas.c index 69d78adaa641..a21b368d7085 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_cblas.c +++ b/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_cblas.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,10 +25,34 @@ * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param N number of indexed elements -* @param za scalar constant -* @param ZX input array -* @param strideX ZX stride length +* @param alpha scalar constant +* @param X input array +* @param strideX X stride length */ -void API_SUFFIX(c_zscal)( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX ) { - cblas_zscal( N, za, ZX, strideX ); +void API_SUFFIX(c_zscal)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX ) { + CBLAS_INT sx = strideX; + if ( sx < 0 ) { + sx = -sx; + } + API_SUFFIX(cblas_zscal)( N, alpha, X, sx ); +} + +/** +* Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant using alternative indexing semantics. +* +* @param N number of indexed elements +* @param alpha scalar constant +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +*/ +void API_SUFFIX(c_zscal_ndarray)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + stdlib_complex128_t *x = (stdlib_complex128_t *)X; + CBLAS_INT sx = strideX; + + x += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); + if ( sx < 0 ) { + sx = -sx; + } + API_SUFFIX(cblas_zscal)( N, alpha, (void *)x, sx ); } diff --git a/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_f.c b/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_f.c index 03ce288927b9..79f28476c51d 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_f.c +++ b/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_f.c @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +20,41 @@ #include "stdlib/blas/base/zscal_fortran.h" #include "stdlib/blas/base/shared.h" #include "stdlib/complex/float64/ctor.h" +#include "stdlib/strided/base/min_view_buffer_index.h" /** * Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. * * @param N number of indexed elements -* @param za scalar constant -* @param ZX input array -* @param strideX ZX stride length +* @param alpha scalar constant +* @param X input array +* @param strideX X stride length */ -void API_SUFFIX(c_zscal)( const CBLAS_INT N, const stdlib_complex128_t za, void *ZX, const CBLAS_INT strideX ) { - zscal( &N, &za, ZX, &strideX ); +void API_SUFFIX(c_zscal)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX ) { + CBLAS_INT sx = strideX; + if ( sx < 0 ) { + sx = -sx; + } + zscal( &N, &alpha, X, &sx ); } + +/** +* Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant using alternative indexing semantics. +* +* @param N number of indexed elements +* @param alpha scalar constant +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +*/ +void API_SUFFIX(c_zscal_ndarray)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + stdlib_complex128_t *x = (stdlib_complex128_t *)X; + CBLAS_INT sx = strideX; + + x += stdlib_strided_min_view_buffer_index( N, strideX, offsetX ); + if ( sx < 0 ) { + sx = -sx; + } + zscal( &N, &alpha, (void *)x, &sx ); +} + diff --git a/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_ndarray.c b/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_ndarray.c new file mode 100644 index 000000000000..03cff9b2e9aa --- /dev/null +++ b/lib/node_modules/@stdlib/blas/base/zscal/src/zscal_ndarray.c @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/blas/base/zscal.h" +#include "stdlib/blas/base/shared.h" +#include "stdlib/complex/float64/ctor.h" +#include "stdlib/complex/float64/base/mul.h" +#include + +/** +* Scales a double-precision complex floating-point vector by a double-precision complex floating-point constant. +* +* @param N number of indexed elements +* @param alpha scalar constant +* @param X input array +* @param strideX X stride length +* @param offsetX starting index for X +*/ +void API_SUFFIX(c_zscal_ndarray)( const CBLAS_INT N, const stdlib_complex128_t alpha, void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + stdlib_complex128_t z; + int64_t is1; + int64_t i; + + if ( N <= 0 ) { + return; + } + stdlib_complex128_t *ip1 = (stdlib_complex128_t *)X; + is1 = (int64_t)strideX; + ip1 += offsetX; + for ( i = 0; i < N; i++, ip1 += is1 ) { + z = *ip1; + *ip1 = stdlib_base_complex128_mul( alpha, z ); + } + return; +} diff --git a/lib/node_modules/@stdlib/blas/base/zscal/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/base/zscal/test/test.ndarray.js index 4e79e1e9c50a..9eae3749bda4 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/test/test.ndarray.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,35 @@ var abs = require( '@stdlib/math/base/special/abs' ); var zscal = require( './../lib/ndarray.js' ); +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -44,12 +73,9 @@ tape( 'the function has an arity of 5', function test( t ) { tape( 'the function scales elements from `zx` by `za`', function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; zx = new Complex128Array([ 0.3, // 1 @@ -84,26 +110,16 @@ tape( 'the function scales elements from `zx` by `za`', function test( t ) { 2.0, 3.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, viewX, expected, 1.0 ); t.end(); }); tape( 'the function supports a `zx` stride', function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; zx = new Complex128Array([ 0.1, // 1 @@ -138,123 +154,96 @@ tape( 'the function supports a `zx` stride', function test( t ) { 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, viewX, expected, 5.0 ); t.end(); }); -tape( 'the function supports a `zx` offset', function test( t ) { +tape( 'the function supports a negative `zx` stride', function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; zx = new Complex128Array([ - 0.1, - 0.1, + 0.1, // 3 + 0.1, // 3 3.0, 6.0, - -0.6, - 0.1, - 4.0, // 1 - 6.0, // 1 + -0.6, // 2 0.1, // 2 - -0.3, // 2 - 7.0, // 3 - 2.0 // 3 + 4.0, + 7.0, + 0.1, // 1 + -0.3, // 1 + 7.0, + 2.0 ]); za = new Complex128( 0.4, -0.7 ); - zscal( 3, za, zx, 1, 3 ); + zscal( 3, za, zx, -2, 4 ); viewX = new Float64Array( zx.buffer ); expected = new Float64Array([ - 0.1, - 0.1, + 0.11, // 3 + -0.03, // 3 3.0, 6.0, - -0.6, - 0.1, - 5.8, // 1 - -0.4, // 1 -0.17, // 2 - -0.19, // 2 - 4.2, // 3 - -4.1 // 3 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 1 + -0.19, // 1 + 7.0, + 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 8.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, viewX, expected, 5.0 ); t.end(); }); -tape( 'the function supports a negative `zx` stride', function test( t ) { +tape( 'the function supports a `zx` offset', function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; zx = new Complex128Array([ - 0.1, // 3 - 0.1, // 3 + 0.1, + 0.1, 3.0, 6.0, - -0.6, // 2 + -0.6, + 0.1, + 4.0, // 1 + 6.0, // 1 0.1, // 2 - 4.0, - 7.0, - 0.1, // 1 - -0.3, // 1 - 7.0, - 2.0 + -0.3, // 2 + 7.0, // 3 + 2.0 // 3 ]); za = new Complex128( 0.4, -0.7 ); - zscal( 3, za, zx, -2, 4 ); + zscal( 3, za, zx, 1, 3 ); viewX = new Float64Array( zx.buffer ); expected = new Float64Array([ - 0.11, // 3 - -0.03, // 3 + 0.1, + 0.1, 3.0, 6.0, + -0.6, + 0.1, + 5.8, // 1 + -0.4, // 1 -0.17, // 2 - 0.46, // 2 - 4.0, - 7.0, - -0.17, // 1 - -0.19, // 1 - 7.0, - 2.0 + -0.19, // 2 + 4.2, // 3 + -4.1 // 3 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, viewX, expected, 8.0 ); t.end(); }); @@ -295,12 +284,9 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports complex access patterns', function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; zx = new Complex128Array([ 0.1, @@ -339,14 +325,7 @@ tape( 'the function supports complex access patterns', function test( t ) { 2.9, // 2 -0.2 // 2 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, viewX, expected, 10.0 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/zscal/test/test.ndarray.native.js b/lib/node_modules/@stdlib/blas/base/zscal/test/test.ndarray.native.js index 7a59816804f0..e1a375cfd691 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/test/test.ndarray.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. @@ -38,6 +38,35 @@ var opts = { }; +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + // TESTS // tape( 'main export is a function', opts, function test( t ) { @@ -53,14 +82,11 @@ tape( 'the function has an arity of 5', opts, function test( t ) { tape( 'the function scales elements from `zx` by `za`', opts, function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; - zx = new Complex128Array( [ + zx = new Complex128Array([ 0.3, // 1 0.1, // 1 0.5, // 2 @@ -73,13 +99,13 @@ tape( 'the function scales elements from `zx` by `za`', opts, function test( t ) 3.0, 2.0, 3.0 - ] ); + ]); za = new Complex128( 0.4, -0.7 ); zscal( 4, za, zx, 1, 0 ); viewX = new Float64Array( zx.buffer ); - expected = new Float64Array( [ + expected = new Float64Array([ 0.19, // 1 -0.17, // 1 0.2, // 2 @@ -92,29 +118,19 @@ tape( 'the function scales elements from `zx` by `za`', opts, function test( t ) 3.0, 2.0, 3.0 - ] ); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + ]); + + isApprox( t, viewX, expected, 1.0 ); t.end(); }); tape( 'the function supports a `zx` stride', opts, function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; - zx = new Complex128Array( [ + zx = new Complex128Array([ 0.1, // 1 0.1, // 1 3.0, @@ -127,13 +143,13 @@ tape( 'the function supports a `zx` stride', opts, function test( t ) { -0.3, // 3 7.0, 2.0 - ] ); + ]); za = new Complex128( 0.4, -0.7 ); zscal( 3, za, zx, 2, 0 ); viewX = new Float64Array( zx.buffer ); - expected = new Float64Array( [ + expected = new Float64Array([ 0.11, // 1 -0.03, // 1 3.0, @@ -146,29 +162,63 @@ tape( 'the function supports a `zx` stride', opts, function test( t ) { -0.19, // 3 7.0, 2.0 - ] ); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + ]); + + isApprox( t, viewX, expected, 5.0 ); + t.end(); +}); + +tape( 'the function supports a negative `zx` stride', opts, function test( t ) { + var expected; + var viewX; + var za; + var zx; + + zx = new Complex128Array([ + 0.1, // 3 + 0.1, // 3 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 1 + -0.3, // 1 + 7.0, + 2.0 + ]); + za = new Complex128( 0.4, -0.7 ); + + zscal( 3, za, zx, -2, 4 ); + + viewX = new Float64Array( zx.buffer ); + expected = new Float64Array([ + 0.11, // 3 + -0.03, // 3 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 1 + -0.19, // 1 + 7.0, + 2.0 + ]); + + isApprox( t, viewX, expected, 5.0 ); t.end(); }); tape( 'the function supports a `zx` offset', opts, function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; - zx = new Complex128Array( [ + zx = new Complex128Array([ 0.1, 0.1, 3.0, @@ -181,13 +231,13 @@ tape( 'the function supports a `zx` offset', opts, function test( t ) { -0.3, // 2 7.0, // 3 2.0 // 3 - ] ); + ]); za = new Complex128( 0.4, -0.7 ); zscal( 3, za, zx, 1, 3 ); viewX = new Float64Array( zx.buffer ); - expected = new Float64Array( [ + expected = new Float64Array([ 0.1, 0.1, 3.0, @@ -200,16 +250,9 @@ tape( 'the function supports a `zx` offset', opts, function test( t ) { -0.19, // 2 4.2, // 3 -4.1 // 3 - ] ); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 8.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + ]); + + isApprox( t, viewX, expected, 8.0 ); t.end(); }); @@ -248,37 +291,13 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu t.end(); }); -tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { - var expected; - var viewX; - var za; - var zx; - - zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - za = new Complex128( 2.0, 2.0 ); - - viewX = new Float64Array( zx.buffer ); - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - - zscal( 4, za, zx, -1, 3 ); - t.deepEqual( viewX, expected, 'returns expected value' ); - - zscal( 4, za, zx, 0, 3 ); - t.deepEqual( viewX, expected, 'returns expected value' ); - - t.end(); -}); - tape( 'the function supports complex access patterns', opts, function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; - zx = new Complex128Array( [ + zx = new Complex128Array([ 0.1, 0.1, 3.0, @@ -293,13 +312,13 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 2.0, 2.0, // 2 3.0 // 2 - ] ); + ]); za = new Complex128( 0.4, -0.7 ); zscal( 2, za, zx, 3, 3 ); viewX = new Float64Array( zx.buffer ); - expected = new Float64Array( [ + expected = new Float64Array([ 0.1, 0.1, 3.0, @@ -314,15 +333,8 @@ tape( 'the function supports complex access patterns', opts, function test( t ) 2.0, 2.9, // 2 -0.2 // 2 - ] ); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 10.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + ]); + + isApprox( t, viewX, expected, 10.0 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/zscal/test/test.zscal.js b/lib/node_modules/@stdlib/blas/base/zscal/test/test.zscal.js index f8feaa12b2c9..9bc8a2001a86 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/test/test.zscal.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/test/test.zscal.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,35 @@ var abs = require( '@stdlib/math/base/special/abs' ); var zscal = require( './../lib/zscal.js' ); +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -44,12 +73,9 @@ tape( 'the function has an arity of 4', function test( t ) { tape( 'the function scales elements from `zx` by `za`', function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; zx = new Complex128Array([ 0.3, // 1 @@ -76,26 +102,16 @@ tape( 'the function scales elements from `zx` by `za`', function test( t ) { 0.14, // 4 0.08 // 4 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, viewX, expected, 1.0 ); t.end(); }); tape( 'the function supports a `zx` stride', function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; zx = new Complex128Array([ 0.1, // 1 @@ -130,26 +146,16 @@ tape( 'the function supports a `zx` stride', function test( t ) { 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, viewX, expected, 5.0 ); t.end(); }); tape( 'the function supports a negative `zx` stride', function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; zx = new Complex128Array([ 0.1, // 3 @@ -184,15 +190,8 @@ tape( 'the function supports a negative `zx` stride', function test( t ) { 7.0, 2.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, viewX, expected, 5.0 ); t.end(); }); @@ -233,13 +232,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu tape( 'the function supports view offsets', function test( t ) { var expected; - var delta; var viewX; - var tol; var zx0; var zx1; var za; - var k; // Initial arrays... zx0 = new Complex128Array([ @@ -274,14 +270,7 @@ tape( 'the function supports view offsets', function test( t ) { 2.0, 3.0 ]); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + + isApprox( t, viewX, expected, 1.0 ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/base/zscal/test/test.zscal.native.js b/lib/node_modules/@stdlib/blas/base/zscal/test/test.zscal.native.js index 0dc596643604..02510078a31e 100644 --- a/lib/node_modules/@stdlib/blas/base/zscal/test/test.zscal.native.js +++ b/lib/node_modules/@stdlib/blas/base/zscal/test/test.zscal.native.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2024 The Stdlib Authors. +* Copyright (c) 2025 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. @@ -38,6 +38,35 @@ var opts = { }; +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + // TESTS // tape( 'main export is a function', opts, function test( t ) { @@ -53,14 +82,11 @@ tape( 'the function has an arity of 4', opts, function test( t ) { tape( 'the function scales elements from `zx` by `za`', opts, function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; - zx = new Complex128Array( [ + zx = new Complex128Array([ 0.3, // 1 0.1, // 1 0.5, // 2 @@ -69,13 +95,13 @@ tape( 'the function scales elements from `zx` by `za`', opts, function test( t ) 0.5, // 3 0.0, // 4 0.2 // 4 - ] ); + ]); za = new Complex128( 0.4, -0.7 ); zscal( 4, za, zx, 1 ); viewX = new Float64Array( zx.buffer ); - expected = new Float64Array( [ + expected = new Float64Array([ 0.19, // 1 -0.17, // 1 0.2, // 2 @@ -84,29 +110,19 @@ tape( 'the function scales elements from `zx` by `za`', opts, function test( t ) 0.2, // 3 0.14, // 4 0.08 // 4 - ] ); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + ]); + + isApprox( t, viewX, expected, 1.0 ); t.end(); }); tape( 'the function supports a `zx` stride', opts, function test( t ) { var expected; - var delta; var viewX; - var tol; var za; var zx; - var k; - zx = new Complex128Array( [ + zx = new Complex128Array([ 0.1, // 1 0.1, // 1 3.0, @@ -119,13 +135,13 @@ tape( 'the function supports a `zx` stride', opts, function test( t ) { -0.3, // 3 7.0, 2.0 - ] ); + ]); za = new Complex128( 0.4, -0.7 ); zscal( 3, za, zx, 2 ); viewX = new Float64Array( zx.buffer ); - expected = new Float64Array( [ + expected = new Float64Array([ 0.11, // 1 -0.03, // 1 3.0, @@ -138,55 +154,71 @@ tape( 'the function supports a `zx` stride', opts, function test( t ) { -0.19, // 3 7.0, 2.0 - ] ); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 5.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + ]); + + isApprox( t, viewX, expected, 5.0 ); t.end(); }); -tape( 'the function returns a reference to the input array', opts, function test( t ) { - var out; +tape( 'the function supports a negative `zx` stride', opts, function test( t ) { + var expected; + var viewX; var za; var zx; - zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - za = new Complex128( 2.0, 2.0 ); + zx = new Complex128Array([ + 0.1, // 3 + 0.1, // 3 + 3.0, + 6.0, + -0.6, // 2 + 0.1, // 2 + 4.0, + 7.0, + 0.1, // 1 + -0.3, // 1 + 7.0, + 2.0 + ]); + za = new Complex128( 0.4, -0.7 ); - out = zscal( 4, za, zx, 1 ); + zscal( 3, za, zx, -2 ); - t.strictEqual( out, zx, 'same reference' ); + viewX = new Float64Array( zx.buffer ); + expected = new Float64Array([ + 0.11, // 3 + -0.03, // 3 + 3.0, + 6.0, + -0.17, // 2 + 0.46, // 2 + 4.0, + 7.0, + -0.17, // 1 + -0.19, // 1 + 7.0, + 2.0 + ]); + + isApprox( t, viewX, expected, 5.0 ); t.end(); }); -tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { - var expected; - var viewX; +tape( 'the function returns a reference to the input array', opts, function test( t ) { + var out; var za; var zx; zx = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); za = new Complex128( 2.0, 2.0 ); - viewX = new Float64Array( zx.buffer ); - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - - zscal( -1, za, zx, 1 ); - t.deepEqual( viewX, expected, 'returns expected value' ); - - zscal( 0, za, zx, 1 ); - t.deepEqual( viewX, expected, 'returns expected value' ); + out = zscal( 4, za, zx, 1 ); + t.strictEqual( out, zx, 'same reference' ); t.end(); }); -tape( 'if provided an `strideX` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { +tape( 'if provided an `N` parameter less than or equal to `0`, the function returns the input array unchanged', opts, function test( t ) { var expected; var viewX; var za; @@ -198,10 +230,10 @@ tape( 'if provided an `strideX` parameter less than or equal to `0`, the functio viewX = new Float64Array( zx.buffer ); expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); - zscal( 4, za, zx, -1 ); + zscal( -1, za, zx, 1 ); t.deepEqual( viewX, expected, 'returns expected value' ); - zscal( 4, za, zx, 0 ); + zscal( 0, za, zx, 1 ); t.deepEqual( viewX, expected, 'returns expected value' ); t.end(); @@ -209,16 +241,13 @@ tape( 'if provided an `strideX` parameter less than or equal to `0`, the functio tape( 'the function supports view offsets', opts, function test( t ) { var expected; - var delta; var viewX; - var tol; var zx0; var zx1; var za; - var k; // Initial arrays... - zx0 = new Complex128Array( [ + zx0 = new Complex128Array([ 0.1, -0.3, 8.0, // 1 @@ -229,7 +258,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { 5.0, // 3 2.0, 3.0 - ] ); + ]); za = new Complex128( 0.4, -0.7 ); // Create offset views... @@ -238,7 +267,7 @@ tape( 'the function supports view offsets', opts, function test( t ) { zscal( 3, za, zx1, 1 ); viewX = new Float64Array( zx0.buffer ); - expected = new Float64Array( [ + expected = new Float64Array([ 0.1, -0.3, 9.5, // 1 @@ -249,15 +278,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { 0.6, // 3 2.0, 3.0 - ] ); - for ( k = 0; k < expected.length; k++ ) { - if ( viewX[ k ] === expected[ k ] ) { - t.strictEqual( viewX[ k ], expected[ k ], 'returns expected value' ); - } else { - delta = abs( viewX[ k ] - expected[ k ] ); - tol = 1.0 * EPS * abs( expected[ k ] ); - t.ok( delta <= tol, 'within tolerance. x: '+viewX[ k ]+'. expected: '+expected[ k ]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + ]); + + isApprox( t, viewX, expected, 1.0 ); t.end(); });