Skip to content

Fix/complex corr #135

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

Merged
merged 4 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pyerrors/correlators.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,8 @@ def __repr__(self, print_range=None):
content_string += "Description: " + self.tag + "\n"
if self.N != 1:
return content_string
if isinstance(self[0], CObs):
return content_string

if print_range[1]:
print_range[1] += 1
Expand Down Expand Up @@ -1136,8 +1138,10 @@ def _apply_func_to_corr(self, func):
for t in range(self.T):
if _check_for_none(self, newcontent[t]):
continue
if np.isnan(np.sum(newcontent[t]).value):
newcontent[t] = None
tmp_sum = np.sum(newcontent[t])
if hasattr(tmp_sum, "value"):
if np.isnan(tmp_sum.value):
newcontent[t] = None
if all([item is None for item in newcontent]):
raise Exception('Operation returns undefined correlator')
return Corr(newcontent)
Expand Down Expand Up @@ -1194,8 +1198,8 @@ def __rtruediv__(self, y):
@property
def real(self):
def return_real(obs_OR_cobs):
if isinstance(obs_OR_cobs, CObs):
return obs_OR_cobs.real
if isinstance(obs_OR_cobs.flatten()[0], CObs):
return np.vectorize(lambda x: x.real)(obs_OR_cobs)
else:
return obs_OR_cobs

Expand All @@ -1204,8 +1208,8 @@ def return_real(obs_OR_cobs):
@property
def imag(self):
def return_imag(obs_OR_cobs):
if isinstance(obs_OR_cobs, CObs):
return obs_OR_cobs.imag
if isinstance(obs_OR_cobs.flatten()[0], CObs):
return np.vectorize(lambda x: x.imag)(obs_OR_cobs)
else:
return obs_OR_cobs * 0 # So it stays the right type

Expand Down
10 changes: 10 additions & 0 deletions tests/correlators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,13 @@ def test_prune():
with pytest.raises(Exception):
corr_mat.prune(3)
corr_mat.prune(4)


def test_complex_Corr():
o1 = pe.pseudo_Obs(1.0, 0.1, "test")
cobs = pe.CObs(o1, -o1)
ccorr = pe.Corr([cobs, cobs, cobs])
assert np.all([ccorr.imag[i] == -ccorr.real[i] for i in range(ccorr.T)])
print(ccorr)
mcorr = pe.Corr(np.array([[ccorr, ccorr], [ccorr, ccorr]]))
assert np.all([mcorr.imag[i] == -mcorr.real[i] for i in range(mcorr.T)])