Skip to content
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

Bounding box in higher dimensions #1149

Closed
wants to merge 5 commits into from

Conversation

rmcaixeta
Copy link
Contributor

To deal with issue #1148

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.70%. Comparing base (86359bb) to head (57c0ffc).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1149      +/-   ##
==========================================
- Coverage   87.72%   87.70%   -0.03%     
==========================================
  Files         191      191              
  Lines        6013     6000      -13     
==========================================
- Hits         5275     5262      -13     
  Misses        738      738              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/boundingboxes.jl Outdated Show resolved Hide resolved
src/boundingboxes.jl Outdated Show resolved Hide resolved
rmcaixeta and others added 2 commits November 27, 2024 11:01
Co-authored-by: Elias Carvalho <73039601+eliascarv@users.noreply.github.com>
@eliascarv
Copy link
Member

eliascarv commented Nov 28, 2024

Code generated by the _pboxes function for some dimensions:

julia> gen(1)
quote
    #= REPL[10]:24 =#
    p = first(points)
    #= REPL[10]:25 =#= lentype(p)
    #= REPL[10]:26 =#
    cmin1 = typemax(ℒ)
    #= REPL[10]:27 =#
    cmax1 = typemin(ℒ)
    #= REPL[10]:29 =#
    for p = points
        #= REPL[10]:30 =#
        c = CoordRefSystems.values(convert(Cartesian, coords(p)))
        #= REPL[10]:31 =#
        cmin1 = min(c[1], cmin1)
        #= REPL[10]:32 =#
        cmax1 = max(c[1], cmax1)
        #= REPL[10]:33 =#
    end
    #= REPL[10]:35 =#
    Box(withcrs(p, (cmin1,)), withcrs(p, (cmax1,)))
end

julia> gen(2)
quote
    #= REPL[10]:24 =#
    p = first(points)
    #= REPL[10]:25 =#= lentype(p)
    #= REPL[10]:26 =#
    cmin1 = typemax(ℒ)
    cmin2 = typemax(ℒ)
    #= REPL[10]:27 =#
    cmax1 = typemin(ℒ)
    cmax2 = typemin(ℒ)
    #= REPL[10]:29 =#
    for p = points
        #= REPL[10]:30 =#
        c = CoordRefSystems.values(convert(Cartesian, coords(p)))
        #= REPL[10]:31 =#
        cmin1 = min(c[1], cmin1)
        cmin2 = min(c[2], cmin2)
        #= REPL[10]:32 =#
        cmax1 = max(c[1], cmax1)
        cmax2 = max(c[2], cmax2)
        #= REPL[10]:33 =#
    end
    #= REPL[10]:35 =#
    Box(withcrs(p, (cmin1, cmin2)), withcrs(p, (cmax1, cmax2)))
end

julia> gen(3)
quote
    #= REPL[10]:24 =#
    p = first(points)
    #= REPL[10]:25 =#= lentype(p)
    #= REPL[10]:26 =#
    cmin1 = typemax(ℒ)
    cmin2 = typemax(ℒ)
    cmin3 = typemax(ℒ)
    #= REPL[10]:27 =#
    cmax1 = typemin(ℒ)
    cmax2 = typemin(ℒ)
    cmax3 = typemin(ℒ)
    #= REPL[10]:29 =#
    for p = points
        #= REPL[10]:30 =#
        c = CoordRefSystems.values(convert(Cartesian, coords(p)))
        #= REPL[10]:31 =#
        cmin1 = min(c[1], cmin1)
        cmin2 = min(c[2], cmin2)
        cmin3 = min(c[3], cmin3)
        #= REPL[10]:32 =#
        cmax1 = max(c[1], cmax1)
        cmax2 = max(c[2], cmax2)
        cmax3 = max(c[3], cmax3)
        #= REPL[10]:33 =#
    end
    #= REPL[10]:35 =#
    Box(withcrs(p, (cmin1, cmin2, cmin3)), withcrs(p, (cmax1, cmax2, cmax3)))
end

julia> gen(4)
quote
    #= REPL[10]:24 =#
    p = first(points)
    #= REPL[10]:25 =#= lentype(p)
    #= REPL[10]:26 =#
    cmin1 = typemax(ℒ)
    cmin2 = typemax(ℒ)
    cmin3 = typemax(ℒ)
    cmin4 = typemax(ℒ)
    #= REPL[10]:27 =#
    cmax1 = typemin(ℒ)
    cmax2 = typemin(ℒ)
    cmax3 = typemin(ℒ)
    cmax4 = typemin(ℒ)
    #= REPL[10]:29 =#
    for p = points
        #= REPL[10]:30 =#
        c = CoordRefSystems.values(convert(Cartesian, coords(p)))
        #= REPL[10]:31 =#
        cmin1 = min(c[1], cmin1)
        cmin2 = min(c[2], cmin2)
        cmin3 = min(c[3], cmin3)
        cmin4 = min(c[4], cmin4)
        #= REPL[10]:32 =#
        cmax1 = max(c[1], cmax1)
        cmax2 = max(c[2], cmax2)
        cmax3 = max(c[3], cmax3)
        cmax4 = max(c[4], cmax4)
        #= REPL[10]:33 =#
    end
    #= REPL[10]:35 =#
    Box(withcrs(p, (cmin1, cmin2, cmin3, cmin4)), withcrs(p, (cmax1, cmax2, cmax3, cmax4)))
end

@eliascarv eliascarv requested a review from juliohm November 28, 2024 12:47
src/boundingboxes.jl Outdated Show resolved Hide resolved
@eliascarv
Copy link
Member

Allocation in heterogeneous collections:
setup

b1 = Box((-3, -1), (0.5, 0.5))
b2 = b1 |> Translate(2, 2)
s = Sphere((0, 0), 2)
m1 = Multi([b1, s])
m2 = Multi([b1, s, b2])

master

julia> @allocated(boundingbox(m1))
2544

julia> @allocated(boundingbox(m2))
3504

PR

julia> @allocated(boundingbox(m1))
2672

julia> @allocated(boundingbox(m2))
3696

Copy link
Member

@juliohm juliohm left a comment

Choose a reason for hiding this comment

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

@rmcaixeta , we explored this idea with generated functions and noticed that the compiler allocates more memory when the Multi geometries or GeometrySet are heterogeneous. The type instability leads to dynamic execution and more bytes per geometry.

Since boundingbox is a pretty fundamental function, which is used in various algorithms for optimization, we are a bit reluctant to support arbitrary N > 3 dimensions.

Could you please elaborate on your use case? If you are trying to simulate an abstract Gaussian process over N > 3 non-physical dimensions, you can either add this method locally to see if the rest of GeoStatsProcesses.jl works, or choose a more general package for Gaussian process simulation that is not developed with geospatial coordinates in mind.

@rmcaixeta
Copy link
Contributor Author

Nice piece of code @eliascarv
Hi @juliohm . The simulation is made in higher dimension (to "remove" some nonstationary features) and mapped back to original space. But that's fine, it apparently works well locally if I just add the initial suggested function. without changing anything in Meshes.jl. I opened the issue because it'd change just a small piece of code, I didn't imagine it'd cause problems. You can cancel the PR then. Have a good conference in Belem soon, cheers

@juliohm
Copy link
Member

juliohm commented Nov 28, 2024

Thank you! Closing the PR.

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.

3 participants