Skip to content

Commit e85fab1

Browse files
authored
feat: add C ndarray API and refactor blas/ext/base/sdssum
PR-URL: #4873 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 291d653 commit e85fab1

24 files changed

+348
-168
lines changed

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

+129-14
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,26 @@ limitations under the License.
3636
var sdssum = require( '@stdlib/blas/ext/base/sdssum' );
3737
```
3838

39-
#### sdssum( N, x, stride )
39+
#### sdssum( N, x, strideX )
4040

4141
Computes the sum of single-precision floating-point strided array elements using extended accumulation.
4242

4343
```javascript
4444
var Float32Array = require( '@stdlib/array/float32' );
4545

4646
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
47-
var N = x.length;
4847

49-
var v = sdssum( N, x, 1 );
48+
var v = sdssum( x.length, x, 1 );
5049
// returns 1.0
5150
```
5251

5352
The function has the following parameters:
5453

5554
- **N**: number of indexed elements.
5655
- **x**: input [`Float32Array`][@stdlib/array/float32].
57-
- **stride**: index increment.
56+
- **strideX**: stride length.
5857

59-
The `N` and `stride` parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element in the strided array,
58+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the sum of every other element:
6059

6160
```javascript
6261
var Float32Array = require( '@stdlib/array/float32' );
@@ -81,25 +80,24 @@ var v = sdssum( 4, x1, 2 );
8180
// returns 5.0
8281
```
8382

84-
#### sdssum.ndarray( N, x, stride, offset )
83+
#### sdssum.ndarray( N, x, strideX, offsetX )
8584

8685
Computes the sum of single-precision floating-point strided array elements using extended accumulation and alternative indexing semantics.
8786

8887
```javascript
8988
var Float32Array = require( '@stdlib/array/float32' );
9089

9190
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
92-
var N = x.length;
9391

94-
var v = sdssum.ndarray( N, x, 1, 0 );
92+
var v = sdssum.ndarray( x.length, x, 1, 0 );
9593
// returns 1.0
9694
```
9795

9896
The function has the following additional parameters:
9997

100-
- **offset**: starting index for the strided array.
98+
- **offsetX**: starting index.
10199

102-
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 every other value in the strided array starting from the second value
100+
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 every other element starting from the second element:
103101

104102
```javascript
105103
var Float32Array = require( '@stdlib/array/float32' );
@@ -132,12 +130,12 @@ var v = sdssum.ndarray( 4, x, 2, 1 );
132130
<!-- eslint no-undef: "error" -->
133131

134132
```javascript
135-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
136-
var filledarrayBy = require( '@stdlib/array/filled-by' );
133+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
137134
var sdssum = require( '@stdlib/blas/ext/base/sdssum' );
138135

139-
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );
140-
136+
var x = discreteUniform( 10, -100, 100, {
137+
'dtype': 'float32'
138+
});
141139
console.log( x );
142140

143141
var v = sdssum( x.length, x, 1 );
@@ -148,6 +146,123 @@ console.log( v );
148146

149147
<!-- /.examples -->
150148

149+
<!-- C interface documentation. -->
150+
151+
* * *
152+
153+
<section class="c">
154+
155+
## C APIs
156+
157+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
158+
159+
<section class="intro">
160+
161+
</section>
162+
163+
<!-- /.intro -->
164+
165+
<!-- C usage documentation. -->
166+
167+
<section class="usage">
168+
169+
### Usage
170+
171+
```c
172+
#include "stdlib/blas/ext/base/sdssum.h"
173+
```
174+
175+
#### stdlib_strided_sdssum( N, \*X, strideX )
176+
177+
Computes the sum of single-precision floating-point strided array elements using extended accumulation.
178+
179+
```c
180+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
181+
182+
float v = stdlib_strided_sdssum( 4, x, 1 );
183+
// returns 10.0f
184+
```
185+
186+
The function accepts the following arguments:
187+
188+
- **N**: `[in] CBLAS_INT` number of indexed elements.
189+
- **X**: `[in] float*` input array.
190+
- **strideX**: `[in] CBLAS_INT` stride length.
191+
192+
```c
193+
float stdlib_strided_sdssum( const CBLAS_INT N, const float *X, const CBLAS_INT strideX );
194+
```
195+
196+
#### stdlib_strided_sdssum_ndarray( N, \*X, strideX, offsetX )
197+
198+
Computes the sum of single-precision floating-point strided array elements using extended accumulation and alternative indexing semantics.
199+
200+
```c
201+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
202+
203+
float v = stdlib_strided_sdssum_ndarray( 4, x, 1, 0 );
204+
// returns 10.0f
205+
```
206+
207+
The function accepts the following arguments:
208+
209+
- **N**: `[in] CBLAS_INT` number of indexed elements.
210+
- **X**: `[in] float*` input array.
211+
- **strideX**: `[in] CBLAS_INT` stride length.
212+
- **offsetX**: `[in] CBLAS_INT` starting index.
213+
214+
```c
215+
float stdlib_strided_sdssum_ndarray( const CBLAS_INT N, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
216+
```
217+
218+
</section>
219+
220+
<!-- /.usage -->
221+
222+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
223+
224+
<section class="notes">
225+
226+
</section>
227+
228+
<!-- /.notes -->
229+
230+
<!-- C API usage examples. -->
231+
232+
<section class="examples">
233+
234+
### Examples
235+
236+
```c
237+
#include "stdlib/blas/ext/base/sdssum.h"
238+
#include <stdio.h>
239+
240+
int main( void ) {
241+
// Create a strided array:
242+
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
243+
244+
// Specify the number of elements:
245+
const int N = 4;
246+
247+
// Specify the stride length:
248+
const int strideX = 2;
249+
250+
// Compute the sum:
251+
float v = stdlib_strided_sdssum( N, x, strideX );
252+
253+
// Print the result:
254+
printf( "Sum: %f\n", v );
255+
}
256+
```
257+
258+
</section>
259+
260+
<!-- /.examples -->
261+
262+
</section>
263+
264+
<!-- /.c -->
265+
151266
<section class="references">
152267
153268
</section>

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
var bench = require( '@stdlib/bench' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var pow = require( '@stdlib/math/base/special/pow' );
26-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
27-
var filledarrayBy = require( '@stdlib/array/filled-by' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
2827
var pkg = require( './../package.json' ).name;
2928
var sdssum = require( './../lib/sdssum.js' );
3029

3130

3231
// VARIABLES //
3332

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

3637

3738
// FUNCTIONS //
@@ -44,8 +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-
48+
var x = uniform( len, -100, 100, options );
4949
return benchmark;
5050

5151
function benchmark( b ) {

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ var bench = require( '@stdlib/bench' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
28-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
29-
var filledarrayBy = require( '@stdlib/array/filled-by' );
28+
var uniform = require( '@stdlib/random/array/uniform' );
3029
var pkg = require( './../package.json' ).name;
3130

3231

@@ -36,7 +35,9 @@ var sdssum = tryRequire( resolve( __dirname, './../lib/sdssum.native.js' ) );
3635
var opts = {
3736
'skip': ( sdssum instanceof Error )
3837
};
39-
var rand = uniform( -10.0, 10.0 );
38+
var options = {
39+
'dtype': 'float32'
40+
};
4041

4142

4243
// FUNCTIONS //
@@ -49,8 +50,7 @@ var rand = uniform( -10.0, 10.0 );
4950
* @returns {Function} benchmark function
5051
*/
5152
function createBenchmark( len ) {
52-
var x = filledarrayBy( len, 'float32', rand );
53-
53+
var x = uniform( len, -100, 100, options );
5454
return benchmark;
5555

5656
function benchmark( b ) {

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
var bench = require( '@stdlib/bench' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var pow = require( '@stdlib/math/base/special/pow' );
26-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
27-
var filledarrayBy = require( '@stdlib/array/filled-by' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
2827
var sdssum = require( './../lib/ndarray.js' );
2928
var pkg = require( './../package.json' ).name;
3029

3130

3231
// VARIABLES //
3332

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

3637

3738
// FUNCTIONS //
@@ -44,8 +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-
48+
var x = uniform( len, -100, 100, options );
4949
return benchmark;
5050

5151
function benchmark( b ) {

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ var bench = require( '@stdlib/bench' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2626
var pow = require( '@stdlib/math/base/special/pow' );
2727
var tryRequire = require( '@stdlib/utils/try-require' );
28-
var uniform = require( '@stdlib/random/base/uniform' ).factory;
29-
var filledarrayBy = require( '@stdlib/array/filled-by' );
28+
var uniform = require( '@stdlib/random/array/uniform' );
3029
var pkg = require( './../package.json' ).name;
3130

3231

@@ -36,7 +35,9 @@ var sdssum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3635
var opts = {
3736
'skip': ( sdssum instanceof Error )
3837
};
39-
var rand = uniform( -10.0, 10.0 );
38+
var options = {
39+
'dtype': 'float32'
40+
};
4041

4142

4243
// FUNCTIONS //
@@ -49,8 +50,7 @@ var rand = uniform( -10.0, 10.0 );
4950
* @returns {Function} benchmark function
5051
*/
5152
function createBenchmark( len ) {
52-
var x = filledarrayBy( len, 'float32', rand );
53-
53+
var x = uniform( len, -100, 100, options );
5454
return benchmark;
5555

5656
function benchmark( b ) {

0 commit comments

Comments
 (0)