Skip to content

Commit dd7189a

Browse files
committed
chore: stuff from code review
1 parent a67287b commit dd7189a

File tree

8 files changed

+54
-121
lines changed

8 files changed

+54
-121
lines changed

lib/node_modules/@stdlib/math/base/special/cabsf/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The [absolute value][absolute-value] of a [complex][@stdlib/complex/float32/ctor
3333
```
3434

3535
<!-- <div class="equation" align="center" data-raw-text="|a + bi| = \sqrt{a^2 + b^2}" data-equation="eq:absolute_value_complex">
36-
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@d4edb68b52a6c646be5683023c5a24890300727f/lib/node_modules/@stdlib/math/base/special/cabsf/docs/img/equation_absolute_value_complex.svg" alt="Absolute value">
36+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@462b40597988f604d5c05a46279cbb16105a24d3/lib/node_modules/@stdlib/math/base/special/cabsf/docs/img/equation_absolute_value_complex.svg" alt="Absolute value">
3737
<br>
3838
</div> -->
3939

@@ -55,7 +55,7 @@ var cabsf = require( '@stdlib/math/base/special/cabsf' );
5555

5656
#### cabsf( z )
5757

58-
Computes an [absolute value][absolute-value] of a single-precision [complex][@stdlib/complex/float32/ctor] floating-point number.
58+
Computes the [absolute value][absolute-value] of a single-precision [complex][@stdlib/complex/float32/ctor] floating-point number.
5959

6060
```javascript
6161
var Complex64 = require( '@stdlib/complex/float32/ctor' );
@@ -78,13 +78,16 @@ var y = cabsf( new Complex64( 5.0, 3.0 ) );
7878

7979
```javascript
8080
var Complex64 = require( '@stdlib/complex/float32/ctor' );
81-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
81+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
8282
var cabsf = require( '@stdlib/math/base/special/cabsf' );
8383

84+
// Create a PRNG to generate uniformly distributed pseudorandom integers:
85+
var rand = discreteUniform( -50, 50 );
86+
8487
var z;
8588
var i;
8689
for ( i = 0; i < 100; i++ ) {
87-
z = new Complex64( discreteUniform( -50, 50 ), discreteUniform( -50, 50 ) );
90+
z = new Complex64( rand(), rand() );
8891
console.log( 'cabsf(%s) = %d', z.toString(), cabsf( z ) );
8992
}
9093
```

lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/c/benchmark.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static double tic( void ) {
7878
*
7979
* @return random number
8080
*/
81-
static double rand_float( void ) {
81+
static float rand_float( void ) {
8282
int r = rand();
8383
return (float)r / ( (float)RAND_MAX + 1.0f );
8484
}
@@ -93,8 +93,8 @@ static double benchmark( void ) {
9393
double elapsed;
9494
float re;
9595
float im;
96-
float y;
9796
double t;
97+
float y;
9898
int i;
9999

100100
t = tic();

lib/node_modules/@stdlib/math/base/special/cabsf/benchmark/julia/benchmark.jl

Lines changed: 39 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# @license Apache-2.0
44
#
5-
# Copyright (c) 2024 The Stdlib Authors.
5+
# Copyright (c) 2021 The Stdlib Authors.
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
@@ -16,129 +16,58 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818

19-
import BenchmarkTools
20-
using Printf
21-
22-
# Benchmark variables:
23-
name = "cabsf";
24-
repeats = 3;
19+
import JSON
2520

2621
"""
27-
print_version()
28-
29-
Prints the TAP version.
22+
gen( re, im, name )
3023
31-
# Examples
32-
33-
``` julia
34-
julia> print_version()
35-
```
36-
"""
37-
function print_version()
38-
@printf( "TAP version 13\n" );
39-
end
40-
41-
"""
42-
print_summary( total, passing )
43-
44-
Print the benchmark summary.
24+
Generate fixture data and write to file.
4525
4626
# Arguments
4727
48-
* `total`: total number of tests
49-
* `passing`: number of passing tests
28+
* `re`: domain (real components)
29+
* `im`: domain (imaginary components)
30+
* `name::AbstractString`: output filename
5031
5132
# Examples
5233
5334
``` julia
54-
julia> print_summary( 3, 3 )
35+
julia> re = range( -1.0, stop = 1.0, length = 2001 );
36+
julia> im = range( -1.0, stop = 1.0, length = 2001 );
37+
julia> gen( re, im, \"data.json\" );
5538
```
5639
"""
57-
function print_summary( total, passing )
58-
@printf( "#\n" );
59-
@printf( "1..%d\n", total ); # TAP plan
60-
@printf( "# total %d\n", total );
61-
@printf( "# pass %d\n", passing );
62-
@printf( "#\n" );
63-
@printf( "# ok\n" );
64-
end
65-
66-
"""
67-
print_results( iterations, elapsed )
68-
69-
Print benchmark results.
70-
71-
# Arguments
72-
73-
* `iterations`: number of iterations
74-
* `elapsed`: elapsed time (in seconds)
75-
76-
# Examples
77-
78-
``` julia
79-
julia> print_results( 1000000, 0.131009101868 )
80-
```
81-
"""
82-
function print_results( iterations, elapsed )
83-
rate = iterations / elapsed
84-
85-
@printf( " ---\n" );
86-
@printf( " iterations: %d\n", iterations );
87-
@printf( " elapsed: %0.9f\n", elapsed );
88-
@printf( " rate: %0.9f\n", rate );
89-
@printf( " ...\n" );
90-
end
91-
92-
"""
93-
benchmark()
94-
95-
Run a benchmark.
96-
97-
# Notes
98-
99-
* Benchmark results are returned as a two-element array: [ iterations, elapsed ].
100-
* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation.
101-
* The elapsed time is in seconds.
102-
103-
# Examples
104-
105-
``` julia
106-
julia> out = benchmark();
107-
```
108-
"""
109-
function benchmark()
110-
t = BenchmarkTools.@benchmark abs( ComplexF32( (rand()*1000.0) - 500.0, (rand()*1000.0) - 500.0 ) ) samples=1e6
111-
112-
# Compute the total "elapsed" time and convert from nanoseconds to seconds:
113-
s = sum( t.times ) / 1.0e9;
114-
115-
# Determine the number of "iterations":
116-
iter = length( t.times );
40+
function gen( re, im, name )
41+
z = complex.( re, im );
42+
y = Array{Float32}( undef, length(z) );
43+
for i in eachindex(z)
44+
y[i] = abs( ComplexF32( z[i] ) );
45+
end
11746

118-
# Return the results:
119-
[ iter, s ];
47+
# Store data to be written to file as a collection:
48+
data = Dict([
49+
("re", re),
50+
("im", im),
51+
("expected", y)
52+
]);
53+
54+
# Based on the script directory, create an output filepath:
55+
filepath = joinpath( dir, name );
56+
57+
# Write the data to the output filepath as JSON:
58+
outfile = open( filepath, "w" );
59+
write( outfile, JSON.json(data) );
60+
write( outfile, "\n" );
61+
close( outfile );
12062
end
12163

122-
"""
123-
main()
124-
125-
Run benchmarks.
126-
127-
# Examples
64+
# Get the filename:
65+
file = @__FILE__;
12866

129-
``` julia
130-
julia> main();
131-
```
132-
"""
133-
function main()
134-
print_version();
135-
for i in 1:repeats
136-
@printf( "# julia::%s\n", name );
137-
results = benchmark();
138-
print_results( results[ 1 ], results[ 2 ] );
139-
@printf( "ok %d benchmark finished\n", i );
140-
end
141-
print_summary( repeats, repeats );
142-
end
67+
# Extract the directory in which this file resides:
68+
dir = dirname( file );
14369

144-
main();
70+
# Generate fixture data:
71+
re = range( -1000.0, stop = 1000.0, length = 2003 );
72+
im = range( -1000.0, stop = 1000.0, length = 2003 );
73+
gen( re, im, "data.json" );

lib/node_modules/@stdlib/math/base/special/cabsf/examples/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2021 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ var Complex64 = require( '@stdlib/complex/float32/ctor' );
2222
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
2323
var cabsf = require( './../lib' );
2424

25+
// Create a PRNG to generate uniformly distributed pseudorandom integers:
2526
var rand = discreteUniform( -50, 50 );
2627

2728
var z;

lib/node_modules/@stdlib/math/base/special/cabsf/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2021 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/math/base/special/cabsf/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var imag = require( '@stdlib/complex/float32/imag' );
2828
// MAIN //
2929

3030
/**
31-
* Computes the absolute value of a double-precision complex floating-point number.
31+
* Computes the absolute value of a single-precision complex floating-point number.
3232
*
3333
* @param {Complex64} z - complex number
3434
* @returns {number} absolute value

lib/node_modules/@stdlib/math/base/special/cabsf/test/fixtures/julia/data.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

lib/node_modules/@stdlib/math/base/special/cabsf/test/fixtures/julia/runner.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# @license Apache-2.0
44
#
5-
# Copyright (c) 2018 The Stdlib Authors.
5+
# Copyright (c) 2021 The Stdlib Authors.
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)