Skip to content

feat: add assign and strided methods to csignumf #7331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
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
42 changes: 28 additions & 14 deletions lib/node_modules/@stdlib/math/base/special/csignumf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -22,16 +22,12 @@ limitations under the License.

> Evaluate the [signum][signum] function of a single-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. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage
Expand Down Expand Up @@ -77,26 +73,44 @@ im = imag( v );
// returns NaN
```

</section>
#### csignumf.assign( re, im, out, strideOut, offsetOut )

<!-- /.usage -->
Evaluates the signum function and assigns the result to a provided output array.

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
```javascript
var Float32Array = require( '@stdlib/array/float32' );

<section class="notes">
var out = new Float32Array( 2 );
var v = csignumf.assign( -4.2, 5.5, out, 1, 0 );
// returns <Float32Array>[ ~-0.607, ~0.795 ]

</section>
var bool = ( out === v );
// returns true
```

<!-- /.notes -->
#### csignumf.strided( z, sz, oz, out, so, oo )

<!-- Package usage examples. -->
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 <Float32Array>[ ~-0.607, ~0.795 ]

var bool = ( out === v );
// returns true
```

</section>

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var Complex64 = require( '@stdlib/complex/float32/ctor' );
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
Original file line number Diff line number Diff line change
@@ -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();
});
89 changes: 83 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/csignumf/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -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
----------
Expand All @@ -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}}
<Function>
> var realf = {{alias:@stdlib/complex/float32/real}}
<Function>
> var imagf = {{alias:@stdlib/complex/float32/imag}}
<Function>
> var v = {{alias}}( new Complex64( -4.2, 5.5 ) )
<Complex64>
> 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 )
<Float32Array>[ ~-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 )
<Float32Array>[ ~-0.607, ~0.795 ]


See Also
--------

Loading
Loading