Skip to content

Commit b8f1f7a

Browse files
committed
Auto-generated commit
1 parent 1f14ba6 commit b8f1f7a

File tree

19 files changed

+1383
-6
lines changed

19 files changed

+1383
-6
lines changed

.github/.keepalive

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

CHANGELOG.md

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

33
> Package changelog.
44
5+
<section class="release" id="unreleased">
6+
7+
## Unreleased (2024-12-26)
8+
9+
<section class="features">
10+
11+
### Features
12+
13+
- [`013c9ac`](https://github.com/stdlib-js/stdlib/commit/013c9ac4695d3ff46ecde12644af8c35aa0be706) - add C implementation for `stats/base/dists/triangular/stdev` [(#4258)](https://github.com/stdlib-js/stdlib/pull/4258)
14+
15+
</section>
16+
17+
<!-- /.features -->
18+
19+
<section class="issues">
20+
21+
### Closed Issues
22+
23+
This release closes the following issue:
24+
25+
[#3823](https://github.com/stdlib-js/stdlib/issues/3823)
26+
27+
</section>
28+
29+
<!-- /.issues -->
30+
31+
<section class="commits">
32+
33+
### Commits
34+
35+
<details>
36+
37+
- [`013c9ac`](https://github.com/stdlib-js/stdlib/commit/013c9ac4695d3ff46ecde12644af8c35aa0be706) - **feat:** add C implementation for `stats/base/dists/triangular/stdev` [(#4258)](https://github.com/stdlib-js/stdlib/pull/4258) _(by Prashant Kumar Yadav)_
38+
39+
</details>
40+
41+
</section>
42+
43+
<!-- /.commits -->
44+
45+
<section class="contributors">
46+
47+
### Contributors
48+
49+
A total of 1 person contributed to this release. Thank you to this contributor:
50+
51+
- Prashant Kumar Yadav
52+
53+
</section>
54+
55+
<!-- /.contributors -->
56+
57+
</section>
58+
59+
<!-- /.release -->
60+
561
<section class="release" id="v0.2.2">
662

763
## 0.2.2 (2024-07-27)

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,100 @@ for ( i = 0; i < 10; i++ ) {
174174

175175
<!-- /.examples -->
176176

177+
<!-- C interface documentation. -->
178+
179+
* * *
180+
181+
<section class="c">
182+
183+
## C APIs
184+
185+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
186+
187+
<section class="intro">
188+
189+
</section>
190+
191+
<!-- /.intro -->
192+
193+
<!-- C usage documentation. -->
194+
195+
<section class="usage">
196+
197+
### Usage
198+
199+
```c
200+
#include "stdlib/stats/base/dists/triangular/stdev.h"
201+
```
202+
203+
#### stdlib_base_dists_triangular_stdev( a, b, c )
204+
205+
Returns the [standard deviation][standard-deviation] of a [triangular][triangular-distribution] distribution with minimum support `a`, maximum support`b`, and mode `c`.
206+
207+
```c
208+
double out = stdlib_base_dists_triangular_stdev( 0.0, 1.0, 0.5 );
209+
// returns ~0.204
210+
```
211+
212+
The function accepts the following arguments:
213+
214+
- **a**: `[in] double` minimum support.
215+
- **b**: `[in] double` maximum support.
216+
- **c**: `[in] double` mode.
217+
218+
```c
219+
double stdlib_base_dists_triangular_stdev( const double a, const double b, const double c );
220+
```
221+
222+
</section>
223+
224+
<!-- /.usage -->
225+
226+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
227+
228+
<section class="notes">
229+
230+
</section>
231+
232+
<!-- /.notes -->
233+
234+
<!-- C API usage examples. -->
235+
236+
<section class="examples">
237+
238+
### Examples
239+
240+
```c
241+
#include "stdlib/stats/base/dists/triangular/stdev.h"
242+
#include <stdlib.h>
243+
#include <stdio.h>
244+
245+
static double random_uniform( const double min, const double max ) {
246+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
247+
return min + ( v*(max-min) );
248+
}
249+
250+
int main( void ) {
251+
double a;
252+
double b;
253+
double c;
254+
double v;
255+
int i;
256+
257+
for ( i = 0; i < 25; i++ ) {
258+
a = random_uniform( 0.0, 10.0 );
259+
b = random_uniform( a, a+10.0 );
260+
c = random_uniform( a, b );
261+
v = stdlib_base_dists_triangular_stdev( a, b, c );
262+
printf( "a: %lf, b: %lf, c: %lf, SD(X;a,b,c): %lf\n", a, b, c, v );
263+
}
264+
}
265+
```
266+
267+
</section>
268+
269+
<!-- /.examples -->
270+
177271
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
178272

179273
<section class="references">

benchmark/benchmark.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench-harness' );
24+
var Float64Array = require( '@stdlib/array-float64' );
2425
var randu = require( '@stdlib/random-base-randu' );
2526
var isnan = require( '@stdlib/math-base-assert-is-nan' );
2627
var EPS = require( '@stdlib/constants-float64-eps' );
@@ -32,17 +33,25 @@ var stdev = require( './../lib' );
3233

3334
bench( pkg, function benchmark( b ) {
3435
var mode;
36+
var len;
3537
var min;
3638
var max;
3739
var y;
3840
var i;
3941

42+
len = 100;
43+
min = new Float64Array( len );
44+
max = new Float64Array( len );
45+
mode = new Float64Array( len );
46+
for ( i = 0; i < len; i++ ) {
47+
min[ i ] = ( randu()*10.0 );
48+
max[ i ] = ( randu()*10.0 ) + min[ i ] + EPS;
49+
mode[ i ] = ( ( max[ i ] - min[ i ] ) * randu() ) + min[ i ];
50+
}
51+
4052
b.tic();
4153
for ( i = 0; i < b.iterations; i++ ) {
42-
min = ( randu()*10.0 );
43-
max = ( randu()*10.0 ) + min + EPS;
44-
mode = ( ( max - min ) * randu() ) + min;
45-
y = stdev( min, max, mode );
54+
y = stdev( min[ i % len ], max[ i % len ], mode[ i % len ] );
4655
if ( isnan( y ) ) {
4756
b.fail( 'should not return NaN' );
4857
}

benchmark/benchmark.native.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench-harness' );
25+
var Float64Array = require( '@stdlib/array-float64' );
26+
var randu = require( '@stdlib/random-base-randu' );
27+
var EPS = require( '@stdlib/constants-float64-eps' );
28+
var isnan = require( '@stdlib/math-base-assert-is-nan' );
29+
var tryRequire = require( '@stdlib/utils-try-require' );
30+
var pkg = require( './../package.json' ).name;
31+
32+
33+
// VARIABLES //
34+
35+
var stdev = tryRequire( resolve( __dirname, './../lib/native.js' ) );
36+
var opts = {
37+
'skip': ( stdev instanceof Error )
38+
};
39+
40+
41+
// MAIN //
42+
43+
bench( pkg+'::native', opts, function benchmark( b ) {
44+
var mode;
45+
var len;
46+
var min;
47+
var max;
48+
var y;
49+
var i;
50+
51+
len = 100;
52+
min = new Float64Array( len );
53+
max = new Float64Array( len );
54+
mode = new Float64Array( len );
55+
for ( i = 0; i < len; i++ ) {
56+
min[ i ] = ( randu()*10.0 );
57+
max[ i ] = ( randu()*10.0 ) + min[ i ] + EPS;
58+
mode[ i ] = ( ( max[ i ] - min[ i ] ) * randu() ) + min[ i ];
59+
}
60+
61+
b.tic();
62+
for ( i = 0; i < b.iterations; i++ ) {
63+
y = stdev( min[ i % len ], max[ i % len ], mode[ i % len ] );
64+
if ( isnan( y ) ) {
65+
b.fail( 'should not return NaN' );
66+
}
67+
}
68+
b.toc();
69+
if ( isnan( y ) ) {
70+
b.fail( 'should not return NaN' );
71+
}
72+
b.pass( 'benchmark finished' );
73+
b.end();
74+
});

0 commit comments

Comments
 (0)