-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutilities.py
More file actions
66 lines (49 loc) · 1.76 KB
/
utilities.py
File metadata and controls
66 lines (49 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
import concurrent.futures
import enum
import re
from colorama import Fore, Style
from tqdm import tqdm
type_to_format = {
"i8": "b", # signed char
"i16": "h",
"i32": "i",
"i64": "q",
}
class Combination(enum.Enum):
HORIZONTAL = 1
VERTICAL = 2
ANY = 3
def get_type(identifier):
m = re.match(r"llvm_v([0-9]+)([if])([0-9]+)_ty", identifier)
if m:
# Vector type
width = int(m.group(1))
element_i_f = m.group(2)
element_bits = int(m.group(3))
element_type = "{}{}".format(element_i_f, element_bits)
if element_type == "f64":
element_type = "double"
elif element_type == "f32":
element_type = "float"
return "<{width} x {element_type}>".format(**locals()), width, element_type, element_bits
m = re.match(r"llvm_([if])([0-9]+)_ty", identifier)
if m:
# Scalar type
ty = m.group(1) + m.group(2)
return ty, 1, m.group(1), int(m.group(2))
# TODO: Possibly remove support for MMX
#if identifier == "llvm_x86mmx_ty":
# return "<1 x i64>", 1, "i64", 64
raise TypeError(Fore.RED + "Bad type: {}".format(identifier) + Style.RESET_ALL)
# https://techoverflow.net/2017/05/18/how-to-use-concurrent-futures-map-with-a-tqdm-progress-bar/
def tqdm_parallel_map(executor, fn, iterable, **kwargs):
"""
Equivalent to executor.map(fn, iterable),
but displays a tqdm-based progress bar.
Does not support timeout or chunksize as executor.submit is used internally
**kwargs is passed to tqdm.
"""
futures_list = [executor.submit(fn, i) for i in iterable]
for f in tqdm(concurrent.futures.as_completed(futures_list), total=len(futures_list), **kwargs):
yield f.result()