Skip to content

Commit 81adab6

Browse files
committed
Modified tests, fixed left.jl as per reviews
1 parent 06083e9 commit 81adab6

32 files changed

+910
-7659
lines changed

src/left.jl

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -165,73 +165,48 @@ function (L::AdjointOperator)(v::AbstractVecOrMat, u, p, t; kwargs...)
165165
# Adjoint operator applied to v means L.L' * v
166166
# For matrices: (A')v = (v'A)'
167167
# This means we need to compute L.L(v', u, p, t)'
168-
# Reshape v to match the adjoint operator's expected size
169-
adjv = reshape(v', size(L.L, 1), :)
170-
result = L.L(adjv, u, p, t; kwargs...)
171-
return reshape(result', size(L, 1), :)
168+
# Update the operator first, then apply adjoint operator
169+
L_updated = update_coefficients(L.L, u, p, t; kwargs...)
170+
# (A')v = (v'A)' where v'A is computed by A'*v'
171+
return (L_updated' * v')'
172172
end
173173

174174
# In-place: w is destination, v is action vector, u is update vector
175175
function (L::AdjointOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
176-
# Need temporary storage for adjoint operations
177-
temp_v = reshape(v', size(L.L, 1), :)
178-
temp_w = similar(temp_v)
179-
180-
# Apply the internal operator
181-
L.L(temp_w, temp_v, u, p, t; kwargs...)
182-
183-
# Copy back to w with adjoint
184-
w .= reshape(temp_w', size(L, 1), :)
176+
# Update the operator in-place
177+
update_coefficients!(L.L, u, p, t; kwargs...)
178+
# Use direct in-place multiplicatieon for adjoints
179+
mul!(w', v', L.L)
185180
return w
186181
end
187182

188183
# In-place with scaling: w = α*(L*v) + β*w
189184
function (L::AdjointOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
190-
# Handle scaling of existing w
191-
if β != 1.0
192-
lmul!(β, w)
193-
end
194-
195-
# Need temporary storage for adjoint operations
196-
temp_v = reshape(v', size(L.L, 1), :)
197-
temp_w = similar(temp_v)
198-
199-
# Apply the internal operator
200-
L.L(temp_w, temp_v, u, p, t, 1.0, 0.0; kwargs...)
201-
202-
# Add α * result' to w
203-
w .+= α .* reshape(temp_w', size(L, 1), :)
185+
# Update the operator in-place
186+
update_coefficients!(L.L, u, p ,t; kwargs...)
187+
mul!(w', v', L.L, α, β)
204188
return w
205189
end
206190

207191
# For TransposedOperator
192+
# Out-of-place
208193
function (L::TransposedOperator)(v::AbstractVecOrMat, u, p, t; kwargs...)
209-
transv = reshape(v', size(L.L, 1), :)
210-
result = L.L(transv, u, p, t; kwargs...)
211-
return reshape(result', size(L, 1), :)
194+
L_updated = update_coefficients(L.L, u, p, t; kwargs...)
195+
# (A^T)v = (v'A)' where v'A is computed by A'*v'
196+
return (L_updated' * v')'
212197
end
213198

199+
# In-place
214200
function (L::TransposedOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t; kwargs...)
215-
temp_v = reshape(v', size(L.L, 1), :)
216-
temp_w = similar(temp_v)
217-
218-
L.L(temp_w, temp_v, u, p, t; kwargs...)
219-
220-
w .= reshape(temp_w', size(L, 1), :)
201+
update_coefficients!(L.L, u, p, t; kwargs...)
202+
mul!(w', v', L.L)
221203
return w
222204
end
223205

206+
# In-place with scaling
224207
function (L::TransposedOperator)(w::AbstractVecOrMat, v::AbstractVecOrMat, u, p, t, α, β; kwargs...)
225-
if β != 1.0
226-
lmul!(β, w)
227-
end
228-
229-
temp_v = reshape(v', size(L.L, 1), :)
230-
temp_w = similar(temp_v)
231-
232-
L.L(temp_w, temp_v, u, p, t, 1.0, 0.0; kwargs...)
233-
234-
w .+= α .* reshape(temp_w', size(L, 1), :)
208+
update_coefficients!(L.L, u, p, t; kwargs...)
209+
mul!(w', v', L.L, α, β)
235210
return w
236211
end
237212
#

0 commit comments

Comments
 (0)