Skip to content

Commit 30c4dd5

Browse files
committed
feat: add stats/base/dsempn
--- 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: na - 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: na - 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 c3320f1 commit 30c4dd5

File tree

22 files changed

+338
-221
lines changed

22 files changed

+338
-221
lines changed

lib/node_modules/@stdlib/stats/base/dsempn/README.md

Lines changed: 131 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,16 @@ where `s` is the sample [standard deviation][standard-deviation].
7070
var dsempn = require( '@stdlib/stats/base/dsempn' );
7171
```
7272

73-
#### dsempn( N, correction, x, stride )
73+
#### dsempn( N, correction, x, strideX )
7474

75-
Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array `x` using a two-pass algorithm.
75+
Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array using a two-pass algorithm.
7676

7777
```javascript
7878
var Float64Array = require( '@stdlib/array/float64' );
7979

8080
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
81-
var N = x.length;
8281

83-
var v = dsempn( N, 1, x, 1 );
82+
var v = dsempn( x.length, 1, x, 1 );
8483
// returns ~1.20185
8584
```
8685

@@ -89,18 +88,16 @@ The function has the following parameters:
8988
- **N**: number of indexed elements.
9089
- **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 [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] 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 corrected sample [standard deviation][standard-deviation], 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).
9190
- **x**: input [`Float64Array`][@stdlib/array/float64].
92-
- **stride**: index increment for `x`.
91+
- **strideX**: stride length for `x`.
9392

94-
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [standard error of the mean][standard-error] of every other element in `x`,
93+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [standard error of the mean][standard-error] of every other element in `x`,
9594

9695
```javascript
9796
var Float64Array = require( '@stdlib/array/float64' );
98-
var floor = require( '@stdlib/math/base/special/floor' );
9997

10098
var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
101-
var N = floor( x.length / 2 );
10299

103-
var v = dsempn( N, 1, x, 2 );
100+
var v = dsempn( 4, 1, x, 2 );
104101
// returns 1.25
105102
```
106103

@@ -110,45 +107,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
110107

111108
```javascript
112109
var Float64Array = require( '@stdlib/array/float64' );
113-
var floor = require( '@stdlib/math/base/special/floor' );
114110

115111
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
116112
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
117113

118-
var N = floor( x0.length / 2 );
119-
120-
var v = dsempn( N, 1, x1, 2 );
114+
var v = dsempn( 4, 1, x1, 2 );
121115
// returns 1.25
122116
```
123117

124-
#### dsempn.ndarray( N, correction, x, stride, offset )
118+
#### dsempn.ndarray( N, correction, x, strideX, offsetX )
125119

126120
Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics.
127121

128122
```javascript
129123
var Float64Array = require( '@stdlib/array/float64' );
130124

131125
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
132-
var N = x.length;
133126

134-
var v = dsempn.ndarray( N, 1, x, 1, 0 );
127+
var v = dsempn.ndarray( x.length, 1, x, 1, 0 );
135128
// returns ~1.20185
136129
```
137130

138131
The function has the following additional parameters:
139132

140-
- **offset**: starting index for `x`.
133+
- **offsetX**: starting index for `x`.
141134

142-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [standard error of the mean][standard-error] for every other value in `x` starting from the second value
135+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [standard error of the mean][standard-error] for every other element in `x` starting from the second element
143136

144137
```javascript
145138
var Float64Array = require( '@stdlib/array/float64' );
146-
var floor = require( '@stdlib/math/base/special/floor' );
147139

148140
var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
149-
var N = floor( x.length / 2 );
150141

151-
var v = dsempn.ndarray( N, 1, x, 2, 1 );
142+
var v = dsempn.ndarray( 4, 1, x, 2, 1 );
152143
// returns 1.25
153144
```
154145

@@ -196,6 +187,125 @@ console.log( v );
196187

197188
<!-- /.examples -->
198189

190+
<!-- C interface documentation. -->
191+
192+
* * *
193+
194+
<section class="c">
195+
196+
## C APIs
197+
198+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
199+
200+
<section class="intro">
201+
202+
</section>
203+
204+
<!-- /.intro -->
205+
206+
<!-- C usage documentation. -->
207+
208+
<section class="usage">
209+
210+
### Usage
211+
212+
```c
213+
#include "stdlib/stats/base/dsempn.h"
214+
```
215+
216+
#### stdlib_strided_dsempn( N, correction, \*X, strideX )
217+
218+
Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array using a two-pass algorithm.
219+
220+
```c
221+
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
222+
223+
double v = stdlib_strided_dsempn( 4, 1.0, x, 2 );
224+
// returns ~1.29099
225+
```
226+
227+
The function accepts the following arguments:
228+
229+
- **N**: `[in] CBLAS_INT` number of indexed elements.
230+
- **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 [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] 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 corrected sample [standard deviation][standard-deviation], 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).
231+
- **X**: `[in] double*` input array.
232+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
233+
234+
```c
235+
double stdlib_strided_dsempn( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX );
236+
```
237+
238+
#### stdlib_strided_dsempn_ndarray( N, correction, \*X, strideX, offsetX )
239+
240+
Computes the [standard error of the mean][standard-error] of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics.
241+
242+
```c
243+
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
244+
245+
double v = stdlib_strided_dsempn_ndarray( 4, 1.0, x, 2, 0 );
246+
// returns ~1.29099
247+
```
248+
249+
The function accepts the following arguments:
250+
251+
- **N**: `[in] CBLAS_INT` number of indexed elements.
252+
- **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 [standard deviation][standard-deviation] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [standard deviation][standard-deviation] 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 corrected sample [standard deviation][standard-deviation], 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).
253+
- **X**: `[in] double*` input array.
254+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
255+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
256+
257+
```c
258+
double stdlib_strided_dsempn_ndarray( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
259+
```
260+
261+
</section>
262+
263+
<!-- /.usage -->
264+
265+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
266+
267+
<section class="notes">
268+
269+
</section>
270+
271+
<!-- /.notes -->
272+
273+
<!-- C API usage examples. -->
274+
275+
<section class="examples">
276+
277+
### Examples
278+
279+
```c
280+
#include "stdlib/stats/base/dsempn.h"
281+
#include <stdio.h>
282+
283+
int main( void ) {
284+
// Create a strided array:
285+
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
286+
287+
// Specify the number of elements:
288+
const int N = 4;
289+
290+
// Specify the stride length:
291+
const int strideX = 2;
292+
293+
// Compute the arithmetic mean:
294+
double v = stdlib_strided_dsempn( N, 1.0, x, strideX );
295+
296+
// Print the result:
297+
printf( "dsempn: %lf\n", v );
298+
}
299+
```
300+
301+
</section>
302+
303+
<!-- /.examples -->
304+
305+
</section>
306+
307+
<!-- /.c -->
308+
199309
* * *
200310
201311
<section class="references">

lib/node_modules/@stdlib/stats/base/dsempn/benchmark/benchmark.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
2524
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2625
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float64Array = require( '@stdlib/array/float64' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
2827
var pkg = require( './../package.json' ).name;
2928
var dsempn = require( './../lib/dsempn.js' );
3029

3130

31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float64'
35+
};
36+
37+
3238
// FUNCTIONS //
3339

3440
/**
@@ -39,13 +45,7 @@ var dsempn = require( './../lib/dsempn.js' );
3945
* @returns {Function} benchmark function
4046
*/
4147
function createBenchmark( len ) {
42-
var x;
43-
var i;
44-
45-
x = new Float64Array( len );
46-
for ( i = 0; i < x.length; i++ ) {
47-
x[ i ] = ( randu()*20.0 ) - 10.0;
48-
}
48+
var x = uniform( len, -10.0, 10.0, options );
4949
return benchmark;
5050

5151
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dsempn/benchmark/benchmark.native.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
2625
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2726
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float64Array = require( '@stdlib/array/float64' );
27+
var uniform = require( '@stdlib/random/array/uniform' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
3029
var pkg = require( './../package.json' ).name;
3130

@@ -36,6 +35,9 @@ var dsempn = tryRequire( resolve( __dirname, './../lib/dsempn.native.js' ) );
3635
var opts = {
3736
'skip': ( dsempn instanceof Error )
3837
};
38+
var options = {
39+
'dtype': 'float64'
40+
};
3941

4042

4143
// FUNCTIONS //
@@ -48,13 +50,7 @@ var opts = {
4850
* @returns {Function} benchmark function
4951
*/
5052
function createBenchmark( len ) {
51-
var x;
52-
var i;
53-
54-
x = new Float64Array( len );
55-
for ( i = 0; i < x.length; i++ ) {
56-
x[ i ] = ( randu()*20.0 ) - 10.0;
57-
}
53+
var x = uniform( len, -10.0, 10.0, options );
5854
return benchmark;
5955

6056
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dsempn/benchmark/benchmark.ndarray.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
2524
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2625
var pow = require( '@stdlib/math/base/special/pow' );
27-
var Float64Array = require( '@stdlib/array/float64' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
2827
var pkg = require( './../package.json' ).name;
2928
var dsempn = require( './../lib/ndarray.js' );
3029

3130

31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float64'
35+
};
36+
37+
3238
// FUNCTIONS //
3339

3440
/**
@@ -39,13 +45,7 @@ var dsempn = require( './../lib/ndarray.js' );
3945
* @returns {Function} benchmark function
4046
*/
4147
function createBenchmark( len ) {
42-
var x;
43-
var i;
44-
45-
x = new Float64Array( len );
46-
for ( i = 0; i < x.length; i++ ) {
47-
x[ i ] = ( randu()*20.0 ) - 10.0;
48-
}
48+
var x = uniform( len, -10.0, 10.0, options );
4949
return benchmark;
5050

5151
function benchmark( b ) {

lib/node_modules/@stdlib/stats/base/dsempn/benchmark/benchmark.ndarray.native.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
2625
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2726
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float64Array = require( '@stdlib/array/float64' );
27+
var uniform = require( '@stdlib/random/array/uniform' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
3029
var pkg = require( './../package.json' ).name;
3130

@@ -36,6 +35,9 @@ var dsempn = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3635
var opts = {
3736
'skip': ( dsempn instanceof Error )
3837
};
38+
var options = {
39+
'dtype': 'float64'
40+
};
3941

4042

4143
// FUNCTIONS //
@@ -48,13 +50,7 @@ var opts = {
4850
* @returns {Function} benchmark function
4951
*/
5052
function createBenchmark( len ) {
51-
var x;
52-
var i;
53-
54-
x = new Float64Array( len );
55-
for ( i = 0; i < x.length; i++ ) {
56-
x[ i ] = ( randu()*20.0 ) - 10.0;
57-
}
53+
var x = uniform( len, -10.0, 10.0, options );
5854
return benchmark;
5955

6056
function benchmark( b ) {

0 commit comments

Comments
 (0)