Skip to content

perf: vectorize standard basis construction - #1890

Merged
vprusso merged 1 commit into
vprusso:masterfrom
09Catho:perf/vectorize-standard-basis
Jul 25, 2026
Merged

perf: vectorize standard basis construction#1890
vprusso merged 1 commit into
vprusso:masterfrom
09Catho:perf/vectorize-standard-basis

Conversation

@09Catho

@09Catho 09Catho commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace the Python-level standard-basis construction loop with numpy.eye
  • preserve flattened and column-vector output shapes
  • broaden exact-output coverage across dimensions 1, 2, and 5

Performance

Measured locally with Python 3.13 and NumPy through the project uv environment:

Dimension Previous Vectorized Speedup
32 1313.3 us/call 16.8 us/call 78.0x
128 18848.0 us/call 58.8 us/call 320.4x

The benchmark also asserted np.array_equal between the previous and new outputs.

Validation

  • uv run pytest toqito/matrices/tests -q (143 passed)
  • uv run ruff check toqito/matrices/standard_basis.py toqito/matrices/tests/test_standard_basis.py
  • uv run ruff format --check toqito/matrices/standard_basis.py toqito/matrices/tests/test_standard_basis.py
  • git diff --check

Closes #1887

Signed-off-by: 09Catho <ashketchume45@gmail.com>
Copilot AI review requested due to automatic review settings July 25, 2026 12:38

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@vprusso

vprusso commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Thanks, and welcome to toqito! Confirmed the np.eye version matches the previous output exactly in both flatten modes across dimensions, and the parametrized exact-equality tests are a nice improvement over the originals. Big speedup too. Merging.

@vprusso
vprusso merged commit 1412606 into vprusso:master Jul 25, 2026
8 checks passed
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.

perf: vectorize a loop-based matrix constructor

3 participants