Skip to content

Commit 7e9ce86

Browse files
committed
refactor!: reorder parameters
BREAKING CHANGE: switch order of `mean` and `correction` parameters To migrate, users should swap `mean` and `correction` arguments. This change ensures that the `*varm*` function signatures follow similar conventions as found in binary APIs, such as those for computing the covariance, where the `mean` parameter immediately precedes the array argument. --- 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: na - 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: passed - 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: passed - task: lint_license_headers status: passed ---
1 parent 488f765 commit 7e9ce86

File tree

23 files changed

+288
-242
lines changed

23 files changed

+288
-242
lines changed

lib/node_modules/@stdlib/stats/strided/dvarm/README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note,
9898
var dvarm = require( '@stdlib/stats/strided/dvarm' );
9999
```
100100

101-
#### dvarm( N, mean, correction, x, strideX )
101+
#### dvarm( N, correction, mean, x, strideX )
102102

103103
Computes the [variance][variance] of a double-precision floating-point strided array provided a known `mean`.
104104

@@ -107,15 +107,15 @@ var Float64Array = require( '@stdlib/array/float64' );
107107

108108
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
109109

110-
var v = dvarm( x.length, 1.0/3.0, 1, x, 1 );
110+
var v = dvarm( x.length, 1, 1.0/3.0, x, 1 );
111111
// returns ~4.3333
112112
```
113113

114114
The function has the following parameters:
115115

116116
- **N**: number of indexed elements.
117-
- **mean**: mean.
118117
- **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction).
118+
- **mean**: mean.
119119
- **x**: input [`Float64Array`][@stdlib/array/float64].
120120
- **stride**: stride length for `x`.
121121

@@ -126,7 +126,7 @@ var Float64Array = require( '@stdlib/array/float64' );
126126

127127
var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
128128

129-
var v = dvarm( 4, 1.25, 1, x, 2 );
129+
var v = dvarm( 4, 1, 1.25, x, 2 );
130130
// returns 6.25
131131
```
132132

@@ -140,11 +140,11 @@ var Float64Array = require( '@stdlib/array/float64' );
140140
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
141141
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
142142

143-
var v = dvarm( 4, 1.25, 1, x1, 2 );
143+
var v = dvarm( 4, 1, 1.25, x1, 2 );
144144
// returns 6.25
145145
```
146146

147-
#### dvarm.ndarray( N, mean, correction, x, strideX, offsetX )
147+
#### dvarm.ndarray( N, correction, mean, x, strideX, offsetX )
148148

149149
Computes the [variance][variance] of a double-precision floating-point strided array provided a known `mean` and using alternative indexing semantics.
150150

@@ -153,7 +153,7 @@ var Float64Array = require( '@stdlib/array/float64' );
153153

154154
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
155155

156-
var v = dvarm.ndarray( x.length, 1.0/3.0, 1, x, 1, 0 );
156+
var v = dvarm.ndarray( x.length, 1, 1.0/3.0, x, 1, 0 );
157157
// returns ~4.33333
158158
```
159159

@@ -168,7 +168,7 @@ var Float64Array = require( '@stdlib/array/float64' );
168168

169169
var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
170170

171-
var v = dvarm.ndarray( 4, 1.25, 1, x, 2, 1 );
171+
var v = dvarm.ndarray( 4, 1, 1.25, x, 2, 1 );
172172
// returns 6.25
173173
```
174174

@@ -202,7 +202,7 @@ var x = discreteUniform( 10, -50, 50, {
202202
});
203203
console.log( x );
204204

205-
var v = dvarm( x.length, 0.0, 1, x, 1 );
205+
var v = dvarm( x.length, 1, 0.0, x, 1 );
206206
console.log( v );
207207
```
208208

@@ -236,51 +236,51 @@ console.log( v );
236236
#include "stdlib/stats/strided/dvarm.h"
237237
```
238238

239-
#### stdlib_strided_dvarm( N, mean, correction, \*X, strideX )
239+
#### stdlib_strided_dvarm( N, correction, mean, \*X, strideX )
240240

241241
Computes the [variance][variance] of a double-precision floating-point strided array provided a known `mean`.
242242

243243
```c
244244
const double x[] = { 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 };
245245

246-
double v = stdlib_strided_dvarm( 4, 1.25, 1.0, x, 2 );
246+
double v = stdlib_strided_dvarm( 4, 1.0, 1.25, x, 2 );
247247
// returns 6.25
248248
```
249249
250250
The function accepts the following arguments:
251251
252252
- **N**: `[in] CBLAS_INT` number of indexed elements.
253-
- **mean**: `[in] double` mean.
254253
- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction).
254+
- **mean**: `[in] double` mean.
255255
- **X**: `[in] double*` input array.
256256
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
257257
258258
```c
259-
double stdlib_strided_dvarm( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX );
259+
double stdlib_strided_dvarm( const CBLAS_INT N, const double correction, const double mean, const double *X, const CBLAS_INT strideX );
260260
```
261261

262-
#### stdlib_strided_dvarm_ndarray( N, mean, correction, \*X, strideX, offsetX )
262+
#### stdlib_strided_dvarm_ndarray( N, correction, mean, \*X, strideX, offsetX )
263263

264264
Computes the [variance][variance] of a double-precision floating-point strided array provided a known `mean` and using alternative indexing semantics.
265265

266266
```c
267267
const double x[] = { 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 };
268268

269-
double v = stdlib_strided_dvarm_ndarray( 4, 1.25, 1.0, x, 2, 1 );
269+
double v = stdlib_strided_dvarm_ndarray( 4, 1.0, 1.25, x, 2, 1 );
270270
// returns 6.25
271271
```
272272
273273
The function accepts the following arguments:
274274
275275
- **N**: `[in] CBLAS_INT` number of indexed elements.
276-
- **mean**: `[in] double` mean.
277276
- **correction**: `[in] double` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction).
277+
- **mean**: `[in] double` mean.
278278
- **X**: `[in] double*` input array.
279279
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
280280
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
281281
282282
```c
283-
double stdlib_strided_dvarm_ndarray( const CBLAS_INT N, const double mean, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
283+
double stdlib_strided_dvarm_ndarray( const CBLAS_INT N, const double correction, const double mean, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
284284
```
285285

286286
</section>
@@ -316,7 +316,7 @@ int main( void ) {
316316
const int strideX = 2;
317317

318318
// Compute the variance:
319-
double v = stdlib_strided_dvarm( N, 4.5, 1, x, strideX );
319+
double v = stdlib_strided_dvarm( N, 1, 4.5, x, strideX );
320320

321321
// Print the result:
322322
printf( "sample variance: %lf\n", v );

lib/node_modules/@stdlib/stats/strided/dvarm/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function createBenchmark( len ) {
5454

5555
b.tic();
5656
for ( i = 0; i < b.iterations; i++ ) {
57-
v = dvarm( x.length, 0.0, 1, x, 1 );
57+
v = dvarm( x.length, 1, 0.0, x, 1 );
5858
if ( isnan( v ) ) {
5959
b.fail( 'should not return NaN' );
6060
}

lib/node_modules/@stdlib/stats/strided/dvarm/benchmark/benchmark.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function createBenchmark( len ) {
5959

6060
b.tic();
6161
for ( i = 0; i < b.iterations; i++ ) {
62-
v = dvarm( x.length, 0.0, 1, x, 1 );
62+
v = dvarm( x.length, 1, 0.0, x, 1 );
6363
if ( isnan( v ) ) {
6464
b.fail( 'should not return NaN' );
6565
}

lib/node_modules/@stdlib/stats/strided/dvarm/benchmark/benchmark.ndarray.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function createBenchmark( len ) {
5454

5555
b.tic();
5656
for ( i = 0; i < b.iterations; i++ ) {
57-
v = dvarm( x.length, 0.0, 1, x, 1, 0 );
57+
v = dvarm( x.length, 1, 0.0, x, 1, 0 );
5858
if ( isnan( v ) ) {
5959
b.fail( 'should not return NaN' );
6060
}

lib/node_modules/@stdlib/stats/strided/dvarm/benchmark/benchmark.ndarray.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function createBenchmark( len ) {
5959

6060
b.tic();
6161
for ( i = 0; i < b.iterations; i++ ) {
62-
v = dvarm( x.length, 0.0, 1, x, 1, 0 );
62+
v = dvarm( x.length, 1, 0.0, x, 1, 0 );
6363
if ( isnan( v ) ) {
6464
b.fail( 'should not return NaN' );
6565
}

lib/node_modules/@stdlib/stats/strided/dvarm/benchmark/c/benchmark.length.c

Lines changed: 49 additions & 3 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;
@@ -107,7 +107,42 @@ static double benchmark( int iterations, int len ) {
107107
v = 0.0;
108108
t = tic();
109109
for ( i = 0; i < iterations; i++ ) {
110-
v = stdlib_strided_dvarm( len, 0.0, 1, x, 1 );
110+
// cppcheck-suppress uninitvar
111+
v = stdlib_strided_dvarm( len, 1, 0.0, x, 1 );
112+
if ( v != v ) {
113+
printf( "should not return NaN\n" );
114+
break;
115+
}
116+
}
117+
elapsed = tic() - t;
118+
if ( v != v ) {
119+
printf( "should not return NaN\n" );
120+
}
121+
return elapsed;
122+
}
123+
124+
/**
125+
* Runs a benchmark.
126+
*
127+
* @param iterations number of iterations
128+
* @param len array length
129+
* @return elapsed time in seconds
130+
*/
131+
static double benchmark2( int iterations, int len ) {
132+
double elapsed;
133+
double x[ len ];
134+
double v;
135+
double t;
136+
int i;
137+
138+
for ( i = 0; i < len; i++ ) {
139+
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
140+
}
141+
v = 0.0;
142+
t = tic();
143+
for ( i = 0; i < iterations; i++ ) {
144+
// cppcheck-suppress uninitvar
145+
v = stdlib_strided_dvarm_ndarray( len, 1, 0.0, x, 1 );
111146
if ( v != v ) {
112147
printf( "should not return NaN\n" );
113148
break;
@@ -142,7 +177,18 @@ int main( void ) {
142177
for ( j = 0; j < REPEATS; j++ ) {
143178
count += 1;
144179
printf( "# c::%s:len=%d\n", NAME, len );
145-
elapsed = benchmark( iter, len );
180+
elapsed = benchmark1( iter, len );
181+
print_results( iter, elapsed );
182+
printf( "ok %d benchmark finished\n", count );
183+
}
184+
}
185+
for ( i = MIN; i <= MAX; i++ ) {
186+
len = pow( 10, i );
187+
iter = ITERATIONS / pow( 10, i-1 );
188+
for ( j = 0; j < REPEATS; j++ ) {
189+
count += 1;
190+
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
191+
elapsed = benchmark2( iter, len );
146192
print_results( iter, elapsed );
147193
printf( "ok %d benchmark finished\n", count );
148194
}

lib/node_modules/@stdlib/stats/strided/dvarm/docs/repl.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
{{alias}}( N, mean, correction, x, strideX )
2+
{{alias}}( N, correction, mean, x, strideX )
33
Computes the variance of a double-precision floating-point strided array
44
provided a known mean.
55

@@ -16,9 +16,6 @@
1616
N: integer
1717
Number of indexed elements.
1818

19-
mean: number
20-
Mean.
21-
2219
correction: number
2320
Degrees of freedom adjustment. Setting this parameter to a value other
2421
than `0` has the effect of adjusting the divisor during the calculation
@@ -31,6 +28,9 @@
3128
sampled from a larger population; this is commonly referred to as
3229
Bessel's correction).
3330

31+
mean: number
32+
Mean.
33+
3434
x: Float64Array
3535
Input array.
3636

@@ -46,22 +46,22 @@
4646
--------
4747
// Standard Usage:
4848
> var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] );
49-
> {{alias}}( x.length, 1.0/3.0, 1, x, 1 )
49+
> {{alias}}( x.length, 1, 1.0/3.0, x, 1 )
5050
~4.3333
5151

5252
// Using `N` and stride parameters:
5353
> x = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] );
54-
> {{alias}}( 3, 1.0/3.0, 1, x, 2 )
54+
> {{alias}}( 3, 1, 1.0/3.0, x, 2 )
5555
~4.3333
5656

5757
// Using view offsets:
5858
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, 1.0 ] );
5959
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
60-
> {{alias}}( 3, 1.0/3.0, 1, x1, 2 )
60+
> {{alias}}( 3, 1, 1.0/3.0, x1, 2 )
6161
~4.3333
6262

6363

64-
{{alias}}.ndarray( N, mean, correction, x, strideX, offsetX )
64+
{{alias}}.ndarray( N, correction, mean, x, strideX, offsetX )
6565
Computes the variance of a double-precision floating-point strided array
6666
provided a known mean and using alternative indexing semantics.
6767

@@ -74,9 +74,6 @@
7474
N: integer
7575
Number of indexed elements.
7676

77-
mean: number
78-
Mean.
79-
8077
correction: number
8178
Degrees of freedom adjustment. Setting this parameter to a value other
8279
than `0` has the effect of adjusting the divisor during the calculation
@@ -89,6 +86,9 @@
8986
sampled from a larger population; this is commonly referred to as
9087
Bessel's correction).
9188

89+
mean: number
90+
Mean.
91+
9292
x: Float64Array
9393
Input array.
9494

@@ -107,12 +107,12 @@
107107
--------
108108
// Standard Usage:
109109
> var x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 2.0 ] );
110-
> {{alias}}.ndarray( x.length, 1.0/3.0, 1, x, 1, 0 )
110+
> {{alias}}.ndarray( x.length, 1, 1.0/3.0, x, 1, 0 )
111111
~4.3333
112112

113113
// Using offset parameter:
114114
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, 1.0 ] );
115-
> {{alias}}.ndarray( 3, 1.0/3.0, 1, x, 2, 1 )
115+
> {{alias}}.ndarray( 3, 1, 1.0/3.0, x, 2, 1 )
116116
~4.3333
117117

118118
See Also

0 commit comments

Comments
 (0)