Skip to content

Commit 2c2658f

Browse files
committed
Auto-generated commit
1 parent 7a383c6 commit 2c2658f

23 files changed

+420
-276
lines changed

CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-12-23)
7+
## Unreleased (2024-12-25)
8+
9+
<section class="features">
10+
11+
### Features
12+
13+
- [`3d7cff6`](https://github.com/stdlib-js/stdlib/commit/3d7cff6731e0593bd1077fc7084f62a9ea807acb) - add C ndarray interface and refactor implementation for `stats/base/dnanminabs` [(#4238)](https://github.com/stdlib-js/stdlib/pull/4238)
14+
15+
</section>
16+
17+
<!-- /.features -->
818

919
<section class="commits">
1020

1121
### Commits
1222

1323
<details>
1424

25+
- [`3d7cff6`](https://github.com/stdlib-js/stdlib/commit/3d7cff6731e0593bd1077fc7084f62a9ea807acb) - **feat:** add C ndarray interface and refactor implementation for `stats/base/dnanminabs` [(#4238)](https://github.com/stdlib-js/stdlib/pull/4238) _(by Aayush Khanna)_
1526
- [`62364f6`](https://github.com/stdlib-js/stdlib/commit/62364f62ea823a3b52c2ad25660ecd80c71f8f36) - **style:** fix C comment alignment _(by Philipp Burckhardt)_
1627
- [`a0eb37f`](https://github.com/stdlib-js/stdlib/commit/a0eb37f8a76369a7b0f6bec74affdf65d8a33b0c) - **refactor:** update `stats/base/dnanminabs` native addon from C++ to C [(#4126)](https://github.com/stdlib-js/stdlib/pull/4126) _(by Vivek maurya)_
1728
- [`9e689ff`](https://github.com/stdlib-js/stdlib/commit/9e689ffcb7c6223afc521f1e574b42f10921cf5e) - **chore:** fix indentation in manifest.json files _(by Philipp Burckhardt)_
@@ -27,8 +38,9 @@
2738

2839
### Contributors
2940

30-
A total of 3 people contributed to this release. Thank you to the following contributors:
41+
A total of 4 people contributed to this release. Thank you to the following contributors:
3142

43+
- Aayush Khanna
3244
- Athan Reines
3345
- Philipp Burckhardt
3446
- Vivek maurya

README.md

Lines changed: 128 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,36 +69,33 @@ To view installation and usage instructions specific to each branch build, be su
6969
var dnanminabs = require( '@stdlib/stats-base-dnanminabs' );
7070
```
7171

72-
#### dnanminabs( N, x, stride )
72+
#### dnanminabs( N, x, strideX )
7373

7474
Computes the minimum absolute value of a double-precision floating-point strided array `x`, ignoring `NaN` values.
7575

7676
```javascript
7777
var Float64Array = require( '@stdlib/array-float64' );
7878

7979
var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
80-
var N = x.length;
8180

82-
var v = dnanminabs( N, x, 1 );
81+
var v = dnanminabs( x.length, x, 1 );
8382
// returns 1.0
8483
```
8584

8685
The function has the following parameters:
8786

8887
- **N**: number of indexed elements.
8988
- **x**: input [`Float64Array`][@stdlib/array/float64].
90-
- **stride**: index increment for `x`.
89+
- **strideX**: stride length for `x`.
9190

92-
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the minimum absolute value of every other element in `x`,
91+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the minimum absolute value of every other element in `x`,
9392

9493
```javascript
9594
var Float64Array = require( '@stdlib/array-float64' );
96-
var floor = require( '@stdlib/math-base-special-floor' );
9795

9896
var x = new Float64Array( [ 1.0, 2.0, -7.0, -2.0, 4.0, 3.0, NaN, NaN ] );
99-
var N = floor( x.length / 2 );
10097

101-
var v = dnanminabs( N, x, 2 );
98+
var v = dnanminabs( 4, x, 2 );
10299
// returns 1.0
103100
```
104101

@@ -108,45 +105,39 @@ Note that indexing is relative to the first index. To introduce an offset, use [
108105

109106
```javascript
110107
var Float64Array = require( '@stdlib/array-float64' );
111-
var floor = require( '@stdlib/math-base-special-floor' );
112108

113109
var x0 = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, NaN, NaN ] );
114110
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
115111

116-
var N = floor( x0.length / 2 );
117-
118-
var v = dnanminabs( N, x1, 2 );
112+
var v = dnanminabs( 4, x1, 2 );
119113
// returns 1.0
120114
```
121115

122-
#### dnanminabs.ndarray( N, x, stride, offset )
116+
#### dnanminabs.ndarray( N, x, strideX, offsetX )
123117

124118
Computes the minimum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
125119

126120
```javascript
127121
var Float64Array = require( '@stdlib/array-float64' );
128122

129123
var x = new Float64Array( [ 1.0, -2.0, NaN, 2.0 ] );
130-
var N = x.length;
131124

132-
var v = dnanminabs.ndarray( N, x, 1, 0 );
125+
var v = dnanminabs.ndarray( x.length, x, 1, 0 );
133126
// returns 1.0
134127
```
135128

136129
The function has the following additional parameters:
137130

138-
- **offset**: starting index for `x`.
131+
- **offsetX**: starting index for `x`.
139132

140-
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 minimum absolute value for every other value in `x` starting from the second value
133+
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 minimum absolute value for every other element in `x` starting from the second element
141134

142135
```javascript
143136
var Float64Array = require( '@stdlib/array-float64' );
144-
var floor = require( '@stdlib/math-base-special-floor' );
145137

146138
var x = new Float64Array( [ 2.0, 1.0, -2.0, -2.0, 3.0, 4.0, NaN, NaN ] );
147-
var N = floor( x.length / 2 );
148139

149-
var v = dnanminabs.ndarray( N, x, 2, 1 );
140+
var v = dnanminabs.ndarray( 4, x, 2, 1 );
150141
// returns 1.0
151142
```
152143

@@ -197,6 +188,123 @@ console.log( v );
197188

198189
<!-- /.examples -->
199190

191+
<!-- C interface documentation. -->
192+
193+
* * *
194+
195+
<section class="c">
196+
197+
## C APIs
198+
199+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
200+
201+
<section class="intro">
202+
203+
</section>
204+
205+
<!-- /.intro -->
206+
207+
<!-- C usage documentation. -->
208+
209+
<section class="usage">
210+
211+
### Usage
212+
213+
```c
214+
#include "stdlib/stats/base/dnanminabs.h"
215+
```
216+
217+
#### stdlib_strided_dnanminabs( N, \*X, strideX )
218+
219+
Calculate the minimum absolute value of a double-precision floating-point strided array, ignoring `NaN` values.
220+
221+
```c
222+
const double x[] = { 1.0, -2.0, 0.0 / 0.0, -4.0 };
223+
224+
double v = stdlib_strided_dnanminabs( 4, x, 1 );
225+
// returns 1.0
226+
```
227+
228+
The function accepts the following arguments:
229+
230+
- **N**: `[in] CBLAS_INT` number of indexed elements.
231+
- **X**: `[in] double*` input array.
232+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
233+
234+
```c
235+
double stdlib_strided_dnanminabs( const CBLAS_INT N, const double *X, const CBLAS_INT strideX );
236+
```
237+
238+
#### stdlib_strided_dnanminabs_ndarray( N, \*X, strideX, offsetX )
239+
240+
Computes the minimum absolute value of a double-precision floating-point strided array, ignoring `NaN` values and using alternative indexing semantics.
241+
242+
```c
243+
const double x[] = { 1.0, -2.0, 0.0 / 0.0, -4.0 };
244+
245+
double v = stdlib_strided_dnanminabs_ndarray( 4, x, 1, 0 );
246+
// returns 1.0
247+
```
248+
249+
The function accepts the following arguments:
250+
251+
- **N**: `[in] CBLAS_INT` number of indexed elements.
252+
- **X**: `[in] double*` input array.
253+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
254+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
255+
256+
```c
257+
double stdlib_strided_dnanminabs_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
258+
```
259+
260+
</section>
261+
262+
<!-- /.usage -->
263+
264+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
265+
266+
<section class="notes">
267+
268+
</section>
269+
270+
<!-- /.notes -->
271+
272+
<!-- C API usage examples. -->
273+
274+
<section class="examples">
275+
276+
### Examples
277+
278+
```c
279+
#include "stdlib/stats/base/dnanminabs.h"
280+
#include <stdio.h>
281+
282+
int main( void ) {
283+
// Create a strided array:
284+
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 };
285+
286+
// Specify the number of elements:
287+
const int N = 5;
288+
289+
// Specify the stride length:
290+
const int strideX = 2;
291+
292+
// Compute the minimum absolute value:
293+
double v = stdlib_strided_dnanminabs( N, x, strideX );
294+
295+
// Print the result:
296+
printf( "minabs: %lf\n", v );
297+
}
298+
```
299+
300+
</section>
301+
302+
<!-- /.examples -->
303+
304+
</section>
305+
306+
<!-- /.c -->
307+
200308
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
201309
202310
<section class="related">

benchmark/c/benchmark.length.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static double rand_double( void ) {
9494
* @param len array length
9595
* @return elapsed time in seconds
9696
*/
97-
static double benchmark( int iterations, int len ) {
97+
static double benchmark1( int iterations, int len ) {
9898
double elapsed;
9999
double x[ len ];
100100
double v;
@@ -111,6 +111,7 @@ static double benchmark( int iterations, int len ) {
111111
v = 0.0;
112112
t = tic();
113113
for ( i = 0; i < iterations; i++ ) {
114+
// cppcheck-suppress uninitvar
114115
v = stdlib_strided_dnanminabs( len, x, 1 );
115116
if ( v != v ) {
116117
printf( "should not return NaN\n" );
@@ -124,6 +125,44 @@ static double benchmark( int iterations, int len ) {
124125
return elapsed;
125126
}
126127

128+
/**
129+
* Runs a benchmark.
130+
*
131+
* @param iterations number of iterations
132+
* @param len array length
133+
* @return elapsed time in seconds
134+
*/
135+
static double benchmark2( int iterations, int len ) {
136+
double elapsed;
137+
double x[ len ];
138+
double v;
139+
double t;
140+
int i;
141+
142+
for ( i = 0; i < len; i++ ) {
143+
if ( rand_double() < 0.2 ) {
144+
x[ i ] = 0.0 / 0.0; // NaN
145+
} else {
146+
x[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
147+
}
148+
}
149+
v = 0.0;
150+
t = tic();
151+
for ( i = 0; i < iterations; i++ ) {
152+
// cppcheck-suppress uninitvar
153+
v = stdlib_strided_dnanminabs_ndarray( len, x, 1, 0 );
154+
if ( v != v ) {
155+
printf( "should not return NaN\n" );
156+
break;
157+
}
158+
}
159+
elapsed = tic() - t;
160+
if ( v != v ) {
161+
printf( "should not return NaN\n" );
162+
}
163+
return elapsed;
164+
}
165+
127166
/**
128167
* Main execution sequence.
129168
*/
@@ -146,7 +185,18 @@ int main( void ) {
146185
for ( j = 0; j < REPEATS; j++ ) {
147186
count += 1;
148187
printf( "# c::%s:len=%d\n", NAME, len );
149-
elapsed = benchmark( iter, len );
188+
elapsed = benchmark1( iter, len );
189+
print_results( iter, elapsed );
190+
printf( "ok %d benchmark finished\n", count );
191+
}
192+
}
193+
for ( i = MIN; i <= MAX; i++ ) {
194+
len = pow( 10, i );
195+
iter = ITERATIONS / pow( 10, i-1 );
196+
for ( j = 0; j < REPEATS; j++ ) {
197+
count += 1;
198+
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
199+
elapsed = benchmark2( iter, len );
150200
print_results( iter, elapsed );
151201
printf( "ok %d benchmark finished\n", count );
152202
}

dist/index.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)