Skip to content

feat: add C ndarray implementation for stats/base/dmeanvarpn #4720

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

Conversation

DhruvArvindSingh
Copy link
Contributor

@DhruvArvindSingh DhruvArvindSingh commented Jan 12, 2025

Resolves None.

Description

What is the purpose of this pull request?

This pull request:

  • Adds C ndarray implementation for stats/base/dmeanvarpn.
  • Updates README.md.

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves None.

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_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: passed
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
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 12, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Jan 12, 2025

Coverage Report

Package Statements Branches Functions Lines
stats/base/dmeanvarpn $\color{green}441/441$
$\color{green}+100.00\%$
$\color{green}26/26$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}441/441$
$\color{green}+100.00\%$

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

@DhruvArvindSingh
Copy link
Contributor Author

/stdlib update-copyright-years

@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 12, 2025
@DhruvArvindSingh DhruvArvindSingh marked this pull request as draft January 12, 2025 18:35
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Jan 12, 2025
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: passed
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
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: passed
  - task: run_c_benchmarks
    status: passed
  - 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
---
@DhruvArvindSingh DhruvArvindSingh marked this pull request as ready for review January 12, 2025 19:51
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 12, 2025
@DhruvArvindSingh DhruvArvindSingh changed the title feat: add C ndarray implementation for stats/base/dmeanvarpn feat: add C ndarray implementation for stats/base/dmeanvarpn Jan 12, 2025
DhruvArvindSingh and others added 2 commits January 14, 2025 03:36
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: passed
  - task: run_c_examples
    status: passed
  - 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: passed
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: passed
---
Comment on lines +257 to +260
double x[] ={ 1.0, -2.0, 2.0 };
double out[2];
stdlib_strided_dmeanvarpn( x.length, 1, x, 1, out, 1 );
// Out = [ ~0.3333, ~4.3333 ]
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
double x[] ={ 1.0, -2.0, 2.0 };
double out[2];
stdlib_strided_dmeanvarpn( x.length, 1, x, 1, out, 1 );
// Out = [ ~0.3333, ~4.3333 ]
const double x[] ={ 1.0, -2.0, 2.0 };
double out[] = { 0.0, 0.0 };
stdlib_strided_dmeanvarpn( x.length, 1, x, 1, out, 1 );

- **correction**: `[in] double` degrees of freedom adjustment.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Out**: `[in] double*` Output array.
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
- **Out**: `[in] double*` Output array.
- **Out**: `[out] double*` Output array.

Comment on lines +281 to +284
const double x[] = { 1.0, -2.0, 2.0 };

stdlib_strided_dmeanvarpn_ndarray( x.length, 1, x, 1, 0, out, 1, 0 );
// Out = [ ~0.3333, ~4.3333 ]
Copy link
Member

Choose a reason for hiding this comment

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

no declaration for Out here

- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` `X` starting index.
- **Out**: `[in] double*` Output array.
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
- **Out**: `[in] double*` Output array.
- **Out**: `[out] double*` Output array.

Copy link
Member

Choose a reason for hiding this comment

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

this is also missing changes in the JavaScript docs regarding removing the usage of math/base/special/floor in examples

@@ -17,7 +17,6 @@
*/

#include "stdlib/stats/base/dmeanvarpn.h"
#include "stdlib/blas/base/shared.h"
Copy link
Member

Choose a reason for hiding this comment

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

why is this being removed? it should be there since we're wrapping function calls in API_SUFFIX which comes from this header

@@ -16,72 +16,76 @@
* limitations under the License.
*/

#include "stdlib/stats/base/dmeanvarpn.h"

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

no need for extra newline

Comment on lines -26 to -34
* ## Method
*
* - This implementation uses a two-pass approach, as suggested by Neely (1966).
*
* ## References
*
* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958).
* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036).
*
Copy link
Member

Choose a reason for hiding this comment

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

references are important, no need to remove them

Comment on lines +57 to 81
CBLAS_INT ix;
CBLAS_INT io;
CBLAS_INT n;
double mu;
double dN;
double M2;
double M;
double d;
double c;
double n;
double i;

if ( strideX < 0 ) {
ix = (1-N) * strideX;
} else {
ix = 0;
}
if ( strideOut < 0 ) {
io = -strideOut;
} else {
io = 0;
}
ix = offsetX;
io = offsetOut;
if ( N <= 0 ) {
Out[ io ] = 0.0 / 0.0; // NaN
Out[ io+strideOut ] = 0.0 / 0.0; // NaN
Out[ io ] = 0.0/0.0;
Out[ io + strideOut ] = 0.0/0.0;
return;
}
dN = (double)N;
n = dN - correction;
n = N - correction;
if ( N == 1 || strideX == 0 ) {
Out[ io ] = X[ ix ];
if ( n <= 0.0 ) {
Out[ io+strideOut ] = 0.0 / 0.0; // NaN
Out[ io+strideOut ] = 0.0/0.0;
} else {
Out[ io+strideOut ] = 0.0;
}
Copy link
Member

Choose a reason for hiding this comment

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

this is copied from the JS ndarray implementation, i would prefer that you refactor the existing C implementation only

Copy link
Member

Choose a reason for hiding this comment

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

this would avoid implicit typecasting etc, for eg see changes on line 101

if ( N == 1 || strideX == 0 ) {
Out[ io ] = X[ ix ];
if ( n <= 0.0 ) {
Out[ io+strideOut ] = 0.0 / 0.0; // NaN
Out[ io+strideOut ] = 0.0/0.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
Out[ io+strideOut ] = 0.0/0.0;
Out[ io+strideOut ] = 0.0 / 0.0; // NaN

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 all other instances

@aayush0325 aayush0325 added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Feb 3, 2025
@kgryte kgryte added Obsolete Issue or pull request which is no longer relevant. autoclose: Already Resolved Pull request which should be auto-closed due proposed changes duplicating already included changes. labels Jun 8, 2025
@stdlib-bot
Copy link
Contributor

Thank you for working on this pull request. However, we cannot accept your contribution as the issue this pull request seeks to resolve has already been addressed in a different pull request or commit.

Thank you again for your interest in stdlib, and we look forward to reviewing your future contributions.

@stdlib-bot stdlib-bot closed this Jun 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autoclose: Already Resolved Pull request which should be auto-closed due proposed changes duplicating already included changes. Needs Changes Pull request which needs changes before being merged. Obsolete Issue or pull request which is no longer relevant. Statistics Issue or pull request related to statistical functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants