scripts: Renamed import math alias m -> mt

Mainly to avoid conflicts with match results m, this frees up the single
letter variables m for other purposes.

Choosing a two letter alias was surprisingly difficult, but mt is nice
in that it somewhat matches it (for itertools) and ft (for functools).
This commit is contained in:
Christopher Haster
2024-11-05 01:58:40 -06:00
parent 96ddc72481
commit 48c2e7784b
20 changed files with 258 additions and 256 deletions

View File

@@ -13,7 +13,7 @@
import collections as co
import csv
import itertools as it
import math as m
import math as mt
import os
import re
@@ -31,24 +31,24 @@ class RInt(co.namedtuple('RInt', 'x')):
except ValueError:
# also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf
x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf
x = -mt.inf
else:
raise
assert isinstance(x, int) or m.isinf(x), x
assert isinstance(x, int) or mt.isinf(x), x
return super().__new__(cls, x)
def __str__(self):
if self.x == m.inf:
if self.x == mt.inf:
return ''
elif self.x == -m.inf:
elif self.x == -mt.inf:
return '-∞'
else:
return str(self.x)
def __int__(self):
assert not m.isinf(self.x)
assert not mt.isinf(self.x)
return self.x
def __float__(self):
@@ -62,9 +62,9 @@ class RInt(co.namedtuple('RInt', 'x')):
new = self.x if self else 0
old = other.x if other else 0
diff = new - old
if diff == +m.inf:
if diff == +mt.inf:
return '%7s' % '+∞'
elif diff == -m.inf:
elif diff == -mt.inf:
return '%7s' % '-∞'
else:
return '%+7d' % diff
@@ -72,16 +72,16 @@ class RInt(co.namedtuple('RInt', 'x')):
def ratio(self, other):
new = self.x if self else 0
old = other.x if other else 0
if m.isinf(new) and m.isinf(old):
if mt.isinf(new) and mt.isinf(old):
return 0.0
elif m.isinf(new):
return +m.inf
elif m.isinf(old):
return -m.inf
elif mt.isinf(new):
return +mt.inf
elif mt.isinf(old):
return -mt.inf
elif not old and not new:
return 0.0
elif not old:
return +m.inf
return +mt.inf
else:
return (new-old) / old
@@ -251,7 +251,7 @@ def collect(ci_paths, *,
for target in targets:
# found a cycle?
if target in seen:
return m.inf
return mt.inf
limit_ = find_limit(target, seen | {target})
limit = max(limit, limit_)
@@ -438,8 +438,8 @@ def table(Result, results, diff_results=None, *,
(getattr(r, k).table()
if getattr(r, k, None) is not None
else types[k].none,
(lambda t: ['+∞%'] if t == +m.inf
else ['-∞%'] if t == -m.inf
(lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)])(
types[k].ratio(
getattr(r, k, None),
@@ -458,8 +458,8 @@ def table(Result, results, diff_results=None, *,
(types[k].diff(
getattr(r, k, None),
getattr(diff_r, k, None)),
(lambda t: ['+∞%'] if t == +m.inf
else ['-∞%'] if t == -m.inf
(lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)] if t
else [])(
types[k].ratio(
@@ -579,9 +579,9 @@ def main(ci_paths,
**args):
# figure out depth
if args.get('depth') is None:
args['depth'] = m.inf if args.get('hot') else 1
args['depth'] = mt.inf if args.get('hot') else 1
elif args.get('depth') == 0:
args['depth'] = m.inf
args['depth'] = mt.inf
# find sizes
if not args.get('use', None):
@@ -674,7 +674,7 @@ def main(ci_paths,
# error on recursion
if args.get('error_on_recursion') and any(
m.isinf(float(r.limit)) for r in results):
mt.isinf(float(r.limit)) for r in results):
sys.exit(2)