-
Notifications
You must be signed in to change notification settings - Fork 0
/
metric.py
56 lines (39 loc) · 954 Bytes
/
metric.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
import math
import time
class metric(object):
@staticmethod
def get1Norm(a: []):
'''
sum of absolute value
'''
return sum(map(abs, a))
@staticmethod
def get2Norm(a: []):
return math.sqrt(sum(map(lambda x: x**2, a)))
@staticmethod
def getInfNorm(a: []):
return max(map(abs, a))
def TestMetric():
a = [1, 2, 3, 4, 5, 6, 7, 8, -9]
print(metric.get1Norm(a))
print(metric.get2Norm(a))
print(metric.getInfNorm(a))
def printTimeElapsed(ff):
def f(*args, **kw):
beg = time.time()
res = ff(*args, **kw)
end = time.time()
fn = ff.__name__
print(f"[Time] function {fn: <30} \tdone, elapsed: {end-beg}s")
return res
return f
@printTimeElapsed
def f(a, b, c):
pass
def TestPrintTimeElapsed():
f(1, 2, 3)
def Test():
TestMetric()
TestPrintTimeElapsed()
if __name__ == "__main__":
Test()