-
Notifications
You must be signed in to change notification settings - Fork 38
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
Create new UnionFind struct for DBSCAN #506
Conversation
void union_1way(int i, int j) const { labels_(i) = representative(j); } | ||
|
||
KOKKOS_FUNCTION | ||
void union_2way(int i, int j) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why union "one" and "two" way? I don't get it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Union-find algorithm essentially merges two (implicit) trees. In general, it does not matter which one is a root, and which one is merged into, and is usually based on which representative is smaller. However, for the boundary points, it matters, as otherwise it may lead to the bridging effect. So the boundary point tree has to be merged into the core point tree, which is what I call union_1way
, which simply assigns a label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't get the name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given what I described, how would you propose to call them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe be more explicit via union_boundary_core
or such?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just not include union_1way
in UnionFind
then (and have the behavior in-line as before) and don't change the name of union_2way
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@masterleinad I need union 1 way in UnionFind, as I do not want to expose labels.
@masterleinad @dalg24 Would you guys feel better if I change the signature to
union(int i, int j, bool one_way = false);
or union(int i, int j, bool any_order = true)
? It may be slightly less performant, as it will introduce an extra unnecessary if
check, but should not be a biggie.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to have two member functions in that case but they should be self-describing. What you essentially want is a version that assigns that updates the left tree ( or the right tree), isn't it?
If so, union_merge_left
and union_merge_any
(or just union
) would be fine with me. Alternatively, introducing a template argument force_merge_left
should not have any runtime overhead and might be nicer by providing only one function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you essentially want is a version that assigns that updates the left tree ( or the right tree), isn't it?
Well, similar, but there is no left tree and right tree. There are two trees, one consisting of a single vertex (corresponding to the boundary point), and one other tree. To me, left
is completely confusing, and does not make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Then calling this function has special requisites, i.e. one of them having only a single vertex, in that case I would certainly use two different names, maybe union_with_single_vertex_tree
or so.
void union_1way(int i, int j) const { labels_(i) = representative(j); } | ||
|
||
KOKKOS_FUNCTION | ||
void union_2way(int i, int j) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't get the name
src/ArborX_DBSCAN.hpp
Outdated
@@ -149,15 +149,16 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives, | |||
Kokkos::View<int *, MemorySpace> labels( | |||
Kokkos::ViewAllocateWithoutInitializing("ArborX::DBSCAN::labels"), n); | |||
ArborX::iota(exec_space, labels); | |||
Details::UnionFind<MemorySpace> union_find{labels}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to expose this? This is an implementation of the callback. Take the labels like you did before and create your union find in the callback constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I could do that in this PR, but I would have to move it out in the dense box PR, as I will also need to update this outside of the callback. So, rather than passing the labels around I like it better to pass union-find struct around. This also makes sense logically, as we could change the way union-find struct implemented (if desired) without changing the callback.
This makes the code more readable, and prepares a stage for the dense box implementation of the algorithm.
74b26ac
to
9e867dc
Compare
@dalg24 Do my comments address your concerns? |
Two SYCL timeouts, but otherwise tests pass. |
@dalg24 Should have addressed your comments. I renamed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if you squash merged or rewrote history
This makes the code more readable, and prepares a stage for the dense
box implementation of the algorithm.