Commit 8dfa6d4
fix(constraints): freeze empty constraint groups without reshape error (#783)
* fix(constraints): freeze empty constraint groups without reshape error
CSRConstraint.from_mutable reshaped con.vars with an inferred -1
dimension. For an empty constraint group (zero rows and zero terms) the
vars array has size 0, and NumPy refuses to infer a (0, -1) reshape,
raising "cannot reshape array of size 0 into shape (0,newaxis)". This
broke the documented lossless freeze round-trip for legitimately empty
groups (e.g. shifted-time difference constraints at n_time == 1).
Pass the explicit _term count instead of -1; NumPy accepts a (0, 0)
reshape and the rest of the method already handles zero-row input.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore: code review
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent c2d9f5c commit 8dfa6d4
3 files changed
Lines changed: 23 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1081 | 1081 | | |
1082 | 1082 | | |
1083 | 1083 | | |
1084 | | - | |
| 1084 | + | |
1085 | 1085 | | |
1086 | 1086 | | |
1087 | 1087 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
107 | 128 | | |
108 | 129 | | |
109 | 130 | | |
| |||
0 commit comments