Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiede committed Sep 22, 2024
1 parent 65bd1aa commit 6d735b0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/instrument/jonesmatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function forward_jones(v::AbstractJonesMatrix, xs::NamedTuple{N}) where {N}
vs = map(eachindex(sm.times)) do index
indices = map(x->getindex(x, index), bmaps)
params = NamedTuple{N}(map(getindex, values(xs), values(indices)))
return jonesmatrix(v, params, indices, index)
return jonesmatrix(v, params, index, Val(1))
end
return SiteArray(vs, sm)
end
Expand Down
22 changes: 11 additions & 11 deletions src/posterior/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ instrumentmodel(d::AbstractVLBIPosterior) = getfield(d, :instrumentmodel)
HypercubeTransform.dimension(d::AbstractVLBIPosterior) = length(d.prior)
EnzymeRules.inactive(::typeof(instrumentmodel), args...) = nothing

@noinline logprior_ref(d, x) = logprior(d, x[])
# @noinline logprior_ref(d, x) = logprior(d, x[])

# function ChainRulesCore.rrule(::typeof(logprior), d::AbstractVLBIPosterior, x)
# p = logprior(d, x)
Expand All @@ -68,18 +68,18 @@ EnzymeRules.inactive(::typeof(instrumentmodel), args...) = nothing
# return p, _logprior_pullback
# end

function _perturb(Δ, x::Union{NamedTuple, Tuple})
return map(x->_perturb(Δ, x), x)
end
# function _perturb(Δ, x::Union{NamedTuple, Tuple})
# return map(x->_perturb(Δ, x), x)
# end

function _perturb(Δ, x)
return Δ*x
end
# function _perturb(Δ, x)
# return Δ*x
# end

function _perturb(Δ, x::AbstractArray)
x .= Δ*x
return x
end
# function _perturb(Δ, x::AbstractArray)
# x .= Δ*x
# return x
# end



Expand Down
11 changes: 11 additions & 0 deletions test/Core/bayes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ using Enzyme
@test LogDensityProblems.capabilities(typeof(tpostc)) === LogDensityProblems.LogDensityOrder{0}()
end

@testset "corr image prior" begin
cprior1 = corr_image_prior(g, 10.0; base=EMRF, order=1)
cprior2 = corr_image_prior(g, 10.0; base=EMRF, order=2)

@test cprior1 isa VLBIImagePriors.HierarchicalPrior
@test cprior2 isa VLBIImagePriors.HierarchicalPrior

bs = beamsize(dcoh)
@test corr_image_prior(g, bs).hyperprior == corr_image_prior(g, dcoh).hyperprior
end


end
Expand Down Expand Up @@ -140,6 +150,7 @@ using FiniteDifferences
post = VLBIPosterior(skym, intm_coh, coh)
tpost = asflat(post)
x = prior_sample(tpost)
fj = instrumentmodel(post, x)
residual(post, Comrade.transform(tpost, x))
gz = Enzyme.gradient(Enzyme.Reverse, Const(tpost), x)
mfd = central_fdm(5,1)
Expand Down
8 changes: 8 additions & 0 deletions test/Core/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,19 @@ end

intm = InstrumentModel(J, intprior)
intm2 = InstrumentModel(J2, intprior)
intjg = InstrumentModel(JG, (;lg = ArrayPrior(IIDSitePrior(ScanSeg(), Normal(0.0, 0.1)))))
show(IOBuffer(), MIME"text/plain"(), intm)



ointm, printm = Comrade.set_array(intm, arrayconfig(dcoh))
ointm2, printm2 = Comrade.set_array(intm2, arrayconfig(dcoh))
ointjg, printjg = Comrade.set_array(intjg, arrayconfig(dcoh))

x = rand(printjg)
fj = forward_jones(JG, x)
@test fj[1][1] == x.lg[1]


Fpre = Comrade.preallocate_jones(F, arrayconfig(dcoh), CirBasis())
Rpre = Comrade.preallocate_jones(JonesR(;add_fr=true), arrayconfig(dcoh), CirBasis())
Expand Down

0 comments on commit 6d735b0

Please sign in to comment.