Skip to content

[RFC]: refactor and add protocol support to stats/base/variancewd #5691

Open
@kgryte

Description

@kgryte

Description

This RFC proposes refactoring and adding accessor protocol support to @stdlib/stats/base/variancewd.

For background on the accessor protocol, see https://blog.stdlib.io/introducing-the-accessor-protocol-for-array-like-objects/.

Examples of what we are looking for:

While the changes proposed in this RFC will not match the implementations found in the above packages, the packages should provide a conceptual idea of what is desired. Do not simply copy-paste the code found in those packages without reasoning about expected behavior and API design.

Key Points

Refactoring

When refactoring and cleaning up existing implementations, pay special attention to the changes made in the commits referred to above. You'll need to go line-by-line in @stdlib/stats/base/variancewd and compare with the changes made in the above commits.

In particular, we're interested in

  1. standardizing language in descriptions so that all packages in stats/base use similar language for describing input parameters and behavior.
  2. updating examples to align with current conventions in stdlib.
  3. simplifying examples and benchmarks to use utilities for generating random arrays.
  4. reducing code duplication by having the main package entry point delegate to the ndarray API.

Accessor protocol

Prior to adding accessor protocol support, check whether the implementation has any strided array dependencies. For example, for certain algorithms for computing the mean, implementations will depend on algorithms for computing the sum. Ensure that the upstream implementations have support for accessor arrays. If not, you'll need to open a separate PR adding support in the upstream dependencies before working on this package.

When adding support for the accessor protocol, you'll need to do the following:

Create an accessors file

Create a new lib/accessors.js file. This file will contain an implementation which can handle accessor arrays.

Modify the ndarray file

Modify the lib/ndarray.js file to delegate to the accessors implementation when one (or more) of the input arrays is an accessor array.

Update tests

Modify the tests to include explicit tests for accessor arrays.

Run tests and other commands

For each of the following commands, please run them from the root stdlib repository directory (not the package folder!).

To run unit tests,

make test TESTS_FILTER=".*/stats/base/variancewd/.*"

To run examples,

make examples EXAMPLES_FILTER=".*/stats/base/variancewd/.*"

To run benchmarks,

make benchmark BENCHMARKS_FILTER=".*/stats/base/variancewd/.*"

Create pull request

Provided all tests, examples, and benchmarks successfully execute and pass and that you've updated the package's documentation, you are now ready to open a pull request!


Notes

  • If you are interested in contributing a PR which addresses this RFC and still getting familiar with our project conventions, please do not submit LLM-generated code. Please consult our contributing guidelines and the associated development guide. Failure to respect project conventions will result in your PR being rejected without review. Thank you for understanding!

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with [RFC]:.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AcceptedRFC feature request which has been accepted.FeatureIssue or pull request for adding a new feature.Good First IssueA good first issue for new contributors!JavaScriptIssue involves or relates to JavaScript.RFCRequest for comments. Feature requests and proposed changes.StatisticsIssue or pull request related to statistical functionality.difficulty: 2May require some initial design or R&D, but should be straightforward to resolve and/or implement.priority: NormalNormal priority concern or feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions