Repository navigation
Commit cb91b76
perf(numba): drop the redundant passes in curvature-matrix F assembly (#505)
Three redundant passes over F in the numba sparse imaging inversion, none of
which changed a single value:
1. A global `curvature_matrix_mirrored_from` ran over the whole (P, P) matrix
after assembly. Every block was already symmetric or had a known transpose:
the mapper x mapper blocks are folded and mirrored inside
`curvature_matrix_via_sparse_operator_from`, and the linear-func x
linear-func blocks already wrote both triangles. The mirror is removed and
the two off-diagonal block writers (mapper x mapper, mapper x linear-func)
now place their transpose alongside the block, so F leaves assembly
symmetric.
2. `_curvature_matrix_mapper_diag` wrapped the three `mapper.unique_mappings`
arrays in `np.array(...)`, copying them on every evaluation. They are
already contiguous ndarrays of the dtype the numba kernel wants (see
`UniqueMappings.__init__`, which casts on construction) and every other
caller in this module passes them through untouched.
3. `_curvature_matrix_mapper_func_blocks_from` formed
`operated_mapping_matrix / noise_map ** 2` inside the mapper loop and then
copied the result again with `np.array`. The weights do not depend on the
mapper, so they are formed once per linear func ahead of the loop and passed
straight to the kernel.
`curvature_matrix_mirrored_from` in `inversion_imaging_numba_util` had no
remaining caller (in this repo or downstream) and is deleted rather than left
as dead numba code.
Also corrects the `curvature_matrix` docstring: it claimed the property is
"not a cached property" and is overwritten in memory by the regularization
add, but it is decorated `@cached_property` and `curvature_reg_matrix` adds
out-of-place via `np.add`.
Bit-identical output verified by capturing `inversion.curvature_matrix` before
and after on the autolens_profiling breakdown fiducial: `np.array_equal` True
for both euclid and hst, with the figures of merit matching the pins exactly
(hst 27661.910133664103, euclid 6213.3068738858765).
`pytest test_autoarray/inversion`: 392 passed.
Step 1 of #505.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fr6iJ5T1RDARWfxttCuGkK1 parent dedde5a commit cb91b76
2 files changed
Lines changed: 35 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | 495 | | |
516 | 496 | | |
517 | 497 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
339 | 343 | | |
340 | 344 | | |
341 | 345 | | |
| |||
344 | 348 | | |
345 | 349 | | |
346 | 350 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
394 | 392 | | |
395 | 393 | | |
396 | 394 | | |
| |||
493 | 491 | | |
494 | 492 | | |
495 | 493 | | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
496 | 499 | | |
497 | 500 | | |
498 | 501 | | |
| |||
540 | 543 | | |
541 | 544 | | |
542 | 545 | | |
543 | | - | |
544 | | - | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
545 | 549 | | |
546 | 550 | | |
547 | 551 | | |
| |||
557 | 561 | | |
558 | 562 | | |
559 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
560 | 574 | | |
561 | 575 | | |
562 | 576 | | |
563 | 577 | | |
564 | 578 | | |
565 | 579 | | |
566 | 580 | | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | 581 | | |
573 | 582 | | |
574 | 583 | | |
575 | 584 | | |
576 | 585 | | |
577 | | - | |
| 586 | + | |
578 | 587 | | |
579 | 588 | | |
580 | 589 | | |
| |||
584 | 593 | | |
585 | 594 | | |
586 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
587 | 601 | | |
588 | 602 | | |
589 | 603 | | |
| |||
0 commit comments