feat: add ndarray/base/reduced-shape#11013
feat: add ndarray/base/reduced-shape#11013headlessNode wants to merge 1 commit intostdlib-js:developfrom
ndarray/base/reduced-shape#11013Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
ndarray/base/reduce-shapendarray/base/reduced-shape
|
@headlessNode What is the use case for this package? Meaning, in what implementation are you wanting to use this or what logic are you aiming to replace? |
|
@kgryte This is found in: any, any-by, every, find and others of the same category. And every future reduction package (count-same-value, count-by, group-values, bifurcate, map-reduce, etc.) will need the same pattern. |
| * var sh = reducedShape( x, [ 0, 1 ] ); | ||
| * // returns [ 3 ] | ||
| */ | ||
| function reducedShape( x, dims ) { |
There was a problem hiding this comment.
If your intent is to replace
stdlib/lib/node_modules/@stdlib/ndarray/any/lib/main.js
Lines 110 to 114 in 6f315ad
then this function should not be taking x as the first argument, but rather a shape. Every time you access a shape, you force materialization. There is a reason we generally try to avoid doing that, as it simply increases GC pressure.
However, you seem to also be unaware of the reason why this package was not added in the first place. While I agree that a named operation (e.g., reducedShape) is nicer for code readability, the reality is that in any and other packages, we actually end up making use of the complement indices array elsewhere in the implementation.
E.g.,
stdlib/lib/node_modules/@stdlib/ndarray/any/lib/main.js
Lines 110 to 134 in 6f315ad
Notice its use in spreadDimensions above. So now you are proposing that we replace two lines with this function, but then have to recompute the complement indices later on in the implementation. That is not what we want.
So, in short, I am not convinced that this package actually gets us anywhere and will actually be used.
Feel free to convince me otherwise.
Resolves stdlib-js/metr-issue-tracker#201.
Description
This pull request:
ndarray/base/reduced-shapeRelated Issues
This pull request has the following related issues:
ndarray/base/reduced-shapemetr-issue-tracker#201Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
Docs, benchmarks & tests written by Claude Code.
@stdlib-js/reviewers