-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
77 lines (52 loc) · 1.81 KB
/
Copy pathutils.py
File metadata and controls
77 lines (52 loc) · 1.81 KB
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
70
71
72
73
74
75
76
77
import matplotlib.pyplot as plt
import numpy as np
RESULTS_PATH = "results"
def get_off_diagonal_diff(size):
operator = np.zeros((size, size))
for index in np.ndindex(size, size):
if (index[0] - index[1]) % size == 1:
operator[index] = -1
elif (index[1] - index[0]) % size == 1:
operator[index] = 1
return operator
def get_off_diagonal_quadratic_diff(size):
operator = np.zeros((size, size))
for index in np.ndindex(size, size):
if (index[0] - index[1]) % size == 1 or (index[1] - index[0]) % size == 1:
operator[index] = 1
elif index[0] == index[1]:
operator[index] = -2
return operator
def get_e(size, order=1):
operator = np.zeros((size, size))
order = order % size
for index in np.ndindex(size, size):
if (index[1] - index[0]) % size == order:
operator[index] = 1
return operator
def get_d_plus(size, fill_distance):
return (get_e(size, 1) - get_e(size, 0)) / fill_distance
def get_d_minus(size, fill_distance):
return (get_e(size, 0) - get_e(size, -1)) / fill_distance
def get_d_plus_minus(size, fill_distance):
return np.matmul(get_d_plus(size, fill_distance), get_d_minus(size, fill_distance))
def from_1d_to_nd(operator, ndim):
zero = np.zeros_like(operator)
return np.block(
[[(operator if i == j else zero) for i in range(ndim)] for j in range(ndim)]
)
def from_point_to_array(operator, size):
return np.block(
[
[np.eye(size) * operator[j, i] for i in range(operator.shape[1])]
for j in range(operator.shape[0])
]
)
def show_matrix(mat, name):
# print(f"name: {name} shape: {mat.shape}")
return
plt.figure()
plt.matshow(mat.real)
plt.title(name)
plt.colorbar()
plt.show()