Repository navigation
Reject shapes with more than INT_MAX entries - #38
Merged
Merged
Conversation
The engine stores expression sizes as C int, so a shape like (65536, 65537) wrapped and segfaulted in compile(). Check d1*d2 in _check_shape and Node.__init__ so the error is raised where the shape is created. Part of #37 (item 1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 13, 2026
dance858
added a commit
that referenced
this pull request
Nov 15, 2026
* Limit sparse constants by nonzeros, not rows times columns 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 * Explain when a constant becomes a dense engine parameter Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012aJMgvtfPYcdJMWR6ox56t --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
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.
The engine stores each expression's d1, d2 and size as C
int. A shape with more than 2**31 - 1 entries wrapped around and crashed incompile(). For example,sp.broadcast(x, (65536, 65537))hit a bus error innew_broadcast/problem_init_derivatives.This PR checks d1·d2 in
_check_shape, which covers Variable, Parameter, Constant, broadcast, reshape and index_flat, and inNode.__init__, which covers derived shapes like matmul and stacking. AValueErroris now raised on the line that creates the oversized shape, before anything reaches C. It addstest_too_many_entries.Part of #37 (item 1). It doesn't check the scope-wide counts (total variables, total parameters, summed constraint size) or the engine's nnz.
🤖 Generated with Claude Code