Skip to content

Commit 32a1d61

Browse files
authored
Merge pull request #74 from sylee957/add_eigenvals_benchmark
Add block diagonal eigenvalues benchmarks
2 parents 7fdab96 + 7dc0faa commit 32a1d61

File tree

1 file changed

+54
-9
lines changed

1 file changed

+54
-9
lines changed

benchmarks/matrices.py

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,64 @@ def time_MatMul_doit(self):
3737

3838
class TimeDiagonalEigenvals:
3939
def setup(self):
40-
def entry(i, j):
41-
if i == j:
42-
return i
43-
elif i > j:
44-
return j
45-
else:
46-
return 0
47-
self.M = Matrix(5, 5, entry)
40+
self.M = Matrix([
41+
[0, 0, 0, 0, 0],
42+
[0, 1, 0, 0, 0],
43+
[0, 1, 2, 0, 0],
44+
[0, 1, 2, 3, 0],
45+
[0, 1, 2, 3, 4]])
4846

4947
def time_eigenvals(self):
5048
self.M.eigenvals()
5149

5250

51+
class TimeBlockDiagonalEigenvals:
52+
"""Benchmark examples obtained by similarly transforming random
53+
block diagonal matrices with permutation matrices to make it look
54+
like non block diagonal.
55+
56+
The original block matrices can be obtained by using
57+
Matrix.connected_components_decomposition.
58+
"""
59+
def setup(self):
60+
self.m22 = Matrix([
61+
[26, 0, 0, 7], [0, 27, 21, 0],
62+
[0, 18, 89, 0], [13, 0, 0, 28]])
63+
self.m222 = Matrix([
64+
[37, 0, 0, 0, 0, 5], [0, 32, 0, 0, 33, 0], [0, 0, 78, 91, 0, 0],
65+
[0, 0, 51, 97, 0, 0], [0, 97, 0, 0, 77, 0], [37, 0, 0, 0, 0, 61]])
66+
self.m2222 = Matrix([
67+
[87, 0, 12, 0, 0, 0, 0, 0], [0, 35, 0, 0, 0, 0, 0, 51],
68+
[31, 0, 47, 0, 0, 0, 0, 0], [0, 0, 0, 84, 0, 41, 0, 0],
69+
[0, 0, 0, 0, 70, 0, 57, 0], [0, 0, 0, 56, 0, 30, 0, 0],
70+
[0, 0, 0, 0, 54, 0, 55, 0], [0, 61, 0, 0, 0, 0, 0, 0]])
71+
self.m33 = Matrix([
72+
[48, 0, 44, 0, 0, 67], [0, 16, 0, 28, 61, 0],
73+
[5, 0, 5, 0, 0, 52], [0, 28, 0, 78, 13, 0],
74+
[0, 3, 0, 52, 35, 0], [98, 0, 86, 0, 0, 70]])
75+
self.m333 = Matrix([
76+
[60, 0, 74, 0, 0, 0, 0, 39, 0], [0, 36, 0, 0, 14, 0, 10, 0, 0],
77+
[33, 0, 32, 0, 0, 0, 0, 46, 0], [0, 0, 0, 9, 0, 46, 0, 0, 7],
78+
[0, 51, 0, 0, 92, 0, 46, 0, 0], [0, 0, 0, 86, 0, 21, 0, 0, 16],
79+
[0, 55, 0, 0, 28, 0, 12, 0, 0], [6, 0, 1, 0, 0, 0, 0, 31, 0],
80+
[0, 0, 0, 61, 0, 59, 0, 0, 57]])
81+
82+
def time_eigenvals_22(self):
83+
self.m22.eigenvals()
84+
85+
def time_eigenvals_222(self):
86+
self.m222.eigenvals()
87+
88+
def time_eigenvals_2222(self):
89+
self.m2222.eigenvals()
90+
91+
def time_eigenvals_33(self):
92+
self.m33.eigenvals()
93+
94+
def time_eigenvals_333(self):
95+
self.m333.eigenvals()
96+
97+
5398
class TimeMatrixGetItem:
5499
def setup(self):
55100
self.M1 = MutableDenseMatrix.zeros(5, 5)
@@ -102,4 +147,4 @@ def time_Case2(self):
102147
m = self.Case2**4
103148

104149
def time_Case3(self):
105-
m = self.Case3**4
150+
m = self.Case3**4

0 commit comments

Comments
 (0)