Conversation
Updated the module file to expose SpatialHashingCellList to the users.
…hashing.jl to correct collision handling. Push collision check in __foreach_neighbor() for better performance. Extend test to test on multiple list sizes. Change plot.jl to test SpatialHashingCellList against the other data structures.
|
@efaulhaber Please take a look at the current state of the spatial hashing implementation. |
|
The problem is that the current code does not set the collision flag correctly for empty cells without any points. function push_cell!(cell_list::SpatialHashingCellList, cell)
(; cell_coords, cell_collision, list_size, NDIMS) = cell_list
key = spatial_hash(cell, list_size)
cell_coord = cell_coords[key]
if cell_coord == ntuple(_ -> typemin(Int), NDIMS)
cell_coords[key] = cell
elseif cell_coord != cell
cell_collision[key] = true
end
endThe issue occurs when using function check_collision(neighbor_cell_::Tuple, neighbor_coords,
cell_list::SpatialHashingCellList, nhs)
(; list_size, cell_collision) = cell_list
if cell_collision[spatial_hash(neighbor_cell_, list_size)]
# Check if `neighbor_coords` are in the cell `neighbor_cell_`
cell_coords_ = cell_coords(neighbor_coords, nhs)
return neighbor_cell_ != cell_coords_
end
return false
end
@inline function __foreach_neighbor(f, system_coords, neighbor_system_coords,
neighborhood_search::GridNeighborhoodSearch,
point, point_coords, search_radius)
(; cell_list, periodic_box) = neighborhood_search
cell = cell_coords(point_coords, neighborhood_search)
for neighbor_cell_ in neighboring_cells(cell, neighborhood_search)
neighbor_cell = Tuple(neighbor_cell_)
neighbors = points_in_cell(neighbor_cell, neighborhood_search)
for neighbor_ in eachindex(neighbors)
neighbor = @inbounds neighbors[neighbor_]
# Making the following `@inbounds` yields a ~2% speedup on an NVIDIA H100.
# But we don't know if `neighbor` (extracted from the cell list) is in bounds.
neighbor_coords = extract_svector(neighbor_system_coords,
Val(ndims(neighborhood_search)), neighbor)
pos_diff = point_coords - neighbor_coords
distance2 = dot(pos_diff, pos_diff)
pos_diff, distance2 = compute_periodic_distance(pos_diff, distance2,
search_radius,
periodic_box)
if distance2 <= search_radius^2
distance = sqrt(distance2)
# Check if `neighbor_coords` are in the cell `neighbor_cell_`.
# For the `SpatialHashingCellList`, this might not be the case
# if we have a collision.
if check_collision(neighbor_cell_, neighbor_coords, cell_list,
neighborhood_search)
continue
end
# Inline to avoid loss of performance
# compared to not using `foreach_point_neighbor`.
@inline f(point, neighbor, pos_diff, distance)
end
end
end
end |
|
Would this work? function check_collision(neighbor_cell::Tuple, neighbor_coords,
cell_list::SpatialHashingCellList, nhs)
(; list_size, cell_collision) = cell_list
hash = spatial_hash(neighbor_cell_, list_size)
if cell_collision[hash]
# Points from multiple cells are in this list.
# Check if `neighbor_coords` are in the cell `neighbor_cell`.
return neighbor_cell != cell_coords(neighbor_coords, nhs)
elseif cell_coords[hash] != neighbor_cell
# `cell_collision` is false for this list, meaning only points from one cell are in the list.
# However, the cell of this list is not our `neighbor_cell`, so `neighbor_coords`
# are not in `neighbor_cell`.
return true
end
return false
end |
…ntNeighbors.jl into SpatialHashing
|
@RubberLanding #86 is merged now. You can go ahead and prepare this PR for review. |
Include SpatialHashingCellList in test/neighborhood_search.jl.
Add check_cell_collision() for benchmarking.
c1b368a to
81c640c
Compare
- add comments - adjust version in Project.toml
There was a problem hiding this comment.
Pull Request Overview
This pull request implements a spatial hashing data structure for neighborhood search and removes some dependencies from the test configuration to streamline the project setup.
- Removed dependencies and compatibility requirements from test/Project.toml
- Cleans up the test configuration to support the new spatial hashing implementation
Files not reviewed (6)
- src/PointNeighbors.jl: Language not supported
- src/cell_lists/cell_lists.jl: Language not supported
- src/cell_lists/spatial_hashing.jl: Language not supported
- src/nhs_grid.jl: Language not supported
- test/cell_lists/spatial_hashing.jl: Language not supported
- test/neighborhood_search.jl: Language not supported
Comments suppressed due to low confidence (1)
test/Project.toml:1
- Ensure that removing these dependencies is intentional and that no tests rely on them for the spatial hashing functionality.
- -[deps]
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #101 +/- ##
==========================================
- Coverage 89.02% 87.94% -1.09%
==========================================
Files 13 15 +2
Lines 556 622 +66
==========================================
+ Hits 495 547 +52
- Misses 61 75 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
efaulhaber
left a comment
There was a problem hiding this comment.
LGTM, but the format check is failing.
|
@efaulhaber If you are starting to add references you should also add a bib file and setup stub docs. |
|
@RubberLanding For the formatting test to not fail you need to use JuliaFormatter.jl and apply it e.g. |
We have references already. But yes, at some point we should do that. |
Implement spatial hashing data structure for neighborhood search.
Depends on #86.