Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/cinvf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,55 @@ var v = cinvf( new Complex64( 2.0, 4.0 ) );
// returns <Complex64>[ ~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 <Float32Array>[ ~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 <Float32Array>[ ~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`.

</section>

<!-- /.usage -->
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#include <stdio.h>
#include <math.h>
#include <complex.h>
#include <time.h>
#include <sys/time.h>

#define NAME "inv"
#define NAME "cinvf"
#define ITERATIONS 1000000
#define REPEATS 3

Expand Down Expand Up @@ -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) );
}

/**
Expand All @@ -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;
Expand Down
Loading
Loading