Browse Source

Remove unnecessary global function(s)

sfxc
haavee 2 years ago
parent
commit
928d2983f3
1 changed files with 10 additions and 11 deletions
  1. +10
    -11
      compare-ms-idi.py

+ 10
- 11
compare-ms-idi.py View File

@@ -59,23 +59,22 @@ n_times = choice(partial(operator.ne, 1), "{0:6d} times".format, const("once"))
#
##################################################################################

SumAttr = lambda a: lambda *args: compose(partial(setattr, args[0], a), sum, Map(GetA(a)))(args)
FloatAttrEq = lambda a: lambda *args: compose(partial(operator.__ge__, 1e-3), abs, Star(operator.sub), Map(GetA(a)))(args)

SumAllAttr = lambda *args: compose(const(None), pam(*map(compose(Star, SumAttr), ['weight', 'exposure', 'n', 'n_neg'])))(args) or args[0]
WeightEq = FloatAttrEq('weight')
ExposureEq = FloatAttrEq('exposure')
NEq = lambda *args: compose(Star(operator.__eq__), Map(GetA('n')))(args)
NoNegatives = lambda *args: compose(operator.__not__, list, Filter(operator.truth), Map(GetA('n_neg')))(args)
SumAttr = lambda a: lambda o0, o1: setattr(o0, a, getattr(o0, a)+getattr(o1, a))
FloatEq = lambda l, r: abs(l-r)<1e-3

Statistics = Type(weight=0, exposure=0, n=0, n_neg=0, source=None,
__repr__ = method(compose(" ".join, Filter(operator.truth),
pam("{0.exposure:9.2f}s wgt={0.weight:9.2f}".format,
compose(choice(partial(operator.ne, 0), "{0:4d}<0".format, const("")), GetA('n_neg')),
compose(n_times, GetA('n'))))),
__eq__ = method(lambda l,r: WeightEq(l, r) and ExposureEq(l, r) and NEq(l, r) and NoNegatives(l, r)),
__ne__ = method(lambda l,r: not (r==l)),
__iadd__ = method(lambda l,r: SumAllAttr(l, r)))
# float members compare differently than integers d'uh, if any of l, r have n_neg!=0 compare unequal
# (so even if l.n_neg == r.n_neg and n_neg > 0, they compare inequal in order to make them being
# reported as having an issue ...)
__eq__ = lambda l,r: FloatEq(l.weight, r.weight) and FloatEq(l.exposure, r.exposure) and l.n==r.n and (l.n_neg+r.n_neg)==0,
__ne__ = lambda l,r: not (r==l),
# object += other => __iadd__(self, other) => __iadd__(*a)
# from each element in args get the attribute(s) of interest and sum them into args[0] (== 'object' == self)
__iadd__ = lambda *a: compose(const(None), pam(*map(compose(Star, SumAttr), ['weight', 'exposure', 'n', 'n_neg'])))(a) or a[0])

DefaultDict = Derived(collections.defaultdict)
Source = lambda **kwargs: Obj(format=kwargs.get('format', 'Missing format='), location=kwargs.get('location', 'Missing location='),


Loading…
Cancel
Save