Skip to content

Commit a350d1d

Browse files
committed
Auto-generated commit
1 parent 7fc024b commit a350d1d

27 files changed

+402
-257
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@
66

77
## Unreleased (2025-01-18)
88

9+
<section class="features">
10+
11+
### Features
12+
13+
- [`5cfc390`](https://github.com/stdlib-js/stdlib/commit/5cfc390ccb133747ade74ea8b0c29d4e08fce639) - add C `ndarray` interface and refactor implementation for `stats/base/dsmeanpn` [(#4331)](https://github.com/stdlib-js/stdlib/pull/4331)
14+
15+
</section>
16+
17+
<!-- /.features -->
18+
919
<section class="commits">
1020

1121
### Commits
1222

1323
<details>
1424

25+
- [`5cfc390`](https://github.com/stdlib-js/stdlib/commit/5cfc390ccb133747ade74ea8b0c29d4e08fce639) - **feat:** add C `ndarray` interface and refactor implementation for `stats/base/dsmeanpn` [(#4331)](https://github.com/stdlib-js/stdlib/pull/4331) _(by Neeraj Pathak, Athan Reines)_
1526
- [`15c26dd`](https://github.com/stdlib-js/stdlib/commit/15c26dd8e62bcc6ef839f1c604e3fe537c4d3ca5) - **refactor:** update `stats/base/dsmeanpn` native addon from C++ to C [(#4723)](https://github.com/stdlib-js/stdlib/pull/4723) _(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)_
@@ -28,9 +39,10 @@
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
45+
- Neeraj Pathak
3446
- Philipp Burckhardt
3547
- Prashant Kumar Yadav
3648

README.md

Lines changed: 133 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,36 +84,33 @@ To view installation and usage instructions specific to each branch build, be su
8484
var dsmeanpn = require( '@stdlib/stats-base-dsmeanpn' );
8585
```
8686

87-
#### dsmeanpn( N, x, stride )
87+
#### dsmeanpn( N, x, strideX )
8888

8989
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array `x` using a two-pass error correction algorithm with extended accumulation and returning an extended precision result.
9090

9191
```javascript
9292
var Float32Array = require( '@stdlib/array-float32' );
9393

9494
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
95-
var N = x.length;
9695

97-
var v = dsmeanpn( N, x, 1 );
96+
var v = dsmeanpn( x.length, x, 1 );
9897
// returns ~0.3333
9998
```
10099

101100
The function has the following parameters:
102101

103102
- **N**: number of indexed elements.
104103
- **x**: input [`Float32Array`][@stdlib/array/float32].
105-
- **stride**: index increment for `x`.
104+
- **strideX**: stride length for `x`.
106105

107-
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,
106+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [arithmetic mean][arithmetic-mean] of every other element in `x`,
108107

109108
```javascript
110109
var Float32Array = require( '@stdlib/array-float32' );
111-
var floor = require( '@stdlib/math-base-special-floor' );
112110

113111
var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
114-
var N = floor( x.length / 2 );
115112

116-
var v = dsmeanpn( N, x, 2 );
113+
var v = dsmeanpn( 4, x, 2 );
117114
// returns 1.25
118115
```
119116

@@ -123,45 +120,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
123120

124121
```javascript
125122
var Float32Array = require( '@stdlib/array-float32' );
126-
var floor = require( '@stdlib/math-base-special-floor' );
127123

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

131-
var N = floor( x0.length / 2 );
132-
133-
var v = dsmeanpn( N, x1, 2 );
127+
var v = dsmeanpn( 4, x1, 2 );
134128
// returns 1.25
135129
```
136130

137-
#### dsmeanpn.ndarray( N, x, stride, offset )
131+
#### dsmeanpn.ndarray( N, x, strideX, offsetX )
138132

139133
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using a two-pass error correction algorithm with extended accumulation and alternative indexing semantics and returning an extended precision result.
140134

141135
```javascript
142136
var Float32Array = require( '@stdlib/array-float32' );
143137

144138
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
145-
var N = x.length;
146139

147-
var v = dsmeanpn.ndarray( N, x, 1, 0 );
140+
var v = dsmeanpn.ndarray( x.length, x, 1, 0 );
148141
// returns ~0.33333
149142
```
150143

151144
The function has the following additional parameters:
152145

153-
- **offset**: starting index for `x`.
146+
- **offsetX**: starting index for `x`.
154147

155-
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 [arithmetic mean][arithmetic-mean] for every other value in `x` starting from the second value
148+
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 [arithmetic mean][arithmetic-mean] for every other element in `x` starting from the second element
156149

157150
```javascript
158151
var Float32Array = require( '@stdlib/array-float32' );
159-
var floor = require( '@stdlib/math-base-special-floor' );
160152

161153
var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
162-
var N = floor( x.length / 2 );
163154

164-
var v = dsmeanpn.ndarray( N, x, 2, 1 );
155+
var v = dsmeanpn.ndarray( 4, x, 2, 1 );
165156
// returns 1.25
166157
```
167158

@@ -174,7 +165,7 @@ var v = dsmeanpn.ndarray( N, x, 2, 1 );
174165
## Notes
175166

176167
- If `N <= 0`, both functions return `NaN`.
177-
- Accumulated intermediate values are stored as double-precision floating-point numbers.
168+
- Accumulated intermediate values are stored as double-precision floating-point numbers.
178169

179170
</section>
180171

@@ -187,18 +178,12 @@ var v = dsmeanpn.ndarray( N, x, 2, 1 );
187178
<!-- eslint no-undef: "error" -->
188179

189180
```javascript
190-
var randu = require( '@stdlib/random-base-randu' );
191-
var round = require( '@stdlib/math-base-special-round' );
192-
var Float32Array = require( '@stdlib/array-float32' );
181+
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
193182
var dsmeanpn = require( '@stdlib/stats-base-dsmeanpn' );
194183

195-
var x;
196-
var i;
197-
198-
x = new Float32Array( 10 );
199-
for ( i = 0; i < x.length; i++ ) {
200-
x[ i ] = round( (randu()*100.0) - 50.0 );
201-
}
184+
var x = discreteUniform( 10, -50, 50, {
185+
'dtype': 'float32'
186+
});
202187
console.log( x );
203188

204189
var v = dsmeanpn( x.length, x, 1 );
@@ -209,6 +194,123 @@ console.log( v );
209194

210195
<!-- /.examples -->
211196

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

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 dsmeanpn = require( './../lib/dsmeanpn.js' );
3029

3130

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

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

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-harness' );
25-
var randu = require( '@stdlib/random-base-randu' );
25+
var uniform = require( '@stdlib/random-array-uniform' );
2626
var isnan = require( '@stdlib/math-base-assert-is-nan' );
2727
var pow = require( '@stdlib/math-base-special-pow' );
28-
var Float32Array = require( '@stdlib/array-float32' );
2928
var tryRequire = require( '@stdlib/utils-try-require' );
3029
var pkg = require( './../package.json' ).name;
3130

@@ -36,6 +35,9 @@ var dsmeanpn = tryRequire( resolve( __dirname, './../lib/dsmeanpn.native.js' ) )
3635
var opts = {
3736
'skip': ( dsmeanpn instanceof Error )
3837
};
38+
var options = {
39+
'dtype': 'float32'
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 Float32Array( 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 ) {

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-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 dsmeanpn = require( './../lib/ndarray.js' );
3029

3130

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

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