Skip to content

feat!: add writable parameter to ndarray/base/remove-singleton-dimensions#9667

Merged
kgryte merged 6 commits intostdlib-js:developfrom
headlessNode:rm-s-dims
Feb 28, 2026
Merged

feat!: add writable parameter to ndarray/base/remove-singleton-dimensions#9667
kgryte merged 6 commits intostdlib-js:developfrom
headlessNode:rm-s-dims

Conversation

@headlessNode
Copy link
Copy Markdown
Member


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: 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: na
  • task: lint_c_examples status: na
  • 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: passed
  • task: lint_license_headers status: passed ---

Resolves stdlib-js/metr-issue-tracker#151.

Description

What is the purpose of this pull request?

This pull request:

  • add writable parameter to ndarray/base/remove-singleton-dimensions

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

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.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

{{TODO: add disclosure if applicable}}


@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: passed
  - 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: na
  - task: lint_c_examples
    status: na
  - 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: passed
  - task: lint_license_headers
    status: passed
---
@headlessNode headlessNode requested a review from kgryte January 10, 2026 07:09
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 10, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented Jan 10, 2026

Coverage Report

Package Statements Branches Functions Lines
ndarray/base/remove-singleton-dimensions $\color{green}131/131$
$\color{green}+0.00%$
$\color{green}5/5$
$\color{green}+0.00%$
$\color{green}1/1$
$\color{green}+0.00%$
$\color{green}131/131$
$\color{green}+0.00%$

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

@headlessNode headlessNode added the METR Pull request associated with the METR project. label Jan 10, 2026
@kgryte kgryte added release: Major Breaking change requiring a new major release. and removed Needs Review A pull request which needs code review. labels Jan 10, 2026
@kgryte kgryte changed the title feat: add writable parameter to ndarray/base/remove-singleton-dimensions feat!: add writable parameter to ndarray/base/remove-singleton-dimensions Jan 10, 2026
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md Outdated
Signed-off-by: Athan <kgryte@gmail.com>
The function accepts the following arguments:

- **x**: input ndarray.
- **writable**: boolean indicating whether a returned ndarray should be writable.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This parameter is somewhat in conflict with the note at L74. Namely, if we return a provided ndarray unchanged, then the writable parameter is ignored.

Copy link
Copy Markdown
Member

@kgryte kgryte Jan 10, 2026

Choose a reason for hiding this comment

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

We have a couple of choices. 1) Always return a new view of the input ndarray. 2) Update the docs here to indicate that the writable parameter will be ignored if the input ndarray doesn't have any singleton dimensions. 3) Pursue (1) plus add the package maybe-remove-singleton-dimensions where this new package does what this package does now, which is returns an input ndarray unchanged iff an input ndarray has no singleton dimensions.

The original rationale for sometimes returning the original input ndarray is for performance, as ndarray view creation is expensive. Having a maybe-* prefix makes this behavior explicit similar to maybe-broadcast-array, etc.

That seem reasonable to you, @headlessNode?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kgryte So, we add a maybe- prefix to this package and add the remove-singleton-dimensions package which always return a new view?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@headlessNode That doesn't quite make sense. It means copy the current package to maybe-* and then modify the existing package to always return a view.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also means that we'll need a follow-up PR to migrate all current downstream usage to use the maybe-* package.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kgryte I've modified the current package to always return a new view. I think adding the maybe-* package and updating downstream usage should be separate PR?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct. Adding and updating should actually be two separate PRs (in addition to the current PR).

Comment thread lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/README.md Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/index.js Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/lib/main.js Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/remove-singleton-dimensions/test/test.js Outdated
Copy link
Copy Markdown
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

Left initial comments.

Copy link
Copy Markdown
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

Left initial comments.

@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Jan 10, 2026
@kgryte
Copy link
Copy Markdown
Member

kgryte commented Jan 10, 2026

For METR, initial review

review_time: 15 mins

---
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: 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: na
  - task: lint_c_examples
    status: na
  - 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: passed
  - task: lint_license_headers
    status: passed
---
---
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: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - 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: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@headlessNode headlessNode requested a review from kgryte January 30, 2026 13:59
@headlessNode headlessNode removed the Needs Changes Pull request which needs changes before being merged. label Jan 30, 2026
@headlessNode headlessNode added the Needs Review A pull request which needs code review. label Jan 30, 2026
---
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: passed
  - 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: na
  - task: lint_c_examples
    status: na
  - 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: passed
  - task: lint_license_headers
    status: passed
---
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Feb 28, 2026
Copy link
Copy Markdown
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

LGTM after some minor clean-up.

@kgryte
Copy link
Copy Markdown
Member

kgryte commented Feb 28, 2026

For METR,

review_time: 25 mins

@kgryte kgryte merged commit e947540 into stdlib-js:develop Feb 28, 2026
14 checks passed
@kgryte
Copy link
Copy Markdown
Member

kgryte commented Feb 28, 2026

@headlessNode You can go ahead and create the METR RFC for creating the package

ndarray/base/maybe-remove-singleton-dimensions

as discussed in the comment discussion above.

@headlessNode headlessNode deleted the rm-s-dims branch February 28, 2026 10:07
Witty-31-06 pushed a commit to Witty-31-06/stdlib that referenced this pull request Mar 7, 2026
…sions`

This commit adds support for a writable parameter. Previously, we'd return a writable ndarray if a provided ndarray was writable, and a read-only ndarray if a provided ndarray was read-only. This is now configurable.

Additionally, this commit changes behavior such that a new view is always returned. Previously, if an input ndarray did not contain singleton dimensions, we'd always return the input ndarray. That is no longer the case.

BREAKING CHANGE: add writable parameter and always return a new view

To migrate, in order to preserve prior writable behavior, users should set the final parameter equal to a boolean indicating whether the input ndarray is writable. If not, pass `false`; if yes, pass `true`.

To preserve prior behavior in which the input ndarray is returned if it does not have singleton dimensions, use `ndarray/base/maybe-remove-singleton-dimensions`.

PR-URL: stdlib-js#9667
Closes: stdlib-js/metr-issue-tracker#151
Co-authored-by: Athan Reines <kgryte@gmail.com>
Reviewed-by: Athan Reines <kgryte@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

METR Pull request associated with the METR project. release: Major Breaking change requiring a new major release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: add writable parameter to ndarray/base/remove-singleton-dimensions

3 participants