Commit 02e7a5e
Auto nonstructural zeros: decide on filled values, deactivate when nothing is droppable (#1110)
Two fixes to the `NonstructuralZeros.Auto` state machine, both aimed at the same
failure: the reduction latching into per-solve `dropzeros` that drops nothing.
1. Defer the activation decision when the starting matrix is entirely zero.
A cache is commonly initialized from a *prototype* — the intended sparsity
pattern with values not filled in yet — and an all-zero sample is
indistinguishable from "100% nonstructural zeros". `Auto` activated on it with
an all-`false` mask, and the first filled solve then flipped every entry, so
`activated == nstart_zeros` unconditionally tripped the non-persistence guard
and set `cache_union = false` permanently. Every later solve then allocated a
fresh `dropzeros` copy while dropping nothing. Deferring to the first matrix
that carries a nonzero decides on real values instead.
2. Deactivate once the union covers every stored entry. The union only grows, so
at that point no future matrix can have anything dropped — the reduction is
provably dead weight. Switching it off is also structure-preserving, since
`reduced` equals the full pattern exactly when this triggers, so the operand
handed to the factorization keeps the structure it just had.
Measured on a prototype-initialized cache (n=200, nnz=598, KLU): 17.7 kB per
solve with `nnz(reduced) == nnz(A)` before, 0 B after. The reduction itself is
unchanged where it pays: a matrix with genuine nonstructural zeros still reduces
(359/598 stored entries kept) at 0 B per solve, and prototype-initialized callers
now *gain* that reduction on the first filled solve instead of latching into the
degraded path.
This also removes a 30x sparse allocation gap in OrdinaryDiffEq's
`NonlinearSolveAlg`, whose inner Jacobian buffer is exactly such a prototype.
Claude-Session: https://claude.ai/code/session_01NB3oFTNzGW79UtDt8AyjsM
Co-authored-by: ChrisRackauckas-Claude <accounts@chrisrackauckas.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent cbfd6b7 commit 02e7a5e
3 files changed
Lines changed: 110 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1200 | 1200 | | |
1201 | 1201 | | |
1202 | 1202 | | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
1203 | 1210 | | |
1204 | 1211 | | |
1205 | 1212 | | |
| |||
1255 | 1262 | | |
1256 | 1263 | | |
1257 | 1264 | | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
1258 | 1269 | | |
1259 | 1270 | | |
1260 | | - | |
| 1271 | + | |
1261 | 1272 | | |
1262 | | - | |
| 1273 | + | |
1263 | 1274 | | |
1264 | 1275 | | |
1265 | 1276 | | |
1266 | | - | |
1267 | 1277 | | |
1268 | 1278 | | |
1269 | 1279 | | |
| |||
1272 | 1282 | | |
1273 | 1283 | | |
1274 | 1284 | | |
1275 | | - | |
1276 | | - | |
| 1285 | + | |
| 1286 | + | |
1277 | 1287 | | |
1278 | 1288 | | |
1279 | 1289 | | |
1280 | 1290 | | |
1281 | | - | |
| 1291 | + | |
1282 | 1292 | | |
1283 | 1293 | | |
1284 | 1294 | | |
1285 | 1295 | | |
1286 | 1296 | | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
1287 | 1320 | | |
| 1321 | + | |
1288 | 1322 | | |
1289 | 1323 | | |
1290 | 1324 | | |
| |||
1319 | 1353 | | |
1320 | 1354 | | |
1321 | 1355 | | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
1322 | 1365 | | |
1323 | 1366 | | |
1324 | 1367 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
285 | 345 | | |
0 commit comments