-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
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 b113669
chore: apply review changes
aman-095 0420e6d
chore: apply changes to addon.c
aman-095 dd5fe0f
docs: update example and fix param name
kgryte ad59951
docs: update examples and descriptions
kgryte 321ecf0
docs: fix variable name
kgryte dd0110a
style: add spaces
kgryte 54213a0
style: fix missing space
kgryte 2caedf0
docs: update C example
kgryte 7a7cccd
docs: update description and example
kgryte be0c01e
docs: update descriptions
kgryte e45a6a7
chore: update keywords
kgryte f813218
build: fix missing dependencies
kgryte 2d92608
style: re-enable lint rule
kgryte ffc5963
docs: update descriptions and fix copy-paste errors
kgryte 757f6ad
docs: update description
kgryte c83f8a9
test: update tests to rely on exact equality
kgryte d807bbc
docs: update comment
kgryte 5b13ce4
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into pr…
kgryte 570ce03
refactor: update paths
kgryte 8d8e966
fix: update function names
kgryte a37d108
chore: apply review changes
aman-095 d278267
docs: update comment
kgryte 87de559
docs: add suffix
kgryte 5982ccb
refactor: lowercase intrinsics and update declaration
kgryte 4dd106c
docs: fix example
kgryte 403e79d
fix: update build configurations
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
lib/node_modules/@stdlib/blas/base/scabs1/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
65 changes: 65 additions & 0 deletions
65
lib/node_modules/@stdlib/blas/base/scabs1/benchmark/benchmark.native.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.