Skip to content

Commit d7f2772

Browse files
committed
refactor: update docs, examples and benchmarks
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5d05626 commit d7f2772

File tree

4 files changed

+76
-31
lines changed

4 files changed

+76
-31
lines changed

lib/node_modules/@stdlib/stats/base/dnanminabs/benchmark/c/benchmark.length.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static double rand_double( void ) {
9494
* @param len array length
9595
* @return elapsed time in seconds
9696
*/
97-
static double benchmark( int iterations, int len ) {
97+
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
9999
double x[ len ];
100100
double v;
@@ -111,6 +111,7 @@ static double benchmark( int iterations, int len ) {
111111
v = 0.0;
112112
t = tic();
113113
for ( i = 0; i < iterations; i++ ) {
114+
// cppcheck-suppress uninitvar
114115
v = stdlib_strided_dnanminabs( len, x, 1 );
115116
if ( v != v ) {
116117
printf( "should not return NaN\n" );
@@ -124,6 +125,44 @@ static double benchmark( int iterations, int len ) {
124125
return elapsed;
125126
}
126127

128+
/**
129+
* Runs a benchmark.
130+
*
131+
* @param iterations number of iterations
132+
* @param len array length
133+
* @return elapsed time in seconds
134+
*/
135+
static double benchmark2( int iterations, int len ) {
136+
double elapsed;
137+
double x[ len ];
138+
double v;
139+
double t;
140+
int i;
141+
142+
for ( i = 0; i < len; i++ ) {
143+
if ( rand_double() < 0.2 ) {
144+
x[ i ] = 0.0 / 0.0; // NaN
145+
} else {
146+
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
147+
}
148+
}
149+
v = 0.0;
150+
t = tic();
151+
for ( i = 0; i < iterations; i++ ) {
152+
// cppcheck-suppress uninitvar
153+
v = stdlib_strided_dnanminabs_ndarray( len, x, 1, 0 );
154+
if ( v != v ) {
155+
printf( "should not return NaN\n" );
156+
break;
157+
}
158+
}
159+
elapsed = tic() - t;
160+
if ( v != v ) {
161+
printf( "should not return NaN\n" );
162+
}
163+
return elapsed;
164+
}
165+
127166
/**
128167
* Main execution sequence.
129168
*/
@@ -146,7 +185,18 @@ int main( void ) {
146185
for ( j = 0; j < REPEATS; j++ ) {
147186
count += 1;
148187
printf( "# c::%s:len=%d\n", NAME, len );
149-
elapsed = benchmark( iter, len );
188+
elapsed = benchmark1( iter, len );
189+
print_results( iter, elapsed );
190+
printf( "ok %d benchmark finished\n", count );
191+
}
192+
}
193+
for ( i = MIN; i <= MAX; i++ ) {
194+
len = pow( 10, i );
195+
iter = ITERATIONS / pow( 10, i-1 );
196+
for ( j = 0; j < REPEATS; j++ ) {
197+
count += 1;
198+
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
199+
elapsed = benchmark2( iter, len );
150200
print_results( iter, elapsed );
151201
printf( "ok %d benchmark finished\n", count );
152202
}

lib/node_modules/@stdlib/stats/base/dnanminabs/docs/repl.txt

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
{{alias}}( N, x, stride )
2+
{{alias}}( N, x, strideX )
33
Computes the minimum absolute value of a double-precision floating-point
44
strided array, ignoring `NaN` values.
55

6-
The `N` and `stride` parameters determine which elements in `x` are accessed
7-
at runtime.
6+
The `N` and stride parameters determine which elements in the strided array
7+
are accessed at runtime.
88

99
Indexing is relative to the first index. To introduce an offset, use a typed
1010
array view.
@@ -19,8 +19,8 @@
1919
x: Float64Array
2020
Input array.
2121

22-
stride: integer
23-
Index increment.
22+
strideX: integer
23+
Stride Length.
2424

2525
Returns
2626
-------
@@ -34,22 +34,19 @@
3434
> {{alias}}( x.length, x, 1 )
3535
1.0
3636

37-
// Using `N` and `stride` parameters:
37+
// Using `N` and stride parameters:
3838
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN ] );
39-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
40-
> var stride = 2;
41-
> {{alias}}( N, x, stride )
39+
> {{alias}}( 3, x, 2 )
4240
1.0
4341

4442
// Using view offsets:
4543
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] );
4644
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
47-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
48-
> stride = 2;
49-
> {{alias}}( N, x1, stride )
45+
> {{alias}}( 3, x1, 2 )
5046
1.0
5147

52-
{{alias}}.ndarray( N, x, stride, offset )
48+
49+
{{alias}}.ndarray( N, x, strideX, offsetX )
5350
Computes the minimum absolute value of a double-precision floating-point
5451
strided array, ignoring `NaN` values and using alternative indexing
5552
semantics.
@@ -66,10 +63,10 @@
6663
x: Float64Array
6764
Input array.
6865

69-
stride: integer
70-
Index increment.
66+
strideX: integer
67+
Stride Length.
7168

72-
offset: integer
69+
offsetX: integer
7370
Starting index.
7471

7572
Returns
@@ -86,8 +83,7 @@
8683

8784
// Using offset parameter:
8885
> var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN ] );
89-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
90-
> {{alias}}.ndarray( N, x, 2, 1 )
86+
> {{alias}}.ndarray( 3, x, 2, 1 )
9187
1.0
9288

9389
See Also

lib/node_modules/@stdlib/stats/base/dnanminabs/docs/types/index.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface Routine {
2727
*
2828
* @param N - number of indexed elements
2929
* @param x - input array
30-
* @param stride - stride length
30+
* @param strideX - stride length
3131
* @returns minimum absolute value
3232
*
3333
* @example
@@ -38,15 +38,15 @@ interface Routine {
3838
* var v = dnanminabs( x.length, x, 1 );
3939
* // returns 1.0
4040
*/
41-
( N: number, x: Float64Array, stride: number ): number;
41+
( N: number, x: Float64Array, strideX: number ): number;
4242

4343
/**
4444
* Computes the minimum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
4545
*
4646
* @param N - number of indexed elements
4747
* @param x - input array
48-
* @param stride - stride length
49-
* @param offset - starting index
48+
* @param strideX - stride length
49+
* @param offsetX - starting index
5050
* @returns minimum absolute value
5151
*
5252
* @example
@@ -57,15 +57,15 @@ interface Routine {
5757
* var v = dnanminabs.ndarray( x.length, x, 1, 0 );
5858
* // returns 1.0
5959
*/
60-
ndarray( N: number, x: Float64Array, stride: number, offset: number ): number;
60+
ndarray( N: number, x: Float64Array, strideX: number, offsetX: number ): number;
6161
}
6262

6363
/**
6464
* Computes the minimum absolute value of a double-precision floating-point strided array, ignoring `NaN` values.
6565
*
6666
* @param N - number of indexed elements
6767
* @param x - input array
68-
* @param stride - stride length
68+
* @param strideX - stride length
6969
* @returns minimum absolute value
7070
*
7171
* @example

lib/node_modules/@stdlib/stats/base/dnanminabs/examples/c/example.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@
1717
*/
1818

1919
#include "stdlib/stats/base/dnanminabs.h"
20-
#include <stdint.h>
2120
#include <stdio.h>
2221

2322
int main( void ) {
2423
// Create a strided array:
25-
double x[] = { 1.0, -2.0, -3.0, 4.0, -5.0, -6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 };
24+
const double x[] = { 1.0, -2.0, -3.0, 4.0, -5.0, -6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 };
2625

2726
// Specify the number of elements:
28-
int64_t N = 5;
27+
const int N = 5;
2928

3029
// Specify the stride length:
31-
int64_t stride = 2;
30+
const int strideX = 2;
3231

3332
// Compute the minimum absolute value:
34-
double v = stdlib_strided_dnanminabs( N, x, stride );
33+
double v = stdlib_strided_dnanminabs( N, x, strideX );
3534

3635
// Print the result:
3736
printf( "minabs: %lf\n", v );

0 commit comments

Comments
 (0)