From dce4dee13ff0caa6de571902ef2ef36e85e7dcb7 Mon Sep 17 00:00:00 2001 From: Dae Woo Kim Date: Thu, 21 May 2026 13:23:26 -0500 Subject: [PATCH 1/6] Use isnothing instead of == nothing for thresh check Co-Authored-By: Claude Sonnet 4.6 --- src/RegisterWorkerAperturesMismatch.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RegisterWorkerAperturesMismatch.jl b/src/RegisterWorkerAperturesMismatch.jl index 7fa32ac..86a63e2 100644 --- a/src/RegisterWorkerAperturesMismatch.jl +++ b/src/RegisterWorkerAperturesMismatch.jl @@ -114,7 +114,7 @@ pre-processing function, but see also `PreprocessSNF`. function AperturesMismatch(fixed, nodes::NTuple{N,K}, maxshift, preprocess=identity; normalization=:pixels, thresh_fac=(0.5)^ndims(fixed), thresh=nothing, correctbias::Bool=true, tid=1, dev=-1) where {K,N} gridsize = map(length, nodes) nimages(fixed) == 1 || error("Register to a single image") - if thresh == nothing + if isnothing(thresh) thresh = (thresh_fac/prod(gridsize)) * (normalization==:pixels ? length(fixed) : sumabs2(fixed)) end T = eltype(fixed) <: AbstractFloat ? eltype(fixed) : Float32 From 25a83b678cf10a6e0e909e15860e084d6f114b78 Mon Sep 17 00:00:00 2001 From: Dae Woo Kim Date: Thu, 21 May 2026 13:27:49 -0500 Subject: [PATCH 2/6] Annotate maxshift as NTuple{N,<:Integer} and add constructor validation test Co-Authored-By: Claude Sonnet 4.6 --- src/RegisterWorkerAperturesMismatch.jl | 2 +- test/internals.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/RegisterWorkerAperturesMismatch.jl b/src/RegisterWorkerAperturesMismatch.jl index 86a63e2..148a22f 100644 --- a/src/RegisterWorkerAperturesMismatch.jl +++ b/src/RegisterWorkerAperturesMismatch.jl @@ -111,7 +111,7 @@ pre-processing function, but see also `PreprocessSNF`. ``` """ -function AperturesMismatch(fixed, nodes::NTuple{N,K}, maxshift, preprocess=identity; normalization=:pixels, thresh_fac=(0.5)^ndims(fixed), thresh=nothing, correctbias::Bool=true, tid=1, dev=-1) where {K,N} +function AperturesMismatch(fixed, nodes::NTuple{N,K}, maxshift::NTuple{N,<:Integer}, preprocess=identity; normalization=:pixels, thresh_fac=(0.5)^ndims(fixed), thresh=nothing, correctbias::Bool=true, tid=1, dev=-1) where {K,N} gridsize = map(length, nodes) nimages(fixed) == 1 || error("Register to a single image") if isnothing(thresh) diff --git a/test/internals.jl b/test/internals.jl index 44ba545..f3cafb5 100644 --- a/test/internals.jl +++ b/test/internals.jl @@ -4,3 +4,10 @@ @test RegisterWorkerAperturesMismatch.cudatype(Int32) == Float32 @test RegisterWorkerAperturesMismatch.cudatype(UInt8) == Float32 end + +@testset "AperturesMismatch constructor argument validation" begin + fixed = rand(Float32, 20, 20) + nodes = (range(1, stop=20, length=4), range(1, stop=20, length=4)) + # Vector maxshift should not match the NTuple{N,<:Integer} signature + @test_throws MethodError AperturesMismatch(fixed, nodes, [3, 3]) +end From ac9be6ecd5372bb2e5d41e96e69353e2a118f278 Mon Sep 17 00:00:00 2001 From: Dae Woo Kim Date: Thu, 21 May 2026 13:32:43 -0500 Subject: [PATCH 3/6] Rename workertid field to tid, add workertid accessor overload Co-Authored-By: Claude Sonnet 4.6 --- src/RegisterWorkerAperturesMismatch.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/RegisterWorkerAperturesMismatch.jl b/src/RegisterWorkerAperturesMismatch.jl index 148a22f..9b3e53a 100644 --- a/src/RegisterWorkerAperturesMismatch.jl +++ b/src/RegisterWorkerAperturesMismatch.jl @@ -6,7 +6,7 @@ using RegisterMismatch, RegisterMismatchCommon # Note: RegisterMismatchCuda is loaded dynamically below when dev >= 0 using RegisterWorkerShell # , RegisterDriver -import RegisterWorkerShell: worker, init!, close!, load_mm_package +import RegisterWorkerShell: worker, init!, close!, load_mm_package, workertid export AperturesMismatch, monitor, monitor!, worker @@ -22,11 +22,13 @@ mutable struct AperturesMismatch{A<:AbstractArray,T,K,N} <: AbstractWorker cs Qs mmis - workertid::Int + tid::Int dev::Int cuda_objects::Dict{Symbol,Any} end +workertid(w::AperturesMismatch) = w.tid + function load_mm_package(dev) if dev >= 0 eval(:(using CUDA, RegisterMismatchCuda)) From 7d039c5d5bbfc2c0c50d5f80e66e71b57fff6fc4 Mon Sep 17 00:00:00 2001 From: Dae Woo Kim Date: Thu, 21 May 2026 13:46:57 -0500 Subject: [PATCH 4/6] Change dev field from Int sentinel to Union{Nothing,Int} Co-Authored-By: Claude Sonnet 4.6 --- src/RegisterWorkerAperturesMismatch.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/RegisterWorkerAperturesMismatch.jl b/src/RegisterWorkerAperturesMismatch.jl index 9b3e53a..2d708ad 100644 --- a/src/RegisterWorkerAperturesMismatch.jl +++ b/src/RegisterWorkerAperturesMismatch.jl @@ -3,7 +3,7 @@ module RegisterWorkerAperturesMismatch using ImageCore, CoordinateTransformations, Interpolations, StaticArrays, SharedArrays using RegisterCore, RegisterDeformation, RegisterFit, RegisterPenalty, RegisterOptimize using RegisterMismatch, RegisterMismatchCommon -# Note: RegisterMismatchCuda is loaded dynamically below when dev >= 0 +# Note: RegisterMismatchCuda is loaded dynamically below when dev !== nothing using RegisterWorkerShell # , RegisterDriver import RegisterWorkerShell: worker, init!, close!, load_mm_package, workertid @@ -23,21 +23,21 @@ mutable struct AperturesMismatch{A<:AbstractArray,T,K,N} <: AbstractWorker Qs mmis tid::Int - dev::Int + dev::Union{Nothing,Int} cuda_objects::Dict{Symbol,Any} end workertid(w::AperturesMismatch) = w.tid function load_mm_package(dev) - if dev >= 0 + if dev !== nothing eval(:(using CUDA, RegisterMismatchCuda)) end nothing end function init!(algorithm::AperturesMismatch) - if algorithm.dev >= 0 + if algorithm.dev !== nothing cuda_init!(algorithm) end nothing @@ -66,8 +66,8 @@ function cuda_init!(algorithm) end function close!(algorithm::AperturesMismatch) - if algorithm.dev >= 0 - if old_active_context != nothing + if algorithm.dev !== nothing + if !isnothing(old_active_context) activate(old_active_context) end end @@ -113,7 +113,7 @@ pre-processing function, but see also `PreprocessSNF`. ``` """ -function AperturesMismatch(fixed, nodes::NTuple{N,K}, maxshift::NTuple{N,<:Integer}, preprocess=identity; normalization=:pixels, thresh_fac=(0.5)^ndims(fixed), thresh=nothing, correctbias::Bool=true, tid=1, dev=-1) where {K,N} +function AperturesMismatch(fixed, nodes::NTuple{N,K}, maxshift::NTuple{N,<:Integer}, preprocess=identity; normalization=:pixels, thresh_fac=(0.5)^ndims(fixed), thresh=nothing, correctbias::Bool=true, tid=1, dev=nothing) where {K,N} gridsize = map(length, nodes) nimages(fixed) == 1 || error("Register to a single image") if isnothing(thresh) @@ -133,7 +133,7 @@ function worker(algorithm::AperturesMismatch, img, tindex, mon) moving0 = getindex_t(img, tindex) moving = algorithm.preprocess(moving0) gridsize = map(length, algorithm.nodes) - use_cuda = algorithm.dev >= 0 + use_cuda = algorithm.dev !== nothing if use_cuda device!(CuDevice(algorithm.dev)) d_fixed = algorithm.cuda_objects[:d_fixed] From 0af768f57bc86b5cd1c8c8fe5a13b8f8f7b15cf0 Mon Sep 17 00:00:00 2001 From: Dae Woo Kim Date: Thu, 21 May 2026 13:48:22 -0500 Subject: [PATCH 5/6] Bump version to 1.0.0 Co-Authored-By: Claude Sonnet 4.6 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 4eaa163..0af190a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RegisterWorkerAperturesMismatch" uuid = "30e56b64-2659-11e9-2fbf-0524297743d8" authors = ["Tim Holy "] -version = "0.2.4" +version = "1.0.0" [deps] CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298" From 05e6d051a4f665a9990666ea73717de10cb1216a Mon Sep 17 00:00:00 2001 From: Dae Woo Kim Date: Thu, 21 May 2026 13:49:55 -0500 Subject: [PATCH 6/6] Add Manifest-v*.toml to .gitignore Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 49541d3..a174b0a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.jl.mem deps/deps.jl Manifest.toml +Manifest-v*.toml