From 658c2b30de0f14d8a1c153d8845c8ba6e92beb70 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Fri, 27 May 2022 14:17:05 +0100 Subject: [PATCH] feat: eigenvalue calculation in pe.covariance is not done if only the correlation matrix is requested. --- pyerrors/obs.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pyerrors/obs.py b/pyerrors/obs.py index 220b1646..d211c541 100644 --- a/pyerrors/obs.py +++ b/pyerrors/obs.py @@ -1452,13 +1452,6 @@ def covariance(obs, visualize=False, correlation=False, smooth=None, **kwargs): if isinstance(smooth, int): corr = _smooth_eigenvalues(corr, smooth) - errors = [o.dvalue for o in obs] - cov = np.diag(errors) @ corr @ np.diag(errors) - - eigenvalues = np.linalg.eigh(cov)[0] - if not np.all(eigenvalues >= 0): - warnings.warn("Covariance matrix is not positive semi-definite (Eigenvalues: " + str(eigenvalues) + ")", RuntimeWarning) - if visualize: plt.matshow(corr, vmin=-1, vmax=1) plt.set_cmap('RdBu') @@ -1467,8 +1460,15 @@ def covariance(obs, visualize=False, correlation=False, smooth=None, **kwargs): if correlation is True: return corr - else: - return cov + + errors = [o.dvalue for o in obs] + cov = np.diag(errors) @ corr @ np.diag(errors) + + eigenvalues = np.linalg.eigh(cov)[0] + if not np.all(eigenvalues >= 0): + warnings.warn("Covariance matrix is not positive semi-definite (Eigenvalues: " + str(eigenvalues) + ")", RuntimeWarning) + + return cov def _smooth_eigenvalues(corr, E):