mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
Merge pull request #117 from fjosw/feat/is_matrix_symmetric
is_matrix_symmetric
This commit is contained in:
commit
58779a8063
2 changed files with 47 additions and 4 deletions
|
@ -237,13 +237,30 @@ class Corr:
|
|||
raise Exception("Corr could not be symmetrized: No redundant values")
|
||||
return Corr(newcontent, prange=self.prange)
|
||||
|
||||
def is_matrix_symmetric(self):
|
||||
"""Checks whether a correlator matrices is symmetric on every timeslice."""
|
||||
if self.N == 1:
|
||||
raise Exception("Only works for correlator matrices.")
|
||||
for t in range(self.T):
|
||||
if self[t] is None:
|
||||
continue
|
||||
for i in range(self.N):
|
||||
for j in range(i + 1, self.N):
|
||||
if self[t][i, j] is self[t][j, i]:
|
||||
continue
|
||||
if hash(self[t][i, j]) != hash(self[t][j, i]):
|
||||
return False
|
||||
return True
|
||||
|
||||
def matrix_symmetric(self):
|
||||
"""Symmetrizes the correlator matrices on every timeslice."""
|
||||
if self.N > 1:
|
||||
transposed = [None if _check_for_none(self, G) else G.T for G in self.content]
|
||||
return 0.5 * (Corr(transposed) + self)
|
||||
if self.N == 1:
|
||||
raise Exception("Trying to symmetrize a correlator matrix, that already has N=1.")
|
||||
if self.is_matrix_symmetric():
|
||||
return 1.0 * self
|
||||
else:
|
||||
transposed = [None if _check_for_none(self, G) else G.T for G in self.content]
|
||||
return 0.5 * (Corr(transposed) + self)
|
||||
|
||||
def GEVP(self, t0, ts=None, sort="Eigenvalue", **kwargs):
|
||||
r'''Solve the generalized eigenvalue problem on the correlator matrix and returns the corresponding eigenvectors.
|
||||
|
@ -284,7 +301,11 @@ class Corr:
|
|||
warnings.warn("Argument 'sorted_list' is deprecated, use 'sort' instead.", DeprecationWarning)
|
||||
sort = kwargs.get("sorted_list")
|
||||
|
||||
symmetric_corr = self.matrix_symmetric()
|
||||
if self.is_matrix_symmetric():
|
||||
symmetric_corr = self
|
||||
else:
|
||||
symmetric_corr = self.matrix_symmetric()
|
||||
|
||||
if sort is None:
|
||||
if (ts is None):
|
||||
raise Exception("ts is required if sort=None.")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue