-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
68 lines (56 loc) · 1.83 KB
/
helpers.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
import numpy as np
from scipy.sparse import identity, kron, diags, coo_matrix
def directSum(matList):
dims = [mat.shape[0] for mat in matList]
leftDims = lambda i : int(np.prod(dims[0:i]))
rightDims = lambda i : int(np.prod(dims[i+1:]))
i = 0
dilated_mats = []
for mat in matList:
if i == 0:
dilated_mats.append(kron(mat, identity(rightDims(0))))
elif i == len(dims):
dilated_mats.append(kron(identity(leftDims(-1)), mat))
else:
dilated_mats.append(kron(kron(identity(leftDims(i)),mat),identity(rightDims(i))))
i+=1
return sum(dilated_mats)
def projOp(N, idxs):
assert max(idxs) < N
diagVals = np.zeros(N)
diagVals[idxs] = 1
proj = diags(diagVals, offsets = 0, format='csr')
return proj
def projComp(N, idxs):
return identity(N) - projOp(N,idxs)
def reflectOp(N, idxs):
return identity(N) - 2*projOp(N,idxs)
def pltDomain(inside, bndry, outside):
# Unpack into x and y coordinates
x_values, y_values = zip(*bndry)
x_int, y_int = zip(*inside)
x_out, y_out = zip(*outside)
# Plot
plt.scatter(x_values, y_values, color="blue", marker="o", label="bndry")
plt.scatter(x_int, y_int, color="red", marker="o", label="interior")
plt.scatter(x_out, y_out, color="green", marker="o", label="outside")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Scatter Plot of Ordered Pairs")
plt.legend()
plt.grid(True)
plt.show()
def shiftOps(N,j):
rows = np.arange(N)
cols = (rows + j) % N
data = np.ones(N)
return coo_matrix((data, (rows, cols)), shape=(N, N)).tocsr()
def vec2grid(vec, dim):
k = np.log2(len(vec))
print(k)
N = int(2**(k/dim))
print(N)
print(len(vec))
#make tuple of d dimension
grid_soln = vec.reshape((N,)*dim)
return grid_soln