mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 23:00:25 +01:00
Complex matrix multiplication speed up my explicitly coding the
derivatives
This commit is contained in:
parent
b1e5777586
commit
877b1a4467
2 changed files with 15 additions and 1 deletions
|
@ -655,6 +655,9 @@ class CObs:
|
||||||
if isinstance(self.imag, Obs):
|
if isinstance(self.imag, Obs):
|
||||||
self.imag.gamma_method(**kwargs)
|
self.imag.gamma_method(**kwargs)
|
||||||
|
|
||||||
|
def is_zero(self):
|
||||||
|
return self.real == 0.0 and self.imag == 0.0
|
||||||
|
|
||||||
def conjugate(self):
|
def conjugate(self):
|
||||||
return CObs(self.real, -self.imag)
|
return CObs(self.real, -self.imag)
|
||||||
|
|
||||||
|
@ -678,7 +681,14 @@ class CObs:
|
||||||
return -1 * (self - other)
|
return -1 * (self - other)
|
||||||
|
|
||||||
def __mul__(self, other):
|
def __mul__(self, other):
|
||||||
if hasattr(other, 'real') and hasattr(other, 'imag'):
|
if all(isinstance(i, Obs) for i in [self.real, self.imag, other.real, other.imag]):
|
||||||
|
return CObs(derived_observable(lambda x, **kwargs: x[0] * x[1] - x[2] * x[3],
|
||||||
|
[self.real, other.real, self.imag, other.imag],
|
||||||
|
man_grad=[other.real.value, self.real.value, -other.imag.value, -self.imag.value]),
|
||||||
|
derived_observable(lambda x, **kwargs: x[2] * x[1] + x[0] * x[3],
|
||||||
|
[self.real, other.real, self.imag, other.imag],
|
||||||
|
man_grad=[other.imag.value, self.imag.value, other.real.value, self.real.value]))
|
||||||
|
elif hasattr(other, 'real') and hasattr(other, 'imag'):
|
||||||
return CObs(self.real * other.real - self.imag * other.imag,
|
return CObs(self.real * other.real - self.imag * other.imag,
|
||||||
self.imag * other.real + self.real * other.imag)
|
self.imag * other.real + self.real * other.imag)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -204,6 +204,10 @@ def test_cobs():
|
||||||
assert (my_cobs - my_cobs.conjugate()).real.is_zero()
|
assert (my_cobs - my_cobs.conjugate()).real.is_zero()
|
||||||
assert not (my_cobs - my_cobs.conjugate()).imag.is_zero()
|
assert not (my_cobs - my_cobs.conjugate()).imag.is_zero()
|
||||||
np.abs(my_cobs)
|
np.abs(my_cobs)
|
||||||
|
|
||||||
|
assert (my_cobs * my_cobs / my_cobs - my_cobs).is_zero()
|
||||||
|
assert (my_cobs + my_cobs - 2 * my_cobs).is_zero()
|
||||||
|
|
||||||
fs = [[lambda x: x[0] + x[1], lambda x: x[1] + x[0]],
|
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]]]
|
[lambda x: x[0] * x[1], lambda x: x[1] * x[0]]]
|
||||||
for other in [1, 1.1, (1.1-0.2j), pe.CObs(obs1), pe.CObs(obs1, obs2)]:
|
for other in [1, 1.1, (1.1-0.2j), pe.CObs(obs1), pe.CObs(obs1, obs2)]:
|
||||||
|
|
Loading…
Add table
Reference in a new issue