Skip to content

Fix issue #25#30

Open
goerch wants to merge 16 commits into
jacobusmmsmit:mainfrom
goerch:main
Open

Fix issue #25#30
goerch wants to merge 16 commits into
jacobusmmsmit:mainfrom
goerch:main

Conversation

@goerch

@goerch goerch commented Nov 2, 2022

Copy link
Copy Markdown
Collaborator

No description provided.

@goerch
goerch requested a review from jacobusmmsmit November 2, 2022 15:56
Comment thread src/DiscreteVoronoi.jl
using Distances: euclidean

Coord = SVector{2,Int}
const Coord = SVector{2,Int}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thumbs up

Comment thread src/core_algorithms.jl
view(grid, TL[1]:BR[1], TL[2]:BR[2]) .= Ref(first(sites))
else
# Otherwise we check if all corners have the same closest site
# Otherwise we check if all corners have the same closest site ...

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part I don't understand

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you modify the code here like

            if all(zip(mins, dists)) do ((min_dist, _), dist)
                    dist > min_dist
                end
                grid[TL[1]:BR[1], TL[2]:BR[2]] .= Ref(min_site)
                return nothing
            else
                @show (distance, mins, dists)
                # grid[TL[1]:BR[1], TL[2]:BR[2]] .= Ref(min_site)
                return nothing
            end

you'll see the non unique sites and if you also set the rectangle to the the site you'll see the test failures for Chebyshev distance. BTW we could also drop the whole code sequence, because filtering is good enough (see the benchmark for different find and filter combinations in legacy).

function centre_anchor_condition(site, sites, TL, BR; distance=euclidean)
centre = @. TL + BR / 2
anchor = find_closest_site(centre, sites)
anchor = find_closest_site(centre, sites; distance=distance)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find, didn't realise this was bugged

Comment thread src/helper_functions.jl Outdated
return nothing
end

function unstable_partition!(f, A)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you benchmark the use of unstable_partition vs EarlyStopper? I'm up for switching because it's simpler, but performance is important.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark added. To improve the last test cases we probably need something like preset_voronoi from the legacy branch.

Results from my system with 1.8.2

(n, s) = (400, 20)
jfa_voronoi!
  41.130 ms (0 allocations: 0 bytes)
dac_voronoi!
  3.201 ms (0 allocations: 0 bytes)
redac_voronoi!
exact_aux = DiscreteVoronoi.exact_aux
  1.085 ms (0 allocations: 0 bytes)
centre_anchor_aux = DiscreteVoronoi.centre_anchor_aux
  1.056 ms (0 allocations: 0 bytes)
redac_voronoi_es!
exact_aux_es = DiscreteVoronoi.exact_aux_es
  979.600 μs (0 allocations: 0 bytes)
centre_anchor_aux_es = DiscreteVoronoi.centre_anchor_aux_es
  946.800 μs (0 allocations: 0 bytes)
(n, s) = (400, 400)
jfa_voronoi!
  48.407 ms (0 allocations: 0 bytes)
dac_voronoi!
  254.303 ms (0 allocations: 0 bytes)
redac_voronoi!
exact_aux = DiscreteVoronoi.exact_aux
  7.985 ms (0 allocations: 0 bytes)
centre_anchor_aux = DiscreteVoronoi.centre_anchor_aux
  6.368 ms (0 allocations: 0 bytes)
redac_voronoi_es!
exact_aux_es = DiscreteVoronoi.exact_aux_es
  7.415 ms (0 allocations: 0 bytes)
centre_anchor_aux_es = DiscreteVoronoi.centre_anchor_aux_es
  5.867 ms (0 allocations: 0 bytes)
(n, s) = (400, 8000)
jfa_voronoi!
  64.304 ms (0 allocations: 0 bytes)
redac_voronoi!
exact_aux = DiscreteVoronoi.exact_aux
  206.388 ms (0 allocations: 0 bytes)
centre_anchor_aux = DiscreteVoronoi.centre_anchor_aux
  51.430 ms (0 allocations: 0 bytes)
redac_voronoi_es!
exact_aux_es = DiscreteVoronoi.exact_aux_es
  199.030 ms (0 allocations: 0 bytes)
centre_anchor_aux_es = DiscreteVoronoi.centre_anchor_aux_es
  50.399 ms (0 allocations: 0 bytes)
(n, s) = (400, 160000)
jfa_voronoi!
  49.841 ms (0 allocations: 0 bytes)
redac_voronoi!
exact_aux = DiscreteVoronoi.exact_aux
  7.645 s (0 allocations: 0 bytes)
centre_anchor_aux = DiscreteVoronoi.centre_anchor_aux
  686.620 ms (0 allocations: 0 bytes)
redac_voronoi_es!
exact_aux_es = DiscreteVoronoi.exact_aux_es
  7.466 s (0 allocations: 0 bytes)
centre_anchor_aux_es = DiscreteVoronoi.centre_anchor_aux_es
  707.790 ms (0 allocations: 0 bytes)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more remark: to replace _findmin with Base.findmin, EarlyStopper needs to support a keys method. Do you know how to implement it?

@goerch

goerch commented Nov 6, 2022

Copy link
Copy Markdown
Collaborator Author

My current benchmark numbers look fine now:

(n, s) = (400, 20)
jfa_voronoi!
  42.500 ms (0 allocations: 0 bytes)
dac_voronoi!
  3.335 ms (0 allocations: 0 bytes)
redac_voronoi!
exact_aux = DiscreteVoronoi.exact_aux
  1.216 ms (0 allocations: 0 bytes)
centre_anchor_aux = DiscreteVoronoi.centre_anchor_aux
  1.168 ms (0 allocations: 0 bytes)
redac_voronoi_es!
exact_aux_es = DiscreteVoronoi.exact_aux_es
  1.142 ms (0 allocations: 0 bytes)
centre_anchor_aux_es = DiscreteVoronoi.centre_anchor_aux_es
  1.070 ms (0 allocations: 0 bytes)
(n, s) = (400, 400)
jfa_voronoi!
  50.611 ms (0 allocations: 0 bytes)
dac_voronoi!
  260.228 ms (0 allocations: 0 bytes)
redac_voronoi!
exact_aux = DiscreteVoronoi.exact_aux
  8.290 ms (0 allocations: 0 bytes)
centre_anchor_aux = DiscreteVoronoi.centre_anchor_aux
  6.158 ms (0 allocations: 0 bytes)
redac_voronoi_es!
exact_aux_es = DiscreteVoronoi.exact_aux_es
  7.802 ms (0 allocations: 0 bytes)
centre_anchor_aux_es = DiscreteVoronoi.centre_anchor_aux_es
  5.792 ms (0 allocations: 0 bytes)
(n, s) = (400, 8000)
jfa_voronoi!
  66.824 ms (0 allocations: 0 bytes)
redac_voronoi!
exact_aux = DiscreteVoronoi.exact_aux
  204.743 ms (0 allocations: 0 bytes)
centre_anchor_aux = DiscreteVoronoi.centre_anchor_aux
  40.037 ms (0 allocations: 0 bytes)
redac_voronoi_es!
exact_aux_es = DiscreteVoronoi.exact_aux_es
  199.415 ms (0 allocations: 0 bytes)
centre_anchor_aux_es = DiscreteVoronoi.centre_anchor_aux_es
  39.513 ms (0 allocations: 0 bytes)
(n, s) = (400, 160000)
jfa_voronoi!
  51.920 ms (0 allocations: 0 bytes)
redac_voronoi!
exact_aux = DiscreteVoronoi.exact_aux
  435.400 μs (0 allocations: 0 bytes)
centre_anchor_aux = DiscreteVoronoi.centre_anchor_aux
  432.400 μs (0 allocations: 0 bytes)
redac_voronoi_es!
exact_aux_es = DiscreteVoronoi.exact_aux_es
  312.100 μs (0 allocations: 0 bytes)
centre_anchor_aux_es = DiscreteVoronoi.centre_anchor_aux_es
  313.900 μs (0 allocations: 0 bytes)

We could include preset_voronoi! into dac_voronoi! and redac_voronoi!. What do you prefer?

@goerch
goerch requested a review from jacobusmmsmit November 6, 2022 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants