Skip to content

Commit e6bdf6c

Browse files
committed
Auto-generated commit
1 parent 63c0caa commit e6bdf6c

30 files changed

+436
-263
lines changed

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44
55
<section class="release" id="unreleased">
66

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

919
<section class="commits">
1020

1121
### Commits
1222

1323
<details>
1424

25+
- [`c155eb0`](https://github.com/stdlib-js/stdlib/commit/c155eb0820f1938b7ff56a719b72a442ccc202a1) - **feat:** add C ndarray interface and refactor implementation for `stats/base/dsvariance` [(#5641)](https://github.com/stdlib-js/stdlib/pull/5641) _(by Prashant Kumar Yadav, stdlib-bot)_
1526
- [`6d3a881`](https://github.com/stdlib-js/stdlib/commit/6d3a881e8df45f6c90f52af25666142603f59ca5) - **refactor:** update `stats/base/dsvariance` native addon from C++ to C [(#4868)](https://github.com/stdlib-js/stdlib/pull/4868) _(by Prashant Kumar Yadav)_
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)_

CONTRIBUTORS

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ Aksshay Balasubramanian <[email protected]>
1717
Aleksandr <[email protected]>
1818
Ali Salesi <[email protected]>
1919
Aman Bhansali <[email protected]>
20+
AmanBhadkariya <[email protected]>
2021
Amit Jimiwal <[email protected]>
2122
Anshu Kumar <[email protected]>
23+
Anshu Kumar <[email protected]>
2224
Anudeep Sanapala <[email protected]>
2325
Athan Reines <[email protected]>
2426
@@ -31,8 +33,10 @@ Dan Rose <[email protected]>
3133
Daniel Killenberger <[email protected]>
3234
Daniel Yu <[email protected]>
3335
Debashis Maharana <[email protected]>
36+
Deep Trivedi <[email protected]>
3437
Desh Deepak Kant <[email protected]>
3538
39+
Dhanyabad behera <[email protected]>
3640
Dhruv Arvind Singh <[email protected]>
3741
Dhruvil Mehta <[email protected]>
3842
Divyansh Seth <[email protected]>
@@ -47,12 +51,14 @@ Gautam sharma <[email protected]>
4751
Golden Kumar <[email protected]>
4852
Gunj Joshi <[email protected]>
4953
Gururaj Gurram <[email protected]>
54+
Haroon Rasheed <[email protected]>
5055
5156
5257
Harshita Kalani <[email protected]>
5358
Hemant M Mehta <[email protected]>
5459
Hridyanshu <[email protected]>
5560
Jaimin Godhani <[email protected]>
61+
Jaison D Souza <[email protected]>
5662
Jalaj Kumar <[email protected]>
5763
James Gelok <[email protected]>
5864
Jaysukh Makvana <[email protected]>
@@ -66,6 +72,7 @@ Justin Dennison <[email protected]>
6672
Justyn Shelby <[email protected]>
6773
Karan Anand <[email protected]>
6874
Karthik Prakash <[email protected]>
75+
Kaushikgtm <[email protected]>
6976
Kohantika Nath <[email protected]>
7077
Krishnam Agarwal <[email protected]>
7178
Krishnendu Das <[email protected]>
@@ -93,7 +100,7 @@ Oneday12323 <[email protected]>
93100
Ori Miles <[email protected]>
94101
Philipp Burckhardt <[email protected]>
95102
Prajwal Kulkarni <[email protected]>
96-
Pranav Goswami <[email protected]>
103+
Pranav Goswami <[email protected]>
97104
Pranjal Jha <[email protected]>
98105
Prashant Kumar Yadav <[email protected]>
99106
Pratik Singh <[email protected]>
@@ -113,6 +120,7 @@ Rutam Kathale <[email protected]>
113120
Ruthwik Chikoti <[email protected]>
114121
Ryan Seal <[email protected]>
115122
Rylan Yang <[email protected]>
123+
SHIVAM YADAV <[email protected]>
116124
Sai Srikar Dumpeti <[email protected]>
117125
Sarthak Paandey <[email protected]>
118126
Saurabh Singh <[email protected]>

README.md

Lines changed: 138 additions & 32 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 dsvariance = require( '@stdlib/stats-base-dsvariance' );
132132
```
133133

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

136-
Computes the [variance][variance] of a single-precision floating-point strided array `x` using extended accumulation and returning an extended precision result.
136+
Computes the [variance][variance] of a single-precision floating-point strided array using extended accumulation and returning an extended precision result.
137137

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

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

144-
var v = dsvariance( N, 1, x, 1 );
143+
var v = dsvariance( 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 [`Float32Array`][@stdlib/array/float32].
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 Float32Array = require( '@stdlib/array-float32' );
159-
var floor = require( '@stdlib/math-base-special-floor' );
160158

161159
var x = new Float32Array( [ 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 = dsvariance( N, 1, x, 2 );
161+
var v = dsvariance( 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 Float32Array = require( '@stdlib/array-float32' );
174-
var floor = require( '@stdlib/math-base-special-floor' );
175171

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

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

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

187181
Computes the [variance][variance] of a single-precision floating-point strided array using extended accumulation and alternative indexing semantics and returning an extended precision result.
188182

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

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

195-
var v = dsvariance.ndarray( N, 1, x, 1, 0 );
188+
var v = dsvariance.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 Float32Array = require( '@stdlib/array-float32' );
207-
var floor = require( '@stdlib/math-base-special-floor' );
208200

209201
var x = new Float32Array( [ 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 = dsvariance.ndarray( N, 1, x, 2, 1 );
203+
var v = dsvariance.ndarray( 4, 1, x, 2, 1 );
213204
// returns 6.25
214205
```
215206

@@ -223,7 +214,7 @@ var v = dsvariance.ndarray( N, 1, x, 2, 1 );
223214

224215
- If `N <= 0`, both functions return `NaN`.
225216
- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`.
226-
- Accumulated intermediate values are stored as double-precision floating-point numbers.
217+
- Accumulated intermediate values are stored as double-precision floating-point numbers.
227218

228219
</section>
229220

@@ -236,18 +227,12 @@ var v = dsvariance.ndarray( N, 1, x, 2, 1 );
236227
<!-- eslint no-undef: "error" -->
237228

238229
```javascript
239-
var randu = require( '@stdlib/random-base-randu' );
240-
var round = require( '@stdlib/math-base-special-round' );
241-
var Float32Array = require( '@stdlib/array-float32' );
230+
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
242231
var dsvariance = require( '@stdlib/stats-base-dsvariance' );
243232

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

253238
var v = dsvariance( x.length, 1, x, 1 );
@@ -258,6 +243,127 @@ console.log( v );
258243

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

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

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 Float32Array = require( '@stdlib/array-float32' );
2827
var pkg = require( './../package.json' ).name;
2928
var dsvariance = require( './../lib/dsvariance.js' );
3029

3130

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

3440
/**
@@ -39,13 +45,7 @@ var dsvariance = require( './../lib/dsvariance.js' );
3945
* @returns {Function} benchmark function
4046
*/
4147
function createBenchmark( len ) {
42-
var x;
43-
var i;
44-
45-
x = new Float32Array( 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)