-
Notifications
You must be signed in to change notification settings - Fork 2
/
_tempita_grid_gen.py
158 lines (138 loc) · 3.95 KB
/
_tempita_grid_gen.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import pickle
from itertools import product
### OPTIONS
## Columns of the matrix backend.
# with ordered by their performance on some synthetic benchmarks.
columns_name = [ # only one column is necessary
"Available_columns::" + stuff
for stuff in (
"INTRUSIVE_SET",
# "SET",
# "HEAP",
# "UNORDERED_SET",
# "NAIVE_VECTOR",
# "VECTOR",
# "INTRUSIVE_LIST",
# "LIST",
"SMALL_VECTOR",
)
]
## Value types : CTYPE, PYTHON_TYPE, short
value_types = [
("int32_t", "np.int32", "i32"), # necessary
("int64_t", "np.int64", "i64"),
("float", "np.float32", "f32"), # necessary for mma (TODO: fixme)
("double", "np.float64", "f64"), # necessary
]
## True, False necessary
vineyards_values = [
#
True,
False,
]
## Kcritical Filtrations
kcritical_options = [
#
True,
False,
]
##
matrix_types = [
#
"Matrix",
# "Graph",
# "Clement",
"GudhiCohomology",
]
def check_combination(backend_type, is_vine, is_kcritical, value_type, column_type):
if backend_type in ["Clement", "Graph"]:
if not is_vine:
return False
if backend_type in ["GudhiCohomology"]:
if is_vine:
return False
if backend_type in ["Graph", "GudhiCohomology"]:
if column_type[0] != 0:
return False
return True
def get_slicer(backend_type, is_vine, is_kcritical, value_type, column_type):
stuff = locals()
ctype, pytype, short_type = value_type
col_idx, col = column_type
PYTHON_TYPE = f"_{'K' if is_kcritical else ''}Slicer_{backend_type}{col_idx}{'_vine' if is_vine else ''}_{short_type}"
CTYPE = f"TrucPythonInterface<BackendsEnum::{backend_type},{'true' if is_vine else 'false'},{'true' if is_kcritical else 'false'},{ctype},{col}>"
IS_SIMPLICIAL = False
IS_VINE = is_vine
IS_KCRITICAL = is_kcritical
FILTRATION_TYPE = (
("Multi_critical_filtration" if is_kcritical else "One_critical_filtration")
+ "["
+ ctype
+ "]"
)
return {
"TRUC_TYPE": CTYPE,
"C_TEMPLATE_TYPE": "C" + PYTHON_TYPE,
"PYTHON_TYPE": PYTHON_TYPE,
"IS_SIMPLICIAL": IS_SIMPLICIAL,
"IS_VINE": IS_VINE,
"IS_KCRITICAL": IS_KCRITICAL,
"C_VALUE_TYPE": ctype,
"PY_VALUE_TYPE": pytype,
"COLUMN_TYPE": col.split("::")[1],
"SHORT_VALUE_TYPE": short_type,
"FILTRATION_TYPE": FILTRATION_TYPE,
"PERS_BACKEND_TYPE": backend_type,
"IS_FLOAT": short_type[0] == "f",
}
# {{for CTYPE_H, CTYPE,PYTHON_TYPE, IS_SIMPLICIAL, IS_VINE, IS_KCRITICAL, C_VALUE_TYPE, PY_VALUE_TYPE, COL, SHORT,FILTRATION_TYPE in slicers}}
slicers = [
get_slicer(**kwargs)
for backend_type, is_vine, is_kcritical, value_type, column_type in product(
matrix_types,
vineyards_values,
kcritical_options,
value_types,
enumerate(columns_name),
)
if check_combination(
**(
kwargs := {
"backend_type": backend_type,
"is_vine": is_vine,
"is_kcritical": is_kcritical,
"value_type": value_type,
"column_type": column_type,
}
)
)
]
for D in slicers:
print(D)
with open("build/tmp/_slicer_names.pkl", "wb") as f:
pickle.dump(slicers, f)
## Simplextree
Filtrations_types = [
(
("Multi_critical_filtration", True)
if kcritical
else ("One_critical_filtration", False)
)
for kcritical in kcritical_options
]
## CTYPE, PYTYPE, SHORT, FILTRATION
to_iter = [
(
CTYPE,
PYTYPE,
SHORT,
Filtration + "[" + CTYPE + "]",
is_kcritical,
("K" if is_kcritical else "") + "F" + SHORT,
)
for (CTYPE, PYTYPE, SHORT), (Filtration, is_kcritical) in product(
value_types, Filtrations_types
)
]
with open("build/tmp/_simplextrees_.pkl", "wb") as f:
pickle.dump(to_iter, f)