Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jul 14, 2023
1 parent fba8f8f commit bdf23af
Show file tree
Hide file tree
Showing 27 changed files with 1,555 additions and 432 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

20 changes: 10 additions & 10 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ Bruno Fenzl <brunofenzl@gmail.com>
Christopher Dambamuromo <chridam@gmail.com>
Dominik Moritz <domoritz@gmail.com>
Frank Kovacs <fran70kk@gmail.com>
Harshita Kalani <95532771+HarshitaKalani@users.noreply.github.com>
James <jdgelok@gmail.com>
Harshita Kalani <harshitakalani02@gmail.com>
James Gelok <jdgelok@gmail.com>
Jithin KS <jithinks112@gmail.com>
Joey Reed <joeyrreed@gmail.com>
Jordan-Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com>
Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com>
Joris Labie <joris.labie1@gmail.com>
Justin Dennison <justin1dennison@gmail.com>
KATTA NAGA NITHIN <88046362+nithinkatta@users.noreply.github.com>
Marcus <mfantham@users.noreply.github.com>
Nithin Katta <88046362+nithinkatta@users.noreply.github.com>
Marcus Fantham <mfantham@users.noreply.github.com>
Matt Cochrane <matthew.cochrane.eng@gmail.com>
Milan Raj <rajsite@users.noreply.github.com>
Momtchil Momtchev <momtchil@momtchev.com>
Naresh Jagadeesan <37257700+Infinage@users.noreply.github.com>
Naresh Jagadeesan <naresh.naresh000@gmail.com>
Ognjen Jevremović <ognjenjevremovic@users.noreply.github.com>
Philipp Burckhardt <pburckhardt@outlook.com>
Pranav <85227306+Pranavchiku@users.noreply.github.com>
Pranav Goswami <goswami.4@iitj.ac.in>
Ricky Reusser <rsreusser@gmail.com>
Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com>
Ryan Seal <splrk@users.noreply.github.com>
Seyyed Parsa Neshaei <spneshaei@users.noreply.github.com>
Shraddheya Shendre <shendreshraddheya@gmail.com>
Stephannie Jiménez Gacha <steff456@hotmail.com>
Yernar Yergaziyev <yernar.yergaziyev@erg.kz>
dorrin-sot <59933477+dorrin-sot@users.noreply.github.com>
drunken_devv <90555965+amitjimiwal@users.noreply.github.com>
Dorrin Sotoudeh <dorrinsotoudeh123@gmail.com>
Amit Jimiwal <amitjimiwal45@gmail.com>
orimiles5 <97595296+orimiles5@users.noreply.github.com>
rei2hu <rei2hu@users.noreply.github.com>
rei2hu <reimu@reimu.ws>
176 changes: 143 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ limitations under the License.
-->

# Signum
# csignum

[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->

> Evaluate the [signum][signum] function of a complex number.
> Evaluate the [signum][signum] function of a double-precision complex floating-point number.
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

Expand Down Expand Up @@ -60,33 +60,41 @@ The [branches.md][branches-url] file summarizes the available branches and displ
var csignum = require( '@stdlib/math-base-special-csignum' );
```

#### csignum( \[out,] re, im )
#### csignum( z )

Evaluates the [signum][signum] function of a `complex` number comprised of a **real** component `re` and an **imaginary** component `im`.
Evaluates the [signum][signum] function of a double-precision complex floating-point number.

```javascript
var v = csignum( -4.2, 5.5 );
// returns [ -0.6069136033622302, 0.79476781392673 ]
var Complex128 = require( '@stdlib/complex-float64' );
var real = require( '@stdlib/complex-real' );
var imag = require( '@stdlib/complex-imag' );

v = csignum( 0.0, 0.0 );
// returns [ 0.0, 0.0 ]
var v = csignum( new Complex128( -4.2, 5.5 ) );
// returns <Complex128>

v = csignum( NaN, NaN );
// returns [ NaN, NaN ]
```
var re = real( v );
// returns -0.6069136033622302

By default, the function returns real and imaginary components as a two-element `array`. To avoid unnecessary memory allocation, the function supports providing an output (destination) object.
var im = imag( v );
// returns 0.79476781392673

```javascript
var Float64Array = require( '@stdlib/array-float64' );
v = csignum( new Complex128( 0.0, 0.0 ) );
// returns <Complex128>

var out = new Float64Array( 2 );
re = real( v );
// returns 0.0

var v = csignum( out, -4.2, 5.5 );
// returns <Float64Array>[ -0.6069136033622302, 0.79476781392673 ]
im = imag( v );
// returns 0.0

var bool = ( v === out );
// returns true
v = csignum( new Complex128( NaN, NaN ) );
// returns <Complex128>

re = real( v );
// returns NaN

im = imag( v );
// returns NaN
```

</section>
Expand All @@ -110,33 +118,135 @@ var bool = ( v === out );
<!-- eslint no-undef: "error" -->

```javascript
var uniform = require( '@stdlib/random-base-uniform' ).factory;
var Complex128 = require( '@stdlib/complex-float64' );
var randu = require( '@stdlib/random-base-randu' );
var real = require( '@stdlib/complex-real' );
var imag = require( '@stdlib/complex-imag' );
var csignum = require( '@stdlib/math-base-special-csignum' );

var re;
var im;
var rand = uniform( -50.0, 50.0 );

var z;
var o;
var w;
var i;

for ( i = 0; i < 100; i++ ) {
re = ( randu()*100.0 ) - 50.0;
im = ( randu()*100.0 ) - 50.0;
z = new Complex128( re, im );
o = csignum( real(z), imag(z) );
w = new Complex128( o[ 0 ], o[ 1 ] );
console.log( 'signum(%s) = %s', z.toString(), w.toString() );
z = new Complex128( rand(), rand() );
console.log( 'csignum(%s) = %s', z, csignum( z ) );
}
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/math/base/special/csignum.h"
```

#### stdlib_base_csignum( z )

Evaluates the [signum][signum] function of a double-precision complex floating-point number.

```c
#include "stdlib/complex/float64.h"
#include "stdlib/complex/real.h"
#include "stdlib/complex/imag.h"

stdlib_complex128_t z = stdlib_complex128( -4.2, 5.5 );

stdlib_complex128_t out = stdlib_base_csignum( z );

double re = stdlib_real( out );
// returns -0.6069136033622302

double im = stdlib_imag( out );
// returns 0.79476781392673
```

The function accepts the following arguments:

- **z**: `[in] stdlib_complex128_t` input value.

```c
stdlib_complex128_t stdlib_base_csignum( const stdlib_complex128_t z );
```
</section>
<!-- /.usage -->
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="notes">
</section>
<!-- /.notes -->
<!-- C API usage examples. -->
<section class="examples">
### Examples
```c
#include "stdlib/math/base/special/csignum.h"
#include "stdlib/complex/float64.h"
#include "stdlib/complex/reim.h"
#include <stdio.h>
int main( void ) {
const stdlib_complex128_t x[] = {
stdlib_complex128( 3.14, 1.5 ),
stdlib_complex128( -3.14, -1.5 ),
stdlib_complex128( 0.0, 0.0 ),
stdlib_complex128( 0.0/0.0, 0.0/0.0 )
};
stdlib_complex128_t v;
stdlib_complex128_t y;
double re1;
double im1;
double re2;
double im2;
int i;
for ( i = 0; i < 4; i++ ) {
v = x[ i ];
y = stdlib_base_csignum( v );
stdlib_reim( v, &re1, &im1 );
stdlib_reim( y, &re2, &im2 );
printf( "csignum(%lf + %lfi) = %lf + %lfi\n", re1, im1, re2, im2 );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">
Expand Down
104 changes: 14 additions & 90 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,113 +21,37 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random-base-randu' );
var isArray = require( '@stdlib/assert-is-array' );
var uniform = require( '@stdlib/random-base-uniform' );
var isnan = require( '@stdlib/math-base-assert-is-nan' );
var Complex128 = require( '@stdlib/complex-float64' );
var cabs = require( '@stdlib/math-base-special-cabs' );
var real = require( '@stdlib/complex-real' );
var imag = require( '@stdlib/complex-imag' );
var pkg = require( './../package.json' ).name;
var csignum = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var re;
var im;
var values;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
re = ( randu()*1000.0 ) - 500.0;
im = ( randu()*1000.0 ) - 500.0;
y = csignum( re, im );
if ( y.length === 0 ) {
b.fail( 'should not be empty' );
}
}
b.toc();
if ( !isArray( y ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::memory_reuse', function benchmark( b ) {
var out;
var re;
var im;
var y;
var i;

out = new Array( 2 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
re = ( randu()*1000.0 ) - 500.0;
im = ( randu()*1000.0 ) - 500.0;
y = csignum( out, re, im );
if ( y.length === 0 ) {
b.fail( 'should not be empty' );
}
}
b.toc();
if ( !isArray( y ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::manual', function benchmark( b ) {
var az;
var re;
var im;
var y;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
re = ( randu()*1000.0 ) - 500.0;
im = ( randu()*1000.0 ) - 500.0;
az = cabs( new Complex128( re, im ) );
y = [ re/az, im/az ];
if ( y.length === 0 ) {
b.fail( 'should not be empty' );
}
}
b.toc();
if ( !isArray( y ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::manual,memory_reuse', function benchmark( b ) {
var az;
var re;
var im;
var y;
var i;

y = new Array( 2 );
values = [
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
new Complex128( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
re = ( randu()*1000.0 ) - 500.0;
im = ( randu()*1000.0 ) - 500.0;
az = cabs( new Complex128( re, im ) );
y[ 0 ] = re / az;
y[ 1 ] = im / az;
if ( y.length === 0 ) {
b.fail( 'should not be empty' );
y = csignum( values[ i%values.length ] );
if ( isnan( real( y ) ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( !isArray( y ) ) {
b.fail( 'should return an array' );
if ( isnan( imag( y ) ) ) {
b.fail( 'should not return not NaN' );
}
b.pass( 'benchmark finished' );
b.end();
Expand Down
Loading

0 comments on commit bdf23af

Please sign in to comment.