1
1
import numpy
2
- from scipy .sparse import random
2
+ from scipy .sparse import random , csr_matrix
3
3
import sparse
4
4
import pytest
5
5
@@ -10,6 +10,7 @@ def myfunc(x, y):
10
10
myufunc = numpy .frompyfunc (myfunc , 2 , 1 , identity = 0 )
11
11
12
12
# @pytest.mark.parametrize("dim", [5000, 10000, 20000])
13
+ @pytest .mark .skip (reason = "Not testing this right now" )
13
14
@pytest .mark .parametrize ("dim" , [250 , 500 , 750 , 1000 , 2500 , 5000 , 7500 , 8000 ])
14
15
@pytest .mark .parametrize ("ufunc" , [numpy .logical_xor , numpy .logical_or , numpy .right_shift , numpy .ldexp ])
15
16
def bench_ufunc_dense (tacoBench , dim , ufunc ):
@@ -21,6 +22,7 @@ def bench():
21
22
22
23
# TODO (rohany): We can parametrize this over the sparsity as well.
23
24
# @pytest.mark.parametrize("dim", [5000, 10000, 20000])
25
+ @pytest .mark .skip (reason = "Not testing this right now" )
24
26
@pytest .mark .parametrize ("dim" , [250 , 500 , 750 , 1000 , 2500 , 5000 , 7500 , 8000 ])
25
27
@pytest .mark .parametrize ("ufunc" , [numpy .logical_xor , numpy .logical_or , numpy .right_shift , numpy .ldexp ])
26
28
def bench_pydata_ufunc_sparse (tacoBench , dim , ufunc ):
@@ -29,3 +31,54 @@ def bench_pydata_ufunc_sparse(tacoBench, dim, ufunc):
29
31
def bench ():
30
32
C = ufunc (A , B )
31
33
tacoBench (bench )
34
+
35
+
36
+ def import_tensor (filename , dim ):
37
+ print (filename )
38
+ with open (filename , 'r' ) as f :
39
+ lines = f .readlines ()
40
+
41
+ count = 0
42
+ indptr = 0
43
+ indices = 0
44
+ data = 0
45
+ for line in lines :
46
+ count += 1
47
+ if count == 5 :
48
+ indptr = line
49
+ indptr = indptr [3 : - 2 ]
50
+ if count == 6 :
51
+ indices = line
52
+ indices = indices [3 : - 2 ]
53
+ if count == 7 :
54
+ data = line
55
+ data = data [1 : - 2 ]
56
+ print ("indptr" , indptr )
57
+ indptr = numpy .fromstring (indptr , dtype = int , sep = "," )
58
+ indices = numpy .fromstring (indices , dtype = int , sep = "," )
59
+ data = numpy .fromstring (data , dtype = float , sep = "," )
60
+ return indptr , indices , data
61
+
62
+ def get_ufunc_str (ufunc ):
63
+ if ufunc == numpy .logical_xor :
64
+ return "xor"
65
+ @pytest .mark .parametrize ("dim" , [250 , 500 , 750 , 1000 , 2500 , 5000 , 7500 , 8000 ])
66
+ @pytest .mark .parametrize ("ufunc" , [numpy .logical_xor ])
67
+ def bench_pydata_import_ufunc_sparse (tacoBench , dim , ufunc ):
68
+ filenameA = "./data/bench_ufunc_sparse_"
69
+ filenameA += get_ufunc_str (ufunc )
70
+ filenameA += "_" + str (dim ) + "_" + "010000_A.txt"
71
+ indptrA , indicesA , dataA = import_tensor (filenameA , dim )
72
+
73
+ A = csr_matrix ((dataA , indicesA , indptrA ), shape = (dim , dim )).toarray ()
74
+
75
+ filenameB = "./data/bench_ufunc_sparse_"
76
+ filenameB += get_ufunc_str (ufunc )
77
+ filenameB += "_" + str (dim ) + "_" + "010000_B.txt"
78
+ indptrB , indicesB , dataB = import_tensor (filenameB , dim )
79
+ B = csr_matrix ((dataB , indicesB , indptrB ), shape = (dim , dim )).toarray ()
80
+ def bench ():
81
+ C = ufunc (A , B )
82
+ return C
83
+ tacoBench (bench )
84
+ print ("Result" , bench ())
0 commit comments