@@ -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 ' ) '
172172end
173173
174174# In-place: w is destination, v is action vector, u is update vector
175175function (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
186181end
187182
188183# In-place with scaling: w = α*(L*v) + β*w
189184function (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
205189end
206190
207191# For TransposedOperator
192+ # Out-of-place
208193function (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 ' ) '
212197end
213198
199+ # In-place
214200function (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
222204end
223205
206+ # In-place with scaling
224207function (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
236211end
237212#
0 commit comments