HolyLab / RegisterOptimize.jl

This package is separated from BlockRegistraton.
2 stars 1 forks source link

ERROR: DimensionMismatch #1

Closed kdw503 closed 5 years ago

kdw503 commented 5 years ago

During the test, met this error. This is code to regenerate the error.

using Test, StaticArrays, Interpolations, Images, CoordinateTransformations
import RegisterOptimize
using RegisterCore, RegisterPenalty, RegisterDeformation, RegisterMismatch, RegisterFit, RegisterOptimize

function build_Ac_b(A, λ, cs::Array{Tc,3}, Qs::Array{TQ,3}) where {Tc,TQ}
    n = size(Qs,3)
    l = size(A,1)
    b = zeros(l*n)
    Ac = zeros(eltype(A), l*n, l*n)
    for i = 1:n
        Ac[(i-1)*l+1:i*l, (i-1)*l+1:i*l] = A
        if i == 1 || i == n
            for k = 1:l
                Ac[(i-1)*l+k,(i-1)*l+k] += λ
            end
        else
            for k = 1:l
                Ac[(i-1)*l+k,(i-1)*l+k] += 2*λ
            end
        end
    end
    for i = 1:n-1
        for k = 1:l
            Ac[(i-1)*l+k, i*l+k] -= λ
            Ac[i*l+k, (i-1)*l+k] -= λ
        end
    end
    for i = 1:length(Qs)
        Ac[2i-1:2i,2i-1:2i] += Qs[i]
        b[2i-1:2i] = Qs[i]*cs[i]
    end
    Ac, b
end

function build_A(knots, λ)
    ap = AffinePenalty(knots, λ)
    FF = ap.F*ap.F'
    nA = 2*size(FF,1)
    FF2 = zeros(nA,nA)
    FF2[1:2:end,1:2:end] = FF
    FF2[2:2:end,2:2:end] = FF
    A = ap.λ*(I - FF2)
    A, ap
end

knots = (range(1, stop=20, length=4),range(1, stop=15, length=4))
A, ap = build_A(knots, 1.0)
gridsize = map(length, knots)

Qs = Array{SMatrix{2,2,Float64,4}}(gridsize..., 5)
cs = Array{SVector{2,Float64}}(gridsize..., 5)
for I in CartesianIndices(size(Qs))
    QF = rand(2,2)
    Qs[I] = QF'*QF
    cs[I] = randn(2)
end
csr = convert(Array{Vector{Float64}, 3}, cs)
Qsr = convert(Array{Matrix{Float64}, 3}, Qs)
λ_t = 1.0
P = RegisterOptimize.TimeHessian(RegisterOptimize.AffineQHessian(ap, Qs, identity), λ_t )
Ac, b = build_Ac_b(A, λ_t,  csr, Qsr)
v = zeros(size(P,1)); v[1] = 1
@test isapprox(P*v, vec(Ac[1,:]), atol=0.0001)
Cody-G commented 5 years ago

I think I'm getting the same error when I run tests locally. Here's the message in case it helps. Instead of solving this I'll focus on QuadDIRECT-related stuff for now.

WARNING: could not import Images.separate into RegisterCore
Error During Test at /home/cody/.julia/dev/RegisterOptimize/test/runtests.jl:148
  Test threw exception DimensionMismatch("g's length 160 inconsistent with (4, 4, 5)")
  Expression: ≈(P * v, vec(Ac[1, :]), atol=0.0001)
  DimensionMismatch("g's length 160 inconsistent with (4, 4, 5)")
  Stacktrace:
   [1] penalty!(::Base.ReinterpretArray{Float64,1,SArray{Tuple{2},Float64,1,2},Array{SArray{Tuple{2},Float64,1,2},1}}, ::Float64, ::Array{GridDeformation{Float64,2,SubArray{SArray{Tuple{2},Float64,1,2},2,Base.ReshapedArray{SArray{Tuple{2},Float64,1,2},3,Base.ReinterpretArray{SArray{Tuple{2},Float64,1,2},1,Float64,Array{Float64,1}},Tuple{}},Tuple{Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}},Int64},true},StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}},1}) at /home/cody/.julia/packages/RegisterPenalty/Neqrl/src/RegisterPenalty.jl:383
   [2] *(::RegisterOptimize.TimeHessian{RegisterOptimize.AffineQHessian{AffinePenalty{Float64,2},SArray{Tuple{2,2},Float64,2,4},3,typeof(identity)},Float64}, ::Array{Float64,1}) at /home/cody/.julia/dev/RegisterOptimize/src/RegisterOptimize.jl:1034
   [3] top-level scope at none:0
   [4] include at ./boot.jl:317 [inlined]
   [5] include_relative(::Module, ::String) at ./loading.jl:1038
   [6] include(::Module, ::String) at ./sysimg.jl:29
   [7] include(::String) at ./client.jl:398
   [8] top-level scope at none:0
   [9] eval(::Module, ::Any) at ./boot.jl:319
   [10] macro expansion at ./logging.jl:317 [inlined]
   [11] exec_options(::Base.JLOptions) at ./client.jl:229
   [12] _start() at ./client.jl:432
ERROR: LoadError: There was an error during testing
in expression starting at /home/cody/.julia/dev/RegisterOptimize/test/runtests.jl:148
kdw503 commented 5 years ago

Yes, I have asked this error to Tim. But, you might not meet this error if you are using just QuadDIRECT registration.