Skip to content

Commit 9b6c5a6

Browse files
aman-095kgryte
andcommitted
feat: add blas/base/scabs1
PR-URL: stdlib-js#2209 Ref: stdlib-js#2039 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent ba7014f commit 9b6c5a6

32 files changed

+2854
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# scabs1
22+
23+
> 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.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var scabs1 = require( '@stdlib/blas/base/scabs1' );
31+
```
32+
33+
#### scabs1( z )
34+
35+
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.
36+
37+
```javascript
38+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
39+
40+
var y = scabs1( new Complex64( 5.0, -3.0 ) );
41+
// returns 8.0
42+
```
43+
44+
</section>
45+
46+
<!-- /.usage -->
47+
48+
<section class="examples">
49+
50+
## Examples
51+
52+
<!-- eslint no-undef: "error" -->
53+
54+
```javascript
55+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
56+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
57+
var scabs1 = require( '@stdlib/blas/base/scabs1' );
58+
59+
var c;
60+
var i;
61+
for ( i = 0; i < 100; i++ ) {
62+
c = new Complex64( discreteUniform( -50, 50 ), discreteUniform( -50, 50 ) );
63+
console.log( 'scabs1(%s) = %d', c.toString(), scabs1( c ) );
64+
}
65+
```
66+
67+
</section>
68+
69+
<!-- /.examples -->
70+
71+
<!-- C interface documentation. -->
72+
73+
* * *
74+
75+
<section class="c">
76+
77+
## C APIs
78+
79+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
80+
81+
<section class="intro">
82+
83+
</section>
84+
85+
<!-- /.intro -->
86+
87+
<!-- C usage documentation. -->
88+
89+
<section class="usage">
90+
91+
### Usage
92+
93+
```c
94+
#include "stdlib/blas/base/scabs1.h"
95+
```
96+
97+
#### c_scabs1( c )
98+
99+
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.
100+
101+
```c
102+
#include "stdlib/complex/float32/ctor.h"
103+
104+
const stdlib_complex64_t c = stdlib_complex64( 5.0f, -3.0f );
105+
106+
float y = c_scabs1( c );
107+
// returns 8.0f
108+
```
109+
110+
The function accepts the following arguments:
111+
112+
- **c**: `[in] stdlib_complex64_t` complex number.
113+
114+
```c
115+
float c_scabs1( const stdlib_complex64_t c );
116+
```
117+
118+
</section>
119+
120+
<!-- /.usage -->
121+
122+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
123+
124+
<section class="notes">
125+
126+
</section>
127+
128+
<!-- /.notes -->
129+
130+
<!-- C API usage examples. -->
131+
132+
<section class="examples">
133+
134+
### Examples
135+
136+
```c
137+
#include "stdlib/blas/base/scabs1.h"
138+
#include "stdlib/complex/float32/ctor.h"
139+
#include "stdlib/complex/realf.h"
140+
#include "stdlib/complex/imagf.h"
141+
#include <stdio.h>
142+
143+
int main( void ) {
144+
const stdlib_complex64_t x[] = {
145+
stdlib_complex64( 3.14f, 1.0f ),
146+
stdlib_complex64( -3.14f, -1.0f ),
147+
stdlib_complex64( 0.0f, 0.0f ),
148+
stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f )
149+
};
150+
151+
float y;
152+
int i;
153+
for ( i = 0; i < 4; i++ ) {
154+
y = c_scabs1( x[ i ] );
155+
printf( "f(%f + %f) = %f\n", stdlib_realf( x[ i ] ), stdlib_imagf( x[ i ] ), y );
156+
}
157+
}
158+
```
159+
160+
</section>
161+
162+
<!-- /.examples -->
163+
164+
</section>
165+
166+
<!-- /.c -->
167+
168+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
169+
170+
<section class="related">
171+
172+
</section>
173+
174+
<!-- /.related -->
175+
176+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
177+
178+
<section class="links">
179+
180+
[absolute-value]: https://en.wikipedia.org/wiki/Absolute_value
181+
182+
[@stdlib/complex/float32/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float32/ctor
183+
184+
</section>
185+
186+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
27+
var pkg = require( './../package.json' ).name;
28+
var scabs1 = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var values;
35+
var y;
36+
var i;
37+
38+
values = [
39+
new Complex64( discreteUniform( -500.0, 500.0 ), discreteUniform( -500.0, 500.0 ) ), // eslint-disable-line max-len
40+
new Complex64( discreteUniform( -500.0, 500.0 ), discreteUniform( -500.0, 500.0 ) ) // eslint-disable-line max-len
41+
];
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
y = scabs1( values[ i%values.length ] );
46+
if ( isnan( y ) ) {
47+
b.fail( 'should not return NaN' );
48+
}
49+
}
50+
b.toc();
51+
if ( isnan( y ) ) {
52+
b.fail( 'should not return NaN' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
28+
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var pkg = require( './../package.json' ).name;
30+
31+
32+
// VARIABLES //
33+
34+
var scabs1 = tryRequire( resolve( __dirname, './../lib/native.js' ) );
35+
var opts = {
36+
'skip': ( scabs1 instanceof Error )
37+
};
38+
39+
40+
// MAIN //
41+
42+
bench( pkg+'::native', opts, function benchmark( b ) {
43+
var values;
44+
var y;
45+
var i;
46+
47+
values = [
48+
new Complex64( discreteUniform( -500.0, 500.0 ), discreteUniform( -500.0, 500.0 ) ), // eslint-disable-line max-len
49+
new Complex64( discreteUniform( -500.0, 500.0 ), discreteUniform( -500.0, 500.0 ) ) // eslint-disable-line max-len
50+
];
51+
52+
b.tic();
53+
for ( i = 0; i < b.iterations; i++ ) {
54+
y = scabs1( values[ i%values.length ] );
55+
if ( isnan( y ) ) {
56+
b.fail( 'should not return NaN' );
57+
}
58+
}
59+
b.toc();
60+
if ( isnan( y ) ) {
61+
b.fail( 'should not return NaN' );
62+
}
63+
b.pass( 'benchmark finished' );
64+
b.end();
65+
});

0 commit comments

Comments
 (0)