Skip to content

Commit 723f4ad

Browse files
committed
feat: add complex/float32/base/identity
Ref: stdlib-js#2261 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent a8f5e17 commit 723f4ad

File tree

18 files changed

+1309
-0
lines changed

18 files changed

+1309
-0
lines changed
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2021 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+
# Identity Function
22+
23+
> Evaluate the [identity function][identity-function] of a single-precision [complex][@stdlib/complex/float32/ctor] floating-point number.
24+
25+
<section class="intro">
26+
27+
The [identity-function][identity-function] is defined as
28+
29+
<!-- <equation class="equation" label="eq:identity_function" align="center" raw="f(z) = z" alt="Identity function"> -->
30+
31+
```math
32+
f(z) = z
33+
```
34+
35+
<!-- <div class="equation" align="center" data-raw-text="f(z) = z" data-equation="eq:identity_function">
36+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@79c18caa8e6697ecbe8bcf813a8d54a470168a75/lib/node_modules/@stdlib/complex/float32/base/identity/docs/img/equation_identity_function.svg" alt="Identity function">
37+
<br>
38+
</div> -->
39+
40+
<!-- </equation> -->
41+
42+
for all `z`.
43+
44+
</section>
45+
46+
<!-- /.intro -->
47+
48+
<section class="usage">
49+
50+
## Usage
51+
52+
```javascript
53+
var cidentityf = require( '@stdlib/complex/float32/base/identity' );
54+
```
55+
56+
#### cidentityf( z )
57+
58+
Evaluates the [identity function][identity-function] for a single-precision [complex][@stdlib/complex/float32/ctor] floating-point number.
59+
60+
```javascript
61+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
62+
var real = require( '@stdlib/complex/float32/real' );
63+
var imag = require( '@stdlib/complex/float32/imag' );
64+
65+
var v = cidentityf( new Complex64( -1.0, 2.0 ) );
66+
// returns <Complex64>
67+
68+
var re = real( v );
69+
// returns -1.0
70+
71+
var im = imag( v );
72+
// returns 2.0
73+
```
74+
75+
</section>
76+
77+
<!-- /.usage -->
78+
79+
<section class="examples">
80+
81+
## Examples
82+
83+
<!-- eslint no-undef: "error" -->
84+
85+
```javascript
86+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
87+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
88+
var cidentityf = require( '@stdlib/complex/float32/base/identity' );
89+
90+
var z;
91+
var i;
92+
for ( i = 0; i < 100; i++ ) {
93+
z = new Complex64( discreteUniform( -50, 50 ), discreteUniform( -50, 50 ) );
94+
console.log( 'identity(%s) = %s', z, cidentityf( z ) );
95+
}
96+
```
97+
98+
</section>
99+
100+
<!-- /.examples -->
101+
102+
<!-- C interface documentation. -->
103+
104+
* * *
105+
106+
<section class="c">
107+
108+
## C APIs
109+
110+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
111+
112+
<section class="intro">
113+
114+
</section>
115+
116+
<!-- /.intro -->
117+
118+
<!-- C usage documentation. -->
119+
120+
<section class="usage">
121+
122+
### Usage
123+
124+
```c
125+
#include "stdlib/complex/float32/base/identity.h"
126+
```
127+
128+
#### stdlib_base_complex64_identity( z )
129+
130+
Evaluates the identity function for a single-precision complex floating-point number.
131+
132+
```c
133+
#include <complex.h>
134+
135+
float complex y = stdlib_base_complex64_identity( 2.0f+2.0f*I );
136+
// returns 2.0f+2.0f*I
137+
```
138+
139+
The function accepts the following arguments:
140+
141+
- **z**: `[in] float complex` input value.
142+
143+
```c
144+
float complex stdlib_base_complex64_identity( const float complex z );
145+
```
146+
147+
</section>
148+
149+
<!-- /.usage -->
150+
151+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
152+
153+
<section class="notes">
154+
155+
</section>
156+
157+
<!-- /.notes -->
158+
159+
<!-- C API usage examples. -->
160+
161+
<section class="examples">
162+
163+
### Examples
164+
165+
```c
166+
#include "stdlib/complex/float32/base/identity.h"
167+
#include <stdio.h>
168+
#include <complex.h>
169+
170+
int main( void ) {
171+
const float complex x[] = { 3.14f+1.0f*I, -3.14f-1.0f*I, 0.0f+0.0f*I, 0.0f/0.0f+0.0f/0.0f*I };
172+
173+
float complex v;
174+
float complex y;
175+
int i;
176+
for ( i = 0; i < 4; i++ ) {
177+
v = x[ i ];
178+
y = stdlib_base_complex64_identity( v );
179+
printf( "f(%f + %f) = %f + %f\n", crealf( v ), cimagf( v ), crealf( y ), cimagf( y ) );
180+
}
181+
}
182+
```
183+
184+
</section>
185+
186+
<!-- /.examples -->
187+
188+
</section>
189+
190+
<!-- /.c -->
191+
192+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
193+
194+
<section class="related">
195+
196+
* * *
197+
198+
## See Also
199+
200+
- <span class="package-name">[`@stdlib/complex/float64/base/identity`][@stdlib/complex/float64/base/identity]</span><span class="delimiter">: </span><span class="description">evaluate the identity function for a double-precision complex floating-point number.</span>
201+
- <span class="package-name">[`@stdlib/number/float32/base/identity`][@stdlib/number/float32/base/identity]</span><span class="delimiter">: </span><span class="description">evaluate the identity function for a single-precision floating-point number.</span>
202+
203+
</section>
204+
205+
<!-- /.related -->
206+
207+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
208+
209+
<section class="links">
210+
211+
[identity-function]: https://en.wikipedia.org/wiki/Identity_function
212+
213+
[@stdlib/complex/float32/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float32/ctor
214+
215+
<!-- <related-links> -->
216+
217+
[@stdlib/complex/float64/base/identity]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64/base/identity
218+
219+
[@stdlib/number/float32/base/identity]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/number/float32/base/identity
220+
221+
<!-- </related-links> -->
222+
223+
</section>
224+
225+
<!-- /.links -->
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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 uniform = require( '@stdlib/random/base/uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
27+
var real = require( '@stdlib/complex/float32/real' );
28+
var imag = require( '@stdlib/complex/float32/imag' );
29+
var pkg = require( './../package.json' ).name;
30+
var cidentityf = require( './../lib' );
31+
32+
33+
// MAIN //
34+
35+
bench( pkg, function benchmark( b ) {
36+
var values;
37+
var y;
38+
var i;
39+
40+
values = [
41+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) ),
42+
new Complex64( uniform( -500.0, 500.0 ), uniform( -500.0, 500.0 ) )
43+
];
44+
45+
b.tic();
46+
for ( i = 0; i < b.iterations; i++ ) {
47+
y = cidentityf( values[ i%values.length ] );
48+
if ( isnanf( real( y ) ) ) {
49+
b.fail( 'should not return NaN' );
50+
}
51+
}
52+
b.toc();
53+
if ( isnanf( imag( y ) ) ) {
54+
b.fail( 'should not return NaN' );
55+
}
56+
b.pass( 'benchmark finished' );
57+
b.end();
58+
});

0 commit comments

Comments
 (0)