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 Feb 18, 2025
1 parent 234dd79 commit 0e7c791
Show file tree
Hide file tree
Showing 20 changed files with 1,337 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,7 @@ jsconfig.json
# Other editor files #
######################
.idea/

# Cursor #
##########
.cursorignore
29 changes: 27 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,37 @@
<section class="release" id="unreleased">

## Unreleased (2025-02-10)
## Unreleased (2025-02-18)

<section class="features">

### Features

- [`e05da28`](https://github.com/stdlib-js/stdlib/commit/e05da283a2493c635c06ab0f19e4aefbcc9e2540) - add C implementation for `stats/base/dists/binomial/stdev` [(#4408)](https://github.com/stdlib-js/stdlib/pull/4408)

</section>

<!-- /.features -->

<section class="issues">

### Closed Issues

This release closes the following issue:

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

</section>

<!-- /.issues -->

<section class="commits">

### Commits

<details>

- [`e05da28`](https://github.com/stdlib-js/stdlib/commit/e05da283a2493c635c06ab0f19e4aefbcc9e2540) - **feat:** add C implementation for `stats/base/dists/binomial/stdev` [(#4408)](https://github.com/stdlib-js/stdlib/pull/4408) _(by Prashant Kumar Yadav, Philipp Burckhardt, stdlib-bot)_
- [`af55f0d`](https://github.com/stdlib-js/stdlib/commit/af55f0d6d6b4d06c36f46357740ea89a4639ab5b) - **bench:** refactor random number generation in `stats/base/dists/binomial` [(#4841)](https://github.com/stdlib-js/stdlib/pull/4841) _(by Karan Anand)_

</details>
Expand All @@ -24,9 +47,11 @@

### Contributors

A total of 1 person contributed to this release. Thank you to this contributor:
A total of 3 people contributed to this release. Thank you to the following contributors:

- Karan Anand
- Philipp Burckhardt
- Prashant Kumar Yadav

</section>

Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ Dominik Moritz <domoritz@gmail.com>
Dorrin Sotoudeh <dorrinsotoudeh123@gmail.com>
EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com>
Frank Kovacs <fran70kk@gmail.com>
GK Bishnoi <gkishan1kyt@gmail.com>
Gaurav <gaurav70380@gmail.com>
Golden Kumar <103646877+AuenKr@users.noreply.github.com>
Gunj Joshi <gunjjoshi8372@gmail.com>
Gururaj Gurram <gururajgurram1512@gmail.com>
Harsh <149176984+hrshya@users.noreply.github.com>
HarshaNP <96897754+GittyHarsha@users.noreply.github.com>
Harshita Kalani <harshitakalani02@gmail.com>
Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com>
Expand Down Expand Up @@ -101,6 +104,7 @@ Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com>
Sarthak Paandey <145528240+SarthakPaandey@users.noreply.github.com>
Saurabh Singh <saurabhsraghuvanshi@gmail.com>
Seyyed Parsa Neshaei <spneshaei@users.noreply.github.com>
Shabareesh Shetty <139731143+ShabiShett07@users.noreply.github.com>
Shashank Shekhar Singh <shashankshekharsingh1205@gmail.com>
Shivam Ahir <11shivam00@gmail.com>
Shraddheya Shendre <shendreshraddheya@gmail.com>
Expand All @@ -125,6 +129,7 @@ Vivek Maurya <vm8118134@gmail.com>
Xiaochuan Ye <tap91624@gmail.com>
Yaswanth Kosuru <116426380+yaswanthkosuru@users.noreply.github.com>
Yernar Yergaziyev <yernar.yergaziyev@erg.kz>
Yuvi Mittal <128018763+yuvi-mittal@users.noreply.github.com>
ekambains <bainsinbusiness@gmail.com>
olenkabilonizhka <62379231+olenkabilonizhka@users.noreply.github.com>
pranav-1720 <123018993+pranav-1720@users.noreply.github.com>
Expand Down
96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,102 @@ 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/binomial/stdev.h"
```

#### stdlib_base_dists_binomial_stdev( n, p )

Returns the [standard deviation][stdev] of a [binomial][binomial-distribution] distribution with number of trials `n` and success probability `p`.

```c
double out = stdlib_base_dists_binomial_stdev( 100, 0.1 );
// returns 3
```

The function accepts the following arguments:

- **n**: `[in] int32_t` number of trials.
- **p**: `[in] double` success probability.

```c
double stdlib_base_dists_binomial_stdev( const int32_t n, const double p );

</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/binomial/stdev.h"
#include "stdlib/math/base/special/ceil.h"
#include <stdlib.h>
#include <stdint.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 ) {
int32_t n;
double p;
double y;
int i;

for ( i = 0; i < 25; i++ ) {
n = stdlib_base_ceil( random_uniform( 0.0, 100.0 ) );
p = random_uniform( 0.0, 1.0 );
y = stdlib_base_dists_binomial_stdev( n, p );
printf( "n: %d, p: %lf, SD(X;n,p): %lf\n", n, p, y );
}

return 0;
}
```
</section>
<!-- /.examples -->
</section>
<!-- /.c -->
<!-- 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
71 changes: 71 additions & 0 deletions benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 uniform = require( '@stdlib/random-base-uniform' );
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
var Float64Array = require( '@stdlib/array-float64' );
var tryRequire = require( '@stdlib/utils-try-require' );
var isnan = require( '@stdlib/math-base-assert-is-nan' );
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 len;
var n;
var p;
var y;
var i;

len = 100;
n = new Float64Array( len );
p = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
n[ i ] = discreteUniform( 1, 100 );
p[ i ] = uniform( 0.0, 1.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = stdev( n[ i % len ], p[ 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 0e7c791

Please # to comment.