Skip to content

Commit 5774557

Browse files
headlessNodekgryte
andauthored
feat: add C ndarray API and refactor blas/ext/base/dcusumors
!PR-URL: #2968 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
1 parent 41f469a commit 5774557

File tree

19 files changed

+354
-160
lines changed

19 files changed

+354
-160
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ stdlib_strided_dcusum( 4, 0.0, x, 1, y, 1 );
208208
The function accepts the following arguments:
209209
210210
- **N**: `[in] CBLAS_INT` number of indexed elements.
211-
- **sum**: `[in] CBLAS_INT` initial sum.
211+
- **sum**: `[in] double` initial sum.
212212
- **X**: `[in] double*` input array.
213213
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
214214
- **Y**: `[out] double*` output array.
215215
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
216216
217217
```c
218-
void stdlib_strided_dcusum( const CBLAS_INT N, const CBLAS_INT sum, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
218+
void stdlib_strided_dcusum( const CBLAS_INT N, const double sum, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
219219
```
220220

221221
<!-- lint disable maximum-heading-length -->
@@ -236,7 +236,7 @@ stdlib_strided_dcusum_ndarray( 4, 0.0, x, 1, 0, y, 1, 0 );
236236
The function accepts the following arguments:
237237
238238
- **N**: `[in] CBLAS_INT` number of indexed elements.
239-
- **sum**: `[in] CBLAS_INT` initial sum.
239+
- **sum**: `[in] double` initial sum.
240240
- **X**: `[in] double*` input array.
241241
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
242242
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
@@ -245,7 +245,7 @@ The function accepts the following arguments:
245245
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
246246
247247
```c
248-
void stdlib_strided_dcusum_ndarray( const CBLAS_INT N, const CBLAS_INT sum, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
248+
void stdlib_strided_dcusum_ndarray( const CBLAS_INT N, const double sum, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
249249
```
250250

251251
</section>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ stdlib_strided_dcusumkbn( 4, 0.0, x, 1, y, 1 );
208208
The function accepts the following arguments:
209209
210210
- **N**: `[in] CBLAS_INT` number of indexed elements.
211-
- **sum**: `[in] CBLAS_INT` initial sum.
211+
- **sum**: `[in] double` initial sum.
212212
- **X**: `[in] double*` input array.
213213
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
214214
- **Y**: `[out] double*` output array.
215215
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
216216
217217
```c
218-
void stdlib_strided_dcusumkbn( const CBLAS_INT N, const CBLAS_INT sum, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
218+
void stdlib_strided_dcusumkbn( const CBLAS_INT N, const double sum, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
219219
```
220220

221221
<!-- lint disable maximum-heading-length -->
@@ -236,7 +236,7 @@ stdlib_strided_dcusumkbn_ndarray( 4, 0.0, x, 1, 0, y, 1, 0 );
236236
The function accepts the following arguments:
237237
238238
- **N**: `[in] CBLAS_INT` number of indexed elements.
239-
- **sum**: `[in] CBLAS_INT` initial sum.
239+
- **sum**: `[in] double` initial sum.
240240
- **X**: `[in] double*` input array.
241241
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
242242
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
@@ -245,7 +245,7 @@ The function accepts the following arguments:
245245
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
246246
247247
```c
248-
void stdlib_strided_dcusumkbn_ndarray( const CBLAS_INT N, const CBLAS_INT sum, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
248+
void stdlib_strided_dcusumkbn_ndarray( const CBLAS_INT N, const double sum, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
249249
```
250250

251251
</section>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ stdlib_strided_dcusumkbn2( 4, 0.0, x, 1, y, 1 );
214214
The function accepts the following arguments:
215215
216216
- **N**: `[in] CBLAS_INT` number of indexed elements.
217-
- **sum**: `[in] CBLAS_INT` initial sum.
217+
- **sum**: `[in] double` initial sum.
218218
- **X**: `[in] double*` input array.
219219
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
220220
- **Y**: `[out] double*` output array.
221221
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
222222
223223
```c
224-
void stdlib_strided_dcusumkbn2( const CBLAS_INT N, const CBLAS_INT sum, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
224+
void stdlib_strided_dcusumkbn2( const CBLAS_INT N, const double sum, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
225225
```
226226

227227
<!-- lint disable maximum-heading-length -->
@@ -242,7 +242,7 @@ stdlib_strided_dcusumkbn2_ndarray( 4, 0.0, x, 1, 0, y, 1, 0 );
242242
The function accepts the following arguments:
243243
244244
- **N**: `[in] CBLAS_INT` number of indexed elements.
245-
- **sum**: `[in] CBLAS_INT` initial sum.
245+
- **sum**: `[in] double` initial sum.
246246
- **X**: `[in] double*` input array.
247247
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
248248
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
@@ -251,7 +251,7 @@ The function accepts the following arguments:
251251
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
252252
253253
```c
254-
void stdlib_strided_dcusumkbn2_ndarray( const CBLAS_INT N, const CBLAS_INT sum, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
254+
void stdlib_strided_dcusumkbn2_ndarray( const CBLAS_INT N, const double sum, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
255255
```
256256

257257
</section>

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

Lines changed: 137 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in the strided input array starting from the second value and to store in the last `N` elements of the strided output array starting from the last element
118+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to calculate the cumulative sum of every other value in the strided input array starting from the second value and to store in the last `N` elements of the strided output array starting from the last element
119119

120120
```javascript
121121
var Float64Array = require( '@stdlib/array/float64' );
@@ -149,12 +149,13 @@ dcusumors.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' );
152+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
154153
var Float64Array = require( '@stdlib/array/float64' );
155154
var dcusumors = require( '@stdlib/blas/ext/base/dcusumors' );
156155

157-
var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) );
156+
var x = discreteUniform( 10, -100, 100, {
157+
'dtype': 'float64'
158+
});
158159
var y = new Float64Array( x.length );
159160

160161
console.log( x );
@@ -168,6 +169,138 @@ console.log( y );
168169

169170
<!-- /.examples -->
170171

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

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
2726
var pow = require( '@stdlib/math/base/special/pow' );
2827
var Float64Array = require( '@stdlib/array/float64' );
@@ -32,7 +31,9 @@ var dcusumors = require( './../lib/dcusumors.js' );
3231

3332
// VARIABLES //
3433

35-
var rand = uniform( -10.0, 10.0 );
34+
var options = {
35+
'dtype': 'float64'
36+
};
3637

3738

3839
// FUNCTIONS //
@@ -45,7 +46,7 @@ var rand = uniform( -10.0, 10.0 );
4546
* @returns {Function} benchmark function
4647
*/
4748
function createBenchmark( len ) {
48-
var x = filledarrayBy( len, 'float64', rand );
49+
var x = uniform( len, -100, 100, options );
4950
var y = new Float64Array( len );
5051
return benchmark;
5152

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
2827
var pow = require( '@stdlib/math/base/special/pow' );
2928
var Float64Array = require( '@stdlib/array/float64' );
@@ -33,7 +32,9 @@ var pkg = require( './../package.json' ).name;
3332

3433
// VARIABLES //
3534

36-
var rand = uniform( -10.0, 10.0 );
35+
var options = {
36+
'dtype': 'float64'
37+
};
3738
var dcusumors = tryRequire( resolve( __dirname, './../lib/dcusumors.native.js' ) );
3839
var opts = {
3940
'skip': ( dcusumors instanceof Error )
@@ -50,7 +51,7 @@ var opts = {
5051
* @returns {Function} benchmark function
5152
*/
5253
function createBenchmark( len ) {
53-
var x = filledarrayBy( len, 'float64', rand );
54+
var x = uniform( len, -100, 100, options );
5455
var y = new Float64Array( len );
5556
return benchmark;
5657

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
2726
var pow = require( '@stdlib/math/base/special/pow' );
2827
var Float64Array = require( '@stdlib/array/float64' );
@@ -32,7 +31,9 @@ var dcusumors = require( './../lib/ndarray.js' );
3231

3332
// VARIABLES //
3433

35-
var rand = uniform( -10.0, 10.0 );
34+
var options = {
35+
'dtype': 'float64'
36+
};
3637

3738

3839
// FUNCTIONS //
@@ -45,7 +46,7 @@ var rand = uniform( -10.0, 10.0 );
4546
* @returns {Function} benchmark function
4647
*/
4748
function createBenchmark( len ) {
48-
var x = filledarrayBy( len, 'float64', rand );
49+
var x = uniform( len, -100, 100, options );
4950
var y = new Float64Array( len );
5051
return benchmark;
5152

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
2827
var pow = require( '@stdlib/math/base/special/pow' );
2928
var Float64Array = require( '@stdlib/array/float64' );
@@ -33,7 +32,9 @@ var pkg = require( './../package.json' ).name;
3332

3433
// VARIABLES //
3534

36-
var rand = uniform( -10.0, 10.0 );
35+
var options = {
36+
'dtype': 'float64'
37+
};
3738
var dcusumors = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3839
var opts = {
3940
'skip': ( dcusumors instanceof Error )
@@ -50,7 +51,7 @@ var opts = {
5051
* @returns {Function} benchmark function
5152
*/
5253
function createBenchmark( len ) {
53-
var x = filledarrayBy( len, 'float64', rand );
54+
var x = uniform( len, -100, 100, options );
5455
var y = new Float64Array( len );
5556
return benchmark;
5657

0 commit comments

Comments
 (0)