diff --git a/lib/node_modules/@stdlib/math/base/special/csignumf/README.md b/lib/node_modules/@stdlib/math/base/special/csignumf/README.md index cb5d79226780..ba3d957e9dd3 100644 --- a/lib/node_modules/@stdlib/math/base/special/csignumf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2025 The Stdlib Authors. +Copyright (c) 2018 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,16 +22,12 @@ limitations under the License. > Evaluate the [signum][signum] function of a single-precision complex floating-point number. - -
- -
## Usage @@ -77,26 +73,44 @@ im = imag( v ); // returns NaN ``` -
+#### csignumf.assign( re, im, out, strideOut, offsetOut ) - +Evaluates the signum function and assigns the result to a provided output array. - +```javascript +var Float32Array = require( '@stdlib/array/float32' ); -
+var out = new Float32Array( 2 ); +var v = csignumf.assign( -4.2, 5.5, out, 1, 0 ); +// returns [ ~-0.607, ~0.795 ] -
+var bool = ( out === v ); +// returns true +``` - +#### csignumf.strided( z, sz, oz, out, so, oo ) - +Evaluates the signum function for single-precision complex numbers stored in a real-valued strided array and assigns results to a strided output array. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); + +var z = new Float32Array( [ -4.2, 5.5 ] ); +var out = new Float32Array( 2 ); + +var v = csignumf.strided( z, 1, 0, out, 1, 0 ); +// returns [ ~-0.607, ~0.795 ] + +var bool = ( out === v ); +// returns true +``` + +
## Examples - - ```javascript var uniform = require( '@stdlib/random/base/uniform' ).factory; var Complex64 = require( '@stdlib/complex/float32/ctor' ); diff --git a/lib/node_modules/@stdlib/math/base/special/csignumf/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/math/base/special/csignumf/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..f09c60f486b6 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/benchmark/benchmark.assign.js @@ -0,0 +1,69 @@ +/** +* @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. +*/ + +'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 pkg = require( './../package.json' ).name; +var csignumf = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// MAIN // + +bench( pkg+':assign', 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 = csignumf.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/csignumf/benchmark/benchmark.strided.js b/lib/node_modules/@stdlib/math/base/special/csignumf/benchmark/benchmark.strided.js new file mode 100644 index 000000000000..6342e1c41e23 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/benchmark/benchmark.strided.js @@ -0,0 +1,65 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float32Array = require( '@stdlib/array/float32' ); +var pkg = require( './../package.json' ).name; +var csignumf = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// MAIN // + +bench( pkg+':strided', 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 = csignumf.strided( z, 1, j, out, 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/csignumf/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/csignumf/docs/repl.txt index 7e43ca521e76..aee835511250 100644 --- a/lib/node_modules/@stdlib/math/base/special/csignumf/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/docs/repl.txt @@ -1,7 +1,6 @@ - {{alias}}( z ) - Evaluates the signum function of a single-precision complex floating-point - number. + Evaluates the signum function of a single-precision + complex floating-point number. Parameters ---------- @@ -15,13 +14,91 @@ Examples -------- - > var v = {{alias}}( new {{alias:@stdlib/complex/float32/ctor}}( -4.2, 5.5 ) ) + > var Complex64 = {{alias:@stdlib/complex/float32/ctor}} + + > var realf = {{alias:@stdlib/complex/float32/real}} + + > var imagf = {{alias:@stdlib/complex/float32/imag}} + + > var v = {{alias}}( new Complex64( -4.2, 5.5 ) ) - > var re = {{alias:@stdlib/complex/float32/real}}( v ) + > var re = realf( v ) ~-0.607 - > var im = {{alias:@stdlib/complex/float32/imag}}( v ) + > var im = imagf( v ) ~0.795 + +{{alias}}.assign( re, im, out, stride, offset ) + Evaluates the signum function and assigns the result to a + provided output array. + + Parameters + ---------- + re: number + Real component. + + im: number + Imaginary component. + + out: Float32Array + Output array. + + stride: integer + Output stride length. + + offset: integer + Starting index for output. + + Returns + ------- + out: Float32Array + Output array. + + Examples + -------- + > var out = new Float32Array( 2 ); + > {{alias}}.assign( -4.2, 5.5, out, 1, 0 ) + [ ~-0.607, ~0.795 ] + + +{{alias}}.strided( z, sz, oz, out, so, oo ) + Evaluates the signum function for single-precision complex numbers + stored in a real-valued strided input array and assigns + the results to a strided output array. + + Parameters + ---------- + z: Float32Array + Input array containing interleaved real and imaginary components. + + sz: integer + Input stride length. + + oz: integer + Starting index for input. + + out: Float32Array + Output array. + + so: integer + Output stride length. + + oo: integer + Starting index for output. + + Returns + ------- + out: Float32Array + Output array. + + Examples + -------- + > var z = new Float32Array( [ -4.2, 5.5 ] ); + > var out = new Float32Array( 2 ); + > {{alias}}.strided( z, 1, 0, out, 1, 0 ) + [ ~-0.607, ~0.795 ] + + See Also -------- diff --git a/lib/node_modules/@stdlib/math/base/special/csignumf/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/csignumf/docs/types/index.d.ts index 329284c21864..8aed67dbb6ed 100644 --- a/lib/node_modules/@stdlib/math/base/special/csignumf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/docs/types/index.d.ts @@ -21,6 +21,72 @@ /// import { Complex64 } from '@stdlib/types/complex'; +import { NumericArray, Collection } from '@stdlib/types/array'; + +/** +* Interface for evaluating the signum function of a single-precision complex number. +*/ +interface Csignumf { + /** + * Evaluates the signum function of a single-precision complex floating-point number. + * + * @param z - input value + * @returns result + * + * @example + * var Complex64 = require( '@stdlib/complex/float32/ctor' ); + * var v = csignumf( new Complex64( -4.0, 3.0 ) ); + * // returns + */ + ( z: Complex64 ): Complex64; + + /** + * Evaluates the signum function and assigns the result to a provided output array. + * + * @param re - real component of the input number + * @param im - imaginary component of the input number + * @param out - output array + * @param strideOut - output stride length + * @param offsetOut - starting index for the output + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var out = new Float32Array( 2 ); + * var v = csignumf.assign( 3.0, 4.0, out, 1, 0 ); + * // returns [ ~0.6, ~0.8 ] + */ + assign>( re: number, im: number, out: T, strideOut: number, offsetOut: number ): T; + + /** + * Evaluates the signum function for single-precision complex numbers in a strided input array and assigns the results to a strided output array. + * + * @param z - input array (interleaved real and imaginary values) + * @param strideZ - stride length for the input array + * @param offsetZ - starting index for the input array + * @param out - output array (interleaved real and imaginary values) + * @param strideOut - stride length for the output array + * @param offsetOut - starting index for the output array + * @returns output array + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * + * var z = new Float32Array( [ 3.0, 4.0 ] ); + * var out = new Float32Array( 2 ); + * csignumf.strided( z, 1, 0, out, 1, 0 ); + * // out => [ ~0.6, ~0.8 ] + */ + strided, U extends NumericArray | Collection>( + z: T, + strideZ: number, + offsetZ: number, + out: U, + strideOut: number, + offsetOut: number + ): U; +} /** * Evaluates the signum function of a single-precision complex floating-point number. @@ -30,19 +96,25 @@ import { Complex64 } from '@stdlib/types/complex'; * * @example * var Complex64 = require( '@stdlib/complex/float32/ctor' ); -* var real = require( '@stdlib/complex/float32/real' ); -* var imag = require( '@stdlib/complex/float32/imag' ); -* * var v = csignumf( new Complex64( -4.2, 5.5 ) ); * // returns * -* var re = real( v ); -* // returns ~-0.607 +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var out = new Float32Array( 2 ); +* var v = csignumf.assign( 3.0, 4.0, out, 1, 0 ); +* // returns [ ~0.6, ~0.8 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); * -* var im = imag( v ); -* // returns ~0.795 +* var z = new Float32Array( [ 3.0, 4.0 ] ); +* var out = new Float32Array( 2 ); +* csignumf.strided( z, 1, 0, out, 1, 0 ); +* // out => [ ~0.6, ~0.8 ] */ -declare function csignumf( z: Complex64 ): Complex64; +declare const csignumf: Csignumf; // EXPORTS // diff --git a/lib/node_modules/@stdlib/math/base/special/csignumf/docs/types/test.ts b/lib/node_modules/@stdlib/math/base/special/csignumf/docs/types/test.ts index b3befff79ae5..62d19e8cbde0 100644 --- a/lib/node_modules/@stdlib/math/base/special/csignumf/docs/types/test.ts +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/docs/types/test.ts @@ -1,4 +1,4 @@ -/* +/** * @license Apache-2.0 * * Copyright (c) 2025 The Stdlib Authors. @@ -22,12 +22,12 @@ import csignumf = require( './index' ); // TESTS // -// The function returns an array of numbers... +// The function returns a Complex64... { csignumf( 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... +// The compiler throws an error if the function is provided a value other than a Complex64... { csignumf( true ); // $ExpectError csignumf( false ); // $ExpectError @@ -43,3 +43,53 @@ import csignumf = require( './index' ); { csignumf(); // $ExpectError } + +// assign(): returns the same array type +{ + const out = new Float32Array( 2 ); + csignumf.assign( 1.0, 2.0, out, 1, 0 ); // $ExpectType Float32Array +} + +// assign(): accepts generic collections +{ + const out = [ 0.0, 0.0 ]; + csignumf.assign( 1.0, 2.0, out, 1, 0 ); // $ExpectType number[] +} + +// assign(): compiler errors for invalid args +{ + const out = new Float32Array( 2 ); + csignumf.assign( '1', 2.0, out, 1, 0 ); // $ExpectError + csignumf.assign( 1.0, true, out, 1, 0 ); // $ExpectError + csignumf.assign( 1.0, 2.0, {}, 1, 0 ); // $ExpectError + csignumf.assign( 1.0, 2.0, out, '1', 0 ); // $ExpectError + csignumf.assign( 1.0, 2.0, out, 1, '0' ); // $ExpectError + csignumf.assign(); // $ExpectError +} + +// strided(): returns the same array type as output +{ + const z = new Float32Array( [ 3.0, 4.0 ] ); + const out = new Float32Array( 2 ); + csignumf.strided( z, 2, 0, out, 2, 0 ); // $ExpectType Float32Array +} + +// strided(): accepts generic collections +{ + const z = [ 3.0, 4.0 ]; + const out = [ 0.0, 0.0 ]; + csignumf.strided( z, 2, 0, out, 2, 0 ); // $ExpectType number[] +} + +// strided(): compiler errors for invalid args +{ + const z = new Float32Array( 2 ); + const out = new Float32Array( 2 ); + csignumf.strided( 'z', 2, 0, out, 2, 0 ); // $ExpectError + csignumf.strided( z, true, 0, out, 2, 0 ); // $ExpectError + csignumf.strided( z, 2, {}, out, 2, 0 ); // $ExpectError + csignumf.strided( z, 2, 0, 42, 2, 0 ); // $ExpectError + csignumf.strided( z, 2, 0, out, '2', 0 ); // $ExpectError + csignumf.strided( z, 2, 0, out, 2, [] ); // $ExpectError + csignumf.strided(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/math/base/special/csignumf/lib/assign.js b/lib/node_modules/@stdlib/math/base/special/csignumf/lib/assign.js new file mode 100644 index 000000000000..8462749b8964 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/lib/assign.js @@ -0,0 +1,64 @@ +'use strict'; + +/** +* @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. +*/ + +// MODULES // + +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); +var csignumf = require( './main.js' ); + + +// MAIN // + +/** +* Evaluates the signum function for a single-precision complex number and assigns results to a strided output array. +* +* @param {number} re - real component +* @param {number} im - imaginary component +* @param {Collection} out - output array +* @param {integer} strideOut - stride length for output array +* @param {NonNegativeInteger} offsetOut - starting index for output array +* @returns {Collection} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* +* var out = assign( 3.0, -4.0, new Float32Array( 2 ), 1, 0 ); +* // returns [ 0.6000000238418579, -0.800000011920929 ] +*/ +function assign( re, im, out, strideOut, offsetOut ) { + var z = new Complex64( re, im ); + var v = csignumf( z ); + + re = float64ToFloat32( re ); + im = float64ToFloat32( im ); + + out[ offsetOut ] = real( v ); + out[ offsetOut + strideOut ] = imag( v ); + + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/math/base/special/csignumf/lib/index.js b/lib/node_modules/@stdlib/math/base/special/csignumf/lib/index.js index 6c012fe58fee..3b19fda51de3 100644 --- a/lib/node_modules/@stdlib/math/base/special/csignumf/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/lib/index.js @@ -59,9 +59,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/csignumf/lib/strided.js b/lib/node_modules/@stdlib/math/base/special/csignumf/lib/strided.js new file mode 100644 index 000000000000..3fc6e2d2a2b3 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/lib/strided.js @@ -0,0 +1,71 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +var real = require( '@stdlib/complex/float32/real' ); +var imag = require( '@stdlib/complex/float32/imag' ); +var csignumf = require( './main.js' ); + + +// MAIN // + +/** +* Computes the signum of a single-precision complex number stored in a real-valued strided array view and assigns the result to a provided strided output array. +* +* @param {Float32Array} z - complex number view (interleaved real and imaginary) +* @param {integer} sz - stride length for `z` +* @param {NonNegativeInteger} oz - starting index for `z` +* @param {Float32Array} out - output array +* @param {integer} so - stride length for `out` +* @param {NonNegativeInteger} oo - starting index for `out` +* @returns {Float32Array} output array +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var strided = require( '@stdlib/math/base/special/csignumf' ).strided; +* +* var z = new Float32Array( [ 3.0, 4.0 ] ); +* var out = new Float32Array( 2 ); +* +* strided( z, 1, 0, out, 1, 0 ); +* console.log( out ); +* // => [ ~0.6, ~0.8 ] +*/ +function strided( z, sz, oz, out, so, oo ) { + var result; + var re; + var im; + + re = z[ oz ]; + im = z[ oz + sz ]; + result = csignumf( new Complex64( re, im ) ); + + out[ oo ] = real( result ); + out[ oo + so ] = imag( result ); + + return out; +} + + +// EXPORTS // + +module.exports = strided; diff --git a/lib/node_modules/@stdlib/math/base/special/csignumf/test/test.assign.js b/lib/node_modules/@stdlib/math/base/special/csignumf/test/test.assign.js new file mode 100644 index 000000000000..195156e1ba13 --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/test/test.assign.js @@ -0,0 +1,135 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var csignumf = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof csignumf.assign, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function evaluates the signum function and writes to output array', function test( t ) { + var expectedRe = data.expected_re; + var expectedIm = data.expected_im; + var returned; + var output; + var delta; + var tol; + var re = data.re; + var im = data.im; + var i; + + for ( i = 0; i < re.length; i++ ) { + // Skip NaN cases for separate dedicated tests: + if ( isnanf( expectedRe[i] ) || isnanf( expectedIm[i] ) ) { + continue; + } + + output = new Float32Array( 2 ); + returned = csignumf.assign( re[i], im[i], output, 1, 0 ); + + t.ok( returned instanceof Float32Array, 'returns a Float32Array' ); + t.strictEqual( returned, output, 'returns same output array reference' ); + + if ( output[ 0 ] === expectedRe[ i ] && output[ 1 ] === expectedIm[ i ] ) { + t.strictEqual( output[ 0 ], expectedRe[ i ], 're: ' + re[ i ] + '. Expected: ' + expectedRe[ i ] ); + t.strictEqual( output[ 1 ], expectedIm[ i ], 'im: ' + im[ i ] + '. Expected: ' + expectedIm[ i ] ); + } else { + delta = absf( output[ 0 ] - expectedRe[ i ] ); + tol = EPS * absf( expectedRe[ i ] ); + t.ok( delta <= tol, 'within tolerance. re: ' + re[ i ] + '. Expected: ' + expectedRe[ i ] + '. Actual: ' + output[ 0 ] + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + + delta = absf( output[ 1 ] - expectedIm[ i ] ); + tol = EPS * absf( expectedIm[ i ] ); + t.ok( delta <= tol, 'within tolerance. im: ' + im[ i ] + '. Expected: ' + expectedIm[ i ] + '. Actual: ' + output[ 1 ] + '. Δ: ' + delta + '. tol: ' + tol + '.' ); + } + } + t.end(); +}); + +tape( 'the function returns NaNs if either input is NaN', function test( t ) { + var returned; + var outNaN; + + outNaN = new Float32Array( 2 ); + returned = csignumf.assign( NaN, NaN, outNaN, 1, 0 ); + + t.ok( returned instanceof Float32Array, 'returns a Float32Array' ); + t.strictEqual( returned, outNaN, 'returns same output array reference' ); + t.strictEqual( isnanf( outNaN[ 0 ] ), true, 'real is NaN' ); + t.strictEqual( isnanf( outNaN[ 1 ] ), true, 'imag is NaN' ); + t.end(); +}); + +tape( 'the function returns +0 if input is +0 +0i', function test( t ) { + var outPosZero = new Float32Array( 2 ); + csignumf.assign( +0.0, +0.0, outPosZero, 1, 0 ); + + t.strictEqual( isPositiveZerof( outPosZero[ 0 ] ), true, 'real is +0' ); + t.strictEqual( isPositiveZerof( outPosZero[ 1 ] ), true, 'imag is +0' ); + t.end(); +}); + +tape( 'the function returns -0 if input is -0 -0i', function test( t ) { + var outNegZero = new Float32Array( 2 ); + csignumf.assign( -0.0, -0.0, outNegZero, 1, 0 ); + + t.strictEqual( isNegativeZerof( outNegZero[ 0 ] ), true, 'real is -0' ); + t.strictEqual( isNegativeZerof( outNegZero[ 1 ] ), true, 'imag is -0' ); + t.end(); +}); + +tape( 'the function returns NaNs if input is infinity', function test( t ) { + var outInf = new Float32Array( 2 ); + csignumf.assign( PINF, PINF, outInf, 1, 0 ); + + t.strictEqual( isnanf( outInf[ 0 ] ), true, 'real is NaN' ); + t.strictEqual( isnanf( outInf[ 1 ] ), true, 'imag is NaN' ); + t.end(); +}); + +tape( 'the function returns NaNs if input is negative infinity', function test( t ) { + var outNegInf = new Float32Array( 2 ); + csignumf.assign( NINF, NINF, outNegInf, 1, 0 ); + + t.strictEqual( isnanf( outNegInf[ 0 ] ), true, 'real is NaN' ); + t.strictEqual( isnanf( outNegInf[ 1 ] ), true, 'imag is NaN' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/math/base/special/csignumf/test/test.strided.js b/lib/node_modules/@stdlib/math/base/special/csignumf/test/test.strided.js new file mode 100644 index 000000000000..f55e0a8dcfbd --- /dev/null +++ b/lib/node_modules/@stdlib/math/base/special/csignumf/test/test.strided.js @@ -0,0 +1,147 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var PINF = require( '@stdlib/constants/float32/pinf' ); +var NINF = require( '@stdlib/constants/float32/ninf' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var absf = require( '@stdlib/math/base/special/absf' ); +var isNegativeZerof = require( '@stdlib/math/base/assert/is-negative-zerof' ); +var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' ); +var Float32Array = require( '@stdlib/array/float32' ); +var csignumf = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof csignumf.strided, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function evaluates the signum function for complex numbers in strided arrays', function test( t ) { + var delta; + var out; + var tol; + var ere; + var eim; + var re; + var im; + var z; + var i; + + re = data.re; + im = data.im; + ere = data.expected_re; + eim = data.expected_im; + + for ( i = 0; i < re.length; i++ ) { + z = new Float32Array( 2 ); + z[ 0 ] = re[ i ]; + z[ 1 ] = im[ i ]; + + out = new Float32Array( 2 ); + csignumf.strided( z, 1, 0, out, 1, 0 ); + + if ( isnanf( ere[ i ] ) || isnanf( eim[ i ] ) ) { + t.strictEqual( isnanf( out[ 0 ] ), true, 're is NaN' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'im is NaN' ); + continue; + } + if ( out[ 0 ] === ere[ i ] && out[ 1 ] === eim[ i ] ) { + t.strictEqual( out[ 0 ], ere[ i ], 're: '+re[ i ]+'. Expected: '+ere[ i ] ); + t.strictEqual( out[ 1 ], eim[ i ], 'im: '+im[ i ]+'. Expected: '+eim[ i ] ); + } else { + delta = absf( out[ 0 ] - ere[ i ] ); + tol = EPS * absf( ere[ i ] ); + t.ok(delta <= tol, 'within tolerance. re: '+re[ i ]+'. Expected: '+ere[ i ]+'. Actual: '+out[ 0 ]+'. Δ: '+delta+'. tol: '+tol+'.'); + + delta = absf( out[ 1 ] - eim[ i ] ); + tol = EPS * absf( eim[ i ] ); + t.ok(delta <= tol, 'within tolerance. im: '+im[ i ]+'. Expected: '+eim[ i ]+'. Actual: '+out[ 1 ]+'. Δ: '+delta+'. tol: '+tol+'.'); + } + } + t.end(); +}); + +tape( 'the function returns +0 if provided +0 +0i', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ +0.0, +0.0 ] ); + + csignumf.strided( z, 1, 0, out, 1, 0 ); + + t.strictEqual( isPositiveZerof( out[ 0 ] ), true, 'real is +0' ); + t.strictEqual( isPositiveZerof( out[ 1 ] ), true, 'imag is +0' ); + + t.end(); +}); + +tape( 'the function returns -0 if provided -0 -0i', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ -0.0, -0.0 ] ); + + csignumf.strided( z, 1, 0, out, 1, 0 ); + + t.strictEqual( isNegativeZerof( out[ 0 ] ), true, 'real is -0' ); + t.strictEqual( isNegativeZerof( out[ 1 ] ), true, 'imag is -0' ); + + t.end(); +}); + +tape( 'the function returns NaNs if provided NaNs', function test( t ) { + var out = new Float32Array( 2 ); + var z = new Float32Array( [ NaN, NaN ] ); + + csignumf.strided( z, 1, 0, out, 1, 0 ); + + t.strictEqual( isnanf( out[ 0 ] ), true, 'real is NaN' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'imag is NaN' ); + + t.end(); +}); + +tape( 'the function returns NaNs if provided infinities', function test( t ) { + var out; + var z; + + z = new Float32Array( [ PINF, PINF ] ); + out = new Float32Array( 2 ); + csignumf.strided( z, 1, 0, out, 1, 0 ); + + t.strictEqual( isnanf( out[ 0 ] ), true, 'real is NaN' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'imag is NaN' ); + + z = new Float32Array( [ NINF, NINF ] ); + csignumf.strided( z, 1, 0, out, 1, 0 ); + + t.strictEqual( isnanf( out[ 0 ] ), true, 'real is NaN' ); + t.strictEqual( isnanf( out[ 1 ] ), true, 'imag is NaN' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/zeros/README.md b/lib/node_modules/@stdlib/ndarray/base/zeros/README.md index 1fae188a6ad4..6d56674c96d9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/zeros/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/zeros/README.md @@ -57,7 +57,7 @@ var dt = arr.dtype; The function accepts the following arguments: -- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be a numeric [data type][@stdlib/ndarray/dtypes] or "generic". +- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be a numeric [data type][@stdlib/ndarray/dtypes] or "generic". - **shape**: array shape. - **order**: specifies whether an [ndarray][@stdlib/ndarray/base/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style).