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
+2 -2
View File
@@ -6,7 +6,7 @@
import collections as co import collections as co
import csv import csv
import itertools as it import itertools as it
import math as m import math as mt
import os import os
@@ -36,7 +36,7 @@ def dat(x):
try: try:
return float(x) return float(x)
# just don't allow infinity or nan # just don't allow infinity or nan
if m.isinf(x) or m.isnan(x): if mt.isinf(x) or mt.isnan(x):
raise ValueError("invalid dat %r" % x) raise ValueError("invalid dat %r" % x)
except ValueError: except ValueError:
pass pass
+9 -9
View File
@@ -6,7 +6,7 @@
import collections as co import collections as co
import csv import csv
import itertools as it import itertools as it
import math as m import math as mt
import os import os
@@ -36,7 +36,7 @@ def dat(x):
try: try:
return float(x) return float(x)
# just don't allow infinity or nan # just don't allow infinity or nan
if m.isinf(x) or m.isnan(x): if mt.isinf(x) or mt.isnan(x):
raise ValueError("invalid dat %r" % x) raise ValueError("invalid dat %r" % x)
except ValueError: except ValueError:
pass pass
@@ -182,23 +182,23 @@ def main(csv_paths, output, *,
else {meas: meas__+'+'+meas_})) else {meas: meas__+'+'+meas_}))
if sum_: append('sum', lambda vs: sum(vs)) if sum_: append('sum', lambda vs: sum(vs))
if prod: append('prod', lambda vs: m.prod(vs)) if prod: append('prod', lambda vs: mt.prod(vs))
if min_: append('min', lambda vs: min(vs, default=0)) if min_: append('min', lambda vs: min(vs, default=0))
if max_: append('max', lambda vs: max(vs, default=0)) if max_: append('max', lambda vs: max(vs, default=0))
if bnd: append('bnd', lambda vs: min(vs, default=0)) if bnd: append('bnd', lambda vs: min(vs, default=0))
if bnd: append('bnd', lambda vs: max(vs, default=0)) if bnd: append('bnd', lambda vs: max(vs, default=0))
if avg: append('avg', lambda vs: sum(vs) / max(len(vs), 1)) if avg: append('avg', lambda vs: sum(vs) / max(len(vs), 1))
if stddev: append('stddev', lambda vs: ( if stddev: append('stddev', lambda vs: (
lambda avg: m.sqrt( lambda avg: mt.sqrt(
sum((v - avg)**2 for v in vs) / max(len(vs), 1)) sum((v - avg)**2 for v in vs) / max(len(vs), 1))
)(sum(vs) / max(len(vs), 1))) )(sum(vs) / max(len(vs), 1)))
if gmean: append('gmean', lambda vs: if gmean: append('gmean', lambda vs:
m.prod(float(v) for v in vs)**(1 / max(len(vs), 1))) mt.prod(float(v) for v in vs)**(1 / max(len(vs), 1)))
if gstddev: append('gstddev', lambda vs: ( if gstddev: append('gstddev', lambda vs: (
lambda gmean: m.exp(m.sqrt( lambda gmean: mt.exp(mt.sqrt(
sum(m.log(v/gmean)**2 for v in vs) / max(len(vs), 1))) sum(mt.log(v/gmean)**2 for v in vs) / max(len(vs), 1)))
if gmean else m.inf if gmean else mt.inf
)(m.prod(float(v) for v in vs)**(1 / max(len(vs), 1)))) )(mt.prod(float(v) for v in vs)**(1 / max(len(vs), 1))))
# write results to CSVS # write results to CSVS
with openio(output, 'w') as f: with openio(output, 'w') as f:
-1
View File
@@ -14,7 +14,6 @@ import csv
import errno import errno
import fnmatch import fnmatch
import itertools as it import itertools as it
import math as m
import os import os
import pty import pty
import re import re
+19 -19
View File
@@ -16,7 +16,7 @@ import collections as co
import csv import csv
import difflib import difflib
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import re import re
import shlex import shlex
@@ -40,24 +40,24 @@ class RInt(co.namedtuple('RInt', 'x')):
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf x = -mt.inf
else: else:
raise raise
assert isinstance(x, int) or m.isinf(x), x assert isinstance(x, int) or mt.isinf(x), x
return super().__new__(cls, x) return super().__new__(cls, x)
def __str__(self): def __str__(self):
if self.x == m.inf: if self.x == mt.inf:
return '' return ''
elif self.x == -m.inf: elif self.x == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.x)
def __int__(self): def __int__(self):
assert not m.isinf(self.x) assert not mt.isinf(self.x)
return self.x return self.x
def __float__(self): def __float__(self):
@@ -71,9 +71,9 @@ class RInt(co.namedtuple('RInt', 'x')):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other else 0 old = other.x if other else 0
diff = new - old diff = new - old
if diff == +m.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
elif diff == -m.inf: elif diff == -mt.inf:
return '%7s' % '-∞' return '%7s' % '-∞'
else: else:
return '%+7d' % diff return '%+7d' % diff
@@ -81,16 +81,16 @@ class RInt(co.namedtuple('RInt', 'x')):
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other 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 return 0.0
elif m.isinf(new): elif mt.isinf(new):
return +m.inf return +mt.inf
elif m.isinf(old): elif mt.isinf(old):
return -m.inf return -mt.inf
elif not old and not new: elif not old and not new:
return 0.0 return 0.0
elif not old: elif not old:
return +m.inf return +mt.inf
else: else:
return (new-old) / old return (new-old) / old
@@ -446,8 +446,8 @@ def table(Result, results, diff_results=None, *,
(getattr(r, k).table() (getattr(r, k).table()
if getattr(r, k, None) is not None if getattr(r, k, None) is not None
else types[k].none, else types[k].none,
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)])( else ['%+.1f%%' % (100*t)])(
types[k].ratio( types[k].ratio(
getattr(r, k, None), getattr(r, k, None),
@@ -466,8 +466,8 @@ def table(Result, results, diff_results=None, *,
(types[k].diff( (types[k].diff(
getattr(r, k, None), getattr(r, k, None),
getattr(diff_r, k, None)), getattr(diff_r, k, None)),
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)] if t else ['%+.1f%%' % (100*t)] if t
else [])( else [])(
types[k].ratio( types[k].ratio(
+21 -21
View File
@@ -16,7 +16,7 @@ import collections as co
import csv import csv
import itertools as it import itertools as it
import json import json
import math as m import math as mt
import os import os
import re import re
import shlex import shlex
@@ -40,24 +40,24 @@ class RInt(co.namedtuple('RInt', 'x')):
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf x = -mt.inf
else: else:
raise raise
assert isinstance(x, int) or m.isinf(x), x assert isinstance(x, int) or mt.isinf(x), x
return super().__new__(cls, x) return super().__new__(cls, x)
def __str__(self): def __str__(self):
if self.x == m.inf: if self.x == mt.inf:
return '' return ''
elif self.x == -m.inf: elif self.x == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.x)
def __int__(self): def __int__(self):
assert not m.isinf(self.x) assert not mt.isinf(self.x)
return self.x return self.x
def __float__(self): def __float__(self):
@@ -71,9 +71,9 @@ class RInt(co.namedtuple('RInt', 'x')):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other else 0 old = other.x if other else 0
diff = new - old diff = new - old
if diff == +m.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
elif diff == -m.inf: elif diff == -mt.inf:
return '%7s' % '-∞' return '%7s' % '-∞'
else: else:
return '%+7d' % diff return '%+7d' % diff
@@ -81,16 +81,16 @@ class RInt(co.namedtuple('RInt', 'x')):
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other 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 return 0.0
elif m.isinf(new): elif mt.isinf(new):
return +m.inf return +mt.inf
elif m.isinf(old): elif mt.isinf(old):
return -m.inf return -mt.inf
elif not old and not new: elif not old and not new:
return 0.0 return 0.0
elif not old: elif not old:
return +m.inf return +mt.inf
else: else:
return (new-old) / old return (new-old) / old
@@ -127,8 +127,8 @@ class RFrac(co.namedtuple('RFrac', 'a,b')):
def notes(self): def notes(self):
t = self.a.x/self.b.x if self.b.x else 1.0 t = self.a.x/self.b.x if self.b.x else 1.0
return ['%' if t == +m.inf return ['%' if t == +mt.inf
else '-∞%' if t == -m.inf else '-∞%' if t == -mt.inf
else '%.1f%%' % (100*t)] else '%.1f%%' % (100*t)]
def diff(self, other): def diff(self, other):
@@ -434,8 +434,8 @@ def table(Result, results, diff_results=None, *,
(getattr(r, k).table() (getattr(r, k).table()
if getattr(r, k, None) is not None if getattr(r, k, None) is not None
else types[k].none, else types[k].none,
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)])( else ['%+.1f%%' % (100*t)])(
types[k].ratio( types[k].ratio(
getattr(r, k, None), getattr(r, k, None),
@@ -454,8 +454,8 @@ def table(Result, results, diff_results=None, *,
(types[k].diff( (types[k].diff(
getattr(r, k, None), getattr(r, k, None),
getattr(diff_r, k, None)), getattr(diff_r, k, None)),
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)] if t else ['%+.1f%%' % (100*t)] if t
else [])( else [])(
types[k].ratio( types[k].ratio(
+19 -19
View File
@@ -16,7 +16,7 @@ import collections as co
import csv import csv
import difflib import difflib
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import re import re
import shlex import shlex
@@ -40,24 +40,24 @@ class RInt(co.namedtuple('RInt', 'x')):
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf x = -mt.inf
else: else:
raise raise
assert isinstance(x, int) or m.isinf(x), x assert isinstance(x, int) or mt.isinf(x), x
return super().__new__(cls, x) return super().__new__(cls, x)
def __str__(self): def __str__(self):
if self.x == m.inf: if self.x == mt.inf:
return '' return ''
elif self.x == -m.inf: elif self.x == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.x)
def __int__(self): def __int__(self):
assert not m.isinf(self.x) assert not mt.isinf(self.x)
return self.x return self.x
def __float__(self): def __float__(self):
@@ -71,9 +71,9 @@ class RInt(co.namedtuple('RInt', 'x')):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other else 0 old = other.x if other else 0
diff = new - old diff = new - old
if diff == +m.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
elif diff == -m.inf: elif diff == -mt.inf:
return '%7s' % '-∞' return '%7s' % '-∞'
else: else:
return '%+7d' % diff return '%+7d' % diff
@@ -81,16 +81,16 @@ class RInt(co.namedtuple('RInt', 'x')):
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other 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 return 0.0
elif m.isinf(new): elif mt.isinf(new):
return +m.inf return +mt.inf
elif m.isinf(old): elif mt.isinf(old):
return -m.inf return -mt.inf
elif not old and not new: elif not old and not new:
return 0.0 return 0.0
elif not old: elif not old:
return +m.inf return +mt.inf
else: else:
return (new-old) / old return (new-old) / old
@@ -446,8 +446,8 @@ def table(Result, results, diff_results=None, *,
(getattr(r, k).table() (getattr(r, k).table()
if getattr(r, k, None) is not None if getattr(r, k, None) is not None
else types[k].none, else types[k].none,
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)])( else ['%+.1f%%' % (100*t)])(
types[k].ratio( types[k].ratio(
getattr(r, k, None), getattr(r, k, None),
@@ -466,8 +466,8 @@ def table(Result, results, diff_results=None, *,
(types[k].diff( (types[k].diff(
getattr(r, k, None), getattr(r, k, None),
getattr(diff_r, k, None)), getattr(diff_r, k, None)),
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)] if t else ['%+.1f%%' % (100*t)] if t
else [])( else [])(
types[k].ratio( types[k].ratio(
+5 -5
View File
@@ -4,7 +4,7 @@ import bisect
import collections as co import collections as co
import functools as ft import functools as ft
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import shutil import shutil
import struct import struct
@@ -269,9 +269,9 @@ def lebesgue_curve(width, height):
# we create a truncated Z-curve by simply filtering out the points # we create a truncated Z-curve by simply filtering out the points
# that are outside our region # that are outside our region
curve = [] curve = []
for i in range(2**(2*m.ceil(m.log2(max(width, height))))): for i in range(2**(2*mt.ceil(mt.log2(max(width, height))))):
# we just operate on binary strings here because it's easier # we just operate on binary strings here because it's easier
b = '{:0{}b}'.format(i, 2*m.ceil(m.log2(i+1)/2)) b = '{:0{}b}'.format(i, 2*mt.ceil(mt.log2(i+1)/2))
x = int(b[1::2], 2) if b[1::2] else 0 x = int(b[1::2], 2) if b[1::2] else 0
y = int(b[0::2], 2) if b[0::2] else 0 y = int(b[0::2], 2) if b[0::2] else 0
if x < width and y < height: if x < width and y < height:
@@ -1330,8 +1330,8 @@ def main(disk, mroots=None, *,
# and then print the bmap # and then print the bmap
for row in range( for row in range(
m.ceil(bmap.height/4) if braille mt.ceil(bmap.height/4) if braille
else m.ceil(bmap.height/2) if dots else mt.ceil(bmap.height/2) if dots
else bmap.height): else bmap.height):
line = bmap.draw(row, line = bmap.draw(row,
mdirs=mdirs, mdirs=mdirs,
+2 -2
View File
@@ -3,7 +3,7 @@
import bisect import bisect
import collections as co import collections as co
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import struct import struct
@@ -920,7 +920,7 @@ def main(disk, roots=None, *,
# dynamically size the id field # dynamically size the id field
w_width = m.ceil(m.log10(max(1, btree.weight)+1)) w_width = mt.ceil(mt.log10(max(1, btree.weight)+1))
# prbyd here means the last rendered rbyd, we update # prbyd here means the last rendered rbyd, we update
# in dbg_branch to always print interleaved addresses # in dbg_branch to always print interleaved addresses
+7 -7
View File
@@ -4,7 +4,7 @@ import bisect
import collections as co import collections as co
import functools as ft import functools as ft
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import struct import struct
@@ -1461,7 +1461,7 @@ def dbg_fstruct(f, block_size, mdir, rid, tag, j, d, data, *,
# dynamically size the id field # dynamically size the id field
w_width = m.ceil(m.log10(max(1, btree.weight)+1)) w_width = mt.ceil(mt.log10(max(1, btree.weight)+1))
# prbyd here means the last rendered rbyd, we update # prbyd here means the last rendered rbyd, we update
# in dbg_branch to always print interleaved addresses # in dbg_branch to always print interleaved addresses
@@ -1719,7 +1719,7 @@ def main(disk, mroots=None, *,
# determine the mleaf_weight from the block_size, this is just for # determine the mleaf_weight from the block_size, this is just for
# printing purposes # printing purposes
mleaf_weight = 1 << m.ceil(m.log2(block_size // 8)) mleaf_weight = 1 << mt.ceil(mt.log2(block_size // 8))
# before we print, we need to do a pass for a few things: # before we print, we need to do a pass for a few things:
# - find the actual mroot # - find the actual mroot
@@ -1888,7 +1888,7 @@ def main(disk, mroots=None, *,
width_ = max(width_, width__) width_ = max(width_, width__)
return 1+depth_, width_ return 1+depth_, width_
depth, f_width = rec_f_width(0, args.get('depth') or m.inf) depth, f_width = rec_f_width(0, args.get('depth') or mt.inf)
# adjust to make space for max depth # adjust to make space for max depth
f_width += 4*(depth-1) f_width += 4*(depth-1)
@@ -1906,8 +1906,8 @@ def main(disk, mroots=None, *,
# dynamically size the id field # dynamically size the id field
w_width = max( w_width = max(
m.ceil(m.log10(max(1, bweight//mleaf_weight)+1)), mt.ceil(mt.log10(max(1, bweight//mleaf_weight)+1)),
m.ceil(m.log10(max(1, rweight)+1)), mt.ceil(mt.log10(max(1, rweight)+1)),
# in case of -1.-1 # in case of -1.-1
2) 2)
@@ -2162,7 +2162,7 @@ def main(disk, mroots=None, *,
prefixes[2+(i==len(dir)-1)] + "| ", prefixes[2+(i==len(dir)-1)] + "| ",
prefixes[2+(i==len(dir)-1)] + " ")) prefixes[2+(i==len(dir)-1)] + " "))
rec_dir(0, args.get('depth') or m.inf) rec_dir(0, args.get('depth') or mt.inf)
if args.get('error_on_corrupt') and corrupted: if args.get('error_on_corrupt') and corrupted:
sys.exit(2) sys.exit(2)
+4 -4
View File
@@ -3,7 +3,7 @@
import bisect import bisect
import collections as co import collections as co
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import struct import struct
@@ -879,7 +879,7 @@ def main(disk, mroots=None, *,
# determine the mleaf_weight from the block_size, this is just for # determine the mleaf_weight from the block_size, this is just for
# printing purposes # printing purposes
mleaf_weight = 1 << m.ceil(m.log2(block_size // 8)) mleaf_weight = 1 << mt.ceil(mt.log2(block_size // 8))
# before we print, we need to do a pass for a few things: # before we print, we need to do a pass for a few things:
# - find the actual mroot # - find the actual mroot
@@ -1510,8 +1510,8 @@ def main(disk, mroots=None, *,
# dynamically size the id field # dynamically size the id field
w_width = max( w_width = max(
m.ceil(m.log10(max(1, bweight//mleaf_weight)+1)), mt.ceil(mt.log10(max(1, bweight//mleaf_weight)+1)),
m.ceil(m.log10(max(1, rweight)+1)), mt.ceil(mt.log10(max(1, rweight)+1)),
# in case of -1.-1 # in case of -1.-1
2) 2)
+3 -3
View File
@@ -3,7 +3,7 @@
import bisect import bisect
import collections as co import collections as co
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import struct import struct
@@ -513,7 +513,7 @@ def dbg_log(data, block_size, rev, eoff, weight, *,
weight_ = max(weight_, weight__) weight_ = max(weight_, weight__)
trunk_ = 0 trunk_ = 0
w_width = m.ceil(m.log10(max(1, weight_)+1)) w_width = mt.ceil(mt.log10(max(1, weight_)+1))
# print revision count # print revision count
if args.get('raw'): if args.get('raw'):
@@ -839,7 +839,7 @@ def dbg_tree(data, block_size, rev, trunk, weight, *,
# dynamically size the id field # dynamically size the id field
w_width = m.ceil(m.log10(max(1, weight)+1)) w_width = mt.ceil(mt.log10(max(1, weight)+1))
rid, tag = -1, 0 rid, tag = -1, 0
for i in it.count(): for i in it.count():
+21 -21
View File
@@ -17,7 +17,7 @@ import errno
import fcntl import fcntl
import functools as ft import functools as ft
import itertools as it import itertools as it
import math as m import math as mt
import multiprocessing as mp import multiprocessing as mp
import os import os
import re import re
@@ -49,24 +49,24 @@ class RInt(co.namedtuple('RInt', 'x')):
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf x = -mt.inf
else: else:
raise raise
assert isinstance(x, int) or m.isinf(x), x assert isinstance(x, int) or mt.isinf(x), x
return super().__new__(cls, x) return super().__new__(cls, x)
def __str__(self): def __str__(self):
if self.x == m.inf: if self.x == mt.inf:
return '' return ''
elif self.x == -m.inf: elif self.x == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.x)
def __int__(self): def __int__(self):
assert not m.isinf(self.x) assert not mt.isinf(self.x)
return self.x return self.x
def __float__(self): def __float__(self):
@@ -80,9 +80,9 @@ class RInt(co.namedtuple('RInt', 'x')):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other else 0 old = other.x if other else 0
diff = new - old diff = new - old
if diff == +m.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
elif diff == -m.inf: elif diff == -mt.inf:
return '%7s' % '-∞' return '%7s' % '-∞'
else: else:
return '%+7d' % diff return '%+7d' % diff
@@ -90,16 +90,16 @@ class RInt(co.namedtuple('RInt', 'x')):
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other 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 return 0.0
elif m.isinf(new): elif mt.isinf(new):
return +m.inf return +mt.inf
elif m.isinf(old): elif mt.isinf(old):
return -m.inf return -mt.inf
elif not old and not new: elif not old and not new:
return 0.0 return 0.0
elif not old: elif not old:
return +m.inf return +mt.inf
else: else:
return (new-old) / old return (new-old) / old
@@ -789,8 +789,8 @@ def table(Result, results, diff_results=None, *,
(getattr(r, k).table() (getattr(r, k).table()
if getattr(r, k, None) is not None if getattr(r, k, None) is not None
else types[k].none, else types[k].none,
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)])( else ['%+.1f%%' % (100*t)])(
types[k].ratio( types[k].ratio(
getattr(r, k, None), getattr(r, k, None),
@@ -809,8 +809,8 @@ def table(Result, results, diff_results=None, *,
(types[k].diff( (types[k].diff(
getattr(r, k, None), getattr(r, k, None),
getattr(diff_r, k, None)), getattr(diff_r, k, None)),
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)] if t else ['%+.1f%%' % (100*t)] if t
else [])( else [])(
types[k].ratio( types[k].ratio(
@@ -1037,9 +1037,9 @@ def report(perf_paths, *,
# figure out depth # figure out depth
if args.get('depth') is None: 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: elif args.get('depth') == 0:
args['depth'] = m.inf args['depth'] = mt.inf
# find sizes # find sizes
if not args.get('use', None): if not args.get('use', None):
+22 -22
View File
@@ -16,7 +16,7 @@ import collections as co
import csv import csv
import functools as ft import functools as ft
import itertools as it import itertools as it
import math as m import math as mt
import multiprocessing as mp import multiprocessing as mp
import os import os
import re import re
@@ -40,24 +40,24 @@ class RInt(co.namedtuple('RInt', 'x')):
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf x = -mt.inf
else: else:
raise raise
assert isinstance(x, int) or m.isinf(x), x assert isinstance(x, int) or mt.isinf(x), x
return super().__new__(cls, x) return super().__new__(cls, x)
def __str__(self): def __str__(self):
if self.x == m.inf: if self.x == mt.inf:
return '' return ''
elif self.x == -m.inf: elif self.x == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.x)
def __int__(self): def __int__(self):
assert not m.isinf(self.x) assert not mt.isinf(self.x)
return self.x return self.x
def __float__(self): def __float__(self):
@@ -71,9 +71,9 @@ class RInt(co.namedtuple('RInt', 'x')):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other else 0 old = other.x if other else 0
diff = new - old diff = new - old
if diff == +m.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
elif diff == -m.inf: elif diff == -mt.inf:
return '%7s' % '-∞' return '%7s' % '-∞'
else: else:
return '%+7d' % diff return '%+7d' % diff
@@ -81,16 +81,16 @@ class RInt(co.namedtuple('RInt', 'x')):
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other 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 return 0.0
elif m.isinf(new): elif mt.isinf(new):
return +m.inf return +mt.inf
elif m.isinf(old): elif mt.isinf(old):
return -m.inf return -mt.inf
elif not old and not new: elif not old and not new:
return 0.0 return 0.0
elif not old: elif not old:
return +m.inf return +mt.inf
else: else:
return (new-old) / old return (new-old) / old
@@ -566,7 +566,7 @@ def collect(obj_path, trace_paths, *,
trace_ranges.append([(None, None)]) trace_ranges.append([(None, None)])
continue continue
perjob = m.ceil(size // jobs) perjob = mt.ceil(size // jobs)
trace_ranges.append([(i, i+perjob) for i in range(0, size, perjob)]) trace_ranges.append([(i, i+perjob) for i in range(0, size, perjob)])
results = [] results = []
@@ -753,8 +753,8 @@ def table(Result, results, diff_results=None, *,
(getattr(r, k).table() (getattr(r, k).table()
if getattr(r, k, None) is not None if getattr(r, k, None) is not None
else types[k].none, else types[k].none,
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)])( else ['%+.1f%%' % (100*t)])(
types[k].ratio( types[k].ratio(
getattr(r, k, None), getattr(r, k, None),
@@ -773,8 +773,8 @@ def table(Result, results, diff_results=None, *,
(types[k].diff( (types[k].diff(
getattr(r, k, None), getattr(r, k, None),
getattr(diff_r, k, None)), getattr(diff_r, k, None)),
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)] if t else ['%+.1f%%' % (100*t)] if t
else [])( else [])(
types[k].ratio( types[k].ratio(
@@ -1015,9 +1015,9 @@ def report(obj_path='', trace_paths=[], *,
# figure out depth # figure out depth
if args.get('depth') is None: 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: elif args.get('depth') == 0:
args['depth'] = m.inf args['depth'] = mt.inf
# find sizes # find sizes
if not args.get('use', None): if not args.get('use', None):
+20 -20
View File
@@ -15,7 +15,7 @@ import collections as co
import csv import csv
import io import io
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import shlex import shlex
import shutil import shutil
@@ -95,7 +95,7 @@ def si(x, w=4):
# #
# note we adjust this so that 100K = .1M, which has more info # note we adjust this so that 100K = .1M, which has more info
# per character # per character
p = 3*int(m.log(abs(x)*10, 10**3)) p = 3*int(mt.log(abs(x)*10, 10**3))
p = min(18, max(-18, p)) p = min(18, max(-18, p))
# format with enough digits # format with enough digits
s = '%.*f' % (w, abs(x) / (10.0**p)) s = '%.*f' % (w, abs(x) / (10.0**p))
@@ -114,7 +114,7 @@ def si2(x, w=5):
# #
# note we adjust this so that 128Ki = .1Mi, which has more info # note we adjust this so that 128Ki = .1Mi, which has more info
# per character # per character
p = 10*int(m.log(abs(x)*10, 2**10)) p = 10*int(mt.log(abs(x)*10, 2**10))
p = min(30, max(-30, p)) p = min(30, max(-30, p))
# format with enough digits # format with enough digits
s = '%.*f' % (w, abs(x) / (2.0**p)) s = '%.*f' % (w, abs(x) / (2.0**p))
@@ -258,7 +258,7 @@ def dat(x):
try: try:
return float(x) return float(x)
# just don't allow infinity or nan # just don't allow infinity or nan
if m.isinf(x) or m.isnan(x): if mt.isinf(x) or mt.isnan(x):
raise ValueError("invalid dat %r" % x) raise ValueError("invalid dat %r" % x)
except ValueError: except ValueError:
pass pass
@@ -270,9 +270,9 @@ def dat(x):
# a hack log that preserves sign, with a linear region between -1 and 1 # a hack log that preserves sign, with a linear region between -1 and 1
def symlog(x): def symlog(x):
if x > 1: if x > 1:
return m.log(x)+1 return mt.log(x)+1
elif x < -1: elif x < -1:
return -m.log(-x)-1 return -mt.log(-x)-1
else: else:
return x return x
@@ -614,9 +614,9 @@ class Grid:
self_i = 0 self_i = 0
other_i = 0 other_i = 0
self_xweight = (self_xweights[self_i] self_xweight = (self_xweights[self_i]
if self_i < len(self_xweights) else m.inf) if self_i < len(self_xweights) else mt.inf)
other_xweight = (other_xweights[other_i] other_xweight = (other_xweights[other_i]
if other_i < len(other_xweights) else m.inf) if other_i < len(other_xweights) else mt.inf)
while self_i < len(self_xweights) and other_i < len(other_xweights): while self_i < len(self_xweights) and other_i < len(other_xweights):
if other_xweight - self_xweight > 0.0000001: if other_xweight - self_xweight > 0.0000001:
new_xweights.append(self_xweight) new_xweights.append(self_xweight)
@@ -635,7 +635,7 @@ class Grid:
self_i += 1 self_i += 1
self_xweight = (self_xweights[self_i] self_xweight = (self_xweights[self_i]
if self_i < len(self_xweights) else m.inf) if self_i < len(self_xweights) else mt.inf)
elif self_xweight - other_xweight > 0.0000001: elif self_xweight - other_xweight > 0.0000001:
new_xweights.append(other_xweight) new_xweights.append(other_xweight)
self_xweight -= other_xweight self_xweight -= other_xweight
@@ -653,7 +653,7 @@ class Grid:
other_i += 1 other_i += 1
other_xweight = (other_xweights[other_i] other_xweight = (other_xweights[other_i]
if other_i < len(other_xweights) else m.inf) if other_i < len(other_xweights) else mt.inf)
else: else:
new_xweights.append(self_xweight) new_xweights.append(self_xweight)
@@ -665,10 +665,10 @@ class Grid:
self_i += 1 self_i += 1
self_xweight = (self_xweights[self_i] self_xweight = (self_xweights[self_i]
if self_i < len(self_xweights) else m.inf) if self_i < len(self_xweights) else mt.inf)
other_i += 1 other_i += 1
other_xweight = (other_xweights[other_i] other_xweight = (other_xweights[other_i]
if other_i < len(other_xweights) else m.inf) if other_i < len(other_xweights) else mt.inf)
# squish so ratios are preserved # squish so ratios are preserved
self_h = sum(self.yweights) self_h = sum(self.yweights)
@@ -712,9 +712,9 @@ class Grid:
self_i = 0 self_i = 0
other_i = 0 other_i = 0
self_yweight = (self_yweights[self_i] self_yweight = (self_yweights[self_i]
if self_i < len(self_yweights) else m.inf) if self_i < len(self_yweights) else mt.inf)
other_yweight = (other_yweights[other_i] other_yweight = (other_yweights[other_i]
if other_i < len(other_yweights) else m.inf) if other_i < len(other_yweights) else mt.inf)
while self_i < len(self_yweights) and other_i < len(other_yweights): while self_i < len(self_yweights) and other_i < len(other_yweights):
if other_yweight - self_yweight > 0.0000001: if other_yweight - self_yweight > 0.0000001:
new_yweights.append(self_yweight) new_yweights.append(self_yweight)
@@ -733,7 +733,7 @@ class Grid:
self_i += 1 self_i += 1
self_yweight = (self_yweights[self_i] self_yweight = (self_yweights[self_i]
if self_i < len(self_yweights) else m.inf) if self_i < len(self_yweights) else mt.inf)
elif self_yweight - other_yweight > 0.0000001: elif self_yweight - other_yweight > 0.0000001:
new_yweights.append(other_yweight) new_yweights.append(other_yweight)
self_yweight -= other_yweight self_yweight -= other_yweight
@@ -751,7 +751,7 @@ class Grid:
other_i += 1 other_i += 1
other_yweight = (other_yweights[other_i] other_yweight = (other_yweights[other_i]
if other_i < len(other_yweights) else m.inf) if other_i < len(other_yweights) else mt.inf)
else: else:
new_yweights.append(self_yweight) new_yweights.append(self_yweight)
@@ -763,10 +763,10 @@ class Grid:
self_i += 1 self_i += 1
self_yweight = (self_yweights[self_i] self_yweight = (self_yweights[self_i]
if self_i < len(self_yweights) else m.inf) if self_i < len(self_yweights) else mt.inf)
other_i += 1 other_i += 1
other_yweight = (other_yweights[other_i] other_yweight = (other_yweights[other_i]
if other_i < len(other_yweights) else m.inf) if other_i < len(other_yweights) else mt.inf)
# squish so ratios are preserved # squish so ratios are preserved
self_w = sum(self.xweights) self_w = sum(self.xweights)
@@ -1117,8 +1117,8 @@ def main(csv_paths, *,
# exceeding the requested dimensions, this means we usually are less # exceeding the requested dimensions, this means we usually are less
# than the requested dimensions by quite a bit when we have many # than the requested dimensions by quite a bit when we have many
# subplots, but it's a tradeoff for a relatively simple implementation # subplots, but it's a tradeoff for a relatively simple implementation
widths = [m.floor(w*width_) for w in grid.xweights] widths = [mt.floor(w*width_) for w in grid.xweights]
heights = [m.floor(w*height_) for w in grid.yweights] heights = [mt.floor(w*height_) for w in grid.yweights]
# tweak dimensions to allow all plots to have a minimum width, # tweak dimensions to allow all plots to have a minimum width,
# this may force the plot to be larger than the requested dimensions, # this may force the plot to be larger than the requested dimensions,
+20 -19
View File
@@ -15,7 +15,7 @@ import csv
import io import io
import itertools as it import itertools as it
import logging import logging
import math as m import math as mt
import numpy as np import numpy as np
import os import os
import shlex import shlex
@@ -98,7 +98,7 @@ def si(x):
if x == 0: if x == 0:
return '0' return '0'
# figure out prefix and scale # figure out prefix and scale
p = 3*int(m.log(abs(x), 10**3)) p = 3*int(mt.log(abs(x), 10**3))
p = min(18, max(-18, p)) p = min(18, max(-18, p))
# format with 3 digits of precision # format with 3 digits of precision
s = '%.3f' % (abs(x) / (10.0**p)) s = '%.3f' % (abs(x) / (10.0**p))
@@ -114,7 +114,7 @@ def si2(x):
if x == 0: if x == 0:
return '0' return '0'
# figure out prefix and scale # figure out prefix and scale
p = 10*int(m.log(abs(x), 2**10)) p = 10*int(mt.log(abs(x), 2**10))
p = min(30, max(-30, p)) p = min(30, max(-30, p))
# format with 3 digits of precision # format with 3 digits of precision
s = '%.3f' % (abs(x) / (2.0**p)) s = '%.3f' % (abs(x) / (2.0**p))
@@ -148,7 +148,8 @@ class AutoMultipleLocator(mpl.ticker.MultipleLocator):
nbins = np.clip(self.axis.get_tick_space(), 1, 9) nbins = np.clip(self.axis.get_tick_space(), 1, 9)
# find the best power, use this as our locator's actual base # find the best power, use this as our locator's actual base
scale = self.base ** (m.ceil(m.log((vmax-vmin) / (nbins+1), self.base))) scale = self.base
** (mt.ceil(mt.log((vmax-vmin) / (nbins+1), self.base)))
self.set_params(scale) self.set_params(scale)
return super().__call__() return super().__call__()
@@ -181,7 +182,7 @@ def dat(x):
try: try:
return float(x) return float(x)
# just don't allow infinity or nan # just don't allow infinity or nan
if m.isinf(x) or m.isnan(x): if mt.isinf(x) or mt.isnan(x):
raise ValueError("invalid dat %r" % x) raise ValueError("invalid dat %r" % x)
except ValueError: except ValueError:
pass pass
@@ -352,9 +353,9 @@ class Grid:
self_i = 0 self_i = 0
other_i = 0 other_i = 0
self_xweight = (self_xweights[self_i] self_xweight = (self_xweights[self_i]
if self_i < len(self_xweights) else m.inf) if self_i < len(self_xweights) else mt.inf)
other_xweight = (other_xweights[other_i] other_xweight = (other_xweights[other_i]
if other_i < len(other_xweights) else m.inf) if other_i < len(other_xweights) else mt.inf)
while self_i < len(self_xweights) and other_i < len(other_xweights): while self_i < len(self_xweights) and other_i < len(other_xweights):
if other_xweight - self_xweight > 0.0000001: if other_xweight - self_xweight > 0.0000001:
new_xweights.append(self_xweight) new_xweights.append(self_xweight)
@@ -373,7 +374,7 @@ class Grid:
self_i += 1 self_i += 1
self_xweight = (self_xweights[self_i] self_xweight = (self_xweights[self_i]
if self_i < len(self_xweights) else m.inf) if self_i < len(self_xweights) else mt.inf)
elif self_xweight - other_xweight > 0.0000001: elif self_xweight - other_xweight > 0.0000001:
new_xweights.append(other_xweight) new_xweights.append(other_xweight)
self_xweight -= other_xweight self_xweight -= other_xweight
@@ -391,7 +392,7 @@ class Grid:
other_i += 1 other_i += 1
other_xweight = (other_xweights[other_i] other_xweight = (other_xweights[other_i]
if other_i < len(other_xweights) else m.inf) if other_i < len(other_xweights) else mt.inf)
else: else:
new_xweights.append(self_xweight) new_xweights.append(self_xweight)
@@ -403,10 +404,10 @@ class Grid:
self_i += 1 self_i += 1
self_xweight = (self_xweights[self_i] self_xweight = (self_xweights[self_i]
if self_i < len(self_xweights) else m.inf) if self_i < len(self_xweights) else mt.inf)
other_i += 1 other_i += 1
other_xweight = (other_xweights[other_i] other_xweight = (other_xweights[other_i]
if other_i < len(other_xweights) else m.inf) if other_i < len(other_xweights) else mt.inf)
# squish so ratios are preserved # squish so ratios are preserved
self_h = sum(self.yweights) self_h = sum(self.yweights)
@@ -450,9 +451,9 @@ class Grid:
self_i = 0 self_i = 0
other_i = 0 other_i = 0
self_yweight = (self_yweights[self_i] self_yweight = (self_yweights[self_i]
if self_i < len(self_yweights) else m.inf) if self_i < len(self_yweights) else mt.inf)
other_yweight = (other_yweights[other_i] other_yweight = (other_yweights[other_i]
if other_i < len(other_yweights) else m.inf) if other_i < len(other_yweights) else mt.inf)
while self_i < len(self_yweights) and other_i < len(other_yweights): while self_i < len(self_yweights) and other_i < len(other_yweights):
if other_yweight - self_yweight > 0.0000001: if other_yweight - self_yweight > 0.0000001:
new_yweights.append(self_yweight) new_yweights.append(self_yweight)
@@ -471,7 +472,7 @@ class Grid:
self_i += 1 self_i += 1
self_yweight = (self_yweights[self_i] self_yweight = (self_yweights[self_i]
if self_i < len(self_yweights) else m.inf) if self_i < len(self_yweights) else mt.inf)
elif self_yweight - other_yweight > 0.0000001: elif self_yweight - other_yweight > 0.0000001:
new_yweights.append(other_yweight) new_yweights.append(other_yweight)
self_yweight -= other_yweight self_yweight -= other_yweight
@@ -489,7 +490,7 @@ class Grid:
other_i += 1 other_i += 1
other_yweight = (other_yweights[other_i] other_yweight = (other_yweights[other_i]
if other_i < len(other_yweights) else m.inf) if other_i < len(other_yweights) else mt.inf)
else: else:
new_yweights.append(self_yweight) new_yweights.append(self_yweight)
@@ -501,10 +502,10 @@ class Grid:
self_i += 1 self_i += 1
self_yweight = (self_yweights[self_i] self_yweight = (self_yweights[self_i]
if self_i < len(self_yweights) else m.inf) if self_i < len(self_yweights) else mt.inf)
other_i += 1 other_i += 1
other_yweight = (other_yweights[other_i] other_yweight = (other_yweights[other_i]
if other_i < len(other_yweights) else m.inf) if other_i < len(other_yweights) else mt.inf)
# squish so ratios are preserved # squish so ratios are preserved
self_w = sum(self.xweights) self_w = sum(self.xweights)
@@ -978,7 +979,7 @@ def main(csv_paths, output, *,
# try different column counts until we fit in the axes # try different column counts until we fit in the axes
for ncol in reversed(range(1, len(legend)+1)): for ncol in reversed(range(1, len(legend)+1)):
# permute the labels, mpl wants to order these column first # permute the labels, mpl wants to order these column first
nrow = m.ceil(len(legend)/ncol) nrow = mt.ceil(len(legend)/ncol)
legend_ = ncol*nrow*[None] legend_ = ncol*nrow*[None]
for x in range(ncol): for x in range(ncol):
for y in range(nrow): for y in range(nrow):
@@ -1012,7 +1013,7 @@ def main(csv_paths, output, *,
# try different column counts until we fit in the axes # try different column counts until we fit in the axes
for ncol in reversed(range(1, len(legend)+1)): for ncol in reversed(range(1, len(legend)+1)):
# permute the labels, mpl wants to order these column first # permute the labels, mpl wants to order these column first
nrow = m.ceil(len(legend)/ncol) nrow = mt.ceil(len(legend)/ncol)
legend_ = ncol*nrow*[None] legend_ = ncol*nrow*[None]
for x in range(ncol): for x in range(ncol):
for y in range(nrow): for y in range(nrow):
+23 -23
View File
@@ -13,7 +13,7 @@
import collections as co import collections as co
import csv import csv
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import re import re
@@ -31,24 +31,24 @@ class RInt(co.namedtuple('RInt', 'x')):
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf x = -mt.inf
else: else:
raise raise
assert isinstance(x, int) or m.isinf(x), x assert isinstance(x, int) or mt.isinf(x), x
return super().__new__(cls, x) return super().__new__(cls, x)
def __str__(self): def __str__(self):
if self.x == m.inf: if self.x == mt.inf:
return '' return ''
elif self.x == -m.inf: elif self.x == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.x)
def __int__(self): def __int__(self):
assert not m.isinf(self.x) assert not mt.isinf(self.x)
return self.x return self.x
def __float__(self): def __float__(self):
@@ -62,9 +62,9 @@ class RInt(co.namedtuple('RInt', 'x')):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other else 0 old = other.x if other else 0
diff = new - old diff = new - old
if diff == +m.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
elif diff == -m.inf: elif diff == -mt.inf:
return '%7s' % '-∞' return '%7s' % '-∞'
else: else:
return '%+7d' % diff return '%+7d' % diff
@@ -72,16 +72,16 @@ class RInt(co.namedtuple('RInt', 'x')):
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other 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 return 0.0
elif m.isinf(new): elif mt.isinf(new):
return +m.inf return +mt.inf
elif m.isinf(old): elif mt.isinf(old):
return -m.inf return -mt.inf
elif not old and not new: elif not old and not new:
return 0.0 return 0.0
elif not old: elif not old:
return +m.inf return +mt.inf
else: else:
return (new-old) / old return (new-old) / old
@@ -251,7 +251,7 @@ def collect(ci_paths, *,
for target in targets: for target in targets:
# found a cycle? # found a cycle?
if target in seen: if target in seen:
return m.inf return mt.inf
limit_ = find_limit(target, seen | {target}) limit_ = find_limit(target, seen | {target})
limit = max(limit, limit_) limit = max(limit, limit_)
@@ -438,8 +438,8 @@ def table(Result, results, diff_results=None, *,
(getattr(r, k).table() (getattr(r, k).table()
if getattr(r, k, None) is not None if getattr(r, k, None) is not None
else types[k].none, else types[k].none,
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)])( else ['%+.1f%%' % (100*t)])(
types[k].ratio( types[k].ratio(
getattr(r, k, None), getattr(r, k, None),
@@ -458,8 +458,8 @@ def table(Result, results, diff_results=None, *,
(types[k].diff( (types[k].diff(
getattr(r, k, None), getattr(r, k, None),
getattr(diff_r, k, None)), getattr(diff_r, k, None)),
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)] if t else ['%+.1f%%' % (100*t)] if t
else [])( else [])(
types[k].ratio( types[k].ratio(
@@ -579,9 +579,9 @@ def main(ci_paths,
**args): **args):
# figure out depth # figure out depth
if args.get('depth') is None: 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: elif args.get('depth') == 0:
args['depth'] = m.inf args['depth'] = mt.inf
# find sizes # find sizes
if not args.get('use', None): if not args.get('use', None):
@@ -674,7 +674,7 @@ def main(ci_paths,
# error on recursion # error on recursion
if args.get('error_on_recursion') and any( 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) sys.exit(2)
+19 -19
View File
@@ -13,7 +13,7 @@ import collections as co
import csv import csv
import difflib import difflib
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import re import re
import shlex import shlex
@@ -36,24 +36,24 @@ class RInt(co.namedtuple('RInt', 'x')):
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf x = -mt.inf
else: else:
raise raise
assert isinstance(x, int) or m.isinf(x), x assert isinstance(x, int) or mt.isinf(x), x
return super().__new__(cls, x) return super().__new__(cls, x)
def __str__(self): def __str__(self):
if self.x == m.inf: if self.x == mt.inf:
return '' return ''
elif self.x == -m.inf: elif self.x == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.x)
def __int__(self): def __int__(self):
assert not m.isinf(self.x) assert not mt.isinf(self.x)
return self.x return self.x
def __float__(self): def __float__(self):
@@ -67,9 +67,9 @@ class RInt(co.namedtuple('RInt', 'x')):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other else 0 old = other.x if other else 0
diff = new - old diff = new - old
if diff == +m.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
elif diff == -m.inf: elif diff == -mt.inf:
return '%7s' % '-∞' return '%7s' % '-∞'
else: else:
return '%+7d' % diff return '%+7d' % diff
@@ -77,16 +77,16 @@ class RInt(co.namedtuple('RInt', 'x')):
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other 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 return 0.0
elif m.isinf(new): elif mt.isinf(new):
return +m.inf return +mt.inf
elif m.isinf(old): elif mt.isinf(old):
return -m.inf return -mt.inf
elif not old and not new: elif not old and not new:
return 0.0 return 0.0
elif not old: elif not old:
return +m.inf return +mt.inf
else: else:
return (new-old) / old return (new-old) / old
@@ -395,8 +395,8 @@ def table(Result, results, diff_results=None, *,
(getattr(r, k).table() (getattr(r, k).table()
if getattr(r, k, None) is not None if getattr(r, k, None) is not None
else types[k].none, else types[k].none,
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)])( else ['%+.1f%%' % (100*t)])(
types[k].ratio( types[k].ratio(
getattr(r, k, None), getattr(r, k, None),
@@ -415,8 +415,8 @@ def table(Result, results, diff_results=None, *,
(types[k].diff( (types[k].diff(
getattr(r, k, None), getattr(r, k, None),
getattr(diff_r, k, None)), getattr(diff_r, k, None)),
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)] if t else ['%+.1f%%' % (100*t)] if t
else [])( else [])(
types[k].ratio( types[k].ratio(
+35 -33
View File
@@ -16,7 +16,7 @@ import collections as co
import csv import csv
import functools as ft import functools as ft
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import re import re
@@ -27,20 +27,22 @@ import re
# #
OPS = { OPS = {
'sum': lambda xs: sum(xs[1:], start=xs[0]), 'sum': lambda xs: sum(xs[1:], start=xs[0]),
'prod': lambda xs: m.prod(xs[1:], start=xs[0]), 'prod': lambda xs: mt.prod(xs[1:], start=xs[0]),
'min': min, 'min': min,
'max': max, 'max': max,
'avg': lambda xs: RFloat(sum(float(x) for x in xs) / len(xs)), 'avg': lambda xs: RFloat(sum(float(x) for x in xs) / len(xs)),
'stddev': lambda xs: ( 'stddev': lambda xs: (
lambda avg: RFloat( lambda avg: RFloat(
m.sqrt(sum((float(x) - avg)**2 for x in xs) / len(xs))) mt.sqrt(sum((float(x) - avg)**2 for x in xs) / len(xs)))
)(sum(float(x) for x in xs) / len(xs)), )(sum(float(x) for x in xs) / len(xs)),
'gmean': lambda xs: RFloat(m.prod(float(x) for x in xs)**(1/len(xs))), 'gmean': lambda xs: RFloat(mt.prod(float(x) for x in xs)**(1/len(xs))),
'gstddev': lambda xs: ( 'gstddev': lambda xs: (
lambda gmean: RFloat( lambda gmean: RFloat(
m.exp(m.sqrt(sum(m.log(float(x)/gmean)**2 for x in xs) / len(xs))) mt.exp(mt.sqrt(
if gmean else m.inf) sum(mt.log(float(x)/gmean)**2 for x in xs)
)(m.prod(float(x) for x in xs)**(1/len(xs))), / len(xs)))
if gmean else mt.inf)
)(mt.prod(float(x) for x in xs)**(1/len(xs))),
} }
@@ -56,24 +58,24 @@ class RInt(co.namedtuple('RInt', 'x')):
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf x = -mt.inf
else: else:
raise raise
assert isinstance(x, int) or m.isinf(x), x assert isinstance(x, int) or mt.isinf(x), x
return super().__new__(cls, x) return super().__new__(cls, x)
def __str__(self): def __str__(self):
if self.x == m.inf: if self.x == mt.inf:
return '' return ''
elif self.x == -m.inf: elif self.x == -mt.inf:
return '-∞' return '-∞'
else: else:
return str(self.x) return str(self.x)
def __int__(self): def __int__(self):
assert not m.isinf(self.x) assert not mt.isinf(self.x)
return self.x return self.x
def __float__(self): def __float__(self):
@@ -87,9 +89,9 @@ class RInt(co.namedtuple('RInt', 'x')):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other else 0 old = other.x if other else 0
diff = new - old diff = new - old
if diff == +m.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
elif diff == -m.inf: elif diff == -mt.inf:
return '%7s' % '-∞' return '%7s' % '-∞'
else: else:
return '%+7d' % diff return '%+7d' % diff
@@ -97,16 +99,16 @@ class RInt(co.namedtuple('RInt', 'x')):
def ratio(self, other): def ratio(self, other):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other 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 return 0.0
elif m.isinf(new): elif mt.isinf(new):
return +m.inf return +mt.inf
elif m.isinf(old): elif mt.isinf(old):
return -m.inf return -mt.inf
elif not old and not new: elif not old and not new:
return 0.0 return 0.0
elif not old: elif not old:
return +m.inf return +mt.inf
else: else:
return (new-old) / old return (new-old) / old
@@ -131,18 +133,18 @@ class RFloat(co.namedtuple('RFloat', 'x')):
except ValueError: except ValueError:
# also accept +-∞ and +-inf # also accept +-∞ and +-inf
if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x): if re.match('^\s*\+?\s*(?:∞|inf)\s*$', x):
x = m.inf x = mt.inf
elif re.match('^\s*-\s*(?:∞|inf)\s*$', x): elif re.match('^\s*-\s*(?:∞|inf)\s*$', x):
x = -m.inf x = -mt.inf
else: else:
raise raise
assert isinstance(x, float), x assert isinstance(x, float), x
return super().__new__(cls, x) return super().__new__(cls, x)
def __str__(self): def __str__(self):
if self.x == m.inf: if self.x == mt.inf:
return '' return ''
elif self.x == -m.inf: elif self.x == -mt.inf:
return '-∞' return '-∞'
else: else:
return '%.1f' % self.x return '%.1f' % self.x
@@ -157,9 +159,9 @@ class RFloat(co.namedtuple('RFloat', 'x')):
new = self.x if self else 0 new = self.x if self else 0
old = other.x if other else 0 old = other.x if other else 0
diff = new - old diff = new - old
if diff == +m.inf: if diff == +mt.inf:
return '%7s' % '+∞' return '%7s' % '+∞'
elif diff == -m.inf: elif diff == -mt.inf:
return '%7s' % '-∞' return '%7s' % '-∞'
else: else:
return '%+7.1f' % diff return '%+7.1f' % diff
@@ -193,8 +195,8 @@ class RFrac(co.namedtuple('RFrac', 'a,b')):
def notes(self): def notes(self):
t = self.a.x/self.b.x if self.b.x else 1.0 t = self.a.x/self.b.x if self.b.x else 1.0
return ['%' if t == +m.inf return ['%' if t == +mt.inf
else '-∞%' if t == -m.inf else '-∞%' if t == -mt.inf
else '%.1f%%' % (100*t)] else '%.1f%%' % (100*t)]
def diff(self, other): def diff(self, other):
@@ -526,8 +528,8 @@ def table(Result, results, diff_results=None, *,
(getattr(r, k).table() (getattr(r, k).table()
if getattr(r, k, None) is not None if getattr(r, k, None) is not None
else types[k].none, else types[k].none,
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)])( else ['%+.1f%%' % (100*t)])(
types[k].ratio( types[k].ratio(
getattr(r, k, None), getattr(r, k, None),
@@ -546,8 +548,8 @@ def table(Result, results, diff_results=None, *,
(types[k].diff( (types[k].diff(
getattr(r, k, None), getattr(r, k, None),
getattr(diff_r, k, None)), getattr(diff_r, k, None)),
(lambda t: ['+∞%'] if t == +m.inf (lambda t: ['+∞%'] if t == +mt.inf
else ['-∞%'] if t == -m.inf else ['-∞%'] if t == -mt.inf
else ['%+.1f%%' % (100*t)] if t else ['%+.1f%%' % (100*t)] if t
else [])( else [])(
types[k].ratio( types[k].ratio(
+1 -1
View File
@@ -14,7 +14,7 @@ import csv
import errno import errno
import fnmatch import fnmatch
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import pty import pty
import re import re
+6 -6
View File
@@ -13,7 +13,7 @@ import collections as co
import functools as ft import functools as ft
import io import io
import itertools as it import itertools as it
import math as m import math as mt
import os import os
import re import re
import shutil import shutil
@@ -257,9 +257,9 @@ def lebesgue_curve(width, height):
# we create a truncated Z-curve by simply filtering out the points # we create a truncated Z-curve by simply filtering out the points
# that are outside our region # that are outside our region
curve = [] curve = []
for i in range(2**(2*m.ceil(m.log2(max(width, height))))): for i in range(2**(2*mt.ceil(mt.log2(max(width, height))))):
# we just operate on binary strings here because it's easier # we just operate on binary strings here because it's easier
b = '{:0{}b}'.format(i, 2*m.ceil(m.log2(i+1)/2)) b = '{:0{}b}'.format(i, 2*mt.ceil(mt.log2(i+1)/2))
x = int(b[1::2], 2) if b[1::2] else 0 x = int(b[1::2], 2) if b[1::2] else 0
y = int(b[0::2], 2) if b[0::2] else 0 y = int(b[0::2], 2) if b[0::2] else 0
if x < width and y < height: if x < width and y < height:
@@ -935,8 +935,8 @@ def main(path='-', *,
# don't forget we've scaled this for braille/dots! # don't forget we've scaled this for braille/dots!
for row in range( for row in range(
m.ceil(bmap.height/4) if braille mt.ceil(bmap.height/4) if braille
else m.ceil(bmap.height/2) if dots else mt.ceil(bmap.height/2) if dots
else bmap.height): else bmap.height):
line = bmap.draw(row, line = bmap.draw(row,
read=read, read=read,
@@ -966,7 +966,7 @@ def main(path='-', *,
if wear: if wear:
mean = (sum(p.wear for p in bmap.pixels) mean = (sum(p.wear for p in bmap.pixels)
/ max(len(bmap.pixels), 1)) / max(len(bmap.pixels), 1))
stddev = m.sqrt(sum((p.wear - mean)**2 for p in bmap.pixels) stddev = mt.sqrt(sum((p.wear - mean)**2 for p in bmap.pixels)
/ max(len(bmap.pixels), 1)) / max(len(bmap.pixels), 1))
worst = max((p.wear for p in bmap.pixels), default=0) worst = max((p.wear for p in bmap.pixels), default=0)