diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/README.md b/lib/node_modules/@stdlib/math/base/special/cinvf/README.md index 1dd768314ca4..a7eb5b6c46a0 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/README.md @@ -57,6 +57,55 @@ var v = cinvf( new Complex64( 2.0, 4.0 ) ); // returns [ ~0.1, ~-0.2 ] ``` +#### cinvf.assign( re, im, out, strideOut, offsetOut ) + +Computes the inverse of a single-precision complex floating-point number and assigns results to a provided output array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var out = new Float32Array( 2 ); +var v = cinvf.assign( 2.0, 4.0, out, 1, 0 ); +// returns [ ~0.1, ~-0.2 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **re**: real component. +- **im**: imaginary component. +- **out**: output array. +- **strideOut**: stride length for `out`. +- **offsetOut**: starting index for `out`. + +#### cinvf.strided( z, sz, oz, out, so, oo ) + +Computes the inverse of a single-precision complex floating-point number stored in a real-valued strided array view and assigns results to a provided strided output array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var z = new Float32Array( [ 2.0, 4.0 ] ); +var out = new Float32Array( 2 ); + +var v = cinvf.strided( z, 1, 0, out, 1, 0 ); +// returns [ ~0.1, ~-0.2 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **z**: complex number strided array view. +- **sz**: stride length for `z`. +- **oz**: starting index for `z`. +- **out**: output array. +- **so**: stride length for `out`. +- **oo**: starting index for `out`. + diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..53a7c26922da --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.assign.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var assign = require( './../lib' ).assign; + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// MAIN // + +bench( format( '%s:assign', pkg ), function benchmark( b ) { + var out; + var re; + var im; + var N; + var i; + var j; + + N = 100; + re = uniform( N, -500.0, 500.0, options ); + im = uniform( N, -500.0, 500.0, options ); + + out = new Float32Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % N; + out = assign( re[ j ], im[ j ], out, 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( isnanf( out[ 0 ] ) || isnanf( out[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.js index 90e0cdf8d2eb..2cc6aabf01b7 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.js @@ -21,37 +21,43 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Complex64Array = require( '@stdlib/array/complex64' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); var pkg = require( './../package.json' ).name; var cinvf = require( './../lib' ); +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + // MAIN // bench( pkg, function benchmark( b ) { - var values; + var zbuf; + var z; var y; var i; - values = [ - new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), - new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) - ]; + zbuf = uniform( 200, -500.0, 500.0, options ); + z = new Complex64Array( zbuf.buffer ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = cinvf( values[ i%values.length ] ); + y = cinvf( z.get( i%100 ) ); if ( isnanf( realf( y ) ) ) { b.fail( 'should not return NaN' ); } } b.toc(); if ( isnanf( imagf( y ) ) ) { - b.fail( 'should not return not NaN' ); + b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.native.js index a7b496aceba9..47eb7e526b4e 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.native.js @@ -22,11 +22,11 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var uniform = require( '@stdlib/random/base/uniform' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Complex64Array = require( '@stdlib/array/complex64' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); -var Complex64 = require( '@stdlib/complex/float32/ctor' ); var tryRequire = require( '@stdlib/utils/try-require' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; @@ -38,30 +38,32 @@ var cinvf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { 'skip': ( cinvf instanceof Error ) }; +var options = { + 'dtype': 'float32' +}; // MAIN // bench( format( '%s::native', pkg ), opts, function benchmark( b ) { - var values; + var zbuf; + var z; var y; var i; - values = [ - new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ), - new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ) - ]; + zbuf = uniform( 200, -500.0, 500.0, options ); + z = new Complex64Array( zbuf.buffer ); b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = cinvf( values[ i%values.length ] ); + y = cinvf( z.get( i%100 ) ); if ( isnanf( realf( y ) ) ) { b.fail( 'should not return NaN' ); } } b.toc(); if ( isnanf( imagf( y ) ) ) { - b.fail( 'should not return not NaN' ); + b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); b.end(); diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.strided.js b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.strided.js new file mode 100644 index 000000000000..ff94b2fd0918 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/benchmark.strided.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var strided = require( './../lib' ).strided; + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// MAIN // + +bench( format( '%s:strided', pkg ), function benchmark( b ) { + var out; + var z; + var N; + var i; + var j; + + N = 50; + z = uniform( N*2, -500.0, 500.0, options ); + + out = new Float32Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = ( i % N ) * 2; + out = strided( z, 1, j, out, 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( isnanf( out[ 0 ] ) || isnanf( out[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/benchmark.c index 806a62cc03e8..271d91890f70 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/benchmark.c @@ -20,9 +20,10 @@ #include #include #include +#include #include -#define NAME "inv" +#define NAME "cinvf" #define ITERATIONS 1000000 #define REPEATS 3 @@ -74,13 +75,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*(max-min) ); } /** @@ -89,32 +92,30 @@ static float rand_float( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { - float re[ 100 ]; - float im[ 100 ]; + float complex z[ 100 ]; + float complex w; double elapsed; double t; + float re; + float im; int i; - float complex z1; - float complex z2; - for ( i = 0; i < 100; i++ ) { - re[ i ] = ( 1000.0f*rand_float() ) - 500.0f; - im[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + re = random_uniform( -500.0f, 500.0f ); + im = random_uniform( -500.0f, 500.0f ); + z[ i ] = re + im*I; } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - z1 = re[ i%100 ] + im[ i%100 ]*I; - - z2 = 1.0f / z1; - if ( z2 != z2 ) { + w = 1.0f / z[ i%100 ]; + if ( w != w ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; - if ( z2 != z2 ) { + if ( w != w ) { printf( "should not return NaN\n" ); } return elapsed; diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/native/benchmark.c index 198134481f4d..4b98b6a8608b 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/benchmark/c/native/benchmark.c @@ -77,13 +77,15 @@ static double tic( void ) { } /** -* Generates a random number on the interval [0,1). +* Generates a random number on the interval [min,max). * -* @return random number +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number */ -static float rand_float( void ) { - int r = rand(); - return (float)r / ( (float)RAND_MAX + 1.0f ); +static float random_uniform( const float min, const float max ) { + float v = (float)rand() / ( (float)RAND_MAX + 1.0f ); + return min + ( v*(max-min) ); } /** @@ -92,35 +94,32 @@ static float rand_float( void ) { * @return elapsed time in seconds */ static double benchmark( void ) { - float u[ 100 ]; - float v[ 100 ]; + stdlib_complex64_t z[ 100 ]; + stdlib_complex64_t w; double elapsed; + double t; float re; float im; - double t; int i; - stdlib_complex64_t x; - stdlib_complex64_t y; - for ( i = 0; i < 100; i++ ) { - u[ i ] = ( 1000.0f*rand_float() ) - 500.0f; - v[ i ] = ( 1000.0f*rand_float() ) - 500.0f; + re = random_uniform( -500.0f, 500.0f ); + im = random_uniform( -500.0f, 500.0f ); + z[ i ] = stdlib_complex64( re, im ); } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = stdlib_complex64( u[ i%100 ], v[ i%100 ] ); - y = stdlib_base_cinvf( x ); - stdlib_complex64_reim( y, &re, &im ); + w = stdlib_base_cinvf( z[ i%100 ] ); + stdlib_complex64_reim( w, &re, &im ); if ( re != re ) { - printf( "unexpected result\n" ); + printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; if ( im != im ) { - printf( "unexpected result\n" ); + printf( "should not return NaN\n" ); } return elapsed; } diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/cinvf/docs/repl.txt index b49f8f232520..304913c7ed48 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/docs/repl.txt @@ -17,6 +17,77 @@ > var v = {{alias}}( new {{alias:@stdlib/complex/float32/ctor}}( 2.0, 4.0 ) ) [ ~0.1, ~-0.2 ] + +{{alias}}.assign( re, im, out, strideOut, offsetOut ) + Computes the inverse of a single-precision complex floating-point number + and assigns results to a provided output array. + + Parameters + ---------- + re: number + Real component. + + im: number + Imaginary component. + + out: ArrayLikeObject + Output array. + + strideOut: integer + Stride length. + + offsetOut: integer + Starting index. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var out = new {{alias:@stdlib/array/float32}}( 2 ); + > {{alias}}.assign( 2.0, 4.0, out, 1, 0 ) + [ ~0.1, ~-0.2 ] + + +{{alias}}.strided( z, sz, oz, out, so, oo ) + Computes the inverse of a single-precision complex floating-point number + stored in a real-valued strided array view and assigns results to a + provided strided output array. + + Parameters + ---------- + z: ArrayLikeObject + Complex number view. + + sz: integer + Stride length for `z`. + + oz: integer + Starting index for `z`. + + out: ArrayLikeObject + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var z = new {{alias:@stdlib/array/float32}}( [ 2.0, 4.0 ] ); + > var out = new {{alias:@stdlib/array/float32}}( 2 ); + > {{alias}}.strided( z, 1, 0, out, 1, 0 ) + [ ~0.1, ~-0.2 ] + See Also -------- diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/cinvf/docs/types/index.d.ts index 6618b36444b2..0b9900df44a0 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/docs/types/index.d.ts @@ -21,11 +21,74 @@ /// import { Complex64 } from '@stdlib/types/complex'; +import { Collection, NumericArray } from '@stdlib/types/array'; + +/** +* Interface for computing the inverse of a single-precision complex floating-point number. +*/ +interface Cinvf { + /** + * Computes the inverse of a single-precision complex floating-point number. + * + * @param z - complex number + * @returns result + * + * @example + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * + * var v = cinvf( new Complex64( 2.0, 4.0 ) ); + * // returns [ ~0.1, ~-0.2 ] + */ + ( z: Complex64 ): Complex64; + + /** + * Computes the inverse of a single-precision complex floating-point number and assigns results to a provided output array. + * + * @param re - real component + * @param im - imaginary component + * @param out - output array + * @param strideOut - stride length + * @param offsetOut - starting index + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var out = new Float32Array( 2 ); + * var v = cinvf.assign( 2.0, 4.0, out, 1, 0 ); + * // returns [ ~0.1, ~-0.2 ] + * + * var bool = ( out === v ); + * // returns true + */ + assign>( re: number, im: number, out: T, strideOut: number, offsetOut: number ): T; + + /** + * Computes the inverse of a single-precision complex floating-point number stored in a real-valued strided array view and assigns results to a provided strided output array. + * + * @param z - complex number view + * @param strideZ - stride length for `z` + * @param offsetZ - starting index for `z` + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var z = new Float32Array( [ 2.0, 4.0 ] ); + * + * var out = cinvf.strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); + * // returns [ ~0.1, ~-0.2 ] + */ + strided, U extends NumericArray | Collection>( z: T, strideZ: number, offsetZ: number, out: U, strideOut: number, offsetOut: number ): U; +} /** * Computes the inverse of a single-precision complex floating-point number. * -* @param z - input value +* @param z - complex number * @returns result * * @example @@ -33,8 +96,26 @@ import { Complex64 } from '@stdlib/types/complex'; * * var v = cinvf( new Complex64( 2.0, 4.0 ) ); * // returns [ ~0.1, ~-0.2 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var out = new Float32Array( 2 ); +* var v = cinvf.assign( 2.0, 4.0, out, 1, 0 ); +* // returns [ ~0.1, ~-0.2 ] +* +* var bool = ( out === v ); +* // returns true +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var z = new Float32Array( [ 2.0, 4.0 ] ); +* +* var out = cinvf.strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); +* // returns [ ~0.1, ~-0.2 ] */ -declare function cinvf( z: Complex64 ): Complex64; +declare var cinvf: Cinvf; // EXPORTS // diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/cinvf/docs/types/test.ts index d5f89f7dabc4..90465f3cf4b5 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/docs/types/test.ts @@ -22,13 +22,14 @@ import cinvf = require( './index' ); // TESTS // -// The function returns a double-precision complex floating-point number... +// The function returns a complex number... { cinvf( new Complex64( 1.0, 2.0 ) ); // $ExpectType Complex64 } // The compiler throws an error if the function is provided a value other than a complex number... { + cinvf( 2 ); // $ExpectError cinvf( true ); // $ExpectError cinvf( false ); // $ExpectError cinvf( null ); // $ExpectError @@ -39,7 +40,207 @@ import cinvf = require( './index' ); cinvf( ( x: number ): number => x ); // $ExpectError } -// The compiler throws an error if the function is provided an unsupported number of arguments... +// The compiler throws an error if the function is provided insufficient arguments... { cinvf(); // $ExpectError } + +// Attached to the main export is an `assign` method which returns a collection... +{ + cinvf.assign( 1.0, 1.0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + cinvf.assign( 1.0, 1.0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + cinvf.assign( 1.0, 1.0, [ 0.0, 0.0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not a number... +{ + const out = new Float32Array( 2 ); + + cinvf.assign( true, 2.0, out, 1, 0 ); // $ExpectError + cinvf.assign( false, 2.0, out, 1, 0 ); // $ExpectError + cinvf.assign( null, 2.0, out, 1, 0 ); // $ExpectError + cinvf.assign( undefined, 2.0, out, 1, 0 ); // $ExpectError + cinvf.assign( '5', 2.0, out, 1, 0 ); // $ExpectError + cinvf.assign( [], 2.0, out, 1, 0 ); // $ExpectError + cinvf.assign( {}, 2.0, out, 1, 0 ); // $ExpectError + cinvf.assign( ( x: number ): number => x, 2.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not a number... +{ + const out = new Float32Array( 2 ); + + cinvf.assign( 1.0, true, out, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, false, out, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, null, out, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, undefined, out, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, '5', out, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, [], out, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, {}, out, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a collection... +{ + cinvf.assign( 1.0, 2.0, 1, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, true, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, false, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, null, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, undefined, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, '5', 1, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, [ '5' ], 1, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, {}, 1, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const out = new Float32Array( 2 ); + + cinvf.assign( 1.0, 2.0, out, true, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, false, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, null, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, undefined, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, '5', 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, [], 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, {}, 0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... +{ + const out = new Float32Array( 2 ); + + cinvf.assign( 1.0, 2.0, out, 1, true ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, 1, false ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, 1, null ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, 1, undefined ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, 1, '5' ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, 1, [] ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, 1, {} ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const out = new Float32Array( 2 ); + + cinvf.assign(); // $ExpectError + cinvf.assign( 1.0 ); // $ExpectError + cinvf.assign( 1.0, 2.0 ); // $ExpectError + cinvf.assign( 1.0, 2.0, out ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, 1 ); // $ExpectError + cinvf.assign( 1.0, 2.0, out, 1, 0, {} ); // $ExpectError +} + +// Attached to the main export is a `strided` method which returns a collection... +{ + const z = new Float32Array( 2 ); + + cinvf.strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + cinvf.strided( z, 1, 0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + cinvf.strided( z, 1, 0, [ 0.0, 0.0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `strided` method is provided a first argument which is not a collection... +{ + const out = new Float32Array( 2 ); + + cinvf.strided( true, 1, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( false, 1, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( null, 1, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( undefined, 1, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( '5', 1, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( [ '5' ], 1, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( {}, 1, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( ( x: number ): number => x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a second argument which is not a number... +{ + const z = new Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cinvf.strided( z, true, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( z, false, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( z, null, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( z, undefined, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( z, '5', 0, out, 1, 0 ); // $ExpectError + cinvf.strided( z, [], 0, out, 1, 0 ); // $ExpectError + cinvf.strided( z, {}, 0, out, 1, 0 ); // $ExpectError + cinvf.strided( z, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a third argument which is not a number... +{ + const z = new Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cinvf.strided( z, 1, true, out, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, false, out, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, null, out, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, undefined, out, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, '5', out, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, [], out, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, {}, out, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fourth argument which is not a collection... +{ + const z = new Float32Array( 2 ); + + cinvf.strided( z, 1, 0, 1, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, true, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, false, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, null, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, undefined, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, '5', 1, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, [ '5' ], 1, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, {}, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fifth argument which is not a number... +{ + const z = new Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cinvf.strided( z, 1, 0, out, true, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, out, false, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, out, null, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, out, undefined, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, out, '5', 0 ); // $ExpectError + cinvf.strided( z, 1, 0, out, [], 0 ); // $ExpectError + cinvf.strided( z, 1, 0, out, {}, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a sixth argument which is not a number... +{ + const z = new Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cinvf.strided( z, 1, 0, out, 1, true ); // $ExpectError + cinvf.strided( z, 1, 0, out, 1, false ); // $ExpectError + cinvf.strided( z, 1, 0, out, 1, null ); // $ExpectError + cinvf.strided( z, 1, 0, out, 1, undefined ); // $ExpectError + cinvf.strided( z, 1, 0, out, 1, '5' ); // $ExpectError + cinvf.strided( z, 1, 0, out, 1, [] ); // $ExpectError + cinvf.strided( z, 1, 0, out, 1, {} ); // $ExpectError + cinvf.strided( z, 1, 0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided an unsupported number of arguments... +{ + const z = new Float32Array( 2 ); + const out = new Float32Array( 2 ); + + cinvf.strided(); // $ExpectError + cinvf.strided( z ); // $ExpectError + cinvf.strided( z, 1 ); // $ExpectError + cinvf.strided( z, 1, 0 ); // $ExpectError + cinvf.strided( z, 1, 0, out ); // $ExpectError + cinvf.strided( z, 1, 0, out, 1 ); // $ExpectError + cinvf.strided( z, 1, 0, out, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/examples/index.js b/lib/node_modules/@stdlib/math/base/special/cinvf/examples/index.js index 0c0009eca510..7401e35943e9 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/examples/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/examples/index.js @@ -24,7 +24,9 @@ var logEachMap = require( '@stdlib/console/log-each-map' ); var cinvf = require( './../lib' ); // Create an array of random numbers: -var arr = new Complex64Array( uniform( 200, -100.0, 100.0 ) ); +var arr = new Complex64Array( uniform( 200, -100.0, 100.0, { + 'dtype': 'float32' +})); // Compute the inverse of each number in the array: logEachMap( '1.0 / (%s) = %s', arr, cinvf ); diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/lib/assign.js b/lib/node_modules/@stdlib/math/base/special/cinvf/lib/assign.js new file mode 100644 index 000000000000..c0e8557304a6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/lib/assign.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 absf = require( '@stdlib/math/base/special/absf' ); +var maxf = require( '@stdlib/math/base/special/maxf' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var FLOAT32_BIGGEST = require( '@stdlib/constants/float32/max' ); +var FLOAT32_SMALLEST = require( '@stdlib/constants/float32/smallest-normal' ); +var EPS = require( '@stdlib/constants/float32/eps' ); + + +// VARIABLES // + +var ONE = f32( 1.0 ); +var TWO = f32( 2.0 ); +var HALF = f32( 0.5 ); +var LARGE_THRESHOLD = f32( FLOAT32_BIGGEST * HALF ); +var SMALL_THRESHOLD = f32( FLOAT32_SMALLEST * f32( TWO/EPS ) ); +var RECIP_EPS_SQR = f32( TWO / f32(EPS*EPS) ); + + +// MAIN // + +/** +* Computes the inverse of a single-precision complex floating-point number and assigns results to a provided output array. +* +* @param {number} re - real component +* @param {number} im - imaginary component +* @param {Collection} out - output array +* @param {integer} strideOut - stride length +* @param {NonNegativeInteger} offsetOut - starting index +* @returns {Collection} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var out = assign( 2.0, 4.0, new Float32Array( 2 ), 1, 0 ); +* // returns [ ~0.1, ~-0.2 ] +*/ +function assign( re, im, out, strideOut, offsetOut ) { + var ab; + var s; + var r; + var t; + + ab = maxf( absf( re ), absf( im ) ); + s = ONE; + if ( ab >= LARGE_THRESHOLD ) { + re = f32( re * HALF ); + im = f32( im * HALF ); + s = f32( s * HALF ); + } else if ( ab <= SMALL_THRESHOLD ) { + re = f32( re * RECIP_EPS_SQR ); + im = f32( im * RECIP_EPS_SQR ); + s = f32( s * RECIP_EPS_SQR ); + } + if ( absf( im ) <= absf( re ) ) { + r = f32( im / re ); + t = f32( ONE / f32( re + f32(im*r) ) ); + re = t; + im = f32( -r * t ); + } else { + r = f32( re / im ); + t = f32( ONE / f32( im + f32(re*r) ) ); + re = f32( r * t ); + im = -t; + } + out[ offsetOut ] = f32( re * s ); + out[ offsetOut+strideOut ] = f32( im * s ); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/cinvf/lib/index.js index 50b4970e6f0e..643995bfe3dc 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/lib/index.js @@ -33,9 +33,20 @@ // MODULES // +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var main = require( './main.js' ); +var assign = require( './assign.js' ); +var strided = require( './strided.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); +setReadOnly( main, 'strided', strided ); // EXPORTS // module.exports = main; + +// exports: { "assign": "main.assign", "strided": "main.strided" } diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/lib/main.js b/lib/node_modules/@stdlib/math/base/special/cinvf/lib/main.js index 1c62fe0ae259..9b04f8ea3f74 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/lib/main.js @@ -20,25 +20,16 @@ // MODULES // -var absf = require( '@stdlib/math/base/special/absf' ); -var maxf = require( '@stdlib/math/base/special/maxf' ); -var f32 = require( '@stdlib/number/float64/base/to-float32' ); -var FLOAT32_BIGGEST = require( '@stdlib/constants/float32/max' ); -var FLOAT32_SMALLEST = require( '@stdlib/constants/float32/smallest-normal' ); -var EPS = require( '@stdlib/constants/float32/eps' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Float32Array = require( '@stdlib/array/float32' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); +var assign = require( './assign.js' ); // VARIABLES // -var ONE = f32( 1.0 ); -var TWO = f32( 2.0 ); -var HALF = f32( 0.5 ); -var LARGE_THRESHOLD = f32( FLOAT32_BIGGEST * HALF ); -var SMALL_THRESHOLD = f32( FLOAT32_SMALLEST * f32( TWO/EPS ) ); -var RECIP_EPS_SQR = f32( TWO / f32(EPS*EPS) ); +var out = new Float32Array( 2 ); // MAIN // @@ -60,40 +51,8 @@ var RECIP_EPS_SQR = f32( TWO / f32(EPS*EPS) ); * // returns [ ~0.1, ~-0.2 ] */ function cinvf( z ) { - var ab; - var re; - var im; - var s; - var r; - var t; - - re = realf( z ); - im = imagf( z ); - ab = maxf( absf(re), absf(im) ); - s = ONE; - if ( ab >= LARGE_THRESHOLD ) { - re = f32( re * HALF ); - im = f32( im * HALF ); - s = f32( s * HALF ); - } else if ( ab <= SMALL_THRESHOLD ) { - re = f32( re * RECIP_EPS_SQR ); - im = f32( im * RECIP_EPS_SQR ); - s = f32( s * RECIP_EPS_SQR ); - } - if ( absf( im ) <= absf( re ) ) { - r = f32( im / re ); - t = f32( ONE / f32( re + f32(im*r) ) ); - re = t; - im = f32( -r * t ); - } else { - r = f32( re / im ); - t = f32( ONE / f32( im + f32(re*r) ) ); - re = f32( r * t ); - im = -t; - } - re = f32( re * s ); - im = f32( im * s ); - return new Complex64( re, im ); + assign( realf( z ), imagf( z ), out, 1, 0 ); + return new Complex64( out[ 0 ], out[ 1 ] ); } diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/lib/strided.js b/lib/node_modules/@stdlib/math/base/special/cinvf/lib/strided.js new file mode 100644 index 000000000000..2dc5c0cec788 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/lib/strided.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 assign = require( './assign.js' ); + + +// MAIN // + +/** +* Computes the inverse of a single-precision complex floating-point number stored in a real-valued strided array view and assigns results to a provided strided output array. +* +* @param {Float32Array} z - complex number view +* @param {integer} strideZ - stride length for `z` +* @param {NonNegativeInteger} offsetZ - starting index for `z` +* @param {Collection} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var z = new Float32Array( [ 2.0, 4.0 ] ); +* +* var out = strided( z, 1, 0, new Float32Array( 2 ), 1, 0 ); +* // returns [ ~0.1, ~-0.2 ] +*/ +function strided( z, strideZ, offsetZ, out, strideOut, offsetOut ) { + return assign( z[ offsetZ ], z[ offsetZ+strideZ ], out, strideOut, offsetOut ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = strided; diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.assign.js b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.assign.js new file mode 100644 index 000000000000..f51da49ee889 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.assign.js @@ -0,0 +1,190 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var cinvf = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cinvf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the inverse of a single-precision complex floating-point number', function test( t ) { + var expected; + var out; + var v; + + out = new Float32Array( 2 ); + v = cinvf( 2.0, 4.0, out, 1, 0 ); + + expected = new Float32Array( [ 0.1, -0.2 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 4 ); + v = cinvf( 2.0, 4.0, out, 2, 0 ); + + expected = new Float32Array( [ 0.1, 0.0, -0.2, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 4 ); + v = cinvf( 2.0, 4.0, out, 2, 1 ); + + expected = new Float32Array( [ 0.0, 0.1, 0.0, -0.2 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 4 ); + v = cinvf( 2.0, 4.0, out, -2, 3 ); + + expected = new Float32Array( [ 0.0, -0.2, 0.0, 0.1 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes a complex inverse', function test( t ) { + var expected; + var out; + + out = new Float32Array( 2 ); + cinvf( 2.0, 2.0, out, 1, 0 ); + + expected = new Float32Array( [ 0.25, -0.25 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( 4.0, 0.0, out, 1, 0 ); + + expected = new Float32Array( [ 0.25, -0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( 0.0, 2.0, out, 1, 0 ); + + expected = new Float32Array( [ 0.0, -0.5 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function may overflow', function test( t ) { + var expected; + var out; + + out = new Float32Array( 2 ); + cinvf( 5.0e-40, 5.0e-40, out, 1, 0 ); + + expected = new Float32Array( [ PINF, NINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( -5.0e-40, 5.0e-40, out, 1, 0 ); + + expected = new Float32Array( [ NINF, NINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( -5.0e-40, -5.0e-40, out, 1, 0 ); + + expected = new Float32Array( [ NINF, PINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( 5.0e-40, -5.0e-40, out, 1, 0 ); + + expected = new Float32Array( [ PINF, PINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( 0.0, 5.0e-40, out, 1, 0 ); + + expected = new Float32Array( [ 0.0, NINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( 0.0, -5.0e-40, out, 1, 0 ); + + expected = new Float32Array( [ 0.0, PINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( 5.0e-40, 0.0, out, 1, 0 ); + + expected = new Float32Array( [ PINF, -0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( -5.0e-40, 0.0, out, 1, 0 ); + + expected = new Float32Array( [ NINF, -0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', function test( t ) { + var out; + + out = new Float32Array( 2 ); + cinvf( NaN, 3.0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( 5.0, NaN, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + out = new Float32Array( 2 ); + cinvf( NaN, NaN, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.js b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.js index cc8affe69798..a5177e26b094 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.js @@ -16,37 +16,15 @@ * limitations under the License. */ -/* eslint-disable id-length */ - 'use strict'; // MODULES // var tape = require( 'tape' ); -var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var PINF = require( '@stdlib/constants/float32/pinf' ); -var NINF = require( '@stdlib/constants/float32/ninf' ); -var Complex64 = require( '@stdlib/complex/float32/ctor' ); -var realf = require( '@stdlib/complex/float32/real' ); -var imagf = require( '@stdlib/complex/float32/imag' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var isAlmostSameValue = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); +var isMethod = require( '@stdlib/assert/is-method' ); var cinvf = require( './../lib' ); -// FIXTURES // - -var data = require( './fixtures/julia/data.json' ); -var largeNegativeImaginaryComponents = require( './fixtures/julia/large_negative_imaginary_components.json' ); -var largeNegativeRealComponents = require( './fixtures/julia/large_negative_real_components.json' ); -var largePositiveImaginaryComponents = require( './fixtures/julia/large_positive_imaginary_components.json' ); -var largePositiveRealComponents = require( './fixtures/julia/large_positive_real_components.json' ); -var tinyNegativeImaginaryComponents = require( './fixtures/julia/tiny_negative_imaginary_components.json' ); -var tinyNegativeRealComponents = require( './fixtures/julia/tiny_negative_real_components.json' ); -var tinyPositiveImaginaryComponents = require( './fixtures/julia/tiny_positive_imaginary_components.json' ); -var tinyPositiveRealComponents = require( './fixtures/julia/tiny_positive_real_components.json' ); - - // TESTS // tape( 'main export is a function', function test( t ) { @@ -55,265 +33,12 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function computes the inverse of a single-precision complex floating-point number', function test( t ) { - var v; - - v = cinvf( new Complex64( 2.0, 4.0 ) ); - t.strictEqual( realf( v ), float64ToFloat32( 0.1 ), 'returns expected value' ); - t.strictEqual( imagf( v ), float64ToFloat32( -0.2 ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function computes a complex inverse', function test( t ) { - var qre; - var qim; - var re; - var im; - var i; - var q; - - re = data.re; - im = data.im; - qre = data.qre; - qim = data.qim; - - for ( i = 0; i < re.length; i++ ) { - q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function computes a complex inverse (large negative imaginary components)', function test( t ) { - var qre; - var qim; - var re; - var im; - var i; - var q; - - re = largeNegativeImaginaryComponents.re; - im = largeNegativeImaginaryComponents.im; - qre = largeNegativeImaginaryComponents.qre; - qim = largeNegativeImaginaryComponents.qim; - - for ( i = 0; i < re.length; i++ ) { - q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function computes a complex inverse (large negative real components)', function test( t ) { - var qre; - var qim; - var re; - var im; - var i; - var q; - - re = largeNegativeRealComponents.re; - im = largeNegativeRealComponents.im; - qre = largeNegativeRealComponents.qre; - qim = largeNegativeRealComponents.qim; - - for ( i = 0; i < re.length; i++ ) { - q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function computes a complex inverse (large positive imaginary components)', function test( t ) { - var qre; - var qim; - var re; - var im; - var i; - var q; - - re = largePositiveImaginaryComponents.re; - im = largePositiveImaginaryComponents.im; - qre = largePositiveImaginaryComponents.qre; - qim = largePositiveImaginaryComponents.qim; - - for ( i = 0; i < re.length; i++ ) { - q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); - } +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( isMethod( cinvf, 'assign' ), true, 'returns expected value' ); t.end(); }); -tape( 'the function computes a complex inverse (large positive real components)', function test( t ) { - var qre; - var qim; - var re; - var im; - var i; - var q; - - re = largePositiveRealComponents.re; - im = largePositiveRealComponents.im; - qre = largePositiveRealComponents.qre; - qim = largePositiveRealComponents.qim; - - for ( i = 0; i < re.length; i++ ) { - q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function computes a complex inverse (tiny negative imaginary components)', function test( t ) { - var qre; - var qim; - var re; - var im; - var i; - var q; - - re = tinyNegativeImaginaryComponents.re; - im = tinyNegativeImaginaryComponents.im; - qre = tinyNegativeImaginaryComponents.qre; - qim = tinyNegativeImaginaryComponents.qim; - - for ( i = 0; i < re.length; i++ ) { - q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function computes a complex inverse (tiny negative real components)', function test( t ) { - var qre; - var qim; - var re; - var im; - var i; - var q; - - re = tinyNegativeRealComponents.re; - im = tinyNegativeRealComponents.im; - qre = tinyNegativeRealComponents.qre; - qim = tinyNegativeRealComponents.qim; - - for ( i = 0; i < re.length; i++ ) { - q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function computes a complex inverse (tiny positive imaginary components)', function test( t ) { - var qre; - var qim; - var re; - var im; - var i; - var q; - - re = tinyPositiveImaginaryComponents.re; - im = tinyPositiveImaginaryComponents.im; - qre = tinyPositiveImaginaryComponents.qre; - qim = tinyPositiveImaginaryComponents.qim; - - for ( i = 0; i < re.length; i++ ) { - q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function computes a complex inverse (tiny positive real components)', function test( t ) { - var qre; - var qim; - var re; - var im; - var i; - var q; - - re = tinyPositiveRealComponents.re; - im = tinyPositiveRealComponents.im; - qre = tinyPositiveRealComponents.qre; - qim = tinyPositiveRealComponents.qim; - - for ( i = 0; i < re.length; i++ ) { - q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function may overflow', function test( t ) { - var v; - - v = cinvf( new Complex64( 5.0e-40, 5.0e-40 ) ); - t.strictEqual( realf( v ), PINF, 'returns expected value' ); - t.strictEqual( imagf( v ), NINF, 'returns expected value' ); - - v = cinvf( new Complex64( -5.0e-40, 5.0e-40 ) ); - t.strictEqual( realf( v ), NINF, 'returns expected value' ); - t.strictEqual( imagf( v ), NINF, 'returns expected value' ); - - v = cinvf( new Complex64( -5.0e-40, -5.0e-40 ) ); - t.strictEqual( realf( v ), NINF, 'returns expected value' ); - t.strictEqual( imagf( v ), PINF, 'returns expected value' ); - - v = cinvf( new Complex64( 5.0e-40, -5.0e-40 ) ); - t.strictEqual( realf( v ), PINF, 'returns expected value' ); - t.strictEqual( imagf( v ), PINF, 'returns expected value' ); - - v = cinvf( new Complex64( 0.0, 5.0e-40 ) ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), NINF, 'returns expected value' ); - - v = cinvf( new Complex64( 0.0, -5.0e-40 ) ); - t.strictEqual( realf( v ), 0.0, 'returns expected value' ); - t.strictEqual( imagf( v ), PINF, 'returns expected value' ); - - v = cinvf( new Complex64( 5.0e-40, 0.0 ) ); - t.strictEqual( realf( v ), PINF, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - - v = cinvf( new Complex64( -5.0e-40, 0.0 ) ); - t.strictEqual( realf( v ), NINF, 'returns expected value' ); - t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', function test( t ) { - var v; - - v = cinvf( new Complex64( NaN, 3.0 ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); - - v = cinvf( new Complex64( 5.0, NaN ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); - - v = cinvf( new Complex64( NaN, NaN ) ); - t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); - t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); - +tape( 'attached to the main export is a `strided` method', function test( t ) { + t.strictEqual( isMethod( cinvf, 'strided' ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.main.js b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.main.js new file mode 100644 index 000000000000..4eab4e9fb9b9 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.main.js @@ -0,0 +1,319 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 id-length */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); +var cinvf = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); +var largeNegativeImaginaryComponents = require( './fixtures/julia/large_negative_imaginary_components.json' ); +var largeNegativeRealComponents = require( './fixtures/julia/large_negative_real_components.json' ); +var largePositiveImaginaryComponents = require( './fixtures/julia/large_positive_imaginary_components.json' ); +var largePositiveRealComponents = require( './fixtures/julia/large_positive_real_components.json' ); +var tinyNegativeImaginaryComponents = require( './fixtures/julia/tiny_negative_imaginary_components.json' ); +var tinyNegativeRealComponents = require( './fixtures/julia/tiny_negative_real_components.json' ); +var tinyPositiveImaginaryComponents = require( './fixtures/julia/tiny_positive_imaginary_components.json' ); +var tinyPositiveRealComponents = require( './fixtures/julia/tiny_positive_real_components.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cinvf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the inverse of a single-precision complex floating-point number', function test( t ) { + var v; + + v = cinvf( new Complex64( 2.0, 4.0 ) ); + t.strictEqual( realf( v ), f32( 0.1 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( -0.2 ), 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes a complex inverse', function test( t ) { + var qre; + var qim; + var re; + var im; + var i; + var q; + + re = data.re; + im = data.im; + qre = data.qre; + qim = data.qim; + + for ( i = 0; i < re.length; i++ ) { + q = cinvf( new Complex64( re[ i ], im[ i ] ) ); + + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes a complex inverse (large negative imaginary components)', function test( t ) { + var qre; + var qim; + var re; + var im; + var i; + var q; + + re = largeNegativeImaginaryComponents.re; + im = largeNegativeImaginaryComponents.im; + qre = largeNegativeImaginaryComponents.qre; + qim = largeNegativeImaginaryComponents.qim; + + for ( i = 0; i < re.length; i++ ) { + q = cinvf( new Complex64( re[ i ], im[ i ] ) ); + + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes a complex inverse (large negative real components)', function test( t ) { + var qre; + var qim; + var re; + var im; + var i; + var q; + + re = largeNegativeRealComponents.re; + im = largeNegativeRealComponents.im; + qre = largeNegativeRealComponents.qre; + qim = largeNegativeRealComponents.qim; + + for ( i = 0; i < re.length; i++ ) { + q = cinvf( new Complex64( re[ i ], im[ i ] ) ); + + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes a complex inverse (large positive imaginary components)', function test( t ) { + var qre; + var qim; + var re; + var im; + var i; + var q; + + re = largePositiveImaginaryComponents.re; + im = largePositiveImaginaryComponents.im; + qre = largePositiveImaginaryComponents.qre; + qim = largePositiveImaginaryComponents.qim; + + for ( i = 0; i < re.length; i++ ) { + q = cinvf( new Complex64( re[ i ], im[ i ] ) ); + + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes a complex inverse (large positive real components)', function test( t ) { + var qre; + var qim; + var re; + var im; + var i; + var q; + + re = largePositiveRealComponents.re; + im = largePositiveRealComponents.im; + qre = largePositiveRealComponents.qre; + qim = largePositiveRealComponents.qim; + + for ( i = 0; i < re.length; i++ ) { + q = cinvf( new Complex64( re[ i ], im[ i ] ) ); + + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes a complex inverse (tiny negative imaginary components)', function test( t ) { + var qre; + var qim; + var re; + var im; + var i; + var q; + + re = tinyNegativeImaginaryComponents.re; + im = tinyNegativeImaginaryComponents.im; + qre = tinyNegativeImaginaryComponents.qre; + qim = tinyNegativeImaginaryComponents.qim; + + for ( i = 0; i < re.length; i++ ) { + q = cinvf( new Complex64( re[ i ], im[ i ] ) ); + + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes a complex inverse (tiny negative real components)', function test( t ) { + var qre; + var qim; + var re; + var im; + var i; + var q; + + re = tinyNegativeRealComponents.re; + im = tinyNegativeRealComponents.im; + qre = tinyNegativeRealComponents.qre; + qim = tinyNegativeRealComponents.qim; + + for ( i = 0; i < re.length; i++ ) { + q = cinvf( new Complex64( re[ i ], im[ i ] ) ); + + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes a complex inverse (tiny positive imaginary components)', function test( t ) { + var qre; + var qim; + var re; + var im; + var i; + var q; + + re = tinyPositiveImaginaryComponents.re; + im = tinyPositiveImaginaryComponents.im; + qre = tinyPositiveImaginaryComponents.qre; + qim = tinyPositiveImaginaryComponents.qim; + + for ( i = 0; i < re.length; i++ ) { + q = cinvf( new Complex64( re[ i ], im[ i ] ) ); + + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function computes a complex inverse (tiny positive real components)', function test( t ) { + var qre; + var qim; + var re; + var im; + var i; + var q; + + re = tinyPositiveRealComponents.re; + im = tinyPositiveRealComponents.im; + qre = tinyPositiveRealComponents.qre; + qim = tinyPositiveRealComponents.qim; + + for ( i = 0; i < re.length; i++ ) { + q = cinvf( new Complex64( re[ i ], im[ i ] ) ); + + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function may overflow', function test( t ) { + var v; + + v = cinvf( new Complex64( 5.0e-40, 5.0e-40 ) ); + t.strictEqual( realf( v ), PINF, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); + + v = cinvf( new Complex64( -5.0e-40, 5.0e-40 ) ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); + + v = cinvf( new Complex64( -5.0e-40, -5.0e-40 ) ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), PINF, 'returns expected value' ); + + v = cinvf( new Complex64( 5.0e-40, -5.0e-40 ) ); + t.strictEqual( realf( v ), PINF, 'returns expected value' ); + t.strictEqual( imagf( v ), PINF, 'returns expected value' ); + + v = cinvf( new Complex64( 0.0, 5.0e-40 ) ); + t.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), NINF, 'returns expected value' ); + + v = cinvf( new Complex64( 0.0, -5.0e-40 ) ); + t.strictEqual( realf( v ), 0.0, 'returns expected value' ); + t.strictEqual( imagf( v ), PINF, 'returns expected value' ); + + v = cinvf( new Complex64( 5.0e-40, 0.0 ) ); + t.strictEqual( realf( v ), PINF, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); + + v = cinvf( new Complex64( -5.0e-40, 0.0 ) ); + t.strictEqual( realf( v ), NINF, 'returns expected value' ); + t.strictEqual( imagf( v ), 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', function test( t ) { + var v; + + v = cinvf( new Complex64( NaN, 3.0 ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); + + v = cinvf( new Complex64( 5.0, NaN ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); + + v = cinvf( new Complex64( NaN, NaN ) ); + t.strictEqual( isnanf( realf( v ) ), true, 'returns expected value' ); + t.strictEqual( isnanf( imagf( v ) ), true, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.native.js index 142e629c7950..9d75ce795e8d 100644 --- a/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.native.js @@ -30,8 +30,8 @@ var NINF = require( '@stdlib/constants/float32/ninf' ); var Complex64 = require( '@stdlib/complex/float32/ctor' ); var realf = require( '@stdlib/complex/float32/real' ); var imagf = require( '@stdlib/complex/float32/imag' ); -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); -var isAlmostSameValue = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var isAlmostSameValuef = require( '@stdlib/number/float32/base/assert/is-almost-same-value' ); var tryRequire = require( '@stdlib/utils/try-require' ); @@ -68,8 +68,8 @@ tape( 'the function computes the inverse of a single-precision complex floating- var v; v = cinvf( new Complex64( 2.0, 4.0 ) ); - t.strictEqual( realf( v ), float64ToFloat32( 0.1 ), 'returns expected value' ); - t.strictEqual( imagf( v ), float64ToFloat32( -0.2 ), 'returns expected value' ); + t.strictEqual( realf( v ), f32( 0.1 ), 'returns expected value' ); + t.strictEqual( imagf( v ), f32( -0.2 ), 'returns expected value' ); t.end(); }); @@ -89,8 +89,8 @@ tape( 'the function computes a complex inverse', opts, function test( t ) { for ( i = 0; i < re.length; i++ ) { q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); } t.end(); }); @@ -111,8 +111,8 @@ tape( 'the function computes a complex inverse (large negative imaginary compone for ( i = 0; i < re.length; i++ ) { q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -133,8 +133,8 @@ tape( 'the function computes a complex inverse (large negative real components)' for ( i = 0; i < re.length; i++ ) { q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -155,8 +155,8 @@ tape( 'the function computes a complex inverse (large positive imaginary compone for ( i = 0; i < re.length; i++ ) { q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -177,8 +177,8 @@ tape( 'the function computes a complex inverse (large positive real components)' for ( i = 0; i < re.length; i++ ) { q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -199,8 +199,8 @@ tape( 'the function computes a complex inverse (tiny negative imaginary componen for ( i = 0; i < re.length; i++ ) { q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); } t.end(); }); @@ -221,8 +221,8 @@ tape( 'the function computes a complex inverse (tiny negative real components)', for ( i = 0; i < re.length; i++ ) { q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); @@ -243,8 +243,8 @@ tape( 'the function computes a complex inverse (tiny positive imaginary componen for ( i = 0; i < re.length; i++ ) { q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 2 ), true, 'returns expected value' ); } t.end(); }); @@ -265,8 +265,8 @@ tape( 'the function computes a complex inverse (tiny positive real components)', for ( i = 0; i < re.length; i++ ) { q = cinvf( new Complex64( re[ i ], im[ i ] ) ); - t.strictEqual( isAlmostSameValue( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); - t.strictEqual( isAlmostSameValue( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( realf( q ), qre[ i ], 2 ), true, 'returns expected value' ); + t.strictEqual( isAlmostSameValuef( imagf( q ), qim[ i ], 1 ), true, 'returns expected value' ); } t.end(); }); diff --git a/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.strided.js b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.strided.js new file mode 100644 index 000000000000..6cf4fa7fe3b4 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/cinvf/test/test.strided.js @@ -0,0 +1,212 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var Float32Array = require( '@stdlib/array/float32' ); +var cinvf = require( './../lib/strided.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cinvf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes the inverse of a single-precision complex floating-point number', function test( t ) { + var expected; + var out; + var z; + var v; + + z = new Float32Array( [ 2.0, 4.0 ] ); + out = new Float32Array( 2 ); + v = cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ 0.1, -0.2 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 2.0, 0.0, 4.0, 0.0 ] ); + out = new Float32Array( 4 ); + v = cinvf( z, 2, 0, out, 2, 0 ); + + expected = new Float32Array( [ 0.1, 0.0, -0.2, 0.0 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, 2.0, 0.0, 4.0 ] ); + out = new Float32Array( 4 ); + v = cinvf( z, 2, 1, out, 2, 1 ); + + expected = new Float32Array( [ 0.0, 0.1, 0.0, -0.2 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 4.0, 2.0 ] ); + out = new Float32Array( 4 ); + v = cinvf( z, -1, 1, out, -2, 3 ); + + expected = new Float32Array( [ 0.0, -0.2, 0.0, 0.1 ] ); + + t.strictEqual( v, out, 'returns expected value' ); + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes a complex inverse', function test( t ) { + var expected; + var out; + var z; + + z = new Float32Array( [ 2.0, 2.0 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ 0.25, -0.25 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 4.0, 0.0 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ 0.25, -0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, 2.0 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ 0.0, -0.5 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function may overflow', function test( t ) { + var expected; + var out; + var z; + + z = new Float32Array( [ 5.0e-40, 5.0e-40 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ PINF, NINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ -5.0e-40, 5.0e-40 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ NINF, NINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ -5.0e-40, -5.0e-40 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ NINF, PINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 5.0e-40, -5.0e-40 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ PINF, PINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, 5.0e-40 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ 0.0, NINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 0.0, -5.0e-40 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ 0.0, PINF ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ 5.0e-40, 0.0 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ PINF, -0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + z = new Float32Array( [ -5.0e-40, 0.0 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + + expected = new Float32Array( [ NINF, -0.0 ] ); + + t.strictEqual( isSameFloat32Array( out, expected ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', function test( t ) { + var out; + var z; + + z = new Float32Array( [ NaN, 3.0 ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + z = new Float32Array( [ 5.0, NaN ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + z = new Float32Array( [ NaN, NaN ] ); + out = new Float32Array( 2 ); + cinvf( z, 1, 0, out, 1, 0 ); + t.strictEqual( isnanf( out[ 0 ] ), true, 'returns expected value' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'returns expected value' ); + + t.end(); +});