-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive.jl
191 lines (122 loc) · 5.22 KB
/
archive.jl
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# ## Custom simulation function
# function groundtruth_sim(nodes::Matrix, image, kernel, positions)
# outputData = EMulx_Tullio(vec(image),apply_td_girf(nodes, kernel),positions)
# return outputData
# end
# ## Single Threaded Explicit Passing Version for Autodiff compat.
# function constructE(nodes::Matrix, positions::Matrix)
# phi = nodes' * positions'
# # Multithreaded
# # Threads.@threads for i in eachindex(phi)
# # E[i] = cispi(-2 * phi[i])
# # end
# E = cispi.(-2 * phi[i])
# return E
# end
# ## Single Threaded Explicit Passing Version for Autodiff compat.
# function constructEH(nodes::Matrix, positions::Matrix)
# phi = positions * nodes
# # Multithreaded
# # Threads.@threads for i in eachindex(phi)
# # EH[i] = cispi(2 * phi[i])
# # end
# EH = cispi.(2 * phi)
# return EH
# end
# ## Efficient function to apply a time domain gradient impulse response function kernel to the trajectory (2D only now)
# function apply_td_girf(nodes::Matrix, kernel::Matrix)
# gradients = nodes_to_gradients(nodes)
# padded = pad_gradients(gradients, size(kernel))
# filtered = filter_gradients(padded, kernel)
# filtered_nodes = gradients_to_nodes(filtered)
# return filtered_nodes
# end
# ## Convert gradients to trajectory nodes
# function gradients_to_nodes(gradients::Matrix)
# nodes = cumsum(gradients, dims = 2)
# return nodes
# end
# ## Filter gradients using Tullio for efficient convolution
# function filter_gradients(gradients::Matrix, kernel::Matrix)
# @tullio d[b, i] := gradients[b, i+a-1] * kernel[b, a]
# return d
# end
# function nodes_to_gradients(nodes::Matrix)
# newNodes = hcat([0;0],nodes)
# gradients = diff(newNodes, dims = 2)
# return gradients
# end
# ## Pad gradients to prepare for Tullio
# function pad_gradients(gradients::Matrix, kernelSize)
# padding = zeros(Float32,kernelSize[1], kernelSize[2] - 1)
# padded = hcat(padding, gradients)
# return padded
# end
# ## Version of Matrix-Vector Multiplication using Tullio.jl. Supposedly very fast and flexible.
# function EHMulx_Tullio(x, nodes::Array{Float64,4}, positions::Matrix{Float64})
# nodes2 = undoReshape(nodes)
# @tullio EH[n, k] := exp <| (1.0im * pi * 2.0 * $positions[i, n] * nodes2[i, k])
# @tullio y[n] := EH[n, k] * $x[k]
# return y
# end
# ## Weighted Version of Matrix-Vector Multiplication using Tullio.jl. Supposedly very fast and flexible.
# function weighted_EHMulx_Tullio(x, nodes::Matrix{Float64}, positions::Matrix{Float64}, weights::Vector{Float64})
# # TODO: ADD DENSITY COMPENSATION FUNCTION AS DESCRIBED IN NOLL, FESSLER and SUTTON
# #@tullio W[k] := sqrt <| $gradients[i,k]*$gradients[i,k] ## Define weights as magnitude of gradients
# @tullio EH[n, k] := exp <| (1.0im * pi * 2.0 * $positions[i, n] * nodes[i, k])
# @tullio y[n] := EH[n, k] * (weights[k]*$x[k])
# return y
# end
# ## Weighted Version of Matrix-Vector Multiplication using Tullio.jl. Supposedly very fast and flexible.
# function weighted_EHMulx_Tullio(x, nodes, positions, weights)
# # TODO: ADD DENSITY COMPENSATION FUNCTION AS DESCRIBED IN NOLL, FESSLER and SUTTON
# #@tullio W[k] := sqrt <| $gradients[i,k]*$gradients[i,k] ## Define weights as magnitude of gradients
# @tullio EH[n, k] := exp <| (1.0im * pi * 2.0 * $positions[i, n] * nodes[i, k])
# @tullio y[n] := EH[n, k] * (weights[k]*$x[k])
# return y
# end
# ## Version of Matrix-Vector Multiplication using Tullio.jl. Supposedly very fast and flexible.
# function EHMulx_Tullio(x, nodes::Matrix{Float64}, positions::Matrix{Float64})
# @tullio EH[n, k] := exp <| (1.0im * pi * 2.0 * $positions[i, n] * nodes[i, k])
# @tullio y[n] := EH[n, k] * $x[k]
# return y
# end
# ## Generic Allocator for the E system matrix
# function prepareE(imShape)
# # construct E in place
# E = Array{ComplexF32}(undef, imShape[1] * imShape[2], imShape[1] * imShape[2])
# positions = getPositions(imShape)
# return E, positions
# end
# ## Memory Efficient Multi-threaded in-place E constructor
# function constructE!(E, nodes::Matrix, positions::Matrix)
# phi = nodes' * positions
# Threads.@threads for i in eachindex(phi)
# E[i] = cispi(-2 * phi[i])
# end
# end
# ## Memory Efficient Multi-threaded in-place EH constructor
# function constructEH!(EH, nodes::Matrix, positions::Matrix)
# phi = positions * nodes'
# Threads.@threads for i in eachindex(phi)
# EH[i] = cispi(2 * phi[i])
# end
# end
# ## Single Threaded Explicit Passing Version for Autodiff compat.
# function EMulx(x, nodes::Matrix, positions::Matrix)
# E = constructE(nodes, positions)
# y = E * x
# return y
# end
# ## Single Threaded Explicit Passing Version for Autodiff compat.
# function EHMulx(x, nodes::Matrix, positions::Matrix)
# EH = constructEH(nodes, positions)
# y = EH * x
# return y
# end
# ## Version of Matrix-Vector Multiplication using Tullio.jl. Supposedly very fast and flexible.
# function EMulx_Tullio(x, nodes::Matrix{Float64}, positions::Matrix{Float64})
# @tullio E[k, n] := exp <| (-1.0im * pi * 2.0 * nodes[i, k] * $positions[i, n])
# @tullio y[k] := E[k, n] * $x[n]
# return y
# end