mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-15 03:53:41 +02:00
expand_deltas renamed to _expand_deltas and made a function instead of
class method
This commit is contained in:
parent
b80b746fae
commit
d26bbdc3bd
2 changed files with 28 additions and 22 deletions
|
@ -329,24 +329,6 @@ class Obs:
|
||||||
self.ddvalue = np.sqrt(self.ddvalue) / self.dvalue
|
self.ddvalue = np.sqrt(self.ddvalue) / self.dvalue
|
||||||
return
|
return
|
||||||
|
|
||||||
def expand_deltas(self, deltas, idx, shape):
|
|
||||||
"""Expand deltas defined on idx to a regular, contiguous range, where holes are filled by 0.
|
|
||||||
If idx is of type range, the deltas are not changed
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
deltas -- List of fluctuations
|
|
||||||
idx -- List or range of configs on which the deltas are defined.
|
|
||||||
shape -- Number of configs in idx.
|
|
||||||
"""
|
|
||||||
if isinstance(idx, range):
|
|
||||||
return deltas
|
|
||||||
else:
|
|
||||||
ret = np.zeros(idx[-1] - idx[0] + 1)
|
|
||||||
for i in range(shape):
|
|
||||||
ret[idx[i] - idx[0]] = deltas[i]
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def calc_gamma(self, deltas, idx, shape, w_max, fft):
|
def calc_gamma(self, deltas, idx, shape, w_max, fft):
|
||||||
"""Calculate Gamma_{AA} from the deltas, which are defined on idx.
|
"""Calculate Gamma_{AA} from the deltas, which are defined on idx.
|
||||||
idx is assumed to be a contiguous range (possibly with a stepsize != 1)
|
idx is assumed to be a contiguous range (possibly with a stepsize != 1)
|
||||||
|
@ -361,7 +343,7 @@ class Obs:
|
||||||
the computation of the autocorrelation function
|
the computation of the autocorrelation function
|
||||||
"""
|
"""
|
||||||
gamma = np.zeros(w_max)
|
gamma = np.zeros(w_max)
|
||||||
deltas = self.expand_deltas(deltas, idx, shape)
|
deltas = _expand_deltas(deltas, idx, shape)
|
||||||
new_shape = len(deltas)
|
new_shape = len(deltas)
|
||||||
if fft:
|
if fft:
|
||||||
max_gamma = min(new_shape, w_max)
|
max_gamma = min(new_shape, w_max)
|
||||||
|
@ -505,7 +487,7 @@ class Obs:
|
||||||
tmp = []
|
tmp = []
|
||||||
for r, r_name in enumerate(self.e_content[e_name]):
|
for r, r_name in enumerate(self.e_content[e_name]):
|
||||||
if expand:
|
if expand:
|
||||||
tmp.append(self.expand_deltas(self.deltas[r_name], self.idl[r_name], self.shape[r_name]) + self.r_values[r_name])
|
tmp.append(_expand_deltas(self.deltas[r_name], self.idl[r_name], self.shape[r_name]) + self.r_values[r_name])
|
||||||
else:
|
else:
|
||||||
tmp.append(self.deltas[r_name] + self.r_values[r_name])
|
tmp.append(self.deltas[r_name] + self.r_values[r_name])
|
||||||
r_length.append(len(tmp[-1]))
|
r_length.append(len(tmp[-1]))
|
||||||
|
@ -829,6 +811,28 @@ class CObs:
|
||||||
return 'CObs[' + str(self) + ']'
|
return 'CObs[' + str(self) + ']'
|
||||||
|
|
||||||
|
|
||||||
|
def _expand_deltas(deltas, idx, shape):
|
||||||
|
"""Expand deltas defined on idx to a regular, contiguous range, where holes are filled by 0.
|
||||||
|
If idx is of type range, the deltas are not changed
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
deltas : list
|
||||||
|
List of fluctuations
|
||||||
|
idx : list
|
||||||
|
List or range of configs on which the deltas are defined.
|
||||||
|
shape : int
|
||||||
|
Number of configs in idx.
|
||||||
|
"""
|
||||||
|
if isinstance(idx, range):
|
||||||
|
return deltas
|
||||||
|
else:
|
||||||
|
ret = np.zeros(idx[-1] - idx[0] + 1)
|
||||||
|
for i in range(shape):
|
||||||
|
ret[idx[i] - idx[0]] = deltas[i]
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def _merge_idx(idl):
|
def _merge_idx(idl):
|
||||||
"""Returns the union of all lists in idl
|
"""Returns the union of all lists in idl
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,10 @@ def test_irregular_matrix_inverse():
|
||||||
|
|
||||||
assert np.allclose(np.linalg.inv(np.vectorize(lambda x: x.value)(invertible_irregular_matrix)) - np.vectorize(lambda x: x.value)(inverse), 0.0)
|
assert np.allclose(np.linalg.inv(np.vectorize(lambda x: x.value)(invertible_irregular_matrix)) - np.vectorize(lambda x: x.value)(inverse), 0.0)
|
||||||
|
|
||||||
check = pe.linalg.matmul(invertible_irregular_matrix, inverse)
|
check1 = pe.linalg.matmul(invertible_irregular_matrix, inverse)
|
||||||
assert np.all([o.is_zero() for o in (check - np.identity(dim)).ravel()])
|
assert np.all([o.is_zero() for o in (check1 - np.identity(dim)).ravel()])
|
||||||
|
check2 = invertible_irregular_matrix @ inverse
|
||||||
|
assert np.all([o.is_zero() for o in (check2 - np.identity(dim)).ravel()])
|
||||||
|
|
||||||
|
|
||||||
def test_matrix_inverse():
|
def test_matrix_inverse():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue