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 23, 2024
1 parent 788c5d5 commit 63d600f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This release closes the following issue:

<details>

- [`0ba282b`](https://github.com/stdlib-js/stdlib/commit/0ba282b89c384f06bbe3ff8ecd71982f05209606) - **chore:** minor clean-up _(by Philipp Burckhardt)_
- [`603c766`](https://github.com/stdlib-js/stdlib/commit/603c76686fc8de480628e5b96efd9733b1f059b5) - **test:** only conditionally run tests _(by Philipp Burckhardt)_
- [`b884459`](https://github.com/stdlib-js/stdlib/commit/b8844596b7f57a356ff38333c0c5da9b63401874) - **feat:** add C implementation for `stats/base/dists/triangular/mean` [(#4006)](https://github.com/stdlib-js/stdlib/pull/4006) _(by Prashant Kumar Yadav, Philipp Burckhardt)_

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ int main( void ) {
for ( i = 0; i < 25; i++ ) {
a = random_uniform( 0.0, 10.0 );
b = random_uniform( 0.0, 10.0 ) + a;
c = a + (b - a) * random_uniform( 0.0, 1.0 ); // mode between a and b
b = random_uniform( a, 10.0 + a );
c = random_uniform( a, b ); // mode between a and b
y = stdlib_base_dists_triangular_mean( a, b, c );
printf( "a: %lf, b: %lf, c: %lf, E(X;a,b,c): %lf\n", a, b, c, y );
}
Expand Down
20 changes: 11 additions & 9 deletions benchmark/c/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ static double tic( void ) {
}

/**
* Generates a random number on the interval [0,20).
* Generates a random number on the interval [min,max).
*
* @return random number
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/
static double rand_double( void ) {
int r = rand();
return 20.0*(double)r / ( (double)RAND_MAX + 1.0 );
static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
return min + ( v*(max-min) );
}

/**
Expand All @@ -96,11 +98,11 @@ static double benchmark( void ) {
double t;
int i;

// Generate random parameters for the triangular distribution
// Generate random parameters for the triangular distribution:
for ( i = 0; i < 100; i++ ) {
a[ i ] = rand_double() * 20.0; // Lower bound
b[ i ] = ( rand_double() * 20.0 ) + a[ i ]; // Upper bound
c[ i ] = ( rand_double() * ( b[i] - a[i] ) ) + a[i]; // Mode
a[ i ] = random_uniform( 0.0, 20.0 ); // Lower bound
b[ i ] = random_uniform( a[i], a[i]+20.0 ); // Upper bound
c[ i ] = random_uniform( a[i], b[i] ); // Mode
}

t = tic();
Expand Down
4 changes: 2 additions & 2 deletions examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ int main( void ) {

for ( i = 0; i < 25; i++ ) {
a = random_uniform( 0.0, 10.0 );
b = random_uniform( 0.0, 10.0 ) + a;
c = a + (b - a) * random_uniform( 0.0, 1.0 ); // mode between a and b
b = random_uniform( a, a+10.0 );
c = random_uniform( a, b ); // mode between a and b
y = stdlib_base_dists_triangular_mean( a, b, c );
printf( "a: %lf, b: %lf, c: %lf, E(X;a,b,c): %lf\n", a, b, c, y );
}
Expand Down
2 changes: 1 addition & 1 deletion lib/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var addon = require( './../src/addon.node' );
*
* @example
* var v = mean( 2.0, 8.0, 4.0 );
* // returns 4.666666666666667
* // returns ~4.667
*
* @example
* var v = mean( -1.0, 5.0, 6.0 );
Expand Down
10 changes: 5 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#include "stdlib/math/base/assert/is_nan.h"

/**
* Evaluates the expected value (mean) of a triangular distribution with lower bound a, upper bound b and mode (peak) c.
* Returns the expected value of a triangular distribution.
*
* @param a lower bound
* @param b upper bound
* @param c mode (peak)
* @returns expected value (mean)
* @param a minimum support
* @param b maximum support
* @param c mode
* @returns expected value
*
* @example
* double v = mean( 0.0, 10.0, 5.0 );
Expand Down

0 comments on commit 63d600f

Please sign in to comment.