mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-12-07 16:12:47 +00:00
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:
@@ -16,7 +16,7 @@ import collections as co
|
||||
import csv
|
||||
import difflib
|
||||
import itertools as it
|
||||
import math as m
|
||||
import math as mt
|
||||
import os
|
||||
import re
|
||||
import shlex
|
||||
@@ -40,24 +40,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):
|
||||
@@ -71,9 +71,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
|
||||
@@ -81,16 +81,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
|
||||
|
||||
@@ -446,8 +446,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),
|
||||
@@ -466,8 +466,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(
|
||||
|
||||
Reference in New Issue
Block a user