mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-03-15 14:50:25 +01:00
feat: linalg.jack_matmul now also works with irregular monte carlo
chains
This commit is contained in:
parent
0954ebee6e
commit
28bf0f1701
2 changed files with 15 additions and 9 deletions
|
@ -187,40 +187,46 @@ def jack_matmul(*operands):
|
|||
"""
|
||||
|
||||
if any(isinstance(o[0, 0], CObs) for o in operands):
|
||||
name = operands[0][0, 0].real.names[0]
|
||||
idl = operands[0][0, 0].real.idl[name]
|
||||
|
||||
def _exp_to_jack(matrix):
|
||||
base_matrix = np.empty_like(matrix)
|
||||
for (n, m), entry in np.ndenumerate(matrix):
|
||||
base_matrix[n, m] = entry.real.export_jackknife() + 1j * entry.imag.export_jackknife()
|
||||
return base_matrix
|
||||
|
||||
def _imp_from_jack(matrix, name):
|
||||
def _imp_from_jack(matrix):
|
||||
base_matrix = np.empty_like(matrix)
|
||||
for (n, m), entry in np.ndenumerate(matrix):
|
||||
base_matrix[n, m] = CObs(import_jackknife(entry.real, name),
|
||||
import_jackknife(entry.imag, name))
|
||||
base_matrix[n, m] = CObs(import_jackknife(entry.real, name, [idl]),
|
||||
import_jackknife(entry.imag, name, [idl]))
|
||||
return base_matrix
|
||||
|
||||
r = _exp_to_jack(operands[0])
|
||||
for op in operands[1:]:
|
||||
r = r @ _exp_to_jack(op)
|
||||
return _imp_from_jack(r, op.ravel()[0].real.names[0])
|
||||
return _imp_from_jack(r)
|
||||
else:
|
||||
name = operands[0][0, 0].names[0]
|
||||
idl = operands[0][0, 0].idl[name]
|
||||
|
||||
def _exp_to_jack(matrix):
|
||||
base_matrix = np.empty_like(matrix)
|
||||
for (n, m), entry in np.ndenumerate(matrix):
|
||||
base_matrix[n, m] = entry.export_jackknife()
|
||||
return base_matrix
|
||||
|
||||
def _imp_from_jack(matrix, name):
|
||||
def _imp_from_jack(matrix):
|
||||
base_matrix = np.empty_like(matrix)
|
||||
for (n, m), entry in np.ndenumerate(matrix):
|
||||
base_matrix[n, m] = import_jackknife(entry, name)
|
||||
base_matrix[n, m] = import_jackknife(entry, name, [idl])
|
||||
return base_matrix
|
||||
|
||||
r = _exp_to_jack(operands[0])
|
||||
for op in operands[1:]:
|
||||
r = r @ _exp_to_jack(op)
|
||||
return _imp_from_jack(r, op.ravel()[0].names[0])
|
||||
return _imp_from_jack(r)
|
||||
|
||||
|
||||
def inv(x):
|
||||
|
|
|
@ -1559,7 +1559,7 @@ def load_object(path):
|
|||
return pickle.load(file)
|
||||
|
||||
|
||||
def import_jackknife(jacks, name):
|
||||
def import_jackknife(jacks, name, idl=None):
|
||||
"""Imports jackknife samples and returns an Obs
|
||||
|
||||
Parameters
|
||||
|
@ -1573,7 +1573,7 @@ def import_jackknife(jacks, name):
|
|||
length = len(jacks) - 1
|
||||
prj = (np.ones((length, length)) - (length - 1) * np.identity(length))
|
||||
samples = jacks[1:] @ prj
|
||||
new_obs = Obs([samples], [name])
|
||||
new_obs = Obs([samples], [name], idl=idl)
|
||||
new_obs._value = jacks[0]
|
||||
return new_obs
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue