-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path03_perform_simple.py
68 lines (49 loc) · 1.44 KB
/
03_perform_simple.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
"""
3. Example: Performance for flattened matrices
----------------------------------------------
Here we compare all algorithms for solving pentadiagonal systems provided
by pentapy (except umf).
To use this script you need to have the following packages installed:
* scipy
* perfplot
* matplotlib
"""
import numpy as np
import perfplot
from pentapy import solve, tools
def get_les(size):
mat = (np.random.random((5, size)) - 0.5) * 1e-5
V = np.array(np.random.random(size) * 1e5)
return mat, V
def solve_1(in_val):
"""PTRANS-I"""
mat, V = in_val
return solve(mat, V, is_flat=True, index_row_wise=False, solver=1)
def solve_2(in_val):
"""PTRANS-II"""
mat, V = in_val
return solve(mat, V, is_flat=True, index_row_wise=False, solver=2)
def solve_3(in_val):
mat, V = in_val
return solve(mat, V, is_flat=True, index_row_wise=False, solver=3)
def solve_4(in_val):
mat, V = in_val
return solve(mat, V, is_flat=True, index_row_wise=False, solver=4)
def solve_5(in_val):
mat, V = in_val
M = tools.create_full(mat)
return np.linalg.solve(M, V)
perfplot.show(
setup=get_les,
kernels=[solve_1, solve_2, solve_3, solve_4, solve_5],
labels=[
"PTRANS-I",
"PTRANS-II",
"scipy.linalg.solve_banded",
"scipy.sparse.linalg.spsolve",
"numpy.linalg.solve",
],
n_range=[2**k for k in range(2, 13)],
xlabel="Size [n]",
logy=True,
)