forked from pydata/sparse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_coo.py
69 lines (47 loc) · 1.47 KB
/
benchmark_coo.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
57
58
59
60
61
62
63
64
65
66
67
68
69
import sparse
import numpy as np
class MatrixMultiplySuite:
def setup(self):
np.random.seed(0)
self.x = sparse.random((100, 100), density=0.01)
self.y = sparse.random((100, 100), density=0.01)
self.x @ self.y # Numba compilation
def time_matmul(self):
self.x @ self.y
class ElemwiseSuite:
def setup(self):
np.random.seed(0)
self.x = sparse.random((100, 100, 100), density=0.01)
self.y = sparse.random((100, 100, 100), density=0.01)
self.x + self.y # Numba compilation
def time_add(self):
self.x + self.y
def time_mul(self):
self.x * self.y
class ElemwiseBroadcastingSuite:
def setup(self):
np.random.seed(0)
self.x = sparse.random((100, 1, 100), density=0.01)
self.y = sparse.random((100, 100), density=0.01)
def time_add(self):
self.x + self.y
def time_mul(self):
self.x * self.y
class IndexingSuite:
def setup(self):
np.random.seed(0)
self.index = np.random.randint(0, 100, 50)
self.x = sparse.random((100, 100, 100), density=0.01)
# Numba compilation
self.x[5]
self.x[self.index]
def time_index_scalar(self):
self.x[5, 5, 5]
def time_index_slice(self):
self.x[:50]
def time_index_slice2(self):
self.x[:50, :50]
def time_index_slice3(self):
self.x[:50, :50, :50]
def time_index_fancy(self):
self.x[self.index]