Skip to content
This repository has been archived by the owner on May 11, 2023. It is now read-only.

dev: Cache expensive (no-argument) LinearOperator methods that are reused in other calculations. #7

Open
daniel-dodd opened this issue Nov 26, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@daniel-dodd
Copy link
Member

Some expensive LinearOperator methods are reused in calculations. For example, the .to_root() method for a DenseLinearOperator returns the Cholesky decomposition that is costly to compute. But once computed, it is cheap to use in matrix operations such as solving linear systems, computing log-determinants, etc. Caching this would enhance performance.

@daniel-dodd daniel-dodd added the enhancement New feature or request label Nov 26, 2022
@daniel-dodd daniel-dodd self-assigned this Nov 26, 2022
@daniel-dodd
Copy link
Member Author

Have investigated this. This has to be functional, otherwise code will break e.g., in lax.scan's.

Root caching (if the dense matrix is not needed in further calculations, or is cheap to compute from the root) can safely be achieved in the current software with:

def compute_and_cache_root(lo: LinearOperator) -> Tuple[LinearOperator, LinearOperator]
    root_lo = lo.to_root()
    cached_lo = lo.from_root(root_lo)
    return root_lo, cached_lo

Might think about adding a cache_root class method, similar to from_root that builds a new class, but that ignores dense matrix construction.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant