Repository navigation
perf(matrices): keep broadcast constraint fields lazy when assembling matrices - #1117
Open
FabianHofmann wants to merge 4 commits into
Open
FabianHofmann wants to merge 4 commits into
FabianHofmann wants to merge 4 commits into
Conversation
… matrices `_row_block` used `ravel()[active]` on sign, rhs and scaling, which materialises full-size copies of stride-0 broadcast views and copies even when every row is active. Broadcast scalar fields now stay 0-d through `_RowBlock`, all-active fields are taken as raveled views, and `_stack`, `_non_unit` and the `con_scaling` concatenation handle 0-d blocks. The public `Matrices` arrays are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F4nx8GJ8mSNvkTagja9dMj
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F4nx8GJ8mSNvkTagja9dMj
Merging this PR will not alter performance
Comparing Footnotes
|
Merge _uniform into _active with a row indexer, drop the 0-d special cases in _non_unit and sign, document 0-d _RowBlock fields, and refocus the test on fully masked and dimensionless constraints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F4nx8KhK8QzSzHhpYKvcSx
FabianHofmann
marked this pull request as ready for review
November 3, 2026 14:38
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes proposed in this Pull Request
Note
The following content was generated by AI.
Model.matricesusedravel()[active]on each constraint'ssign,rhsandscalingin_row_block. When those fields are stored lazily as stride-0np.broadcast_toviews (a scalar sign or scaling), this builds full-size copies. It also copies when every row is active.Changes in
linopy/matrices.py:_RowBlock(sign, rhs, scaling).reshape(-1)) and the boolean-mask copy is skipped._non_unithandles 0-d scaling._stackmultiplies by a 0-d row scaling directly instead of callingrepeat_per_row, and assigns 0-d rhs/sign by broadcasting.con_scalingconcatenation broadcasts 0-d blocks to their row count.The public
Matricesfields and dtypes stay the same (senseis still aU1array, andbandcon_scalingare still full float arrays), so this is not a breaking change.Tests in
test/test_matrices.py:test_row_block_keeps_broadcast_fields_lazy: scalar sign and scaling stay 0-d, with all rows active and with some masked.test_matrices_scalar_and_array_fields(dense and sparse): covers scalar sign/scaling, masked rows, mixed signs and per-cell scaling. It compares A, b, sense, con_scaling and clabels against explicit expected arrays. The same expected arrays also pass against the unmodifiedmasterimplementation.Benchmark
SciGrid-DE tiled to 1.79M vars / 4.29M rows / 7.18M nnz, cloud VM, best of 5:
In line profiles,
con.sign.values.ravel()[active].astype("U1")alone took about 140 ms before this change.Checklist
AGENTS.md).doc.doc/release_notes.rstof the upcoming release is included.Generated by Claude Code