From 788620198336ec7e79da9a8051a54b8bce0e5e64 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Mon, 27 Sep 2021 16:39:33 +0100 Subject: [PATCH] repr and print of correlator class altered --- pyerrors/correlators.py | 26 ++++++++++++++++++++++---- pyerrors/pyerrors.py | 4 ++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index a9df546d..c7e18563 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -342,11 +342,25 @@ class Corr: dump_object(self,filename) return + def print(self, range=[0, None]): + print(self.__repr__(range)) - def __repr__(self): - return("Corr[T="+str(self.T)+" , N="+str(self.N)+" , content="+str(self.content)+"]") + def __repr__(self, range=[0, None]): + if range[1]: + range[1] += 1 + content_string = 'x0/a\tCorr(x0/a)\n------------------\n' + for i, sub_corr in enumerate(self.content[range[0]:range[1]]): + if sub_corr is None: + content_string += str(i + range[0]) + '\n' + else: + content_string += str(i + range[0]) + for element in sub_corr: + content_string += '\t' + element.__repr__()[4:-1] + content_string += '\n' + return content_string def __str__(self): - return ("Corr[T="+str(self.T)+" , N="+str(self.N)+" , content="+str(self.content)+"]") + return self.__repr__() + #return ("Corr[T="+str(self.T)+" , N="+str(self.N)+" , content="+str([o[0] for o in [o for o in self.content]])+"]") #We define the basic operations, that can be performed with correlators. #While */+- get defined here, they only work for Corr*Obs and not Obs*Corr. @@ -462,7 +476,11 @@ class Corr: else: raise TypeError("type of exponent not supported") - #The numpy functions: + def __abs__(self): + newcontent=[None if (item is None) else np.abs(item) for item in self.content] + return Corr(newcontent) + +#The numpy functions: def sqrt(self): return self**0.5 diff --git a/pyerrors/pyerrors.py b/pyerrors/pyerrors.py index 2c022440..f9bbb946 100644 --- a/pyerrors/pyerrors.py +++ b/pyerrors/pyerrors.py @@ -555,8 +555,8 @@ class Obs: return np.array([self / o for o in y]) elif(y.__class__.__name__=="Corr"): - return NotImplemented - + return NotImplemented + else: return derived_observable(lambda x, **kwargs: x[0] / y, [self], man_grad=[1 / y])