Skip to content

Commit 8582e3f

Browse files
headlessNodekgryte
andauthored
feat: add C ndarray API and refactor blas/ext/base/sasumpw
PR-URL: #4764 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent e02cd5b commit 8582e3f

24 files changed

+458
-295
lines changed

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

Lines changed: 127 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,26 @@ The [_L1_ norm][l1norm] is defined as
5151
var sasumpw = require( '@stdlib/blas/ext/base/sasumpw' );
5252
```
5353

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

5656
Computes the sum of absolute values ([_L1_ norm][l1norm]) of single-precision floating-point strided array elements using pairwise summation.
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 = sasumpw( N, x, 1 );
63+
var v = sasumpw( x.length, x, 1 );
6564
// returns 5.0
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+
- **stride**: stride length.
7372

74-
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of absolute values of every other element in `x`,
73+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of absolute values of every other element:
7574

7675
```javascript
7776
var Float32Array = require( '@stdlib/array/float32' );
@@ -96,25 +95,24 @@ var v = sasumpw( 4, x1, 2 );
9695
// returns 9.0
9796
```
9897

99-
#### sasumpw.ndarray( N, x, stride, offset )
98+
#### sasumpw.ndarray( N, x, strideX, offsetX )
10099

101100
Computes the sum of absolute values ([_L1_ norm][l1norm]) of single-precision floating-point strided array elements using pairwise summation and alternative indexing semantics.
102101

103102
```javascript
104103
var Float32Array = require( '@stdlib/array/float32' );
105104

106105
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
107-
var N = x.length;
108106

109-
var v = sasumpw.ndarray( N, x, 1, 0 );
107+
var v = sasumpw.ndarray( x.length, x, 1, 0 );
110108
// returns 5.0
111109
```
112110

113111
The function has the following additional parameters:
114112

115-
- **offset**: starting index for `x`.
113+
- **offsetX**: starting index.
116114

117-
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 sum of absolute values of 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 sum of absolute values of every other element starting from the second element:
118116

119117
```javascript
120118
var Float32Array = require( '@stdlib/array/float32' );
@@ -147,11 +145,12 @@ var v = sasumpw.ndarray( 4, x, 2, 1 );
147145
<!-- eslint no-undef: "error" -->
148146

149147
```javascript
150-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
151-
var filledarrayBy = require( '@stdlib/array/filled-by' );
148+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
152149
var sasumpw = require( '@stdlib/blas/ext/base/sasumpw' );
153150

154-
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );
151+
var x = discreteUniform( 10, -100, 100, {
152+
'dtype': 'float32'
153+
});
155154
console.log( x );
156155

157156
var v = sasumpw( x.length, x, 1 );
@@ -162,8 +161,123 @@ console.log( v );
162161

163162
<!-- /.examples -->
164163

164+
<!-- C interface documentation. -->
165+
165166
* * *
166167

168+
<section class="c">
169+
170+
## C APIs
171+
172+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
173+
174+
<section class="intro">
175+
176+
</section>
177+
178+
<!-- /.intro -->
179+
180+
<!-- C usage documentation. -->
181+
182+
<section class="usage">
183+
184+
### Usage
185+
186+
```c
187+
#include "stdlib/blas/ext/base/sasumpw.h"
188+
```
189+
190+
#### stdlib_strided_sasumpw( N, \*X, strideX )
191+
192+
Computes the sum of absolute values ([_L1_ norm][l1norm]) of single-precision floating-point strided array elements using pairwise summation.
193+
194+
```c
195+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }
196+
197+
float v = stdlib_strided_sasumpw( 4, x, 1 );
198+
// returns 10.0f
199+
```
200+
201+
The function accepts the following arguments:
202+
203+
- **N**: `[in] CBLAS_INT` number of indexed elements.
204+
- **X**: `[in] float*` input array.
205+
- **strideX**: `[in] CBLAS_INT` stride length.
206+
207+
```c
208+
float stdlib_strided_sasumpw( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
209+
```
210+
211+
#### stdlib_strided_sasumpw_ndarray( N, \*X, strideX, offsetX )
212+
213+
Computes the sum of absolute values ([_L1_ norm][l1norm]) of single-precision floating-point strided array elements using pairwise summation and alternative indexing semantics.
214+
215+
```c
216+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }
217+
218+
float v = stdlib_strided_sasumpw_ndarray( 4, x, 1, 0 );
219+
// returns 10.0f
220+
```
221+
222+
The function accepts the following arguments:
223+
224+
- **N**: `[in] CBLAS_INT` number of indexed elements.
225+
- **X**: `[in] float*` input array.
226+
- **strideX**: `[in] CBLAS_INT` stride length.
227+
- **offsetX**: `[in] CBLAS_INT` starting index.
228+
229+
```c
230+
float stdlib_strided_sasumpw_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
231+
```
232+
233+
</section>
234+
235+
<!-- /.usage -->
236+
237+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
238+
239+
<section class="notes">
240+
241+
</section>
242+
243+
<!-- /.notes -->
244+
245+
<!-- C API usage examples. -->
246+
247+
<section class="examples">
248+
249+
### Examples
250+
251+
```c
252+
#include "stdlib/blas/ext/base/sasumpw.h"
253+
#include <stdio.h>
254+
255+
int main( void ) {
256+
// Create a strided array:
257+
const float x[] = { 1.0f, -2.0f, 3.0f, -4.0f, 5.0f, -6.0f, 7.0f, -8.0f };
258+
259+
// Specify the number of indexed elements:
260+
const int N = 8;
261+
262+
// Specify a stride:
263+
const int strideX = 1;
264+
265+
// Compute the sum:
266+
float v = stdlib_strided_sasumpw( N, x, strideX );
267+
268+
// Print the result:
269+
printf( "sumabs: %f\n", v );
270+
}
271+
```
272+
273+
</section>
274+
275+
<!-- /.examples -->
276+
277+
</section>
278+
279+
<!-- /.c -->
280+
167281
<section class="references">
168282
169283
## References

lib/node_modules/@stdlib/blas/ext/base/sasumpw/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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2726
var pow = require( '@stdlib/math/base/special/pow' );
2827
var pkg = require( './../package.json' ).name;
@@ -31,7 +30,9 @@ var sasumpw = require( './../lib/sasumpw.js' );
3130

3231
// VARIABLES //
3332

34-
var rand = uniform( -100.0, 100.0 );
33+
var options = {
34+
'dtype': 'float32'
35+
};
3536

3637

3738
// FUNCTIONS //
@@ -44,7 +45,7 @@ var rand = uniform( -100.0, 100.0 );
4445
* @returns {Function} benchmark function
4546
*/
4647
function createBenchmark( len ) {
47-
var x = filledarrayBy( len, 'float32', rand );
48+
var x = uniform( len, -100, 100, options );
4849
return benchmark;
4950

5051
function benchmark( b ) {

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

Lines changed: 5 additions & 5 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-
3028
var tryRequire = require( '@stdlib/utils/try-require' );
3129
var pkg = require( './../package.json' ).name;
3230

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

4242

4343
// FUNCTIONS //
@@ -50,7 +50,7 @@ var rand = uniform( -100.0, 100.0 );
5050
* @returns {Function} benchmark function
5151
*/
5252
function createBenchmark( len ) {
53-
var x = filledarrayBy( len, 'float32', rand );
53+
var x = uniform( len, -100, 100, options );
5454
return benchmark;
5555

5656
function benchmark( b ) {

lib/node_modules/@stdlib/blas/ext/base/sasumpw/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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2726
var pow = require( '@stdlib/math/base/special/pow' );
2827
var pkg = require( './../package.json' ).name;
@@ -31,7 +30,9 @@ var sasumpw = require( './../lib/ndarray.js' );
3130

3231
// VARIABLES //
3332

34-
var rand = uniform( -100.0, 100.0 );
33+
var options = {
34+
'dtype': 'float32'
35+
};
3536

3637

3738
// FUNCTIONS //
@@ -44,7 +45,7 @@ var rand = uniform( -100.0, 100.0 );
4445
* @returns {Function} benchmark function
4546
*/
4647
function createBenchmark( len ) {
47-
var x = filledarrayBy( len, 'float32', rand );
48+
var x = uniform( len, -100, 100, options );
4849
return benchmark;
4950

5051
function benchmark( b ) {

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

Lines changed: 5 additions & 5 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
2827
var pow = require( '@stdlib/math/base/special/pow' );
2928
var tryRequire = require( '@stdlib/utils/try-require' );
@@ -36,8 +35,9 @@ var sasumpw = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3635
var opts = {
3736
'skip': ( sasumpw instanceof Error )
3837
};
39-
40-
var rand = uniform( -100.0, 100.0 );
38+
var options = {
39+
'dtype': 'float32'
40+
};
4141

4242

4343
// FUNCTIONS //
@@ -50,7 +50,7 @@ var rand = uniform( -100.0, 100.0 );
5050
* @returns {Function} benchmark function
5151
*/
5252
function createBenchmark( len ) {
53-
var x = filledarrayBy( len, 'float32', rand );
53+
var x = uniform( len, -100, 100, options );
5454
return benchmark;
5555

5656
function benchmark( b ) {

0 commit comments

Comments
 (0)