-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_minkowski.py
49 lines (40 loc) · 1.41 KB
/
test_minkowski.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
import numpy as np
import time
from mdscuda.minkowski import minkowski_pairs, minkowski_pairs_tiled, matmul, matmul_tiled
N_SAMPLES = 10000
N_FEATURES = 1000
X = np.random.normal(size = (N_SAMPLES, N_FEATURES))
A = np.random.normal(size = (1000, 500))
B = np.random.normal(size = (500, 1000))
#A = np.full(shape = (1000, 500), fill_value=3)
#B = np.full(shape = (500, 1000), fill_value=4)
def test_euclidean_tiled():
print()
tick = time.perf_counter()
DELTA = minkowski_pairs(X, sqform = False)
print('euc pairs', time.perf_counter() - tick)
#print(DELTA)
tick = time.perf_counter()
DELTA_tiled = minkowski_pairs_tiled(X, sqform = False)
print('euc pairs tiled', time.perf_counter() - tick)
#print(DELTA_tiled)
epsilon = 1e-5
#print((np.abs(DELTA - DELTA_tiled)).max())
within_epsilon = (np.abs(DELTA - DELTA_tiled) < epsilon).all()
print('within epsilon', within_epsilon)
assert within_epsilon
def test_matmul_tiled():
print()
tick = time.perf_counter()
AB = matmul(A, B)
print('matmul', time.perf_counter() - tick)
#print(AB)
tick = time.perf_counter()
AB_tiled = matmul_tiled(A, B)
print('matmul tiled', time.perf_counter() - tick)
#print(AB_tiled)
epsilon = 1e-8
#print((np.abs(AB - AB_tiled)).max())
within_epsilon = (np.abs(AB - AB_tiled) < epsilon).all()
print('within epsilon', within_epsilon)
assert within_epsilon