Description
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:
stats/base/min
: fbb31fb (package)stats/base/cumax
: 11f1341 (package)stats/base/cumin
: 528efd8 (package)stats/base/mediansorted
: 065f865 (package)stats/base/mskmax
: 417e653 (package)
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
- standardizing language in descriptions so that all packages in
stats/base
use similar language for describing input parameters and behavior. - updating examples to align with current conventions in stdlib.
- simplifying examples and benchmarks to use utilities for generating random arrays.
- 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]:
.