Repository navigation
Commit 11295de
authored
Cache common subexpressions in IndexMap (#2802)
* Cache common subexpressions in IndexMap
* Address review: tests, benchmark and experimental comment
* Document that the `nl_cache` field is experimental and must only be
accessed through `map_indices`.
* Use an `IdDict` since common subexpressions are identified by object
identity.
* Skip the cache when the variable map is the identity (rebased on #3118).
* Also use the cache for `VectorNonlinearFunction`.
* Keep the `IndexMap(var_map, con_map)` constructor.
* Add tests.
Benchmark of `map_indices` on `f_{k+1} = sin(f_k) * f_k + f_k` with
`f_0 = sin(x)`, whose tree has O(3^n) nodes but whose DAG has O(n)
nodes, comparing `map_indices(Base.Fix1(getindex, map), f)` (no cache)
with `map_indices(map, f)` (cache):
| n | no cache (μs) | cache (μs) | no cache (bytes) | cache (bytes) |
|----|---------------|------------|------------------|---------------|
| 1 | 0.136 | 0.322 | 896 | 1120 |
| 4 | 4.1 | 1.15 | 25008 | 3728 |
| 8 | 349 | 2.88 | 1994928 | 7216 |
| 12 | 35900 | 5.97 | 161559936 | 12736 |
* Fix Vale wording and Julia nightly display assertion
Replace the Latin abbreviation rejected by Vale. Build the unary-plus expectation from an Expr so the NL reader test follows Julia's display syntax across versions.
Validation: test/FileFormats/NL/test_read.jl passes on Julia 1.13.3 and installed nightly 1.15.0-DEV.244; coverage markers confirm the new lines execute. Vale reports no errors on the changed files. Repository-wide JuliaFormatter 2.14.7 leaves no unstaged diff.1 parent ccef35f commit 11295de
4 files changed
Lines changed: 77 additions & 1 deletion
File tree
- src/Utilities
- copy
- test
- FileFormats/NL
- Utilities
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
36 | 44 | | |
37 | 45 | | |
38 | 46 | | |
| |||
121 | 129 | | |
122 | 130 | | |
123 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| 370 | + | |
370 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
371 | 375 | | |
372 | 376 | | |
373 | 377 | | |
| |||
380 | 384 | | |
381 | 385 | | |
382 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
383 | 391 | | |
384 | 392 | | |
385 | 393 | | |
| |||
389 | 397 | | |
390 | 398 | | |
391 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
392 | 403 | | |
393 | 404 | | |
394 | 405 | | |
395 | 406 | | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
396 | 410 | | |
397 | 411 | | |
398 | 412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
| 651 | + | |
| 652 | + | |
651 | 653 | | |
652 | | - | |
| 654 | + | |
653 | 655 | | |
654 | 656 | | |
655 | 657 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1144 | 1144 | | |
1145 | 1145 | | |
1146 | 1146 | | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
1147 | 1181 | | |
1148 | 1182 | | |
1149 | 1183 | | |
0 commit comments