Skip to content

Commit a1edb83

Browse files
authored
feat: add C ndarray API and refactor blas/ext/base/scusumors
PR-URL: #4813 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 0eac1eb commit a1edb83

File tree

20 files changed

+384
-204
lines changed

20 files changed

+384
-204
lines changed

lib/node_modules/@stdlib/blas/ext/base/scusumors/README.md

Lines changed: 144 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ The function has the following parameters:
6161
- **N**: number of indexed elements.
6262
- **sum**: initial sum.
6363
- **x**: input [`Float32Array`][@stdlib/array/float32].
64-
- **strideX**: index increment for `x`.
64+
- **strideX**: stride length for `x`.
6565
- **y**: output [`Float32Array`][@stdlib/array/float32].
66-
- **strideY**: index increment for `y`.
66+
- **strideY**: stride length for `y`.
6767

68-
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`,
68+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative sum of every other element:
6969

7070
```javascript
7171
var Float32Array = require( '@stdlib/array/float32' );
@@ -115,7 +115,7 @@ The function has the following additional parameters:
115115
- **offsetX**: starting index for `x`.
116116
- **offsetY**: starting index for `y`.
117117

118-
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 sum 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
118+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to calculate the cumulative sum of every other element starting from the second element and to store in the last `N` elements of `y` starting from the last element:
119119

120120
```javascript
121121
var Float32Array = require( '@stdlib/array/float32' );
@@ -149,15 +149,17 @@ scusumors.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 );
149149
<!-- eslint no-undef: "error" -->
150150

151151
```javascript
152-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
153-
var filledarrayBy = require( '@stdlib/array/filled-by' );
154-
var Float32Array = require( '@stdlib/array/float32' );
152+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
155153
var scusumors = require( '@stdlib/blas/ext/base/scusumors' );
156154

157-
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );
158-
var y = new Float32Array( x.length );
159-
155+
var x = discreteUniform( 10, -100, 100, {
156+
'dtype': 'float32'
157+
});
160158
console.log( x );
159+
160+
var y = discreteUniform( 10, -100, 100, {
161+
'dtype': 'float32'
162+
});
161163
console.log( y );
162164

163165
scusumors( x.length, 0.0, x, 1, y, -1 );
@@ -168,6 +170,138 @@ console.log( y );
168170

169171
<!-- /.examples -->
170172

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

lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
25-
var filledarrayBy = require( '@stdlib/array/filled-by' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2625
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2726
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float32Array = require( '@stdlib/array/float32' );
2927
var pkg = require( './../package.json' ).name;
3028
var scusumors = require( './../lib/scusumors.js' );
3129

3230

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

3540
/**
@@ -40,11 +45,8 @@ var scusumors = require( './../lib/scusumors.js' );
4045
* @returns {Function} benchmark function
4146
*/
4247
function createBenchmark( len ) {
43-
var y;
44-
var x;
45-
46-
x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) );
47-
y = new Float32Array( len );
48+
var x = uniform( len, -100, 100, options );
49+
var y = uniform( len, -100, 100, options );
4850

4951
return benchmark;
5052

lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.native.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
26-
var filledarrayBy = require( '@stdlib/array/filled-by' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2726
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2827
var pow = require( '@stdlib/math/base/special/pow' );
29-
var Float32Array = require( '@stdlib/array/float32' );
3028
var tryRequire = require( '@stdlib/utils/try-require' );
3129
var pkg = require( './../package.json' ).name;
3230

@@ -37,6 +35,9 @@ var scusumors = tryRequire( resolve( __dirname, './../lib/scusumors.native.js' )
3735
var opts = {
3836
'skip': ( scusumors instanceof Error )
3937
};
38+
var options = {
39+
'dtype': 'float32'
40+
};
4041

4142

4243
// FUNCTIONS //
@@ -49,11 +50,8 @@ var opts = {
4950
* @returns {Function} benchmark function
5051
*/
5152
function createBenchmark( len ) {
52-
var x;
53-
var y;
54-
55-
x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) );
56-
y = new Float32Array( len );
53+
var x = uniform( len, -100, 100, options );
54+
var y = uniform( len, -100, 100, options );
5755

5856
return benchmark;
5957

lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
25-
var filledarrayBy = require( '@stdlib/array/filled-by' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
2625
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2726
var pow = require( '@stdlib/math/base/special/pow' );
28-
var Float32Array = require( '@stdlib/array/float32' );
2927
var pkg = require( './../package.json' ).name;
3028
var scusumors = require( './../lib/ndarray.js' );
3129

3230

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

3540
/**
@@ -40,11 +45,8 @@ var scusumors = require( './../lib/ndarray.js' );
4045
* @returns {Function} benchmark function
4146
*/
4247
function createBenchmark( len ) {
43-
var x;
44-
var y;
45-
46-
x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) );
47-
y = new Float32Array( len );
48+
var x = uniform( len, -100, 100, options );
49+
var y = uniform( len, -100, 100, options );
4850

4951
return benchmark;
5052

lib/node_modules/@stdlib/blas/ext/base/scusumors/benchmark/benchmark.ndarray.native.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
25-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
26-
var filledarrayBy = require( '@stdlib/array/filled-by' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
2726
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2827
var pow = require( '@stdlib/math/base/special/pow' );
29-
var Float32Array = require( '@stdlib/array/float32' );
3028
var tryRequire = require( '@stdlib/utils/try-require' );
3129
var pkg = require( './../package.json' ).name;
3230

@@ -37,6 +35,9 @@ var scusumors = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) )
3735
var opts = {
3836
'skip': ( scusumors instanceof Error )
3937
};
38+
var options = {
39+
'dtype': 'float32'
40+
};
4041

4142

4243
// FUNCTIONS //
@@ -49,11 +50,8 @@ var opts = {
4950
* @returns {Function} benchmark function
5051
*/
5152
function createBenchmark( len ) {
52-
var x;
53-
var y;
54-
55-
x = filledarrayBy( len, 'float32', uniform( -10.0, 10.0 ) );
56-
y = new Float32Array( len );
53+
var x = uniform( len, -100, 100, options );
54+
var y = uniform( len, -100, 100, options );
5755

5856
return benchmark;
5957

0 commit comments

Comments
 (0)