Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/betainc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,106 @@ logEachMap( 'x: %0.4f, \t a: %0.4f, \t b: %0.4f, \t f(x,a,b): %0.4f', x, a, b, b

<!-- /.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/math/base/special/betainc.h"
```

#### stdlib_base_betainc( x, a, b, regularized, upper )

Evaluates the incomplete beta function.

```c
double y = stdlib_base_betainc( 0.5, 2.0, 2.0, true, false );
// returns 0.5
```

The function accepts the following arguments:

- **x**: `[in] double` function parameter.
- **a**: `[in] double` function parameter.
- **b**: `[in] double` function parameter.
- **regularized**: `[in] bool` indicating if the function should evaluate the regularized incomplete beta function.
- **upper**: `[in] bool` indicating if the function should return the upper tail of the incomplete beta function.

```c
double stdlib_base_betainc( const double x, const double a, const double b, const bool regularized, const bool upper );
```

</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/math/base/special/betainc.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 x;
double a;
double b;
double v;
int i;

for ( i = 0; i < 100; i++ ) {
x = random_uniform( 0.0, 1.0 );
a = random_uniform( 0.0, 10.0 );
b = random_uniform( 0.0, 10.0 );
v = stdlib_base_betainc( x, a, b, true, false );
printf( "x: %lf, a: %lf, b: %lf, f(x,a,b): %lf\n", x, a, b, v );
}
}
```

</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
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ var betainc = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( assert ) {
var opts;
var x;
var y;
var a;
var b;
var i;

x = uniform( 100, 0.0, 1.0 );
a = uniform( 100, EPS, 1000.0 );
b = uniform( 100, EPS, 1000.0 );
opts = {
'dtype': 'float64'
};
x = uniform( 100, 0.0, 1.0, opts );
a = uniform( 100, EPS, 1000.0, opts );
b = uniform( 100, EPS, 1000.0, opts );

assert.tic();
for ( i = 0; i < assert.iterations; i++ ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 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' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var tryRequire = require( '@stdlib/utils/try-require' );
var format = require( '@stdlib/string/format' );
var EPS = require( '@stdlib/constants/float64/eps' );
var pkg = require( './../package.json' ).name;


// VARIABLES //

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


// MAIN //

bench( format( '%s::native:regularized=true,upper=true', pkg ), opts, function benchmark( assert ) {
var arrayOpts;
var x;
var y;
var a;
var b;
var i;

arrayOpts = {
'dtype': 'float64'
};
x = uniform( 100, 0.0, 1.0, arrayOpts );
a = uniform( 100, EPS, 1000.0, arrayOpts );
b = uniform( 100, EPS, 1000.0, arrayOpts );

assert.tic();
for ( i = 0; i < assert.iterations; i++ ) {
y = betainc( x[ i % x.length ], a[ i % a.length ], b[ i % b.length ], true, true );

Check warning on line 60 in lib/node_modules/@stdlib/math/base/special/betainc/benchmark/benchmark.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 91. Maximum allowed is 80
if ( isnan( y ) ) {
assert.fail( 'should not return NaN' );
}
}
assert.toc();
if ( isnan( y ) ) {
assert.fail( 'should not return NaN' );
}
assert.pass( 'benchmark finished' );
assert.end();
});

bench( format( '%s::native:regularized=true,upper=false', pkg ), opts, function benchmark( assert ) {
var arrayOpts;
var x;
var y;
var a;
var b;
var i;

arrayOpts = {
'dtype': 'float64'
};
x = uniform( 100, 0.0, 1.0, arrayOpts );
a = uniform( 100, EPS, 1000.0, arrayOpts );
b = uniform( 100, EPS, 1000.0, arrayOpts );

assert.tic();
for ( i = 0; i < assert.iterations; i++ ) {
y = betainc( x[ i % x.length ], a[ i % a.length ], b[ i % b.length ], true, false );

Check warning on line 90 in lib/node_modules/@stdlib/math/base/special/betainc/benchmark/benchmark.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 92. Maximum allowed is 80
if ( isnan( y ) ) {
assert.fail( 'should not return NaN' );
}
}
assert.toc();
if ( isnan( y ) ) {
assert.fail( 'should not return NaN' );
}
assert.pass( 'benchmark finished' );
assert.end();
});

bench( format( '%s::native:regularized=false,upper=true', pkg ), opts, function benchmark( assert ) {
var arrayOpts;
var x;
var y;
var a;
var b;
var i;

arrayOpts = {
'dtype': 'float64'
};
x = uniform( 100, 0.0, 1.0, arrayOpts );
a = uniform( 100, EPS, 1000.0, arrayOpts );
b = uniform( 100, EPS, 1000.0, arrayOpts );

assert.tic();
for ( i = 0; i < assert.iterations; i++ ) {
y = betainc( x[ i % x.length ], a[ i % a.length ], b[ i % b.length ], false, true );

Check warning on line 120 in lib/node_modules/@stdlib/math/base/special/betainc/benchmark/benchmark.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 92. Maximum allowed is 80
if ( isnan( y ) ) {
assert.fail( 'should not return NaN' );
}
}
assert.toc();
if ( isnan( y ) ) {
assert.fail( 'should not return NaN' );
}
assert.pass( 'benchmark finished' );
assert.end();
});

bench( format( '%s::native:regularized=false,upper=false', pkg ), opts, function benchmark( assert ) {
var arrayOpts;
var x;
var y;
var a;
var b;
var i;

arrayOpts = {
'dtype': 'float64'
};
x = uniform( 100, 0.0, 1.0, arrayOpts );
a = uniform( 100, EPS, 1000.0, arrayOpts );
b = uniform( 100, EPS, 1000.0, arrayOpts );

assert.tic();
for ( i = 0; i < assert.iterations; i++ ) {
y = betainc( x[ i % x.length ], a[ i % a.length ], b[ i % b.length ], false, false );

Check warning on line 150 in lib/node_modules/@stdlib/math/base/special/betainc/benchmark/benchmark.native.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 93. Maximum allowed is 80
if ( isnan( y ) ) {
assert.fail( 'should not return NaN' );
}
}
assert.toc();
if ( isnan( y ) ) {
assert.fail( 'should not return NaN' );
}
assert.pass( 'benchmark finished' );
assert.end();
});
Loading