Skip to content

feat(stdlib): add array construction and reshaping utilities - #2513

Open
ss2165 wants to merge 2 commits into
codex/array-queriesfrom
codex/array-structure
Open

ss2165 wants to merge 2 commits into
codex/array-queriesfrom
codex/array-structure

Conversation

@ss2165

@ss2165 ss2165 commented Nov 10, 2026

Copy link
Copy Markdown
Member

Add consuming concat, append, split, zip, unzip, flatten, and chunk operations supporting linear elements, plus borrowed subarray copying with runtime starts and compile-time sizes.

Closes #2480

@ss2165
ss2165 added this pull request to stack #2501 November 10, 2026 11:28
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectguppylang
Branchcodex/array-structure
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

@codecov-commenter

codecov-commenter commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.88%. Comparing base (921d671) to head (d7494c5).

Files with missing lines Patch % Lines
guppylang/src/guppylang/std/array.py 55.55% 36 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                   @@
##           codex/array-queries    #2513      +/-   ##
=======================================================
- Coverage                93.05%   92.88%   -0.17%     
=======================================================
  Files                      167      167              
  Lines                    17221    17302      +81     
=======================================================
+ Hits                     16025    16071      +46     
- Misses                    1196     1231      +35     

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

@ss2165
ss2165 requested a balanced review from Copilot November 10, 2026 11:34
@ss2165
ss2165 force-pushed the codex/array-structure branch from ab51bb5 to 30f09e0 Compare November 10, 2026 11:36
@ss2165 ss2165 changed the title feat(array): add construction and reshaping utilities feat(stdlib): add construction and reshaping utilities Nov 10, 2026

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.

🟢 Approval recommended

No active review issues are recorded for the new array construction and reshaping utilities.

No open issues 🎉

What changed in this PR

Adds safe array construction and reshaping utilities to the standard library, addressing #2480 with consuming operations that support linear elements and borrowed subarray copying.

Changes:

  • Adds concat, appended, split_at, zip, unzip, flatten, and chunks.
  • Adds subarray with runtime start indices, compile-time sizes, and bounds validation.
  • Adds integration coverage for ordering, empty arrays, linear qubit transfers, and invalid bounds or shapes.
File Description
tests/​integration/​test_array_structure.py Tests concatenation, appending, splitting, and linear transfers.
tests/​integration/​test_array_shapes.py Tests subarray copying, shape transformations, and validation failures.
guppylang/​src/​guppylang/​std/​array.py Implements and documents the new array utilities and validation helpers.

Review effort: Balanced

@ss2165
ss2165 marked this pull request as ready for review November 10, 2026 11:44
@ss2165
ss2165 requested a review from a team as a code owner November 10, 2026 11:44
@ss2165
ss2165 requested a review from hsemenenko November 10, 2026 11:44
@codspeed

codspeed Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 8 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-structure (d7494c5) with codex/array-queries (e220f6a)1

Open in CodSpeed

Footnotes

  1. No successful run was found on codex/array-queries (921d671) during the generation of this report, so 4ed6d3f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@ss2165
ss2165 force-pushed the codex/array-structure branch from 30f09e0 to 2470d11 Compare November 10, 2026 12:02
@ss2165 ss2165 changed the title feat(stdlib): add construction and reshaping utilities feat(stdlib): add array construction and reshaping utilities Nov 10, 2026

@hsemenenko hsemenenko 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.

🚀


@guppy
@no_type_check
def concat[T, n: nat, m: nat](

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.

concat could be used in an __add__ method so we can write xs + ys.

"""Validate a split position before computing its output shape."""
if not 0 <= position <= size:
msg = f"Split position {position} is out of bounds for array of size {size}"
raise ValueError(msg)

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.

This error message (and others) are inconsistent with Guppy error messaging and don't highlight the Guppy source where the error occurred. Implementing this would require a custom call checker so is perhaps beyond the scope of this PR.

@ss2165
ss2165 force-pushed the codex/array-structure branch from 2470d11 to d7494c5 Compare November 10, 2026 15:00

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]: Safe array construction and reshaping

4 participants