Skip to content

Commit 6ae3c11

Browse files
authored
feat: add C ndarray API and refactor blas/ext/base/dsapxsum
PR-URL: #3225 Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com> Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
1 parent 0c14905 commit 6ae3c11

24 files changed

+381
-176
lines changed

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

+135-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# dsapxsum
2222

23-
> Add a constant to each single-precision floating-point strided array element and compute the sum using extended accumulation and returning an extended precision result.
23+
> Add a scalar constant to each single-precision floating-point strided array element, and compute the sum using extended accumulation and returning an extended precision result.
2424
2525
<section class="intro">
2626

@@ -36,26 +36,27 @@ limitations under the License.
3636
var dsapxsum = require( '@stdlib/blas/ext/base/dsapxsum' );
3737
```
3838

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

41-
Adds a constant to each single-precision floating-point strided array element and computes the sum using extended accumulation and returning an extended precision result.
41+
Adds a scalar constant to each single-precision floating-point strided array element, and computes the sum using extended accumulation and returning an extended precision result.
4242

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

4646
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
4747

48-
var v = dsapxsum( 3, 5.0, x, 1 );
48+
var v = dsapxsum( x.length, 5.0, x, 1 );
4949
// returns 16.0
5050
```
5151

5252
The function has the following parameters:
5353

5454
- **N**: number of indexed elements.
55+
- **alpha**: scalar constant.
5556
- **x**: input [`Float32Array`][@stdlib/array/float32].
56-
- **stride**: index increment for `x`.
57+
- **strideX**: stride length for `x`.
5758

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

6061
```javascript
6162
var Float32Array = require( '@stdlib/array/float32' );
@@ -80,24 +81,24 @@ var v = dsapxsum( 4, 5.0, x1, 2 );
8081
// returns 25.0
8182
```
8283

83-
#### dsapxsum.ndarray( N, alpha, x, stride, offset )
84+
#### dsapxsum.ndarray( N, alpha, x, strideX, offsetX )
8485

85-
Adds a constant to each single-precision floating-point strided array element and computes the sum using extended accumulation and alternative indexing semantics and returning an extended precision result.
86+
Adds a scalar constant to each single-precision floating-point strided array element, and computes the sum using extended accumulation and alternative indexing semantics and returning an extended precision result.
8687

8788
```javascript
8889
var Float32Array = require( '@stdlib/array/float32' );
8990

9091
var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
9192

92-
var v = dsapxsum.ndarray( 3, 5.0, x, 1, 0 );
93+
var v = dsapxsum.ndarray( x.length, 5.0, x, 1, 0 );
9394
// returns 16.0
9495
```
9596

9697
The function has the following additional parameters:
9798

98-
- **offset**: starting index for `x`.
99+
- **offsetX**: starting index for `x`.
99100

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 access every other value in the strided array starting from the second value
101+
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 access every other element starting from the second element:
101102

102103
```javascript
103104
var Float32Array = require( '@stdlib/array/float32' );
@@ -130,11 +131,12 @@ var v = dsapxsum.ndarray( 4, 5.0, x, 2, 1 );
130131
<!-- eslint no-undef: "error" -->
131132

132133
```javascript
133-
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
134-
var filledarrayBy = require( '@stdlib/array/filled-by' );
134+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
135135
var dsapxsum = require( '@stdlib/blas/ext/base/dsapxsum' );
136136

137-
var x = filledarrayBy( 10, 'float32', discreteUniform( 0, 100 ) );
137+
var x = discreteUniform( 10.0, -100, 100, {
138+
'dtype': 'float32'
139+
});
138140
console.log( x );
139141

140142
var v = dsapxsum( x.length, 5.0, x, 1 );
@@ -145,6 +147,125 @@ console.log( v );
145147

146148
<!-- /.examples -->
147149

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

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

+5-4
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 pkg = require( './../package.json' ).name;
@@ -31,7 +30,9 @@ var dsapxsum = require( './../lib/dsapxsum.js' );
3130

3231
// VARIABLES //
3332

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

3637

3738
// FUNCTIONS //
@@ -44,7 +45,7 @@ var rand = uniform( -10.0, 10.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/dsapxsum/benchmark/benchmark.native.js

+5-4
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 tryRequire = require( '@stdlib/utils/try-require' );
@@ -36,7 +35,9 @@ var dsapxsum = tryRequire( resolve( __dirname, './../lib/dsapxsum.native.js' ) )
3635
var opts = {
3736
'skip': ( dsapxsum instanceof Error )
3837
};
39-
var rand = uniform( -10.0, 10.0 );
38+
var options = {
39+
'dtype': 'float32'
40+
};
4041

4142

4243
// FUNCTIONS //
@@ -49,7 +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+
var x = uniform( len, -100, 100, options );
5354
return benchmark;
5455

5556
function benchmark( b ) {

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

+5-4
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 pkg = require( './../package.json' ).name;
@@ -31,7 +30,9 @@ var dsapxsum = require( './../lib/ndarray.js' );
3130

3231
// VARIABLES //
3332

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

3637

3738
// FUNCTIONS //
@@ -44,7 +45,7 @@ var rand = uniform( -10.0, 10.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/dsapxsum/benchmark/benchmark.ndarray.native.js

+5-4
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 tryRequire = require( '@stdlib/utils/try-require' );
@@ -36,7 +35,9 @@ var dsapxsum = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
3635
var opts = {
3736
'skip': ( dsapxsum instanceof Error )
3837
};
39-
var rand = uniform( -10.0, 10.0 );
38+
var options = {
39+
'dtype': 'float32'
40+
};
4041

4142

4243
// FUNCTIONS //
@@ -49,7 +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+
var x = uniform( len, -100, 100, options );
5354
return benchmark;
5455

5556
function benchmark( b ) {

0 commit comments

Comments
 (0)