Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stats): add C implementation for stats/base/dists/chisquare/mgf #4593

Merged
merged 13 commits into from
Jan 8, 2025

Conversation

anandkaranubc
Copy link
Contributor

Resolves

#3506


Description

Purpose of this pull request

This pull request:

  • Adds a C implementation of the moment-generating function (MGF) for a chi-squared distribution.
  • Includes benchmarks for the C implementation.
  • Provides examples demonstrating the usage of the moment-generating function (MGF) for a chi-squared distribution in C.

Related Issues

Does this pull request have any related issues?

This pull request:


Questions

Any questions for reviewers of this pull request?

No.


Other Information

Any other relevant information?

No.


Checklist

Please ensure the following tasks are completed before submitting this pull request:


@stdlib-js/reviewers

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Jan 6, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Jan 6, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/chisquare/mgf $\color{green}259/259$
$\color{green}+100.00\%$
$\color{green}19/19$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}259/259$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@anandkaranubc
Copy link
Contributor Author

/stdlib lint-autofix

@stdlib-bot stdlib-bot added bot: In Progress Pull request is currently awaiting automation. and removed bot: In Progress Pull request is currently awaiting automation. labels Jan 6, 2025
@anandkaranubc
Copy link
Contributor Author

@Planeshifter @kgryte

Thank you for the OH. I was wondering if I can get some feedback from you on this PR. This is my most recent PR of all the ones I have created, based on learning from previous ones. I hope I can use the feedback I get on this PR and make any necessary changes in my other PRs as well based on this one. Thank you so much!

@Planeshifter
Copy link
Member

@anandkaranubc Taking a look now...

@Planeshifter Planeshifter self-requested a review January 7, 2025 23:23

result = stdlib_base_dists_chisquare_mgf( t, k );

printf( "t: %lf, k: %lf, MGF: %lf \n", t, k, result );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See JS example:

Suggested change
printf( "t: %lf, k: %lf, MGF: %lf \n", t, k, result );
printf( "t: %lf, k: %lf, M_X(t;k): %lf \n", t, k, result );

@Planeshifter
Copy link
Member

/stdlib update-copyright-years

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Jan 7, 2025
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Jan 7, 2025

result = stdlib_base_dists_chisquare_mgf( t, k );

printf( "t: %lf, k: %lf, MGF: %lf \n", t, k, result );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printf( "t: %lf, k: %lf, MGF: %lf \n", t, k, result );
printf( "t: %lf, k: %lf, M_X(t;k): %lf \n", t, k, result );

Comment on lines 29 to 32
double t;
double k;
double result;
int i;
Copy link
Member

@Planeshifter Planeshifter Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, we order variable declarations by length:

Suggested change
double t;
double k;
double result;
int i;
double result;
double t;
double k;
int i;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for mentioning! Was checking the other PRs comments so that I may fix the similar mistakes in mine! ehe!

@Planeshifter
Copy link
Member

/stdlib lint-autofix

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Jan 7, 2025
Comment on lines 21 to 22
"include": "./include",
"example": "./examples",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered alphabetically to make the CI linter happy:

Suggested change
"include": "./include",
"example": "./examples",
"example": "./examples",
"include": "./include",

@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Jan 7, 2025
#include <stdio.h>

static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
Copy link
Member

@Planeshifter Planeshifter Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be tab-indented. We had a bug on CI that caused the EditorConfig linting to not catch these. Make sure you have EditorConfig setup in your IDE; then saving C files should automatically indent them using TABs

# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
{
# List of files to include in this file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be two-space indented. Should be correctly formatted on save when EditorConfig is setup.

# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md
# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md
{
# Define variables to be used throughout the configuration for all targets:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two-space indentation.

Comment on lines 30 to 41
* @example
* double y = stdlib_base_dists_chisquare_mgf( 0.4, 2.0 );
* // returns ~5.0
*
* @example
* double y = stdlib_base_dists_chisquare_mgf( -1.0, 5.0 );
* // returns ~0.0642
*
* @example
* double y = stdlib_base_dists_chisquare_mgf( 0.0, 10.0 );
* // returns 1.0
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per convention, we only keep one example in the C files:

Suggested change
* @example
* double y = stdlib_base_dists_chisquare_mgf( 0.4, 2.0 );
* // returns ~5.0
*
* @example
* double y = stdlib_base_dists_chisquare_mgf( -1.0, 5.0 );
* // returns ~0.0642
*
* @example
* double y = stdlib_base_dists_chisquare_mgf( 0.0, 10.0 );
* // returns 1.0
*/
* @example
* double y = stdlib_base_dists_chisquare_mgf( 0.4, 2.0 );
* // returns ~5.0
*/

* // returns 1.0
*/
double stdlib_base_dists_chisquare_mgf( const double t, const double k ) {
if ( stdlib_base_is_nan( t ) || stdlib_base_is_nan( k ) || k < 0.0 || t >= 0.5 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be TAB-indentation here. You could also break up the if-clause over multiple lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes have been merged successfully! 😃

Copy link
Member

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your updates! PR should be in good shape now. Will merge shortly after CI checks have passed.

@Planeshifter Planeshifter added the Ready To Merge A pull request which is ready to be merged. label Jan 8, 2025
@stdlib-bot stdlib-bot removed Needs Review A pull request which needs code review. Needs Changes Pull request which needs changes before being merged. labels Jan 8, 2025
@stdlib-bot
Copy link
Contributor

PR Commit Message

feat(stats): add C implementation for `stats/base/dists/chisquare/mgf`

PR-URL: https://github.com/stdlib-js/stdlib/pull/4593
Ref: https://github.com/stdlib-js/stdlib/issues/3506

Co-authored-by: Karan Anand <[email protected]>
Co-authored-by: Philipp Burckhardt <[email protected]>
Co-authored-by: stdlib-bot <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
Signed-off-by: Philipp Burckhardt <[email protected]>

Please review the above commit message and make any necessary adjustments.

@Planeshifter Planeshifter merged commit 6def8d6 into stdlib-js:develop Jan 8, 2025
28 of 29 checks passed
@anandkaranubc anandkaranubc deleted the rfc/chisquare-mgf branch January 8, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready To Merge A pull request which is ready to be merged. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: Add C implementation for @stdlib/stats/base/dists/chisquare/mgf
4 participants