-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.py
More file actions
45 lines (34 loc) · 1.29 KB
/
utils.py
File metadata and controls
45 lines (34 loc) · 1.29 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
'''
Copyright (C) 2020 Daniel Duque (see license.txt)
'''
import numpy as np
import time
def make_patch_spines_invisible(ax):
ax.set_frame_on(True)
ax.patch.set_visible(False)
for sp in ax.spines.values():
sp.set_visible(False)
def roundup(x, l):
return int(np.ceil(x / l)) * l
def round_closest(x, l):
return int(np.around(x / l)) * l
def timeit(method):
def timed(*args, **kw):
ts = time.time()
result = method(*args, **kw)
te = time.time()
if 'log_time' in kw and kw['log_time'] is not None:
name = kw.get('log_name', method.__name__.upper())
call_time = (te - ts)
if name not in kw['log_time']:
kw['log_time'][name] = {'calls': 1, 'max_time': call_time, 'avg_time': call_time}
else:
avg = kw['log_time'][name]['avg_time']
calls = kw['log_time'][name]['calls']
kw['log_time'][name]['avg_time'] = (avg * calls + call_time) / (calls + 1)
kw['log_time'][name]['calls'] = calls + 1
kw['log_time'][name]['max_time'] = np.maximum(kw['log_time'][name]['max_time'], call_time)
else:
print(f'{method.__name__}: {(te - ts): 10.5f} s')
return result
return timed