Skip to content

Commit 085aeea

Browse files
authored
feat: add C ndarray interface and refactor implementation for stats/base/scumin
PR-URL: #4694 Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 95bdc42 commit 085aeea

22 files changed

+364
-271
lines changed

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

Lines changed: 135 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ The function has the following parameters:
5454

5555
- **N**: number of indexed elements.
5656
- **x**: input [`Float32Array`][@stdlib/array/float32].
57-
- **strideX**: index increment for `x`.
57+
- **strideX**: stride length for `x`.
5858
- **y**: output [`Float32Array`][@stdlib/array/float32].
59-
- **strideY**: index increment for `y`.
59+
- **strideY**: stride length for `y`.
6060

61-
The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative minimum of every other element in `x`,
61+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative minimum of every other element in `x`,
6262

6363
```javascript
6464
var Float32Array = require( '@stdlib/array/float32' );
@@ -108,7 +108,7 @@ The function has the following additional parameters:
108108
- **offsetX**: starting index for `x`.
109109
- **offsetY**: starting index for `y`.
110110

111-
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative minimum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element
111+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative minimum of every other element in `x` starting from the second element and to store in the last `N` elements of `y` starting from the last element
112112

113113
```javascript
114114
var Float32Array = require( '@stdlib/array/float32' );
@@ -141,20 +141,14 @@ scumin.ndarray( 4, x, 2, 1, y, -1, y.length-1 );
141141
<!-- eslint no-undef: "error" -->
142142

143143
```javascript
144-
var randu = require( '@stdlib/random/base/randu' );
145-
var round = require( '@stdlib/math/base/special/round' );
144+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
146145
var Float32Array = require( '@stdlib/array/float32' );
147146
var scumin = require( '@stdlib/stats/base/scumin' );
148147

149-
var y;
150-
var x;
151-
var i;
152-
153-
x = new Float32Array( 10 );
154-
y = new Float32Array( x.length );
155-
for ( i = 0; i < x.length; i++ ) {
156-
x[ i ] = round( randu()*100.0 );
157-
}
148+
var x = discreteUniform( 10, -50, 50, {
149+
'dtype': 'float32'
150+
});
151+
var y = new Float32Array( x.length );
158152
console.log( x );
159153
console.log( y );
160154

@@ -166,6 +160,132 @@ console.log( y );
166160

167161
<!-- /.examples -->
168162

163+
<!-- C interface documentation. -->
164+
165+
* * *
166+
167+
<section class="c">
168+
169+
## C APIs
170+
171+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
172+
173+
<section class="intro">
174+
175+
</section>
176+
177+
<!-- /.intro -->
178+
179+
<!-- C usage documentation. -->
180+
181+
<section class="usage">
182+
183+
### Usage
184+
185+
```c
186+
#include "stdlib/stats/base/scumin.h"
187+
```
188+
189+
#### stdlib_strided_scumin( N, \*X, strideX, \*Y, strideY )
190+
191+
Computes the cumulative minimum of single-precision floating-point strided array elements.
192+
193+
```c
194+
const float x[] = { 1.0f, 2.0f, -3.0f, 4.0f, -5.0f, 6.0f, 7.0f, 8.0f };
195+
float y[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
196+
197+
stdlib_strided_scumin( 4, x, 2, y, -2 );
198+
```
199+
200+
The function accepts the following arguments:
201+
202+
- **N**: `[in] CBLAS_INT` number of indexed elements.
203+
- **X**: `[in] float*` input array.
204+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
205+
- **Y**: `[out] float*` output array.
206+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
207+
208+
```c
209+
void stdlib_strided_scumin( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY );
210+
```
211+
212+
#### stdlib_strided_scumin_ndarray(N, \*X, strideX, offsetX, \*Y, strideY, offsetY )
213+
214+
Computes the cumulative minimum of single-precision floating-point strided array elements using alternative indexing semantics.
215+
216+
```c
217+
const float x[] = { 1.0f, 2.0f, -3.0f, 4.0f, -5.0f, 6.0f, 7.0f, 8.0f };
218+
float y[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
219+
220+
stdlib_strided_scumin_ndarray( 4, x, 2, 0, y, -2, 0 );
221+
```
222+
223+
The function accepts the following arguments:
224+
225+
- **N**: `[in] CBLAS_INT` number of indexed elements.
226+
- **X**: `[in] float*` input array.
227+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
228+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
229+
- **Y**: `[out] float*` output array.
230+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
231+
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
232+
233+
```c
234+
void stdlib_strided_scumin_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
235+
```
236+
237+
</section>
238+
239+
<!-- /.usage -->
240+
241+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
242+
243+
<section class="notes">
244+
245+
</section>
246+
247+
<!-- /.notes -->
248+
249+
<!-- C API usage examples. -->
250+
251+
<section class="examples">
252+
253+
### Examples
254+
255+
```c
256+
#include "stdlib/stats/base/scumin.h"
257+
#include <stdio.h>
258+
259+
int main( void ) {
260+
// Create strided arrays:
261+
const float x[] = { 1.0f, 2.0f, -3.0f, 4.0f, -5.0f, 6.0f, 7.0f, 8.0f };
262+
float y[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
263+
264+
// Specify the number of elements:
265+
const int N = 4;
266+
267+
// Specify stride lengths:
268+
const int strideX = 2;
269+
const int strideY = -2;
270+
271+
// Compute the cumulative minimum:
272+
stdlib_strided_scumin( N, x, strideX, y, strideY );
273+
274+
// Print the result:
275+
for ( int i = 0; i < 8; i++ ) {
276+
printf( "y[ %d ] = %f\n", i, y[ i ] );
277+
}
278+
}
279+
```
280+
281+
</section>
282+
283+
<!-- /.examples -->
284+
285+
</section>
286+
287+
<!-- /.c -->
288+
169289
<section class="references">
170290
171291
</section>

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var Float32Array = require( '@stdlib/array/float32' );
2828
var pkg = require( './../package.json' ).name;
2929
var scumin = require( './../lib/scumin.js' );
3030

3131

32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float32'
36+
};
37+
38+
3239
// FUNCTIONS //
3340

3441
/**
@@ -39,15 +46,8 @@ var scumin = require( './../lib/scumin.js' );
3946
* @returns {Function} benchmark function
4047
*/
4148
function createBenchmark( len ) {
42-
var y;
43-
var x;
44-
var i;
45-
46-
x = new Float32Array( len );
47-
y = new Float32Array( len );
48-
for ( i = 0; i < x.length; i++ ) {
49-
x[ i ] = ( randu()*20.0 ) - 10.0;
50-
}
49+
var x = uniform( len, -10.0, 10.0, options );
50+
var y = new Float32Array( len );
5151
return benchmark;
5252

5353
function benchmark( b ) {

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var pow = require( '@stdlib/math/base/special/pow' );
2828
var Float32Array = require( '@stdlib/array/float32' );
@@ -36,6 +36,9 @@ var scumin = tryRequire( resolve( __dirname, './../lib/scumin.native.js' ) );
3636
var opts = {
3737
'skip': ( scumin instanceof Error )
3838
};
39+
var options = {
40+
'dtype': 'float32'
41+
};
3942

4043

4144
// FUNCTIONS //
@@ -48,15 +51,8 @@ var opts = {
4851
* @returns {Function} benchmark function
4952
*/
5053
function createBenchmark( len ) {
51-
var x;
52-
var y;
53-
var i;
54-
55-
x = new Float32Array( len );
56-
y = new Float32Array( len );
57-
for ( i = 0; i < x.length; i++ ) {
58-
x[ i ] = ( randu()*20.0 ) - 10.0;
59-
}
54+
var x = uniform( len, -10.0, 10.0, options );
55+
var y = new Float32Array( len );
6056
return benchmark;
6157

6258
function benchmark( b ) {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var Float32Array = require( '@stdlib/array/float32' );
2828
var pkg = require( './../package.json' ).name;
2929
var scumin = require( './../lib/ndarray.js' );
3030

3131

32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float32'
36+
};
37+
38+
3239
// FUNCTIONS //
3340

3441
/**
@@ -39,15 +46,8 @@ var scumin = require( './../lib/ndarray.js' );
3946
* @returns {Function} benchmark function
4047
*/
4148
function createBenchmark( len ) {
42-
var x;
43-
var y;
44-
var i;
45-
46-
x = new Float32Array( len );
47-
y = new Float32Array( len );
48-
for ( i = 0; i < x.length; i++ ) {
49-
x[ i ] = ( randu()*20.0 ) - 10.0;
50-
}
49+
var x = uniform( len, -10.0, 10.0, options );
50+
var y = new Float32Array( len );
5151
return benchmark;
5252

5353
function benchmark( b ) {

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

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

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2626
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2727
var pow = require( '@stdlib/math/base/special/pow' );
2828
var Float32Array = require( '@stdlib/array/float32' );
@@ -36,6 +36,9 @@ var scumin = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3636
var opts = {
3737
'skip': ( scumin instanceof Error )
3838
};
39+
var options = {
40+
'dtype': 'float32'
41+
};
3942

4043

4144
// FUNCTIONS //
@@ -48,15 +51,8 @@ var opts = {
4851
* @returns {Function} benchmark function
4952
*/
5053
function createBenchmark( len ) {
51-
var x;
52-
var y;
53-
var i;
54-
55-
x = new Float32Array( len );
56-
y = new Float32Array( len );
57-
for ( i = 0; i < x.length; i++ ) {
58-
x[ i ] = ( randu()*20.0 ) - 10.0;
59-
}
54+
var x = uniform( len, -10.0, 10.0, options );
55+
var y = new Float32Array( len );
6056
return benchmark;
6157

6258
function benchmark( b ) {

0 commit comments

Comments
 (0)