* Added "lazy string printout" which will speed up errorbar algebra--i.e.

we only need to evaluate the string representation when
  the string printout isrequired.
master
Wirawan Purwanto 11 years ago
parent c8aad2e2f8
commit ed1242dc66
  1. 13
      math/stats/errorbar.py

@ -151,6 +151,7 @@ class errorbar(object):
This value is custom-made.""" This value is custom-made."""
ebproc = staticmethod(compress_errorbar_cxx) ebproc = staticmethod(compress_errorbar_cxx)
lazy_string = True
def __init__(self, val, err, eb=None, ebproc=None): def __init__(self, val, err, eb=None, ebproc=None):
self.val = val self.val = val
@ -158,6 +159,7 @@ class errorbar(object):
if ebproc != None: if ebproc != None:
self.ebproc = ebproc self.ebproc = ebproc
if eb == None: if eb == None:
if not self.lazy_string:
self.eb = self.ebproc(val, err) self.eb = self.ebproc(val, err)
else: else:
self.eb = eb self.eb = eb
@ -173,12 +175,23 @@ class errorbar(object):
def __str__(self): def __str__(self):
if getattr(self, "eb", None): if getattr(self, "eb", None):
return self.eb return self.eb
elif getattr(self, "eb", None) == None and getattr(self, "ebproc", None) != None:
self.eb = self.ebproc(self.val, self.err)
return self.eb
else: else:
return "%g +- %g" % (self.val, self.err) return "%g +- %g" % (self.val, self.err)
display = __str__ display = __str__
def __repr__(self): def __repr__(self):
return "errorbar(%s,%s,'%s')" % (self.val, self.err, self.display()) return "errorbar(%s,%s,'%s')" % (self.val, self.err, self.display())
def update(self, val, err):
self.val = val
self.err = err
self.ebupdate()
return self
def ebupdate(self): def ebupdate(self):
if self.lazy_string:
self.eb = None
else:
self.eb = self.ebproc(self.val, self.err) self.eb = self.ebproc(self.val, self.err)
def copy(self): def copy(self):
return self.__class__(self.val, self.err, self.eb, self.ebproc) return self.__class__(self.val, self.err, self.eb, self.ebproc)

Loading…
Cancel
Save