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

@@ -17,7 +17,7 @@ import errno
import fcntl
import functools as ft
import itertools as it
import math as m
import math as mt
import multiprocessing as mp
import os
import re
@@ -49,24 +49,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):
@@ -80,9 +80,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
@@ -90,16 +90,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
@@ -789,8 +789,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),
@@ -809,8 +809,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(
@@ -1037,9 +1037,9 @@ def report(perf_paths, *,
# 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):