Skip to content

feat: add C implementation for stats/base/dists/planck/logpmf #5001

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

yuvi-mittal
Copy link
Contributor

Resolves #5000

Description

What is the purpose of this pull request?

This pull request:

Add C implementation for @stdlib/stats/base/dists/planck/logpmf

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

---
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
Copy link
Contributor

stdlib-bot commented Jan 31, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/planck/logpmf $\color{green}282/282$
$\color{green}+100.00\%$
$\color{green}21/21$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}282/282$
$\color{green}+100.00\%$

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

"@stdlib/math/base/assert/is-nan",
"@stdlib/math/base/assert/is-nonnegative-integer",
"@stdlib/math/base/special/expm1",
"@stdlib/constants/float64/pi",
Copy link
Member

Choose a reason for hiding this comment

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

pi should be removed as it is not used in the main.c file right.

Copy link
Member

Choose a reason for hiding this comment

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

same goes for the other builds as well!

@@ -21,8 +21,10 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var Float64Array = require( '@stdlib/array/float64' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
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
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );

should be removed as it is not used in the file anywhere

Copy link
Member

Choose a reason for hiding this comment

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

same comment for the native file as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually it is been used in pkg+':factory'(benchmark 2) , as it uses random/array/discrete-uniform , so i made two variable one for array and one for base .

Copy link
Member

@Neerajpathak07 Neerajpathak07 Feb 3, 2025

Choose a reason for hiding this comment

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

Yeah, but the the ::factory code block should have the discreteUniformbase number generation logic for len = 100 and var x having a Float64array val just as you did it for the above code block!!

@Neerajpathak07
Copy link
Member

@yuvi-mittal
Please change the PR title to:-
feat: add C implementation for stats/base/dists/planck/logpmf

@yuvi-mittal yuvi-mittal changed the title feat: Add C implementation for @stdlib/stats/base/dists/planck/logpmf feat: add C implementation for stats/base/dists/planck/logpmf Feb 2, 2025
@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Feb 2, 2025
---
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
---
@Planeshifter Planeshifter added the bot: Update Copyright Years Pull request needing the copyright years of its files updated. label Feb 15, 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 Feb 15, 2025
@Planeshifter Planeshifter added bot: Lint Autofix Pull request needing applicable lint errors to be automatically fixed. and removed bot: In Progress Pull request is currently awaiting automation. labels Feb 15, 2025
@stdlib-bot stdlib-bot added bot: In Progress Pull request is currently awaiting automation. and removed bot: Lint Autofix Pull request needing applicable lint errors to be automatically fixed. labels Feb 15, 2025
@Planeshifter Planeshifter changed the title feat: add C implementation for stats/base/dists/planck/logpmf feat: add C implementation for stats/base/dists/planck/logpmf Feb 15, 2025
@Planeshifter Planeshifter removed the bot: In Progress Pull request is currently awaiting automation. label Feb 15, 2025
@yuvi-mittal
Copy link
Contributor Author

@Planeshifter , this PR is ready to be merged too i believe !

* @private
* @param {number} x - input value
* @param {number} lambda - shape parameter
* @returns {number} evaluated log(PMF)
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
* @returns {number} evaluated log(PMF)
* @returns {number} evaluated logPMF

*
* @param x input value
* @param lambda shape parameter
* @return evaluated log PMF
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
* @return evaluated log PMF
* @return evaluated logPMF

@@ -101,7 +101,7 @@ y = mylogpmf( 1.0 );

## Notes

- In virtually all cases, using the `logpmf` or `logcdf` functions is preferable to manually computing the logarithm of the `pmf` or `cdf`, respectively, since the latter is prone to overflow and underflow.
In virtually all cases, using the `logpmf` or `logcdf` functions is preferable to manually computing the logarithm of the `pmf` or `cdf`, respectively, since the latter is prone to overflow and underflow.
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
In virtually all cases, using the `logpmf` or `logcdf` functions is preferable to manually computing the logarithm of the `pmf` or `cdf`, respectively, since the latter is prone to overflow and underflow.
- In virtually all cases, using the `logpmf` or `logcdf` functions is preferable to manually computing the logarithm of the `pmf` or `cdf`, respectively, since the latter is prone to overflow and underflow.

Comment on lines +201 to +204
#include <stdio.h>
static int random_discrete_uniform( const int min, const int max ) {
return min + ( rand() % ( max - min + 1 ) );
}
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
#include <stdio.h>
static int random_discrete_uniform( const int min, const int max ) {
return min + ( rand() % ( max - min + 1 ) );
}
#include <stdio.h>
static int random_discrete_uniform( const int min, const int max ) {
return min + ( rand() % ( max - min + 1 ) );
}

Comment on lines +54 to +55
x[i] = discreteUniformBase(0, 40);
lambda[i] = uniformBase(1.0, 10.0);
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
x[i] = discreteUniformBase(0, 40);
lambda[i] = uniformBase(1.0, 10.0);
x[i] = discreteUniformBase( 0, 40 );
lambda[i] = uniformBase( 1.0, 10.0 );

* @param total total number of tests
* @param passing total number of passing tests
*/

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't have empty lines between documentation blocks and functions in this file.

Comment on lines +77 to +92
/**
* Generates a random number on the interval [min,max).
*
* @param min minimum value (inclusive)
* @param max maximum value (exclusive)
* @return random number
*/

static int random_discrete_uniform( int min, int max ) {
return min + rand() % ( max - min + 1 );
}

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

Choose a reason for hiding this comment

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

Need to document both functions here.

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 efforts, @yuvi-mittal! This should be fairly close, but there are a bunch of errors that need to be resolved before it can be merged.

@yuvi-mittal
Copy link
Contributor Author

I will check them by EOD, but I have one question—why aren't these linting errors showing on my local system? There are no lint errors locally.

@Planeshifter
Copy link
Member

Planeshifter commented Mar 7, 2025

@yuvi-mittal Thanks for taking care of these! All checks are green on CI too, so there is nothing wrong with your local setup. Simple explanation is that we have various conventions that are currently not yet enforced via automated linting because we didn't have the bandwidth to do so or which would be infeasible to automatically check.

@yuvi-mittal
Copy link
Contributor Author

@kgryte , The PR looks good to me , can you please review if there is any issue !

@Planeshifter
Copy link
Member

@yuvi-mittal The comments I left still need to be addressed.

@yuvi-mittal
Copy link
Contributor Author

Yess , Sorry . I will look into that !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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/planck/logpmf
4 participants