Skip to content

feat: add C implementation for stats/base/dists/normal/logcdf #3988

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

manvith2003
Copy link
Contributor

@manvith2003 manvith2003 commented Dec 17, 2024

Resolves #3774

Description

What is the purpose of this pull request?

This pull request:

  • adds C implementation for stats/base/dists/normal/logcdf along with relevant tests, docs, examples and benchmarks.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

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


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Dec 17, 2024
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Dec 17, 2024

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/normal/logcdf $\color{green}325/325$
$\color{green}+100.00\%$
$\color{green}27/27$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}325/325$
$\color{green}+100.00\%$

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

@Planeshifter Planeshifter changed the title feat: add C implementation for stats/base/dists/normal/logcdf feat: add C implementation for stats/base/dists/normal/logcdf Dec 18, 2024
@Planeshifter Planeshifter self-requested a review January 15, 2025 01:55
@Planeshifter
Copy link
Member

/stdlib update-copyright-years

@stdlib-bot stdlib-bot added the bot: In Progress Pull request is currently awaiting automation. label Feb 21, 2025
@stdlib-bot stdlib-bot removed the bot: In Progress Pull request is currently awaiting automation. label Feb 21, 2025
* // returns ~-0.023
*/
double stdlib_base_dists_normal_logcdf( const double x, const double mu, const double sigma ) {

Copy link
Member

Choose a reason for hiding this comment

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

Empty line can be removed.

Comment on lines +33 to +37
* @param x input value
* @param mu mean of the distribution
* @param sigma standard deviation of the distribution
* @return evaluated log CDF
*
Copy link
Member

Choose a reason for hiding this comment

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

Parameter descriptions should be aligned.


#### stdlib_base_dists_normal_logcdf( x, mu, sigma )

Evaluates the logarithm of the cumulative distribution function (logCDF) for a normal distribution.
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
Evaluates the logarithm of the cumulative distribution function (logCDF) for a normal distribution.
Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [normal][normal-distribution] distribution with parameters `mu` (mean) and `sigma` (standard deviation).

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.

A few small edits, but looks good overall!

#include <time.h>

static double random_uniform( const double min, const double max ) {
double v = (double)rand() / ( (double)RAND_MAX + 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.

All C files in this PR should use TAB-indentation.

#include "stdlib/math/base/special/abs2.h"
#include "stdlib/constants/float64/ninf.h"

#define INV_SQRT_TWO 0.7071067811865475 // 1/sqrt(2)
Copy link
Member

Choose a reason for hiding this comment

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

Let's use static const double rather than #define for defining constants (offers type safety and scoped visibility of the contsant to the file, preventing any name clashes).

@Planeshifter Planeshifter added the bot: Update Copyright Years Pull request needing the copyright years of its files updated. label May 10, 2025
@stdlib-bot stdlib-bot added bot: In Progress Pull request is currently awaiting automation. and removed bot: Update Copyright Years Pull request needing the copyright years of its files updated. labels May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: In Progress Pull request is currently awaiting automation. Needs Review A pull request which needs code review. 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/normal/logcdf
3 participants