conjugate method added to CObs class

This commit is contained in:
Fabian Joswig 2021-10-18 14:48:16 +01:00
parent 7b0645bda0
commit b1e5777586
2 changed files with 8 additions and 1 deletions

View file

@ -655,6 +655,9 @@ class CObs:
if isinstance(self.imag, Obs):
self.imag.gamma_method(**kwargs)
def conjugate(self):
return CObs(self.real, -self.imag)
def __add__(self, other):
if hasattr(other, 'real') and hasattr(other, 'imag'):
return CObs(self.real + other.real,
@ -701,7 +704,7 @@ class CObs:
return self.real == other.real and self.imag == other.imag
def __str__(self):
return '(' + str(self.real) + int(self.imag > - np.finfo(np.float64).eps) * '+' + str(self.imag) + 'j)'
return '(' + str(self.real) + int(self.imag >= 0.0) * '+' + str(self.imag) + 'j)'
def __repr__(self):
return 'CObs[' + str(self) + ']'

View file

@ -199,6 +199,10 @@ def test_cobs():
obs2 = pe.pseudo_Obs(-0.2, 0.03, 't')
my_cobs = pe.CObs(obs1, obs2)
assert not (my_cobs + my_cobs.conjugate()).real.is_zero()
assert (my_cobs + my_cobs.conjugate()).imag.is_zero()
assert (my_cobs - my_cobs.conjugate()).real.is_zero()
assert not (my_cobs - my_cobs.conjugate()).imag.is_zero()
np.abs(my_cobs)
fs = [[lambda x: x[0] + x[1], lambda x: x[1] + x[0]],
[lambda x: x[0] * x[1], lambda x: x[1] * x[0]]]