Skip to content

Commit

Permalink
unwrap: Initialize image reliability in deterministic order
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHargrave committed Dec 29, 2024
1 parent 3e79857 commit 508a6aa
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/unwrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ mutable struct Pixel{T}
return pixel
end
end
Pixel(v, rng) = Pixel{typeof(v)}(0, v, rand(rng), 1)
Pixel(v, rel::Float64) = Pixel{typeof(v)}(0, v, rel, 1)
Pixel(v, rng::AbstractRNG) = Pixel(v, rand(rng))
@inline Base.length(p::Pixel) = p.head.groupsize

struct Edge{T}
Expand Down Expand Up @@ -146,8 +147,13 @@ end
# function to broadcast
function init_pixels(wrapped_image::AbstractArray{T, N}, rng) where {T, N}
pixel_image = similar(wrapped_image, Pixel{T})
Threads.@threads for i in eachindex(wrapped_image, pixel_image)
pixel_image[i] = Pixel(wrapped_image[i], rng)

# Initialize reliability values before going parallel. This ensures that
# reliability values are generated in a deterministic order.
rels = rand(rng, T, size(wrapped_image))

Threads.@threads for i in eachindex(wrapped_image, pixel_image, rels)
pixel_image[i] = Pixel(wrapped_image[i], rels[i])
end
return pixel_image
end
Expand Down

0 comments on commit 508a6aa

Please sign in to comment.