Skip to content

Commit 478caac

Browse files
committed
Fix formatting of our Python scripts.
1 parent cc04113 commit 478caac

File tree

7 files changed

+118
-33
lines changed

7 files changed

+118
-33
lines changed

lexical-benchmark/etc/plot.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import argparse
1111
import json
1212
import os
13-
import re
1413

1514
import matplotlib.pyplot as plt
1615
import matplotlib.ticker as ticker
@@ -21,6 +20,7 @@
2120
etc = os.path.dirname(os.path.realpath(__file__))
2221
home = os.path.dirname(etc)
2322

23+
2424
def parse_args(argv=None):
2525
'''Create and parse our command line arguments.'''
2626

@@ -42,6 +42,7 @@ def parse_args(argv=None):
4242
)
4343
return parser.parse_args(argv)
4444

45+
4546
def filename(basename, args):
4647
'''Get a resilient name for the benchmark data.'''
4748

@@ -52,6 +53,7 @@ def filename(basename, args):
5253
name = f'{name}_features={args.features}'
5354
return name
5455

56+
5557
def format_time(time):
5658
'''Format time to be a nice value.'''
5759

@@ -71,14 +73,17 @@ def strip_zero(value):
7173
time /= 1000
7274
return f'{strip_zero(str(round(time, 3)))} s'
7375

76+
7477
def float_sort_key(x):
7578
'''Sort key for an float value.'''
7679
return (x[0], int(x[1:]))
7780

81+
7882
def integer_sort_key(x):
7983
'''Sort key for an integral value.'''
8084
return (x[0], int(x[1:]))
8185

86+
8287
def plot_bar(
8388
prefix=None,
8489
xlabel=None,
@@ -115,13 +120,13 @@ def plot_ax(ax, xticks):
115120
ax.legend(libraries, fancybox=True, framealpha=1, shadow=True, borderpad=1)
116121

117122
fig = plt.figure(figsize=(10, 8))
118-
index = 1
119123
ax = fig.add_subplot(1, 1, 1)
120124
plot_ax(ax, xticks)
121125

122126
fig.savefig(path, format='svg')
123127
fig.clf()
124128

129+
125130
def plot_scatter(
126131
prefix=None,
127132
xlabel=None,
@@ -146,7 +151,7 @@ def plot_ax(ax, xticks):
146151

147152
for library in libraries:
148153
ys = [data[f'{prefix}_{i}_{library}'] for i in xticks]
149-
points = ax.semilogy(
154+
_ = ax.semilogy(
150155
xticks, ys, '-o', mec='k', ms=15,
151156
mew=1, alpha=.8, label=library
152157
)
@@ -170,6 +175,7 @@ def plot_ax(ax, xticks):
170175
fig.savefig(path, format='svg')
171176
fig.clf()
172177

178+
173179
def plot_write_float(args):
174180
'''Plot the write float dataset.'''
175181

@@ -235,6 +241,7 @@ def plot_write_float(args):
235241
title='Random Data: BigInts',
236242
)
237243

244+
238245
def plot_write_integer(args):
239246
'''Plot the write integer dataset.'''
240247

@@ -301,6 +308,7 @@ def plot_write_integer(args):
301308
title='Random Data: Large Negative',
302309
)
303310

311+
304312
def plot_parse_float(args):
305313
'''Plot the parse float dataset.'''
306314

@@ -392,6 +400,7 @@ def plot_parse_float(args):
392400
key=lambda x: int(x),
393401
)
394402

403+
395404
def plot_parse_integer(args):
396405
'''Plot the parse integer dataset.'''
397406

@@ -452,6 +461,7 @@ def plot_parse_integer(args):
452461
title='Random Data: Large Negative',
453462
)
454463

464+
455465
def main(argv=None):
456466
'''Entry point.'''
457467

@@ -469,5 +479,6 @@ def main(argv=None):
469479
else:
470480
raise NotImplementedError
471481

482+
472483
if __name__ == '__main__':
473484
main()

lexical-benchmark/etc/run.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
etc = os.path.dirname(os.path.realpath(__file__))
1717
home = os.path.dirname(etc)
1818

19+
1920
def parse_args(argv=None):
2021
'''Create and parse our command line arguments.'''
2122

@@ -42,6 +43,7 @@ def parse_args(argv=None):
4243
)
4344
return parser.parse_args(argv)
4445

46+
4547
def filename(basename, args):
4648
'''Get a resilient name for the benchmark data.'''
4749

@@ -52,6 +54,7 @@ def filename(basename, args):
5254
name = f'{name}_features={args.features}'
5355
return name
5456

57+
5558
@contextlib.contextmanager
5659
def change_directory(path):
5760
'''Change directory and return to the original directory afterwards.'''
@@ -63,6 +66,7 @@ def change_directory(path):
6366
finally:
6467
os.chdir(cwd)
6568

69+
6670
def process_rust_benchmark(line):
6771
'''Process the result of an individual Rust benchmark.'''
6872

@@ -83,6 +87,7 @@ def process_rust_benchmark(line):
8387

8488
return group, name, speed
8589

90+
8691
def run_benchmark(args):
8792
'''Run a single benchmark.'''
8893

@@ -109,6 +114,7 @@ def run_benchmark(args):
109114

110115
return data
111116

117+
112118
def main(argv=None):
113119
'''Entry point.'''
114120

@@ -121,5 +127,6 @@ def main(argv=None):
121127
with open(f'{home}/results/{filename(bench, args)}.json', 'w') as file:
122128
json.dump(data, file)
123129

130+
124131
if __name__ == '__main__':
125132
main()

lexical-parse-float/etc/correctness/test-parse-unittests/to_toml.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
# FLOAT HELPERS
3838
# -------------
3939

40+
4041
class FloatMixin:
4142
'''Mixing for floating-point methods.'''
4243

@@ -87,13 +88,13 @@ def mantissa(self):
8788
class Float32(FloatMixin):
8889
'''Wrapper around a 32-bit floating point value.'''
8990

90-
SIGN_MASK = np.uint32(0x80000000)
91-
EXPONENT_MASK = np.uint32(0x7F800000)
92-
HIDDEN_BIT_MASK = np.uint32(0x00800000)
93-
MANTISSA_MASK = np.uint32(0x007FFFFF)
94-
MANTISSA_SIZE = np.int32(23)
95-
EXPONENT_BIAS = np.int32(127 + MANTISSA_SIZE)
96-
DENORMAL_EXPONENT = np.int32(1 - EXPONENT_BIAS)
91+
SIGN_MASK = np.uint32(0x80000000) # noqa
92+
EXPONENT_MASK = np.uint32(0x7F800000) # noqa
93+
HIDDEN_BIT_MASK = np.uint32(0x00800000) # noqa
94+
MANTISSA_MASK = np.uint32(0x007FFFFF) # noqa
95+
MANTISSA_SIZE = np.int32(23) # noqa
96+
EXPONENT_BIAS = np.int32(127 + MANTISSA_SIZE) # noqa
97+
DENORMAL_EXPONENT = np.int32(1 - EXPONENT_BIAS) # noqa
9798

9899
def __init__(self, value):
99100
self.value = np.float32(value)
@@ -103,13 +104,13 @@ def __init__(self, value):
103104
class Float64(FloatMixin):
104105
'''Wrapper around a 64-bit floating point value.'''
105106

106-
SIGN_MASK = np.uint64(0x8000000000000000)
107-
EXPONENT_MASK = np.uint64(0x7FF0000000000000)
108-
HIDDEN_BIT_MASK = np.uint64(0x0010000000000000)
109-
MANTISSA_MASK = np.uint64(0x000FFFFFFFFFFFFF)
110-
MANTISSA_SIZE = np.int32(52)
111-
EXPONENT_BIAS = np.int32(1023 + MANTISSA_SIZE)
112-
DENORMAL_EXPONENT = np.int32(1 - EXPONENT_BIAS)
107+
SIGN_MASK = np.uint64(0x8000000000000000) # noqa
108+
EXPONENT_MASK = np.uint64(0x7FF0000000000000) # noqa
109+
HIDDEN_BIT_MASK = np.uint64(0x0010000000000000) # noqa
110+
MANTISSA_MASK = np.uint64(0x000FFFFFFFFFFFFF) # noqa
111+
MANTISSA_SIZE = np.int32(52) # noqa
112+
EXPONENT_BIAS = np.int32(1023 + MANTISSA_SIZE) # noqa
113+
DENORMAL_EXPONENT = np.int32(1 - EXPONENT_BIAS) # noqa
113114

114115
def __init__(self, value):
115116
self.value = np.float64(value)
@@ -180,6 +181,7 @@ def test_mantissa(self):
180181
float32 = Float32("1e-45")
181182
self.assertEqual(float32.mantissa(), np.uint32(1))
182183

184+
183185
class TestFloat64(unittest.TestCase):
184186

185187
def test_to_bits(self):
@@ -249,6 +251,7 @@ def run_tests():
249251
'''Run unittest suite.'''
250252
unittest.main(argv=sys.argv[:1])
251253

254+
252255
def create_test(test):
253256
'''Create conversion test table.'''
254257

@@ -263,6 +266,7 @@ def create_test(test):
263266

264267
return conversion_test
265268

269+
266270
def main(source, destination):
267271
'''Run main script.'''
268272

@@ -284,6 +288,7 @@ def main(source, destination):
284288
with open(destination, 'w') as fout:
285289
print(tomlkit.dumps(document), file=fout)
286290

291+
287292
if __name__ == '__main__':
288293
args = parser.parse_args()
289294
if args.test:

lexical-parse-float/etc/powers_table.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,19 @@ def print_large(radix, max_exp):
8181
print(f'pub const LARGE_POW{radix}: [u32; {len(limb32)}] = [')
8282
for value in limb32:
8383
print(f' {value},')
84-
print(f'];')
85-
print(f'')
84+
print('];')
85+
print('')
8686

8787
print(f'/// Pre-computed large power-of-{radix} for 64-bit limbs.')
8888
print('#[cfg(all(target_pointer_width = "64", not(target_arch = "sparc")))]')
8989
print(f'pub const LARGE_POW{radix}: [u64; {len(limb64)}] = [')
9090
for value in limb64:
9191
print(f' {value},')
92-
print(f'];')
93-
print(f'')
92+
print('];')
93+
print('')
9494
print(f'/// Step for large power-of-{radix} for 32-bit limbs.')
9595
print(f'pub const LARGE_POW{radix}_STEP: u32 = {5 * max_exp};')
96-
print(f'')
96+
print('')
9797

9898

9999
def print_tables(radix, f64_pow_limit, f32_exp_limit, f64_exp_limit):
@@ -106,11 +106,11 @@ def print_tables(radix, f64_pow_limit, f32_exp_limit, f64_exp_limit):
106106

107107
def f32_exponent_limit(radix):
108108
return {
109-
3 : (-15, 15),
110-
5 : (-10, 10),
111-
6 : (-15, 15),
112-
7 : (-8, 8),
113-
9 : (-7, 7),
109+
3 : (-15, 15), # noqa
110+
5 : (-10, 10), # noqa
111+
6 : (-15, 15), # noqa
112+
7 : (-8, 8), # noqa
113+
9 : (-7, 7), # noqa
114114
11: (-6, 6),
115115
12: (-15, 15),
116116
13: (-6, 6),
@@ -206,7 +206,10 @@ def f64_power_limit(radix):
206206
}[radix]
207207

208208

209-
radixes = [3, 5, 6, 7, 9, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36]
209+
radixes = [
210+
3, 5, 6, 7, 9, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21,
211+
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36
212+
]
210213
for radix in radixes:
211214
f64_pow_limit = f64_power_limit(radix)
212215
f32_exp_limit = f32_exponent_limit(radix)[1]

0 commit comments

Comments
 (0)