File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ import ot
4
+ import numpy as np
5
+
6
+ # import pytest
7
+
8
+
9
+ def test_parmap ():
10
+
11
+ n = 100
12
+
13
+ def f (i ):
14
+ return 1.0 * i * i
15
+
16
+ a = np .arange (n )
17
+
18
+ l1 = map (f , a )
19
+
20
+ l2 = ot .utils .parmap (f , a )
21
+
22
+ assert np .allclose (l1 , l2 )
23
+
24
+
25
+ def test_tic_toc ():
26
+
27
+ import time
28
+
29
+ ot .tic ()
30
+ time .sleep (0.5 )
31
+ t = ot .toc ()
32
+ t2 = ot .toq ()
33
+
34
+ # test timing
35
+ assert np .allclose (0.5 , t , rtol = 1e-2 , atol = 1e-2 )
36
+
37
+ # test toc vs toq
38
+ assert np .allclose (t , t2 , rtol = 1e-2 , atol = 1e-2 )
39
+
40
+
41
+ def test_kernel ():
42
+
43
+ n = 100
44
+
45
+ x = np .random .randn (n , 2 )
46
+
47
+ K = ot .utils .kernel (x , x )
48
+
49
+ # gaussian kernel has ones on the diagonal
50
+ assert np .allclose (np .diag (K ), np .ones (n ))
51
+
52
+
53
+ def test_unif ():
54
+
55
+ n = 100
56
+
57
+ u = ot .unif (n )
58
+
59
+ assert np .allclose (1 , np .sum (u ))
60
+
61
+
62
+ def test_dist ():
63
+
64
+ n = 100
65
+
66
+ x = np .random .randn (n , 2 )
67
+
68
+ D = np .zeros ((n , n ))
69
+ for i in range (n ):
70
+ for j in range (n ):
71
+ D [i , j ] = np .sum (np .square (x [i , :] - x [j , :]))
72
+
73
+ D2 = ot .dist (x , x )
74
+
75
+ # dist shoul return squared euclidean
76
+ assert np .allclose (D , D2 )
You can’t perform that action at this time.
0 commit comments