Skip to content

feat(stdlib): add array mutation and rotation utilities - #2515

Open
ss2165 wants to merge 1 commit into
codex/array-structurefrom
codex/array-mutation
Open

ss2165 wants to merge 1 commit into
codex/array-structurefrom
codex/array-mutation

Conversation

@ss2165

@ss2165 ss2165 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Add array swap and fill methods, plus in-place left and right rotations supporting linear elements. Signed rotation amounts wrap modulo the array length; negative amounts rotate in the opposite direction. Empty arrays are unchanged.

Closes #2481

@ss2165
ss2165 added this pull request to stack #2501 November 10, 2026 12:01
@ss2165
ss2165 force-pushed the codex/array-mutation branch from 3634583 to d11fd5c Compare November 10, 2026 12:02
@ss2165 ss2165 changed the title feat(stdlib): add mutation and rotation utilities feat(stdlib): add array mutation and rotation utilities Nov 10, 2026
@codecov-commenter

codecov-commenter commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 43.90244% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.76%. Comparing base (d7494c5) to head (a334a0f).

Files with missing lines Patch % Lines
guppylang/src/guppylang/std/array.py 43.90% 23 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           codex/array-structure    #2515      +/-   ##
=========================================================
- Coverage                  92.88%   92.76%   -0.12%     
=========================================================
  Files                        167      167              
  Lines                      17302    17343      +41     
=========================================================
+ Hits                       16071    16089      +18     
- Misses                      1231     1254      +23     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectguppylang
Branchcodex/array-mutation
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes
(Result Δ%)
Upper Boundary
nodes
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
59.84 x 1e3
(0.00%)Baseline: 59.84 x 1e3
60.44 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
4,514.00
(0.00%)Baseline: 4,514.00
4,559.14
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
26.87 x 1e3
(0.00%)Baseline: 26.87 x 1e3
27.14 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
1,182.00
(0.00%)Baseline: 1,182.00
1,193.82
(99.01%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_benchmark_compile📈 view plot
🚷 view threshold
6.70 x 1e3
(0.00%)Baseline: 6.70 x 1e3
6.77 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
279.00
(0.00%)Baseline: 279.00
281.79
(99.01%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_pop_benchmark_compile📈 view plot
🚷 view threshold
9.22 x 1e3
(0.00%)Baseline: 9.22 x 1e3
9.31 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
371.00
(0.00%)Baseline: 371.00
374.71
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@codspeed

codspeed Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 7 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 11 untouched benchmarks


Comparing codex/array-mutation (a334a0f) with codex/array-structure (d7494c5)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Rotation accepts amounts above the array length despite issue #2481 requiring 0 ≤ k ≤ n, leaving a contract conflict that must be reconciled.

1 open issue
What changed in this PR

Adds array mutation and in-place rotation utilities to the standard library, addressing #2481 while preserving support for linear elements.

Changes:

  • Adds swap and fill methods, retaining existing swap and reverse operations.
  • Implements left and right rotations using three reversals, with nonnegative amounts wrapping modulo array length.
  • Adds integration tests for mutation results, linear elements, empty arrays, and invalid inputs.
File Description
tests/​integration/​test_array_mutation.py Tests mutations, rotations, linear-element preservation, and error handling.
guppylang/​src/​guppylang/​std/​array.py Adds mutation methods, rotation helpers, and API documentation.

Review effort: Balanced

Comment thread guppylang/src/guppylang/std/array.py Resolved
@ss2165
ss2165 force-pushed the codex/array-mutation branch from d11fd5c to 99e52fd Compare November 10, 2026 15:00
@ss2165
ss2165 marked this pull request as ready for review November 10, 2026 15:19
@ss2165
ss2165 requested a review from a team as a code owner November 10, 2026 15:19
@ss2165
ss2165 requested a review from cqc-alec November 10, 2026 15:19
Comment thread guppylang/src/guppylang/std/array.py Resolved
@ss2165
ss2165 force-pushed the codex/array-mutation branch from 99e52fd to 6f66c19 Compare November 10, 2026 16:10
@ss2165
ss2165 force-pushed the codex/array-mutation branch from 6f66c19 to a334a0f Compare November 10, 2026 17:09
@ss2165
ss2165 requested a review from cqc-alec November 10, 2026 17:21

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Array mutation and in-place rotations

4 participants