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 7, 2025
1 parent a3beda5 commit ed45099
Show file tree
Hide file tree
Showing 19 changed files with 1,553 additions and 6 deletions.
28 changes: 26 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-01-21)
## Unreleased (2025-02-07)

<section class="features">

### Features

- [`b1f7e5c`](https://github.com/stdlib-js/stdlib/commit/b1f7e5c17b39382bd4b5246792ee6caa04449f80) - add C implementation for `stats/base/dists/beta/logpdf` [(#4050)](https://github.com/stdlib-js/stdlib/pull/4050)

</section>

<!-- /.features -->

<section class="issues">

### Closed Issues

This release closes the following issue:

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

</section>

<!-- /.issues -->

<section class="commits">

### Commits

<details>

- [`b1f7e5c`](https://github.com/stdlib-js/stdlib/commit/b1f7e5c17b39382bd4b5246792ee6caa04449f80) - **feat:** add C implementation for `stats/base/dists/beta/logpdf` [(#4050)](https://github.com/stdlib-js/stdlib/pull/4050) _(by Neeraj Pathak, stdlib-bot)_
- [`9394549`](https://github.com/stdlib-js/stdlib/commit/939454926b745326a5b14bcd0924a0526baa93da) - **bench:** refactor random number generation in `stats/base/dists/beta` [(#4837)](https://github.com/stdlib-js/stdlib/pull/4837) _(by Karan Anand)_

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

### Contributors

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

- Karan Anand
- Neeraj Pathak

</section>

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Marcus Fantham <mfantham@users.noreply.github.com>
Matt Cochrane <matthew.cochrane.eng@gmail.com>
Mihir Pandit <129577900+MSP20086@users.noreply.github.com>
Milan Raj <rajsite@users.noreply.github.com>
Mohammad Bin Aftab <48010758+MohammadBinAftab@users.noreply.github.com>
Mohammad Kaif <mdkaifprofession@gmail.com>
Momtchil Momtchev <momtchil@momtchev.com>
Muhammad Haris <harriskhan047@outlook.com>
Expand Down
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,106 @@ 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/beta/logpdf.h"
```

#### stdlib_base_dists_beta_logpdf( x, alpha, beta )

Evaluates the natural logarithm of the probability density function (logPDF) for a beta distribution with first shape parameter `alpha` and second shape parameter `beta`.

```c
double y = stdlib_base_dists_beta_logpdf( 0.5, 1.0, 1.0 );
// returns 0.0
```

The function accepts the following arguments:

- **x**: `[in] double` input value.
- **alpha**: `[in] double` first shape parameter.
- **beta**: `[in] double` second shape parameter.

```c
double stdlib_base_dists_beta_logpdf( const double x, double alpha, const double beta );
```
</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/beta/logpdf.h"
#include "stdlib/constants/float64/eps.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 alpha;
double beta;
double x;
double y;
int i;
for ( i = 0; i < 10; i++ ) {
x = random_uniform( 0.0, 1.0 );
alpha = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
beta = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
y = stdlib_base_dists_beta_logpdf( x, alpha, beta );
printf( "x: %1f. α: %1f. β: %1f. ln(f(x;α,β)): %lf\n", x, alpha, beta, y );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

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

var bench = require( '@stdlib/bench-harness' );
var uniform = require( '@stdlib/random-base-uniform' );
var Float64Array = require( '@stdlib/array-float64' );
var uniform = require( '@stdlib/random-base-uniform' );
var isnan = require( '@stdlib/math-base-assert-is-nan' );
var EPS = require( '@stdlib/constants-float64-eps' );
var pkg = require( './../package.json' ).name;
Expand All @@ -40,13 +40,13 @@ bench( pkg, function benchmark( b ) {
var i;

len = 100;
x = new Float64Array( len );
alpha = new Float64Array( len );
beta = new Float64Array( len );
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( EPS, 2.0 );
alpha[ i ] = uniform( EPS, 100.0 );
beta[ i ] = uniform( EPS, 100.0 );
x[ i ] = uniform( EPS, 2.0 );
}

b.tic();
Expand Down Expand Up @@ -76,6 +76,7 @@ bench( pkg+':factory', function benchmark( b ) {
alpha = 100.56789;
beta = 55.54321;
mylogpdf = logpdf.factory( alpha, beta );

len = 100;
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
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) 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 Float64Array = require( '@stdlib/array-float64' );
var isnan = require( '@stdlib/math-base-assert-is-nan' );
var tryRequire = require( '@stdlib/utils-try-require' );
var EPS = require( '@stdlib/constants-float64-eps' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

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


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var alpha;
var beta;
var len;
var x;
var y;
var i;

len = 100;
alpha = new Float64Array( len );
beta = new Float64Array( len );
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
alpha[ i ] = uniform( EPS, 100.0 );
beta[ i ] = uniform( EPS, 100.0 );
x[ i ] = uniform( EPS, 2.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = logpdf( x[ i % len ], alpha[ i % len ], beta[ 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 ed45099

Please sign in to comment.