Skip to content

Add demo of iterator based topological relations types #1235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

halleysfifthinc
Copy link
Contributor

As we discussed on Zulip, here is a draft PR of my implementation of the topological
relations for HalfEdgeTopologys using the iterator interface. You are welcome to add/use
these however much or little you want, but I have no immediate need for these to be
upstreamed.

Script showing performance benefits of the non-allocating iteration interface:

function vertex_normals_master(msh, fnorms)
    vT = eltype(fnorms)
    vnorms = similar(fnorms, nvertices(msh))
    C = Coboundary{0,2}(topology(msh))

    for i in eachindex(vnorms)
        v = zero(vT)
        for j in C(i)
            v += fnorms[j]
        end
        vnorms[i] = Meshes.unormalize(v)
    end
    return vnorms
end

function vertex_normals_iterable(msh, fnorms)
    vT = eltype(fnorms)
    vnorms = similar(fnorms, nvertices(msh))
    S = Shared{FACE,VERTEX}(msh)

    for i in eachindex(vnorms)
        v = zero(vT)
        for j in S(i)
            v += fnorms[j]
        end
        vnorms[i] = Meshes.unormalize(v)
    end
    return vnorms
end

sphere = topoconvert(HalfEdgeTopology, simplexify(Sphere(Point(0,0,0), 1)))
fnorm = normal.(elements(sphere))
julia> @benchmark vertex_normals_master(sphere, fnorm)
BenchmarkTools.Trial: 2521 samples with 1 evaluation per sample.
 Range (min … max):  1.664 ms …  18.377 ms  ┊ GC (min … max): 0.00% … 85.70%
 Time  (median):     1.763 ms               ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.975 ms ± 912.216 μs  ┊ GC (mean ± σ):  7.22% ± 11.68%

  ██▅▃▃▂▂▁                                                    ▁
  █████████▇█▆▃▅▃▃▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▅▆▆▆▆▆▇▆ █
  1.66 ms      Histogram: log(frequency) by time      6.67 ms <

 Memory estimate: 1.89 MiB, allocs estimate: 61831.

julia> @benchmark vertex_normals_iterable(sphere, fnorm)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
 Range (min … max):  169.017 μs …  6.926 ms  ┊ GC (min … max): 0.00% … 95.40%
 Time  (median):     181.195 μs              ┊ GC (median):    0.00%
 Time  (mean ± σ):   191.566 μs ± 89.738 μs  ┊ GC (mean ± σ):  1.33% ±  3.32%

  ▂▆█▅▃▄▅▅▅▄▅▅▃▂▂▁▁▃▃▃▂▂▃▃▂▃▄▅▃▂▂▂▁▁▂▂▁     ▁▁ ▁▁▁▁▁▁▁         ▂
  █████████████████████████████████████▇▇▆█████████████▆▆▆▅▆▅▅ █
  169 μs        Histogram: log(frequency) by time       248 μs <

 Memory estimate: 59.88 KiB, allocs estimate: 3.

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.

1 participant