MCPcopy Create free account
hub / github.com/PythonOT/POT / convert_to_html_table

Function convert_to_html_table

benchmarks/benchmark.py:52–105  ·  view source on GitHub ↗
(results, param_name, main_title=None, comments=None)

Source from the content-addressed store, hash-verified

50
51
52def convert_to_html_table(results, param_name, main_title=None, comments=None):
53 string = "<table>\n"
54 keys = list(results.keys())
55 params, names, devices, bitsizes = zip(*keys)
56
57 devices_names = sorted(list(set(zip(devices, names))))
58 params = sorted(list(set(params)))
59 bitsizes = sorted(list(set(bitsizes)))
60 length = len(devices_names) + 1
61 cpus_cols = list(devices).count("CPU") / len(bitsizes) / len(params)
62 gpus_cols = list(devices).count("GPU") / len(bitsizes) / len(params)
63 assert cpus_cols + gpus_cols == len(devices_names)
64
65 if main_title is not None:
66 string += (
67 f'<tr><th align="center" colspan="{length}">{str(main_title)}</th></tr>\n'
68 )
69
70 for i, bitsize in enumerate(bitsizes):
71 if i != 0:
72 string += f'<tr><td colspan="{length}">&nbsp;</td></tr>\n'
73
74 # make bitsize header
75 text = f"{bitsize} bits"
76 if comments is not None:
77 text += " - "
78 if isinstance(comments, (tuple, list)) and len(comments) == len(bitsizes):
79 text += str(comments[i])
80 else:
81 text += str(comments)
82 string += f'<tr><th align="center">Bitsize</th>'
83 string += f'<th align="center" colspan="{length - 1}">{text}</th></tr>\n'
84
85 # make device header
86 string += f'<tr><th align="center">Device</th>'
87 string += f'<th align="center" colspan="{cpus_cols}">CPU</th>'
88 string += f'<th align="center" colspan="{gpus_cols}">GPU</th></tr>\n'
89
90 # make param_name / backend header
91 string += f'<tr><th align="center">{param_name}</th>'
92 for device, name in devices_names:
93 string += f'<th align="center">{name}</th>'
94 string += "</tr>\n"
95
96 # make results rows
97 for param in params:
98 string += f'<tr><td align="center">{param}</td>'
99 for device, name in devices_names:
100 key = (param, name, device, bitsize)
101 string += f'<td align="center">{results[key]:.4f}</td>'
102 string += "</tr>\n"
103
104 string += "</table>"
105 return string

Callers 2

sinkhorn_knopp.pyFile · 0.85
emd.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected