Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Dec 26, 2024
1 parent 1f14ba6 commit b8f1f7a
Show file tree
Hide file tree
Showing 19 changed files with 1,383 additions and 6 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,62 @@

> Package changelog.
<section class="release" id="unreleased">

## Unreleased (2024-12-26)

<section class="features">

### Features

- [`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)

</section>

<!-- /.features -->

<section class="issues">

### Closed Issues

This release closes the following issue:

[#3823](https://github.com/stdlib-js/stdlib/issues/3823)

</section>

<!-- /.issues -->

<section class="commits">

### Commits

<details>

- [`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)_

</details>

</section>

<!-- /.commits -->

<section class="contributors">

### Contributors

A total of 1 person contributed to this release. Thank you to this contributor:

- Prashant Kumar Yadav

</section>

<!-- /.contributors -->

</section>

<!-- /.release -->

<section class="release" id="v0.2.2">

## 0.2.2 (2024-07-27)
Expand Down
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,100 @@ for ( i = 0; i < 10; i++ ) {

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/stats/base/dists/triangular/stdev.h"
```

#### stdlib_base_dists_triangular_stdev( a, b, c )

Returns the [standard deviation][standard-deviation] of a [triangular][triangular-distribution] distribution with minimum support `a`, maximum support`b`, and mode `c`.

```c
double out = stdlib_base_dists_triangular_stdev( 0.0, 1.0, 0.5 );
// returns ~0.204
```

The function accepts the following arguments:

- **a**: `[in] double` minimum support.
- **b**: `[in] double` maximum support.
- **c**: `[in] double` mode.

```c
double stdlib_base_dists_triangular_stdev( const double a, const double b, const double c );
```
</section>
<!-- /.usage -->
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
<section class="notes">
</section>
<!-- /.notes -->
<!-- C API usage examples. -->
<section class="examples">
### Examples
```c
#include "stdlib/stats/base/dists/triangular/stdev.h"
#include <stdlib.h>
#include <stdio.h>
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v*(max-min) );
}
int main( void ) {
double a;
double b;
double c;
double v;
int i;
for ( i = 0; i < 25; i++ ) {
a = random_uniform( 0.0, 10.0 );
b = random_uniform( a, a+10.0 );
c = random_uniform( a, b );
v = stdlib_base_dists_triangular_stdev( a, b, c );
printf( "a: %lf, b: %lf, c: %lf, SD(X;a,b,c): %lf\n", a, b, c, v );
}
}
```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">
Expand Down
17 changes: 13 additions & 4 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// MODULES //

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

bench( pkg, function benchmark( b ) {
var mode;
var len;
var min;
var max;
var y;
var i;

len = 100;
min = new Float64Array( len );
max = new Float64Array( len );
mode = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
min[ i ] = ( randu()*10.0 );
max[ i ] = ( randu()*10.0 ) + min[ i ] + EPS;
mode[ i ] = ( ( max[ i ] - min[ i ] ) * randu() ) + min[ i ];
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
min = ( randu()*10.0 );
max = ( randu()*10.0 ) + min + EPS;
mode = ( ( max - min ) * randu() ) + min;
y = stdev( min, max, mode );
y = stdev( min[ i % len ], max[ i % len ], mode[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
74 changes: 74 additions & 0 deletions benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench-harness' );
var Float64Array = require( '@stdlib/array-float64' );
var randu = require( '@stdlib/random-base-randu' );
var EPS = require( '@stdlib/constants-float64-eps' );
var isnan = require( '@stdlib/math-base-assert-is-nan' );
var tryRequire = require( '@stdlib/utils-try-require' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

var stdev = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( stdev instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var mode;
var len;
var min;
var max;
var y;
var i;

len = 100;
min = new Float64Array( len );
max = new Float64Array( len );
mode = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
min[ i ] = ( randu()*10.0 );
max[ i ] = ( randu()*10.0 ) + min[ i ] + EPS;
mode[ i ] = ( ( max[ i ] - min[ i ] ) * randu() ) + min[ i ];
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = stdev( min[ i % len ], max[ i % len ], mode[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
});
Loading

0 comments on commit b8f1f7a

Please sign in to comment.