Skip to content

Commit 43119d6

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

32 files changed

+2858
-0
lines changed

Diff for: lib/node_modules/@stdlib/blas/base/dcabs1/README.md

+186
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+
# dcabs1
22+
23+
> Compute the sum of the [absolute values][absolute-value] of the real part and imaginary components of a double-precision [complex][@stdlib/complex/float64/ctor] floating-point number.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dcabs1 = require( '@stdlib/blas/base/dcabs1' );
31+
```
32+
33+
#### dcabs1( z )
34+
35+
Computes the sum of the [absolute values][absolute-value] of the real part and imaginary components of a double-precision [complex][@stdlib/complex/float64/ctor] floating-point number.
36+
37+
```javascript
38+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
39+
40+
var y = dcabs1( new Complex128( 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 Complex128 = require( '@stdlib/complex/float64/ctor' );
56+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
57+
var dcabs1 = require( '@stdlib/blas/base/dcabs1' );
58+
59+
var z;
60+
var i;
61+
for ( i = 0; i < 100; i++ ) {
62+
z = new Complex128( discreteUniform( -5, 5 ), discreteUniform( -5, 5 ) );
63+
console.log( 'dcabs1(%s) = %d', z.toString(), dcabs1( z ) );
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/dcabs1.h"
95+
```
96+
97+
#### c_dcabs1( z )
98+
99+
Computes the sum of the [absolute values][absolute-value] of the real and imaginary components of a double-precision [complex][@stdlib/complex/float64/ctor] floating-point number.
100+
101+
```c
102+
#include "stdlib/complex/float64/ctor.h"
103+
104+
const stdlib_complex128_t c = stdlib_complex128( 5.0, -3.0 );
105+
106+
double y = c_dcabs1( z );
107+
// returns 8.0
108+
```
109+
110+
The function accepts the following arguments:
111+
112+
- **z**: `[in] stdlib_complex128_t` complex number.
113+
114+
```c
115+
double c_dcabs1( const stdlib_complex128_t z );
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/dcabs1.h"
138+
#include "stdlib/complex/float64/ctor.h"
139+
#include "stdlib/complex/real.h"
140+
#include "stdlib/complex/imag.h"
141+
#include <stdio.h>
142+
143+
int main( void ) {
144+
const stdlib_complex128_t x[] = {
145+
stdlib_complex128( 3.14, 1.0 ),
146+
stdlib_complex128( -3.14, -1.0 ),
147+
stdlib_complex128( 0.0, 0.0 ),
148+
stdlib_complex128( 0.0/0.0, 0.0/0.0 )
149+
};
150+
151+
float y;
152+
int i;
153+
for ( i = 0; i < 4; i++ ) {
154+
y = c_dcabs1( x[ i ] );
155+
printf( "f(%lf + %lf) = %lf\n", stdlib_real( x[ i ] ), stdlib_imag( 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/float64/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64/ctor
183+
184+
</section>
185+
186+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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' ).factory;
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
27+
var pkg = require( './../package.json' ).name;
28+
var dcabs1 = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var rand = discreteUniform( -500.0, 500.0 );
34+
35+
36+
// MAIN //
37+
38+
bench( pkg, function benchmark( b ) {
39+
var values;
40+
var y;
41+
var i;
42+
43+
values = [
44+
new Complex128( rand(), rand() ),
45+
new Complex128( rand(), rand() )
46+
];
47+
48+
b.tic();
49+
for ( i = 0; i < b.iterations; i++ ) {
50+
y = dcabs1( values[ i%values.length ] );
51+
if ( isnan( y ) ) {
52+
b.fail( 'should not return NaN' );
53+
}
54+
}
55+
b.toc();
56+
if ( isnan( y ) ) {
57+
b.fail( 'should not return NaN' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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' ).factory;
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
28+
var tryRequire = require( '@stdlib/utils/try-require' );
29+
var pkg = require( './../package.json' ).name;
30+
31+
32+
// VARIABLES //
33+
34+
var dcabs1 = tryRequire( resolve( __dirname, './../lib/native.js' ) );
35+
var opts = {
36+
'skip': ( dcabs1 instanceof Error )
37+
};
38+
var rand = discreteUniform( -500.0, 500.0 );
39+
40+
41+
// MAIN //
42+
43+
bench( pkg+'::native', opts, function benchmark( b ) {
44+
var values;
45+
var y;
46+
var i;
47+
48+
values = [
49+
new Complex128( rand(), rand() ),
50+
new Complex128( rand(), rand() )
51+
];
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
y = dcabs1( values[ i%values.length ] );
56+
if ( isnan( y ) ) {
57+
b.fail( 'should not return NaN' );
58+
}
59+
}
60+
b.toc();
61+
if ( isnan( y ) ) {
62+
b.fail( 'should not return NaN' );
63+
}
64+
b.pass( 'benchmark finished' );
65+
b.end();
66+
});

0 commit comments

Comments
 (0)