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 15 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
57 changes: 46 additions & 11 deletions lib/node_modules/@stdlib/math/base/special/csignumf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,19 +73,58 @@ im = imag( v );
// returns NaN
```

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

<!-- /.usage -->
Evaluates the signum function of single-precision complex floating-point number and assigns the result to a provided output array.

```javascript
var Float32Array = require( '@stdlib/array/float32' );

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
var out = new Float32Array( 2 );
var v = csignumf.assign( -4.2, 5.5, out, 1, 0 );
// returns <Float32Array>[ ~-0.607, ~0.795 ]

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

</section>
The function supports the following parameters:

<!-- /.notes -->
- **re**: real component of the complex number.
- **im**: imaginary component of the complex number.
- **out**: output array.
- **strideOut**: stride length for `out`.
- **offsetOut**: starting index for `out`.

#### csignumf.strided( z, sz, oz, out, so, oo )

<!-- Package usage examples. -->
Evaluates the signum function for single-precision complex floating-point number 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
```

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 -->

<section class="examples">

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();
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,76 @@
> var im = {{alias:@stdlib/complex/float32/imag}}( v )
~0.795

See Also

{{alias}}.assign( re, im, out, strideOut, offsetOut )
Evaluates the signum function of a single-precision floating-point complex
number and assigns results to a provided output array.

Parameters
----------
re: number
Real component of the complex number.

im: number
Imaginary component of the complex number.

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( -4.2, 5.5, out, 1, 0 )
<Float32Array>[ ~-0.607, ~0.795 ]


{{alias}}.strided( z, sz, oz, out, so, oo )
Evaluates the signum function of a single-precision floating-point complex
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}}( [ -4.2, 5.5 ] );
> var out = new {{alias:@stdlib/array/float32}}( 2 );
> {{alias}}.strided( z, 1, 0, out, 1, 0 )
<Float32Array>[ ~-0.607, ~0.795 ]

See Also
--------
Loading