Skip to content

feat: add blas/base/scabs1 #2209

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

Merged
merged 27 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2e1edb9
feat: add BLAS routine for scabs1
aman-095 Apr 27, 2024
b113669
chore: apply review changes
aman-095 Apr 28, 2024
0420e6d
chore: apply changes to addon.c
aman-095 Apr 30, 2024
dd5fe0f
docs: update example and fix param name
kgryte Jun 5, 2024
ad59951
docs: update examples and descriptions
kgryte Jun 5, 2024
321ecf0
docs: fix variable name
kgryte Jun 5, 2024
dd0110a
style: add spaces
kgryte Jun 5, 2024
54213a0
style: fix missing space
kgryte Jun 5, 2024
2caedf0
docs: update C example
kgryte Jun 5, 2024
7a7cccd
docs: update description and example
kgryte Jun 5, 2024
be0c01e
docs: update descriptions
kgryte Jun 5, 2024
e45a6a7
chore: update keywords
kgryte Jun 6, 2024
f813218
build: fix missing dependencies
kgryte Jun 6, 2024
2d92608
style: re-enable lint rule
kgryte Jun 6, 2024
ffc5963
docs: update descriptions and fix copy-paste errors
kgryte Jun 6, 2024
757f6ad
docs: update description
kgryte Jun 6, 2024
c83f8a9
test: update tests to rely on exact equality
kgryte Jun 6, 2024
d807bbc
docs: update comment
kgryte Jun 6, 2024
5b13ce4
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into pr…
kgryte Jun 6, 2024
570ce03
refactor: update paths
kgryte Jun 6, 2024
8d8e966
fix: update function names
kgryte Jun 6, 2024
a37d108
chore: apply review changes
aman-095 Jun 6, 2024
d278267
docs: update comment
kgryte Jun 7, 2024
87de559
docs: add suffix
kgryte Jun 7, 2024
5982ccb
refactor: lowercase intrinsics and update declaration
kgryte Jun 7, 2024
4dd106c
docs: fix example
kgryte Jun 7, 2024
403e79d
fix: update build configurations
kgryte Jun 7, 2024
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
186 changes: 186 additions & 0 deletions lib/node_modules/@stdlib/blas/base/scabs1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<!--

@license Apache-2.0

Copyright (c) 2024 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.

-->

# scabs1

> Compute the sum of the [absolute values][absolute-value] of the real and imaginary components of a single-precision [complex][@stdlib/complex/float32/ctor] floating-point number.

<section class="usage">

## Usage

```javascript
var scabs1 = require( '@stdlib/blas/base/scabs1' );
```

#### scabs1( z )

Computes the sum of the [absolute values][absolute-value] of the real and imaginary components of a single-precision [complex][@stdlib/complex/float32/ctor] floating-point number.

```javascript
var Complex64 = require( '@stdlib/complex/float32/ctor' );

var y = scabs1( new Complex64( 5.0, -3.0 ) );
// returns 8.0
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

```javascript
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var scabs1 = require( '@stdlib/blas/base/scabs1' );

var c;
var i;
for ( i = 0; i < 100; i++ ) {
c = new Complex64( discreteUniform( -50, 50 ), discreteUniform( -50, 50 ) );
console.log( 'scabs1(%s) = %d', c.toString(), scabs1( c ) );
}
```

</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/blas/base/scabs1.h"
```

#### c_scabs1( c )

Computes the sum of the [absolute values][absolute-value] of the real and imaginary components of a single-precision [complex][@stdlib/complex/float32/ctor] floating-point number.

```c
#include "stdlib/complex/float32/ctor.h"

const stdlib_complex64_t c = stdlib_complex64( 5.0f, -3.0f );

float y = c_scabs1( c );
// returns 8.0f
```

The function accepts the following arguments:

- **c**: `[in] stdlib_complex64_t` complex number.

```c
float c_scabs1( const stdlib_complex64_t c );
```

</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/blas/base/scabs1.h"
#include "stdlib/complex/float32/ctor.h"
#include "stdlib/complex/realf.h"
#include "stdlib/complex/imagf.h"
#include <stdio.h>

int main( void ) {
const stdlib_complex64_t x[] = {
stdlib_complex64( 3.14f, 1.0f ),
stdlib_complex64( -3.14f, -1.0f ),
stdlib_complex64( 0.0f, 0.0f ),
stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f )
};

float y;
int i;
for ( i = 0; i < 4; i++ ) {
y = c_scabs1( x[ i ] );
printf( "f(%f + %f) = %f\n", stdlib_realf( x[ i ] ), stdlib_imagf( x[ i ] ), y );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[absolute-value]: https://en.wikipedia.org/wiki/Absolute_value

[@stdlib/complex/float32/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float32/ctor

</section>

<!-- /.links -->
56 changes: 56 additions & 0 deletions lib/node_modules/@stdlib/blas/base/scabs1/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var pkg = require( './../package.json' ).name;
var scabs1 = require( './../lib' );


// MAIN //

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

values = [
new Complex64( discreteUniform( -500.0, 500.0 ), discreteUniform( -500.0, 500.0 ) ), // eslint-disable-line max-len
new Complex64( discreteUniform( -500.0, 500.0 ), discreteUniform( -500.0, 500.0 ) ) // eslint-disable-line max-len
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = scabs1( values[ i%values.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
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) 2024 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 resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var scabs1 = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( scabs1 instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var values;
var y;
var i;

values = [
new Complex64( discreteUniform( -500.0, 500.0 ), discreteUniform( -500.0, 500.0 ) ), // eslint-disable-line max-len
new Complex64( discreteUniform( -500.0, 500.0 ), discreteUniform( -500.0, 500.0 ) ) // eslint-disable-line max-len
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = scabs1( values[ i%values.length ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading
Loading