Skip to content

Commit 3f0096b

Browse files
committed
Auto-generated commit
1 parent aaf0d78 commit 3f0096b

24 files changed

+426
-208
lines changed

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,50 @@
22

33
> Package changelog.
44
5+
<section class="release" id="unreleased">
6+
7+
## Unreleased (2024-11-11)
8+
9+
<section class="features">
10+
11+
### Features
12+
13+
- [`f0ecdad`](https://github.com/stdlib-js/stdlib/commit/f0ecdad9731cd40ae9047a87981d2688693e54dc) - add C `ndarray` API and refactor `blas/ext/base/dnannsumkbn2` [(#2990)](https://github.com/stdlib-js/stdlib/pull/2990)
14+
15+
</section>
16+
17+
<!-- /.features -->
18+
19+
<section class="commits">
20+
21+
### Commits
22+
23+
<details>
24+
25+
- [`f0ecdad`](https://github.com/stdlib-js/stdlib/commit/f0ecdad9731cd40ae9047a87981d2688693e54dc) - **feat:** add C `ndarray` API and refactor `blas/ext/base/dnannsumkbn2` [(#2990)](https://github.com/stdlib-js/stdlib/pull/2990) _(by Muhammad Haris)_
26+
27+
</details>
28+
29+
</section>
30+
31+
<!-- /.commits -->
32+
33+
<section class="contributors">
34+
35+
### Contributors
36+
37+
A total of 1 person contributed to this release. Thank you to this contributor:
38+
39+
- Muhammad Haris
40+
41+
</section>
42+
43+
<!-- /.contributors -->
44+
45+
</section>
46+
47+
<!-- /.release -->
48+
549
<section class="release" id="v0.2.2">
650

751
## 0.2.2 (2024-07-28)

README.md

Lines changed: 127 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ The function has the following parameters:
8787

8888
- **N**: number of indexed elements.
8989
- **x**: input [`Float64Array`][@stdlib/array/float64].
90-
- **strideX**: index increment for `x`.
90+
- **strideX**: stride length for `x`.
9191
- **out**: output [`Float64Array`][@stdlib/array/float64] whose first element is the sum and whose second element is the number of non-NaN elements.
92-
- **strideOut**: index increment for `out`.
92+
- **strideOut**: stride length for `out`.
9393

9494
The `N` and stride parameters determine which elements are accessed at runtime. For example, to compute the sum of every other element in `x`,
9595

@@ -139,7 +139,7 @@ The function has the following additional parameters:
139139
- **offsetX**: starting index for `x`.
140140
- **offsetOut**: starting index for `out`.
141141

142-
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 `x` starting from the second value
142+
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 sum of every other element starting from the second element:
143143

144144
```javascript
145145
var Float64Array = require( '@stdlib/array-float64' );
@@ -197,8 +197,132 @@ console.log( out );
197197

198198
<!-- /.examples -->
199199

200+
<!-- C interface documentation. -->
201+
200202
* * *
201203

204+
<section class="c">
205+
206+
## C APIs
207+
208+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
209+
210+
<section class="intro">
211+
212+
</section>
213+
214+
<!-- /.intro -->
215+
216+
<!-- C usage documentation. -->
217+
218+
<section class="usage">
219+
220+
### Usage
221+
222+
```c
223+
#include "stdlib/blas/ext/base/dnannsumkbn2.h"
224+
```
225+
226+
#### stdlib_strided_dnannsumkbn2( N, \*X, strideX, \*n )
227+
228+
Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm.
229+
230+
```c
231+
const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 };
232+
CBLAS_INT n = 0;
233+
234+
double v = stdlib_strided_dnannsumkbn2( 4, x, 1, &n );
235+
// returns 7.0
236+
```
237+
238+
The function accepts the following arguments:
239+
240+
- **N**: `[in] CBLAS_INT` number of indexed elements.
241+
- **X**: `[in] double*` input array.
242+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
243+
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
244+
245+
```c
246+
double stdlib_strided_dnannsumkbn2( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, CBLAS_INT *n );
247+
```
248+
249+
#### stdlib_strided_dnannsumkbn2_ndarray( N, \*X, strideX, offsetX, \*n )
250+
251+
Computes the sum of double-precision floating-point strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics.
252+
253+
```c
254+
const double x[] = { 1.0, 2.0, 0.0/0.0, 4.0 };
255+
CBLAS_INT n = 0;
256+
257+
double v = stdlib_strided_dnannsumkbn2_ndarray( 4, x, 1, 0, &n );
258+
// returns 7.0
259+
```
260+
261+
The function accepts the following arguments:
262+
263+
- **N**: `[in] CBLAS_INT` number of indexed elements.
264+
- **X**: `[in] double*` input array.
265+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
266+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
267+
- **n**: `[out] CBLAS_INT*` number of non-NaN elements.
268+
269+
```c
270+
double stdlib_strided_dnannsumkbn2_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, CBLAS_INT *n );
271+
```
272+
273+
</section>
274+
275+
<!-- /.usage -->
276+
277+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
278+
279+
<section class="notes">
280+
281+
</section>
282+
283+
<!-- /.notes -->
284+
285+
<!-- C API usage examples. -->
286+
287+
<section class="examples">
288+
289+
### Examples
290+
291+
```c
292+
#include "stdlib/blas/ext/base/dnannsumkbn2.h"
293+
#include "stdlib/blase/base/shared.h"
294+
#include <stdio.h>
295+
296+
int main( void ) {
297+
// Create a strided array:
298+
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0/0.0, 0.0/0.0 };
299+
300+
// Specify the number of elements:
301+
const int N = 5;
302+
303+
// Specify the stride length:
304+
const int strideX = 2;
305+
306+
// Initialize a variable for storing the number of non-NaN elements:
307+
CBLAS_INT n = 0;
308+
309+
// Compute the sum:
310+
double v = stdlib_strided_dnannsumkbn2( N, x, strideX, &n );
311+
312+
// Print the result:
313+
printf( "sum: %lf\n", v );
314+
printf( "n: %"CBLAS_IFMT"\n", n );
315+
}
316+
```
317+
318+
</section>
319+
320+
<!-- /.examples -->
321+
322+
</section>
323+
324+
<!-- /.c -->
325+
202326
<section class="references">
203327
204328
## References

benchmark/benchmark.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ var dnannsumkbn2 = require( './../lib/dnannsumkbn2.js' );
3333

3434
// FUNCTIONS //
3535

36+
/**
37+
* Returns a random number.
38+
*
39+
* @private
40+
* @returns {number} random number
41+
*/
42+
function rand() {
43+
if ( bernoulli( 0.7 ) > 0 ) {
44+
return discreteUniform( -10.0, 10.0 );
45+
}
46+
return NaN;
47+
}
48+
3649
/**
3750
* Creates a benchmark function.
3851
*
@@ -44,14 +57,7 @@ function createBenchmark( len ) {
4457
var out;
4558
var x;
4659

47-
function clbk() {
48-
if ( bernoulli( 0.7 ) > 0 ) {
49-
return discreteUniform( -10, 10 );
50-
}
51-
return NaN;
52-
}
53-
54-
x = filledarrayBy( len, 'float64', clbk );
60+
x = filledarrayBy( len, 'float64', rand );
5561
out = new Float64Array( 2 );
5662
return benchmark;
5763

benchmark/benchmark.native.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ var opts = {
4242

4343
// FUNCTIONS //
4444

45+
/**
46+
* Returns a random number.
47+
*
48+
* @private
49+
* @returns {number} random number
50+
*/
51+
function rand() {
52+
if ( bernoulli( 0.8 ) > 0 ) {
53+
return discreteUniform( -10.0, 10.0 );
54+
}
55+
return NaN;
56+
}
57+
4558
/**
4659
* Creates a benchmark function.
4760
*
@@ -53,14 +66,7 @@ function createBenchmark( len ) {
5366
var out;
5467
var x;
5568

56-
function clbk() {
57-
if ( bernoulli( 0.7 ) > 0 ) {
58-
return discreteUniform( -10, 10 );
59-
}
60-
return NaN;
61-
}
62-
63-
x = filledarrayBy( len, 'float64', clbk );
69+
x = filledarrayBy( len, 'float64', rand );
6470
out = new Float64Array( 2 );
6571
return benchmark;
6672

benchmark/benchmark.ndarray.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ var dnannsumkbn2 = require( './../lib/ndarray.js' );
3333

3434
// FUNCTIONS //
3535

36+
/**
37+
* Returns a random number.
38+
*
39+
* @private
40+
* @returns {number} random number
41+
*/
42+
function rand() {
43+
if ( bernoulli( 0.8 ) > 0 ) {
44+
return discreteUniform( -10.0, 10.0 );
45+
}
46+
return NaN;
47+
}
48+
3649
/**
3750
* Creates a benchmark function.
3851
*
@@ -44,14 +57,7 @@ function createBenchmark( len ) {
4457
var out;
4558
var x;
4659

47-
function clbk() {
48-
if ( bernoulli( 0.7 ) > 0 ) {
49-
return discreteUniform( -10, 10 );
50-
}
51-
return NaN;
52-
}
53-
54-
x = filledarrayBy( len, 'float64', clbk );
60+
x = filledarrayBy( len, 'float64', rand );
5561
out = new Float64Array( 2 );
5662
return benchmark;
5763

benchmark/benchmark.ndarray.native.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ var opts = {
4242

4343
// FUNCTIONS //
4444

45+
/**
46+
* Returns a random number.
47+
*
48+
* @private
49+
* @returns {number} random number
50+
*/
51+
function rand() {
52+
if ( bernoulli( 0.8 ) > 0 ) {
53+
return discreteUniform( -10.0, 10.0 );
54+
}
55+
return NaN;
56+
}
57+
4558
/**
4659
* Creates a benchmark function.
4760
*
@@ -53,14 +66,7 @@ function createBenchmark( len ) {
5366
var out;
5467
var x;
5568

56-
function clbk() {
57-
if ( bernoulli( 0.7 ) > 0 ) {
58-
return discreteUniform( -10, 10 );
59-
}
60-
return NaN;
61-
}
62-
63-
x = filledarrayBy( len, 'float64', clbk );
69+
x = filledarrayBy( len, 'float64', rand );
6470
out = new Float64Array( 2 );
6571
return benchmark;
6672

0 commit comments

Comments
 (0)