HolyLab / BlockRegistrationScheduler.jl

Multi-core image registration scheduler
1 stars 0 forks source link

Rigid registration breaks with large rotations #43

Closed Cody-G closed 6 years ago

Cody-G commented 6 years ago

It's easiest to demonstrate this by changing the magnitude of the rotation in the test file:

https://github.com/HolyLab/BlockRegistrationScheduler/blob/master/test/rigid.jl#L7

If I change that to pi/8.85 or higher I get the error below. (I truncated the trace a bit)

ERROR: LoadError: MethodError: Cannot `convert` an object of type ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3} to an object of type Float64
This may have arisen from a call to the constructor Float64(...),
since type constructors fall back to convert methods.
Stacktrace:
 [1] setindex!(::Array{Float64,2}, ::ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3}, ::Int64, ::Int64) at ./array.jl:584
 [2] macro expansion at ./cartesian.jl:64 [inlined]
 [3] macro expansion at /home/cody/.julia/v0.6/AffineTransforms/src/tformedarrays.jl:123 [inlined]
 [4] _transform!(::Array{Float64,2}, ::AffineTransforms.TransformedArray{Float64,2,Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},AffineTransforms.AffineTransform{ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3},ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3},2}}, ::Array{ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3},1}) at /home/cody/.julia/v0.6/AffineTransforms/src/tformedarrays.jl:115
 [5] #transform!#3(::Array{Float64,1}, ::Array{Float64,1}, ::Function, ::Array{Float64,2}, ::AffineTransforms.TransformedArray{Float64,2,Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},AffineTransforms.AffineTransform{ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3},ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3},2}}) at /home/cody/.julia/v0.6/AffineTransforms/src/tformedarrays.jl:95
 [6] transform!(::Array{Float64,2}, ::AffineTransforms.TransformedArray{Float64,2,Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},AffineTransforms.AffineTransform{ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3},ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3},2}}) at /home/cody/.julia/v0.6/AffineTransforms/src/tformedarrays.jl:89
 [7] #transform#1(::Array{Any,1}, ::Function, ::AffineTransforms.TransformedArray{Float64,2,Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},AffineTransforms.AffineTransform{ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3},ForwardDiff.Dual{ForwardDiff.Tag{RegisterOptimize.RigidValue{2,Array{Float32,2},Interpolations.FilledExtrapolation{Float64,2,Interpolations.BSplineInterpolation{Float32,2,Array{Float32,2},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,0},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.InPlace}},Interpolations.OnCell,Float64},Array{Float64,2}},Float64},Float64,3},2}}) at /home/cody/.julia/v0.6/AffineTransforms/src/tformedarrays.jl:71

Most of the time our rotations are not that large, but this could still bite us at some point.

timholy commented 6 years ago

This seems to be a very strange Heisenbug: for example, if I just force those functions to recompile (e.g., make trivial edits while using Revise), then it would work.

Seems to be fixed by https://github.com/JuliaMath/Interpolations.jl/pull/190

Cody-G commented 6 years ago

This seems to have fixed the problem, thanks! Would have taken me forever to find that.