Skip to content

feat: add ndarray/base/rotr90#11030

Merged
kgryte merged 19 commits intostdlib-js:developfrom
headlessNode:nd-rot90
Apr 10, 2026
Merged

feat: add ndarray/base/rotr90#11030
kgryte merged 19 commits intostdlib-js:developfrom
headlessNode:nd-rot90

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: passed
  • 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#203.

Description

What is the purpose of this pull request?

This pull request:

  • add ndarray/base/rot90

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.".

Primarily written by Claude Code.


@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: passed
  - 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
---
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Mar 18, 2026
@headlessNode headlessNode added Feature Issue or pull request for adding a new feature. METR Pull request associated with the METR project. labels Mar 18, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented Mar 18, 2026

Coverage Report

Package Statements Branches Functions Lines
ndarray/base/rotr90 $\color{green}152/152$
$\color{green}+0.00%$
$\color{green}10/10$
$\color{green}+0.00%$
$\color{green}1/1$
$\color{green}+0.00%$
$\color{green}152/152$
$\color{green}+0.00%$

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

* // returns <ndarray>[ [ 2, 4 ], [ 1, 3 ] ]
*
*/
function rot90( x, k, 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.

Why did you choose not to support providing a list of dimensions, as done in NumPy?

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.

It looks like you chose to follow Julia here, but I don't think that was the correct choice within the wider context of packages we should add. My recommendation:

  1. Rename this utility to rotlr90 to reflect that we are only rotating the last two dimensions.
  2. Add a new package rot90 which allows specifying the two dimensions to rotate.

In principle, the former could simply be a wrapper around the latter.

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, I think Julia's behavior is more obvious here for left-right rotation. NumPy's behavior of rotating from the first axis toward the second axis with the default of (0,1) is a bit odd, as the default behavior of rot90 is to rotate counterclockwise, which, IMHO, is the opposite of common user intuition.

So I would update the rotation equivalently. Meaning, k = 1 should be implemented as k = 3 is now, etc.

Copy link
Copy Markdown
Member

@kgryte kgryte Mar 19, 2026

Choose a reason for hiding this comment

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

Okay. After chatting with ChatGPT about this (link, I want to amend my recommendation:

  1. Rename and refactor the utility to rotr90( x, k, writable ) where k > 0 means to rotate clockwise and k < 0 means to rotate counterclockwise. This API should operate on a matrix or stack of matrices.
  2. Once merged, create another utility called rotl90( x, k, writable ), which does the reverse of rotr90, with k > 0 means to rotate counterclockwise and k < 0 means to rotate clockwise. This utility will effectively be a very thin wrapper for rotr90( x, -k, writable ), as done in Julia.
  3. Create a new rot90( x, dims, k, writable ) utility which allows specifying the plane of rotation. The default behavior of the top-level ndarray/rot90 package should follow NumPy's default semantics, with the exception that the default dimensions should be [ -2, -1 ] (i.e., the last two dimensions).

This approach should satisfy the dual interpretations of rotation. The rot(r|l)90 utilities provide convenience APIs when thinking of matrices as images and the rot90 utility provides an API for thinking of rotations in terms of linear algebra.

Comment thread lib/node_modules/@stdlib/ndarray/base/rot90/lib/main.js Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rot90/lib/main.js Outdated
@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Mar 19, 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: passed
  - 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
---
---
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: 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: 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
---
@headlessNode headlessNode added Needs Review A pull request which needs code review. and removed Needs Changes Pull request which needs changes before being merged. labels Mar 24, 2026
@headlessNode headlessNode requested a review from kgryte March 24, 2026 23:24
@headlessNode headlessNode changed the title feat: add ndarray/base/rot90 feat: add ndarray/base/rotr90 Mar 24, 2026
@github-actions github-actions Bot mentioned this pull request Mar 25, 2026
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
headlessNode and others added 3 commits April 8, 2026 03:22
---
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: 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: 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: na
  - task: lint_license_headers
    status: passed
---
@headlessNode headlessNode added Needs Review A pull request which needs code review. and removed Needs Changes Pull request which needs changes before being merged. labels Apr 7, 2026
@headlessNode headlessNode requested a review from kgryte April 7, 2026 23:07
@kgryte kgryte removed the Needs Review A pull request which needs code review. label Apr 10, 2026
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts Outdated
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt Outdated
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt Outdated
Co-authored-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt Outdated
kgryte added 2 commits April 9, 2026 19:28
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment thread lib/node_modules/@stdlib/ndarray/base/rotr90/README.md Outdated
Signed-off-by: Athan <kgryte@gmail.com>
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 clean-up.

@kgryte
Copy link
Copy Markdown
Member

kgryte commented Apr 10, 2026

For METR,

review_time: 33 mins

@kgryte kgryte merged commit cda31f5 into stdlib-js:develop Apr 10, 2026
13 checks passed
@headlessNode headlessNode deleted the nd-rot90 branch April 10, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue or pull request for adding a new feature. METR Pull request associated with the METR project.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC]: add ndarray/base/rot90

3 participants