diff --git a/src/instrument/jonesmatrices.jl b/src/instrument/jonesmatrices.jl index 9b88c911..2042b4c6 100644 --- a/src/instrument/jonesmatrices.jl +++ b/src/instrument/jonesmatrices.jl @@ -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 diff --git a/src/posterior/abstract.jl b/src/posterior/abstract.jl index 2e18b8d9..4566fbfa 100644 --- a/src/posterior/abstract.jl +++ b/src/posterior/abstract.jl @@ -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) @@ -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 diff --git a/test/Core/bayes.jl b/test/Core/bayes.jl index 8d814557..fc51de7a 100644 --- a/test/Core/bayes.jl +++ b/test/Core/bayes.jl @@ -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 @@ -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) diff --git a/test/Core/models.jl b/test/Core/models.jl index 35651106..e7f7a80b 100644 --- a/test/Core/models.jl +++ b/test/Core/models.jl @@ -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())