Skip to content

Commit a13603b

Browse files
authored
feat: add C ndarray API and refactor blas/ext/base/dcusum
PR-URL: #2954 Reviewed-by: Athan Reines <[email protected]>
1 parent c4172be commit a13603b

File tree

24 files changed

+316
-101
lines changed

24 files changed

+316
-101
lines changed

lib/node_modules/@stdlib/blas/ext/base/dapxsum/examples/c/example.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "stdlib/blas/ext/base/dapxsum.h"
20-
#include <stdint.h>
2120
#include <stdio.h>
2221

2322
int main( void ) {

lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn/examples/c/example.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "stdlib/blas/ext/base/dapxsumkbn.h"
20-
#include <stdint.h>
2120
#include <stdio.h>
2221

2322
int main( void ) {

lib/node_modules/@stdlib/blas/ext/base/dapxsumkbn2/examples/c/example.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "stdlib/blas/ext/base/dapxsumkbn2.h"
20-
#include <stdint.h>
2120
#include <stdio.h>
2221

2322
int main( void ) {

lib/node_modules/@stdlib/blas/ext/base/dapxsumors/examples/c/example.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "stdlib/blas/ext/base/dapxsumors.h"
20-
#include <stdint.h>
2120
#include <stdio.h>
2221

2322
int main( void ) {

lib/node_modules/@stdlib/blas/ext/base/dapxsumpw/examples/c/example.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "stdlib/blas/ext/base/dapxsumpw.h"
20-
#include <stdint.h>
2120
#include <stdio.h>
2221

2322
int main( void ) {

lib/node_modules/@stdlib/blas/ext/base/dasumpw/examples/c/example.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include "stdlib/blas/ext/base/dasumpw.h"
20-
#include <stdint.h>
2120
#include <stdio.h>
2221

2322
int main( void ) {

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

Lines changed: 138 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The function has the following parameters:
6565
- **y**: output [`Float64Array`][@stdlib/array/float64].
6666
- **strideY**: index increment 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 the strided input array,
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 the strided input array,
6969

7070
```javascript
7171
var Float64Array = require( '@stdlib/array/float64' );
@@ -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, 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
119119

120120
```javascript
121121
var Float64Array = require( '@stdlib/array/float64' );
@@ -148,12 +148,13 @@ dcusum.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 );
148148
<!-- eslint no-undef: "error" -->
149149

150150
```javascript
151-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
152-
var filledarrayBy = require( '@stdlib/array/filled-by' );
151+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
153152
var Float64Array = require( '@stdlib/array/float64' );
154153
var dcusum = require( '@stdlib/blas/ext/base/dcusum' );
155154

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

159160
console.log( x );
@@ -167,6 +168,138 @@ console.log( y );
167168

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

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

lib/node_modules/@stdlib/blas/ext/base/dcusum/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 dcusum = require( './../lib/dcusum.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/dcusum/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' );
@@ -37,7 +36,9 @@ var dcusum = tryRequire( resolve( __dirname, './../lib/dcusum.native.js' ) );
3736
var opts = {
3837
'skip': ( dcusum instanceof Error )
3938
};
40-
var rand = uniform( -10.0, 10.0 );
39+
var options = {
40+
'dtype': 'float64'
41+
};
4142

4243

4344
// FUNCTIONS //
@@ -50,7 +51,7 @@ var rand = uniform( -10.0, 10.0 );
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/dcusum/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 dcusum = 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

0 commit comments

Comments
 (0)