Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lru_cache to _calculate_amat_eigenvecs to speed up pswf_operator #10

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
6 changes: 4 additions & 2 deletions hera_filters/dspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from scipy.optimize import leastsq, lsq_linear
import copy
from scipy import linalg
from functools import lru_cache

#DEFAULT PARAMETERS FOR CLEANs
CLEAN_DEFAULTS_1D={'tol':1e-9, 'window':'none',
Expand Down Expand Up @@ -2198,7 +2199,8 @@ def fit_solution_matrix(weights, design_matrix, cache=None, hash_decimal=10, fit
cache[opkey] = None
return cache[opkey]

def _calculate_amat(k, c):
@lru_cache(maxsize=8)
def _calculate_amat_eigenvecs(k, c):
"""
Computes the eigenvalues and eigenvectors of the decay coefficient matrix
used to compute prolate spheroidal wave functions. More information can be
Expand Down Expand Up @@ -2363,7 +2365,7 @@ def pswf_operator(
for fn, (fw, fc) in enumerate(zip(filter_half_widths, filter_centers)):
# Compute eigenvectors
c = fw * np.pi * (xmax - xmin)
eigenvals, eigenvecs = _calculate_amat(kmax, c)
eigenvals, eigenvecs = _calculate_amat_eigenvecs(kmax, c)

# Sort eigenvectors by largest eigenvalue
idx = np.argsort(eigenvals)
Expand Down