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 Jan 19, 2025
1 parent ad58cc8 commit 7d45a92
Show file tree
Hide file tree
Showing 21 changed files with 1,396 additions and 7 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ indent_style = tab
[*.{f,f.txt}]
indent_style = space
indent_size = 2
insert_final_newline = false

# Set properties for shell files:
[*.{sh,sh.txt}]
Expand Down
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

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

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

## Unreleased (2025-01-19)

<section class="features">

### Features

- [`ecd8369`](https://github.com/stdlib-js/stdlib/commit/ecd836903721f0f381eb71739a785cb0077ccf01) - add C implementation for `stats/base/dists/cosine/mgf` [(#4510)](https://github.com/stdlib-js/stdlib/pull/4510)

</section>

<!-- /.features -->

<section class="issues">

### Closed Issues

This release closes the following issue:

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

</section>

<!-- /.issues -->

<section class="commits">

### Commits

<details>

- [`ecd8369`](https://github.com/stdlib-js/stdlib/commit/ecd836903721f0f381eb71739a785cb0077ccf01) - **feat:** add C implementation for `stats/base/dists/cosine/mgf` [(#4510)](https://github.com/stdlib-js/stdlib/pull/4510) _(by Prashant Kumar Yadav, Philipp Burckhardt, stdlib-bot)_

</details>

</section>

<!-- /.commits -->

<section class="contributors">

### Contributors

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

- Philipp Burckhardt
- Prashant Kumar Yadav

</section>

<!-- /.contributors -->

</section>

<!-- /.release -->

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

## 0.2.2 (2024-07-28)
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Daniel Killenberger <[email protected]>
Daniel Yu <[email protected]>
Debashis Maharana <[email protected]>
Desh Deepak Kant <[email protected]>
Dev Goel <[email protected]>
Dhruv Arvind Singh <[email protected]>
Divyansh Seth <[email protected]>
Dominic Lim <[email protected]>
Expand All @@ -50,6 +51,7 @@ Joey Reed <[email protected]>
Jordan Gallivan <[email protected]>
Joris Labie <[email protected]>
Justin Dennison <[email protected]>
Karan Anand <[email protected]>
Karthik Prakash <[email protected]>
Kohantika Nath <[email protected]>
Krishnendu Das <[email protected]>
Expand Down
107 changes: 107 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,113 @@ 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/cosine/mgf.h"
```

#### stdlib_base_dists_cosine_mgf( t, mu, s )

Returns the [moment-generating function][mgf] (MGF) for a [raised cosine][cosine-distribution] distribution with parameters `mu` (location parameter) and `s` (scale parameter).

```c
double out = stdlib_base_dists_cosine_mgf( 0.5, 0.0, 1.0 );
// returns ~1.016
```

The function accepts the following arguments:

- **t**: `[in] double` input value.
- **mu**: `[in] double` location parameter.
- **s**: `[in] double` scale parameter.

```c
double stdlib_base_dists_cosine_mgf( const double t, const double mu, const double s );
```
</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/cosine/mgf.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 mu;
double s;
double t;
double y;
int i;
for ( i = 0; i < 10; i++ ) {
t = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 );
mu = random_uniform( -50.0, 50.0 );
s = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
y = stdlib_base_dists_cosine_mgf( t, mu, s );
printf( "t: %lf, µ: %lf, s: %lf, M_X(t;µ,s): %lf\n", t, mu, s , 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">

</section>

<!-- /.references -->

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

<section class="related">
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 @@ -31,18 +32,26 @@ var mgf = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var mu;
var s;
var t;
var y;
var i;

len = 100;
t = new Float64Array( len );
mu = new Float64Array( len );
s = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
t[ i ] = ( randu()*10.0 ) + EPS;
mu[ i ] = ( randu()*20.0 ) - 10.0;
s[ i ] = ( randu()*5.0 ) + EPS;
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
t = ( randu()*10.0 ) + EPS;
mu = ( randu()*100.0 ) - 50.0;
s = ( randu()*20.0 ) + EPS;
y = mgf( t, mu, s );
y = mgf( t[ i % len ], mu[ i % len ], s[ 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) 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 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 mgf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
var opts = {
'skip': ( mgf instanceof Error )
};


// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var len;
var mu;
var s;
var t;
var y;
var i;

len = 100;
t = new Float64Array( len );
mu = new Float64Array( len );
s = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
t[ i ] = ( randu()*10.0 ) + EPS;
mu[ i ] = ( randu()*20.0 ) - 10.0;
s[ i ] = ( randu()*5.0 ) + EPS;
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = mgf( t[ i % len ], mu[ i % len ], s[ 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 7d45a92

Please sign in to comment.