Repository navigation
Limit sparse constants by nonzeros, not rows times columns - #41
Merged
Merged
Conversation
A scipy.sparse constant is passed to the engine as CSR, so only its dimensions and nonzero count must fit in a C int. The check from #38 rejected it by rows times columns, which ruled out e.g. the 126015 x 78478 branch incidence matrix of a 78k-bus power network. Such a constant can be the matrix of a matmul or quad_form; any use that needs it dense is still rejected, now when the expression is compiled. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012aJMgvtfPYcdJMWR6ox56t
dance858
commented
Nov 15, 2026
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012aJMgvtfPYcdJMWR6ox56t
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.
A
scipy.sparseconstant is passed to the engine as CSR, so only its dimensions and nonzero count need to fit in a C int. The check from #38 rejected it by rows times columns, which ruled out, for example, the 126,015 x 78,478 branch incidence matrix of the 78,484-bus pglib-opf network (about 9.9e9 entries, 126,015 nonzeros).Constantchecks a sparse value with_check_sparse_size(rows, columns and nonzeros at mostINT_MAX) instead of_check_shape.quad_form. Any other use needs it dense: elementwise operations are still rejected when the node is created, and a constant that reaches the engine as a dense parameter is now rejected in_build_one.Tested with a 65536 x 65537 sparse matrix in left and right matmul (
test_large_sparse_constant). With this change the OPF benchmark in diffengine-paper-benchmarks builds the 78,484-bus network and matches CasADi to 3e-11.🤖 Generated with Claude Code
https://claude.ai/code/session_012aJMgvtfPYcdJMWR6ox56t