Skip to content

Commit

Permalink
fix mul! add associated test
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyiyin97 committed May 3, 2022
1 parent b6ba28d commit 32ee9f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/TimeModeling/LinearOperators/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ adjoint(L::LazyScal) = LazyScal(L.s, adjoint(L.P))

mul!(out::SourceType{T}, F::judiPropagator{T, O}, q::SourceType{T}) where {T<:Number, O} = begin y = F*q; copyto!(out, y) end
mul!(out::SourceType{T}, F::judiPropagator{T, O}, q::Vector{T}) where {T<:Number, O} = begin y = F*q; copyto!(out, y) end
mul!(out::SourceType{T}, F::joLinearFunction{T, T}, q::SourceType{T}) where {T<:Number} = begin y = F*q; copyto!(out, y) end
mul!(out::Union{SourceType{T1},SourceType{T2}}, F::joAbstractLinearOperator{T2, T1}, q::SourceType{T2}) where {T1<:Number, T2<:Number} = begin y = F*q; copyto!(out, y) end
mul!(out::SourceType{T}, F::judiAbstractJacobian{T, :born, FT}, q::Vector{T}) where {T<:Number, FT} = begin y = F*q[:]; copyto!(out, y) end
mul!(out::SourceType{T}, F::judiAbstractJacobian{T, :born, FT}, q::Array{T, N}) where {T<:Number, FT, N} = begin y = F*q[:]; copyto!(out, y) end
mul!(out::Array{T, 2}, F::judiAbstractJacobian{T, :adjoint_born, FT}, q::SourceType{T}) where {T<:Number, FT} = begin y = F*q; copyto!(out, y) end
Expand Down
5 changes: 2 additions & 3 deletions src/TimeModeling/Types/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ vec(x::judiMultiSourceVector) = vcat(vec.(x.data)...)
time_sampling(ms::judiMultiSourceVector) = [1 for i=1:ms.nsrc]
############################################################################################################################
# Linear algebra `*`
(msv::judiMultiSourceVector{T})(x::Vector{T}) where {T<:AbstractFloat} = x
(msv::judiMultiSourceVector{T})(x::judiMultiSourceVector{T}) where {T} = x
(msv::judiMultiSourceVector{mT})(x::Vector{T}) where {mT, T<:Array} = begin y = deepcopy(msv); y.data .= x; return y end
(msv::judiMultiSourceVector{mT})(x::AbstractVector{T}) where {mT<:Number, T<:Number} = x
(msv::judiMultiSourceVector{mT})(x::AbstractVector{T}) where {mT, T<:Array} = begin y = deepcopy(msv); y.data .= x; return y end

function *(J::Union{Matrix{vDT}, joAbstractLinearOperator}, x::judiMultiSourceVector{vDT}) where vDT
outvec = try J.fop(x) catch; J*vec(x) end
Expand Down
13 changes: 13 additions & 0 deletions test/test_linear_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@
@test isapprox(dobs_out, Md'*dobs; rtol=ftol)

# Check JUDI-JOLI compat

# check JOLI operator w/ judiVector
mul!(dobs_out, J*D, dm)
mul!(dobs, J*D, dm.data)
dlin = J*D*dm
@test isapprox(dobs_out, dlin; rtol=ftol)
@test isapprox(dobs_out, dobs; rtol=ftol)
# check JOLI operator w/ judiVector
DFT = joDFT(n; DDT=Float32, RDT=ComplexF32)
mul!(dm, adjoint(J*DFT), dlin)
dm1 = adjoint(J*DFT) * dlin
@test isapprox(dm1.data, dm; rtol=ftol)

dm1 = M * J' * Md * dobs
@test length(dm1) == prod(model0.n)
@test dm1[1] == 0
Expand Down

0 comments on commit 32ee9f1

Please sign in to comment.