Skip to content

Commit 51ffafe

Browse files
committed
Auto-generated commit
1 parent 4bd74c4 commit 51ffafe

30 files changed

+408
-278
lines changed

.editorconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ indent_style = tab
8686
[*.{f,f.txt}]
8787
indent_style = space
8888
indent_size = 2
89-
insert_final_newline = false
9089

9190
# Set properties for shell files:
9291
[*.{sh,sh.txt}]

CHANGELOG.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-12-27)
7+
## Unreleased (2025-02-03)
8+
9+
<section class="features">
10+
11+
### Features
12+
13+
- [`7feea68`](https://github.com/stdlib-js/stdlib/commit/7feea68e633b9044a8bb6c8b3741f5708395dd97) - add C ndarray interface and refactor implementation for `stats/base/dvariancepn` [(#4688)](https://github.com/stdlib-js/stdlib/pull/4688)
14+
15+
</section>
16+
17+
<!-- /.features -->
818

919
<section class="commits">
1020

1121
### Commits
1222

1323
<details>
1424

15-
- [`9e3fd66`](https://github.com/stdlib-js/stdlib/commit/9e3fd661879b02f4200c28c3629fb122fa055d4b) - **refactor:** update `stats/base/dvariancepn` native addon from C++ to C [(#4279)](https://github.com/stdlib-js/stdlib/pull/4279) _(by Vivek maurya)_
25+
- [`7feea68`](https://github.com/stdlib-js/stdlib/commit/7feea68e633b9044a8bb6c8b3741f5708395dd97) - **feat:** add C ndarray interface and refactor implementation for `stats/base/dvariancepn` [(#4688)](https://github.com/stdlib-js/stdlib/pull/4688) _(by Prashant Kumar Yadav, Athan Reines)_
26+
- [`9e3fd66`](https://github.com/stdlib-js/stdlib/commit/9e3fd661879b02f4200c28c3629fb122fa055d4b) - **refactor:** update `stats/base/dvariancepn` native addon from C++ to C [(#4279)](https://github.com/stdlib-js/stdlib/pull/4279) _(by Vivek Maurya)_
1627
- [`62364f6`](https://github.com/stdlib-js/stdlib/commit/62364f62ea823a3b52c2ad25660ecd80c71f8f36) - **style:** fix C comment alignment _(by Philipp Burckhardt)_
1728
- [`9e689ff`](https://github.com/stdlib-js/stdlib/commit/9e689ffcb7c6223afc521f1e574b42f10921cf5e) - **chore:** fix indentation in manifest.json files _(by Philipp Burckhardt)_
1829
- [`272ae7a`](https://github.com/stdlib-js/stdlib/commit/272ae7ac5c576c68cfab1b6e304c86407faa20cd) - **docs:** remove comment _(by Athan Reines)_
@@ -28,11 +39,12 @@
2839

2940
### Contributors
3041

31-
A total of 3 people contributed to this release. Thank you to the following contributors:
42+
A total of 4 people contributed to this release. Thank you to the following contributors:
3243

3344
- Athan Reines
3445
- Philipp Burckhardt
35-
- Vivek maurya
46+
- Prashant Kumar Yadav
47+
- Vivek Maurya
3648

3749
</section>
3850

CONTRIBUTORS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Daniel Killenberger <[email protected]>
2727
Daniel Yu <[email protected]>
2828
Debashis Maharana <[email protected]>
2929
Desh Deepak Kant <[email protected]>
30+
31+
Dhruv Arvind Singh <[email protected]>
3032
Divyansh Seth <[email protected]>
3133
Dominic Lim <[email protected]>
3234
Dominik Moritz <[email protected]>
@@ -49,6 +51,7 @@ Joey Reed <[email protected]>
4951
Jordan Gallivan <[email protected]>
5052
Joris Labie <[email protected]>
5153
Justin Dennison <[email protected]>
54+
Karan Anand <[email protected]>
5255
Karthik Prakash <[email protected]>
5356
Kohantika Nath <[email protected]>
5457
Krishnendu Das <[email protected]>
@@ -117,7 +120,7 @@ UtkershBasnet <[email protected]>
117120
Vaibhav Patel <[email protected]>
118121
Varad Gupta <[email protected]>
119122
Vinit Pandit <[email protected]>
120-
Vivek maurya <[email protected].com>
123+
Vivek Maurya <vm8118134@gmail.com>
121124
Xiaochuan Ye <[email protected]>
122125
Yaswanth Kosuru <[email protected]>
123126
Yernar Yergaziyev <[email protected]>

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Copyright (c) 2016-2024 The Stdlib Authors.
1+
Copyright (c) 2016-2025 The Stdlib Authors.

README.md

Lines changed: 135 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,16 @@ To view installation and usage instructions specific to each branch build, be su
131131
var dvariancepn = require( '@stdlib/stats-base-dvariancepn' );
132132
```
133133

134-
#### dvariancepn( N, correction, x, stride )
134+
#### dvariancepn( N, correction, x, strideX )
135135

136136
Computes the [variance][variance] of a double-precision floating-point strided array `x` using a two-pass algorithm.
137137

138138
```javascript
139139
var Float64Array = require( '@stdlib/array-float64' );
140140

141141
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
142-
var N = x.length;
143142

144-
var v = dvariancepn( N, 1, x, 1 );
143+
var v = dvariancepn( x.length, 1, x, 1 );
145144
// returns ~4.3333
146145
```
147146

@@ -150,18 +149,16 @@ The function has the following parameters:
150149
- **N**: number of indexed elements.
151150
- **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).
152151
- **x**: input [`Float64Array`][@stdlib/array/float64].
153-
- **stride**: index increment for `x`.
152+
- **strideX**: stride length for `x`.
154153

155-
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`,
154+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`,
156155

157156
```javascript
158157
var Float64Array = require( '@stdlib/array-float64' );
159-
var floor = require( '@stdlib/math-base-special-floor' );
160158

161159
var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
162-
var N = floor( x.length / 2 );
163160

164-
var v = dvariancepn( N, 1, x, 2 );
161+
var v = dvariancepn( 4, 1, x, 2 );
165162
// returns 6.25
166163
```
167164

@@ -171,45 +168,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
171168

172169
```javascript
173170
var Float64Array = require( '@stdlib/array-float64' );
174-
var floor = require( '@stdlib/math-base-special-floor' );
175171

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

179-
var N = floor( x0.length / 2 );
180-
181-
var v = dvariancepn( N, 1, x1, 2 );
175+
var v = dvariancepn( 4, 1, x1, 2 );
182176
// returns 6.25
183177
```
184178

185-
#### dvariancepn.ndarray( N, correction, x, stride, offset )
179+
#### dvariancepn.ndarray( N, correction, x, strideX, offsetX )
186180

187181
Computes the [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics.
188182

189183
```javascript
190184
var Float64Array = require( '@stdlib/array-float64' );
191185

192186
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
193-
var N = x.length;
194187

195-
var v = dvariancepn.ndarray( N, 1, x, 1, 0 );
188+
var v = dvariancepn.ndarray( x.length, 1, x, 1, 0 );
196189
// returns ~4.33333
197190
```
198191

199192
The function has the following additional parameters:
200193

201-
- **offset**: starting index for `x`.
194+
- **offsetX**: starting index for `x`.
202195

203-
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 [variance][variance] for every other value in `x` starting from the second value
196+
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 [variance][variance] for every other element in `x` starting from the second element
204197

205198
```javascript
206199
var Float64Array = require( '@stdlib/array-float64' );
207-
var floor = require( '@stdlib/math-base-special-floor' );
208200

209201
var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
210-
var N = floor( x.length / 2 );
211202

212-
var v = dvariancepn.ndarray( N, 1, x, 2, 1 );
203+
var v = dvariancepn.ndarray( 4, 1, x, 2, 1 );
213204
// returns 6.25
214205
```
215206

@@ -235,18 +226,12 @@ var v = dvariancepn.ndarray( N, 1, x, 2, 1 );
235226
<!-- eslint no-undef: "error" -->
236227

237228
```javascript
238-
var randu = require( '@stdlib/random-base-randu' );
239-
var round = require( '@stdlib/math-base-special-round' );
240-
var Float64Array = require( '@stdlib/array-float64' );
229+
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
241230
var dvariancepn = require( '@stdlib/stats-base-dvariancepn' );
242231

243-
var x;
244-
var i;
245-
246-
x = new Float64Array( 10 );
247-
for ( i = 0; i < x.length; i++ ) {
248-
x[ i ] = round( (randu()*100.0) - 50.0 );
249-
}
232+
var x = discreteUniform( 10, -50, 50, {
233+
'dtype': 'float64'
234+
});
250235
console.log( x );
251236

252237
var v = dvariancepn( x.length, 1, x, 1 );
@@ -257,6 +242,125 @@ console.log( v );
257242

258243
<!-- /.examples -->
259244

245+
<!-- C interface documentation. -->
246+
247+
* * *
248+
249+
<section class="c">
250+
251+
## C APIs
252+
253+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
254+
255+
<section class="intro">
256+
257+
</section>
258+
259+
<!-- /.intro -->
260+
261+
<!-- C usage documentation. -->
262+
263+
<section class="usage">
264+
265+
### Usage
266+
267+
```c
268+
#include "stdlib/stats/base/dvariancepn.h"
269+
```
270+
271+
#### stdlib_strided_dvariancepn( N, correction, \*X, strideX )
272+
273+
Computes the [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm.
274+
275+
```c
276+
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }
277+
278+
double v = stdlib_strided_dvariancepn( 8, 1.0, x, 1 );
279+
// returns 6.0
280+
```
281+
282+
The function accepts the following arguments:
283+
284+
- **N**: `[in] CBLAS_INT` number of indexed elements.
285+
- **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).
286+
- **X**: `[in] double*` input array.
287+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
288+
289+
```c
290+
double stdlib_strided_dvariancepn( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX );
291+
```
292+
293+
#### stdlib_strided_dvariancepn_ndarray( N, correction, \*X, strideX, offsetX )
294+
295+
Computes the [variance][variance] of a double-precision floating-point strided array using a two-pass algorithm and alternative indexing semantics.
296+
297+
```c
298+
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }
299+
300+
double v = stdlib_strided_dvariancepn_ndarray( 4, 1.0, x, 2, 0 );
301+
// returns ~6.666667
302+
```
303+
304+
The function accepts the following arguments:
305+
306+
- **N**: `[in] CBLAS_INT` number of indexed elements.
307+
- **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).
308+
- **X**: `[in] double*` input array.
309+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
310+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
311+
312+
```c
313+
double stdlib_strided_dvariancepn_ndarray( const CBLAS_INT N, const double correction, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
314+
```
315+
316+
</section>
317+
318+
<!-- /.usage -->
319+
320+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
321+
322+
<section class="notes">
323+
324+
</section>
325+
326+
<!-- /.notes -->
327+
328+
<!-- C API usage examples. -->
329+
330+
<section class="examples">
331+
332+
### Examples
333+
334+
```c
335+
#include "stdlib/stats/base/dvariancepn.h"
336+
#include <stdio.h>
337+
338+
int main( void ) {
339+
// Create a strided array:
340+
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
341+
342+
// Specify the number of elements:
343+
const int N = 4;
344+
345+
// Specify the stride length:
346+
const int strideX = 2;
347+
348+
// Compute the variance:
349+
double v = stdlib_strided_dvariancepn( N, 1.0, x, strideX );
350+
351+
// Print the result:
352+
printf( "sample variance: %lf\n", v );
353+
}
354+
```
355+
356+
</section>
357+
358+
<!-- /.examples -->
359+
360+
</section>
361+
362+
<!-- /.c -->
363+
260364
* * *
261365
262366
<section class="references">
@@ -314,7 +418,7 @@ See [LICENSE][stdlib-license].
314418
315419
## Copyright
316420
317-
Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
421+
Copyright &copy; 2016-2025. The Stdlib [Authors][stdlib-authors].
318422
319423
</section>
320424

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-harness' );
24-
var randu = require( '@stdlib/random-base-randu' );
24+
var uniform = require( '@stdlib/random-array-uniform' );
2525
var isnan = require( '@stdlib/math-base-assert-is-nan' );
2626
var pow = require( '@stdlib/math-base-special-pow' );
27-
var Float64Array = require( '@stdlib/array-float64' );
2827
var pkg = require( './../package.json' ).name;
2928
var dvariancepn = require( './../lib/dvariancepn.js' );
3029

3130

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

3440
/**
@@ -39,13 +45,7 @@ var dvariancepn = require( './../lib/dvariancepn.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 ) {

0 commit comments

Comments
 (0)