Skip to content

Commit e98081d

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into gcusum-accessor
2 parents de71e0d + 068bbeb commit e98081d

File tree

29 files changed

+411
-245
lines changed

29 files changed

+411
-245
lines changed

lib/node_modules/@stdlib/blas/ext/base/gcusumkbn/docs/types/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import gcusumkbn = require( './index' );
2828
const y = new Float64Array( 10 );
2929

3030
gcusumkbn( x.length, 0.0, x, 1, y, 1 ); // $ExpectType Float64Array
31-
gcusumkbn( x.length, 0.0, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType AccessorArray
31+
gcusumkbn( x.length, 0.0, new AccessorArray( x ), 1, new AccessorArray( y ), 1 ); // $ExpectType AccessorArray<number>
3232
}
3333

3434
// The compiler throws an error if the function is provided a first argument which is not a number...
@@ -142,7 +142,7 @@ import gcusumkbn = require( './index' );
142142
const y = new Float64Array( 10 );
143143

144144
gcusumkbn.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ); // $ExpectType Float64Array
145-
gcusumkbn.ndarray( x.length, 0.0, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType AccessorArray
145+
gcusumkbn.ndarray( x.length, 0.0, new AccessorArray( x ), 1, 0, new AccessorArray( y ), 1, 0 ); // $ExpectType AccessorArray<number>
146146
}
147147

148148
// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...

lib/node_modules/@stdlib/blas/ext/base/gcusumkbn/lib/accessors.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ var abs = require( '@stdlib/math/base/special/abs' );
5555
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
5656
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
5757
*
58-
* var x = toAccessorArray( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
59-
* var y = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
58+
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ];
59+
* var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
6060
*
61-
* gcusumkbn( 4, 0.0, arraylike2object( x ), 2, 1, arraylike2object( y ), 1, 0 );
61+
* gcusumkbn( 4, 0.0, arraylike2object( toAccessorArray( x ) ), 2, 1, arraylike2object( toAccessorArray( y ) ), 1, 0 );
62+
* // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ]
6263
*/
6364
function gcusumkbn( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
6465
var xbuf;

lib/node_modules/@stdlib/blas/ext/base/gcusumkbn/lib/ndarray.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ function gcusumkbn( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {
7272
ox = arraylike2object( x );
7373
oy = arraylike2object( y );
7474
if ( ox.accessorProtocol || oy.accessorProtocol ) {
75-
return accessors( N, sum, ox, strideX, offsetX, oy, strideY, offsetY );
75+
accessors( N, sum, ox, strideX, offsetX, oy, strideY, offsetY );
76+
return y;
7677
}
7778
ix = offsetX;
7879
iy = offsetY;

lib/node_modules/@stdlib/blas/ext/base/gcusumkbn/test/test.main.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,20 @@ tape( 'the function returns a reference to the output array', function test( t )
230230
t.end();
231231
});
232232

233+
tape( 'the function returns a reference to the output array (accessors)', function test( t ) {
234+
var out;
235+
var x;
236+
var y;
237+
238+
x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
239+
y = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
240+
241+
out = gcusumkbn( x.length, 0.0, x, 1, y, 1 );
242+
243+
t.strictEqual( out, y, 'same reference' );
244+
t.end();
245+
});
246+
233247
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) {
234248
var expected;
235249
var x;

lib/node_modules/@stdlib/blas/ext/base/gcusumkbn/test/test.ndarray.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ tape( 'the function returns a reference to the output array', function test( t )
227227
t.end();
228228
});
229229

230+
tape( 'the function returns a reference to the output array (accessors)', function test( t ) {
231+
var out;
232+
var x;
233+
var y;
234+
235+
x = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
236+
y = toAccessorArray( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
237+
238+
out = gcusumkbn( x.length, 0.0, x, 1, 0, y, 1, 0 );
239+
240+
t.strictEqual( out, y, 'same reference' );
241+
t.end();
242+
});
243+
230244
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `y` unchanged', function test( t ) {
231245
var expected;
232246
var x;

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

Lines changed: 119 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2020 The Stdlib Authors.
5+
Copyright (c) 2024 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -51,36 +51,33 @@ The [arithmetic mean][arithmetic-mean] is defined as
5151
var dsmean = require( '@stdlib/stats/base/dsmean' );
5252
```
5353

54-
#### dsmean( N, x, stride )
54+
#### dsmean( N, x, strideX )
5555

5656
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array `x` using extended accumulation and returning an extended precision result.
5757

5858
```javascript
5959
var Float32Array = require( '@stdlib/array/float32' );
6060

6161
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
62-
var N = x.length;
6362

64-
var v = dsmean( N, x, 1 );
65-
// returns ~0.3333
63+
var v = dsmean( x.length, x, 1 );
64+
// returns ~0.33333
6665
```
6766

6867
The function has the following parameters:
6968

7069
- **N**: number of indexed elements.
7170
- **x**: input [`Float32Array`][@stdlib/array/float32].
72-
- **stride**: index increment for `x`.
71+
- **strideX**: stride length for `x`.
7372

74-
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`,
73+
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`,
7574

7675
```javascript
7776
var Float32Array = require( '@stdlib/array/float32' );
78-
var floor = require( '@stdlib/math/base/special/floor' );
7977

8078
var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
81-
var N = floor( x.length / 2 );
8279

83-
var v = dsmean( N, x, 2 );
80+
var v = dsmean( 4, x, 2 );
8481
// returns 1.25
8582
```
8683

@@ -90,45 +87,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
9087

9188
```javascript
9289
var Float32Array = require( '@stdlib/array/float32' );
93-
var floor = require( '@stdlib/math/base/special/floor' );
9490

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

98-
var N = floor( x0.length / 2 );
99-
100-
var v = dsmean( N, x1, 2 );
94+
var v = dsmean( 4, x1, 2 );
10195
// returns 1.25
10296
```
10397

104-
#### dsmean.ndarray( N, x, stride, offset )
98+
#### dsmean.ndarray( N, x, strideX, offsetX )
10599

106100
Computes the [arithmetic mean][arithmetic-mean] of a single-precision floating-point strided array using extended accumulation and alternative indexing semantics and returning an extended precision result.
107101

108102
```javascript
109103
var Float32Array = require( '@stdlib/array/float32' );
110104

111105
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
112-
var N = x.length;
113106

114-
var v = dsmean.ndarray( N, x, 1, 0 );
107+
var v = dsmean.ndarray( x.length, x, 1, 0 );
115108
// returns ~0.33333
116109
```
117110

118111
The function has the following additional parameters:
119112

120-
- **offset**: starting index for `x`.
113+
- **offsetX**: starting index for `x`.
121114

122-
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
115+
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
123116

124117
```javascript
125118
var Float32Array = require( '@stdlib/array/float32' );
126-
var floor = require( '@stdlib/math/base/special/floor' );
127119

128120
var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
129-
var N = floor( x.length / 2 );
130121

131-
var v = dsmean.ndarray( N, x, 2, 1 );
122+
var v = dsmean.ndarray( 4, x, 2, 1 );
132123
// returns 1.25
133124
```
134125

@@ -141,7 +132,7 @@ var v = dsmean.ndarray( N, x, 2, 1 );
141132
## Notes
142133

143134
- If `N <= 0`, both functions return `NaN`.
144-
- Accumulated intermediate values are stored as double-precision floating-point numbers.
135+
- Accumulated intermediate values are stored as double-precision floating-point numbers.
145136

146137
</section>
147138

@@ -154,18 +145,12 @@ var v = dsmean.ndarray( N, x, 2, 1 );
154145
<!-- eslint no-undef: "error" -->
155146

156147
```javascript
157-
var randu = require( '@stdlib/random/base/randu' );
158-
var round = require( '@stdlib/math/base/special/round' );
159-
var Float32Array = require( '@stdlib/array/float32' );
148+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
160149
var dsmean = require( '@stdlib/stats/base/dsmean' );
161150

162-
var x;
163-
var i;
164-
165-
x = new Float32Array( 10 );
166-
for ( i = 0; i < x.length; i++ ) {
167-
x[ i ] = round( (randu()*100.0) - 50.0 );
168-
}
151+
var x = discreteUniform( 10, -50, 50, {
152+
'dtype': 'float32'
153+
});
169154
console.log( x );
170155

171156
var v = dsmean( x.length, x, 1 );
@@ -176,6 +161,107 @@ console.log( v );
176161

177162
<!-- /.examples -->
178163

164+
<!-- C usage documentation. -->
165+
166+
<section class="usage">
167+
168+
### Usage
169+
170+
```c
171+
#include "stdlib/stats/base/dsmean.h"
172+
```
173+
174+
#### stdlib_strided_dsmean( N, \*X, strideX )
175+
176+
Computes the arithmetic mean of a single-precision floating-point strided array using extended accumulation and returning an extended precision result.
177+
178+
```c
179+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
180+
181+
double v = stdlib_strided_dsmean( 4, x, 2 );
182+
// returns 4.0
183+
```
184+
185+
The function accepts the following arguments:
186+
187+
- **N**: `[in] CBLAS_INT` number of indexed elements.
188+
- **X**: `[in] float*` input array.
189+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
190+
191+
```c
192+
double stdlib_strided_dsmean( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
193+
```
194+
195+
#### stdlib_strided_dsmean_ndarray( N, \*X, strideX, offsetX )
196+
197+
Computes the arithmetic mean of a single-precision floating-point strided array using extended accumulation and alternative indexing semantics and returning an extended precision result.
198+
199+
```c
200+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
201+
202+
double v = stdlib_strided_dsmean_ndarray( 4, x, 2, 0 );
203+
// returns 4.0
204+
```
205+
206+
The function accepts the following arguments:
207+
208+
- **N**: `[in] CBLAS_INT` number of indexed elements.
209+
- **X**: `[in] float*` input array.
210+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
211+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
212+
213+
```c
214+
double stdlib_strided_dsmean_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
215+
```
216+
217+
</section>
218+
219+
<!-- /.usage -->
220+
221+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
222+
223+
<section class="notes">
224+
225+
</section>
226+
227+
<!-- /.notes -->
228+
229+
<!-- C API usage examples. -->
230+
231+
<section class="examples">
232+
233+
### Examples
234+
235+
```c
236+
#include "stdlib/stats/base/dsmean.h"
237+
#include <stdio.h>
238+
239+
int main( void ) {
240+
// Create a strided array:
241+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
242+
243+
// Specify the number of elements:
244+
const int N = 4;
245+
246+
// Specify the stride length:
247+
const int strideX = 2;
248+
249+
// Compute the arithmetic mean:
250+
double v = stdlib_strided_dsmean( N, x, strideX );
251+
252+
// Print the result:
253+
printf( "mean: %lf\n", v );
254+
}
255+
```
256+
257+
</section>
258+
259+
<!-- /.examples -->
260+
261+
</section>
262+
263+
<!-- /.c -->
264+
179265
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
180266
181267
<section class="related">

lib/node_modules/@stdlib/stats/base/dsmean/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' );
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 dsmean = require( './../lib/dsmean.js' );
3029

3130

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

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