Skip to content

Commit 82c995d

Browse files
authored
Merge pull request #178 from sbaldu/feature-default-convolutiona-kernel
Reorder `make_clusters` arguments and provide default value to convolutional kernel
2 parents ad29594 + bb7ee75 commit 82c995d

File tree

9 files changed

+47
-45
lines changed

9 files changed

+47
-45
lines changed

CLUEstering/BindingModules/Run.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ void run(float dc,
2121
clue::PointsHost<Ndim> h_points(queue, n_points, std::get<0>(pData), std::get<1>(pData));
2222
clue::PointsDevice<Ndim> d_points(queue, n_points);
2323

24-
algo.make_clusters(h_points, d_points, kernel, queue, block_size);
24+
algo.make_clusters(queue, h_points, d_points, kernel, block_size);
2525
}

benchmark/dataset_size/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void to_csv(const TimeMeasures& measures, const std::string& filename) {
8181
void run(clue::PointsHost<2>& h_points, clue::PointsDevice<2>& d_points, clue::Queue& queue) {
8282
const float dc{1.5f}, rhoc{10.f}, outlier{1.5f};
8383
clue::Clusterer<2> algo(queue, dc, rhoc, outlier);
84-
algo.make_clusters(h_points, d_points, clue::FlatKernel{.5f}, queue);
84+
algo.make_clusters(queue, h_points, d_points);
8585
}
8686

8787
int main(int argc, char* argv[]) {

benchmark/profiling/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void run(const std::string& input_file) {
1717
const float dc{1.5f}, rhoc{10.f}, outlier{1.5f};
1818
clue::Clusterer<2> algo(queue, dc, rhoc, outlier);
1919

20-
algo.make_clusters(h_points, d_points, clue::FlatKernel{.5f}, queue);
20+
algo.make_clusters(queue, h_points, d_points);
2121
auto clusters = algo.getClusters(h_points);
2222
}
2323

docs/getting-started.dox

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
*
2323
* // Launch the clustering
2424
* // The results will be stored in the `clue::PointsHost` object
25-
* const std::size_t block_size{256};
26-
* algo.make_clusters(h_points, d_points, clue::FlatKernel{.5f}, queue, block_size);
25+
* algo.make_clusters(queue, h_points, d_points);
2726
* // Read the data from the host points
2827
* auto clusters_indexes = h_points.clusterIndexes(); // Get the cluster index for each points
2928
* auto seed_map =
@@ -49,9 +48,10 @@
4948
* Then, the `clue::Clusterer`, which is the object that handles the internal allocations and contains the algorithm logic, is created. The `Clusterer`
5049
* requires the CLUE algorithm's parameters to be passed. Their meaning is explained in the introduction section, along with a description of the algorithm.
5150
*
52-
* Finally, the algorithm is launched with the `make_clusters` method, which takes as arguments the host and device points, the kernel to use for the
53-
* clustering, the queue to use for the operations and the bloch size. The input data is copied from the host to the device container, the algorithm is then
54-
* executed on the device, where the results are computed and finally copied back to the host container.
51+
* Finally, the algorithm is launched with the `make_clusters` method, which takes as arguments the queue to use for the device operations, the host and
52+
* device points and optionally the kernel to use for computing the points' density and the block-size that the kernels are launched with.
53+
* The input data is copied from the host to the device container, the algorithm is then executed on the device, where the results are computed and finally
54+
* copied back to the host container.
5555
*
5656
* The results of the clustering can then be read from the host points: the `clue::PointsHost::clusterIndexes` method returns a span of integers
5757
* representing the cluster index for each point, while the `clue::PointsHost::isSeed` method returns a boolean array indicating which points are the seeds

examples/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main() {
1515

1616
// Launch the clustering
1717
// The results will be stored in the `clue::PointsHost` object
18-
algo.make_clusters(h_points, d_points, clue::FlatKernel{.5f}, queue);
18+
algo.make_clusters(queue, h_points, d_points);
1919
// Read the data from the host points
2020
auto clusters_indexes = h_points.clusterIndexes(); // Get the cluster index for each points
2121
auto seed_map =

include/CLUEstering/core/Clusterer.hpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,58 +128,60 @@ namespace clue {
128128

129129
/// @brief Construct the clusters from host points
130130
///
131-
/// @param h_points Host points to cluster
132-
/// @param kernel The convolutional kernel to use for clustering
133131
/// @param queue The queue to use for the device operations
132+
/// @param h_points Host points to cluster
133+
/// @param kernel The convolutional kernel to use for computing the local densities, default is FlatKernel with height 0.5
134134
/// @param block_size The size of the blocks to use for clustering, default is 256
135-
template <concepts::convolutional_kernel Kernel>
136-
void make_clusters(PointsHost& h_points,
137-
const Kernel& kernel,
138-
Queue& queue,
135+
template <concepts::convolutional_kernel Kernel = FlatKernel>
136+
void make_clusters(Queue& queue,
137+
PointsHost& h_points,
138+
const Kernel& kernel = FlatKernel{.5f},
139139
std::size_t block_size = 256);
140140
/// @brief Construct the clusters from host points
141141
///
142142
/// @param h_points Host points to cluster
143-
/// @param kernel The convolutional kernel to use for clustering
143+
/// @param kernel The convolutional kernel to use for computing the local densities, default is FlatKernel with height 0.5
144144
/// @param block_size The size of the blocks to use for clustering, default is 256
145145
/// @note This method creates a temporary queue for the operations on the device
146-
template <concepts::convolutional_kernel Kernel>
147-
void make_clusters(PointsHost& h_points, const Kernel& kernel, std::size_t block_size = 256);
146+
template <concepts::convolutional_kernel Kernel = FlatKernel>
147+
void make_clusters(PointsHost& h_points,
148+
const Kernel& kernel = FlatKernel{.5f},
149+
std::size_t block_size = 256);
148150
/// @brief Construct the clusters from host and device points
149151
///
152+
/// @param queue The queue to use for the device operations
150153
/// @param h_points Host points to cluster
151154
/// @param dev_points Device points to cluster
152-
/// @param kernel The convolutional kernel to use for clustering
153-
/// @param queue The queue to use for the device operations
155+
/// @param kernel The convolutional kernel to use for computing the local densities, default is FlatKernel with height 0.5
154156
/// @param block_size The size of the blocks to use for clustering, default is 256
155-
template <concepts::convolutional_kernel Kernel>
156-
void make_clusters(PointsHost& h_points,
157+
template <concepts::convolutional_kernel Kernel = FlatKernel>
158+
void make_clusters(Queue& queue,
159+
PointsHost& h_points,
157160
PointsDevice& dev_points,
158-
const Kernel& kernel,
159-
Queue& queue,
161+
const Kernel& kernel = FlatKernel{.5f},
160162
std::size_t block_size = 256);
161163
/// @brief Construct the clusters from host and device points
162164
///
163165
/// @param h_points Host points to cluster
164166
/// @param dev_points Device points to cluster
165-
/// @param kernel The convolutional kernel to use for clustering
167+
/// @param kernel The convolutional kernel to use for computing the local densities, default is FlatKernel with height 0.5
166168
/// @param block_size The size of the blocks to use for clustering, default is 256
167169
/// @note This method creates a temporary queue for the operations on the device
168-
template <concepts::convolutional_kernel Kernel>
170+
template <concepts::convolutional_kernel Kernel = FlatKernel>
169171
void make_clusters(PointsHost& h_points,
170172
PointsDevice& dev_points,
171-
const Kernel& kernel,
173+
const Kernel& kernel = FlatKernel{.5f},
172174
std::size_t block_size = 256);
173175
/// @brief Construct the clusters from device points
174176
///
175-
/// @param dev_points Device points to cluster
176-
/// @param kernel The convolutional kernel to use for clustering
177177
/// @param queue The queue to use for the device operations
178+
/// @param dev_points Device points to cluster
179+
/// @param kernel The convolutional kernel to use for computing the local densities, default is FlatKernel with height 0.5
178180
/// @param block_size The size of the blocks to use for clustering, default is 256
179-
template <concepts::convolutional_kernel Kernel>
180-
void make_clusters(PointsDevice& dev_points,
181-
const Kernel& kernel,
182-
Queue& queue,
181+
template <concepts::convolutional_kernel Kernel = FlatKernel>
182+
void make_clusters(Queue& queue,
183+
PointsDevice& dev_points,
184+
const Kernel& kernel = FlatKernel{.5f},
183185
std::size_t block_size = 256);
184186

185187
/// @brief Specify which coordinates are periodic

include/CLUEstering/core/detail/Clusterer.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ namespace clue {
8080

8181
template <uint8_t Ndim>
8282
template <concepts::convolutional_kernel Kernel>
83-
inline void Clusterer<Ndim>::make_clusters(PointsHost& h_points,
83+
inline void Clusterer<Ndim>::make_clusters(Queue& queue,
84+
PointsHost& h_points,
8485
const Kernel& kernel,
85-
Queue& queue,
8686
std::size_t block_size) {
8787
d_points = std::make_optional<PointsDevice>(queue, h_points.size());
8888
auto& dev_points = *d_points;
@@ -109,10 +109,10 @@ namespace clue {
109109
}
110110
template <uint8_t Ndim>
111111
template <concepts::convolutional_kernel Kernel>
112-
inline void Clusterer<Ndim>::make_clusters(PointsHost& h_points,
112+
inline void Clusterer<Ndim>::make_clusters(Queue& queue,
113+
PointsHost& h_points,
113114
PointsDevice& dev_points,
114115
const Kernel& kernel,
115-
Queue& queue,
116116
std::size_t block_size) {
117117
setup(queue, h_points, dev_points);
118118
make_clusters_impl(h_points, dev_points, kernel, queue, block_size);
@@ -134,9 +134,9 @@ namespace clue {
134134
}
135135
template <uint8_t Ndim>
136136
template <concepts::convolutional_kernel Kernel>
137-
inline void Clusterer<Ndim>::make_clusters(PointsDevice& dev_points,
137+
inline void Clusterer<Ndim>::make_clusters(Queue& queue,
138+
PointsDevice& dev_points,
138139
const Kernel& kernel,
139-
Queue& queue,
140140
std::size_t block_size) {
141141
setupTiles(queue, dev_points);
142142
setupFollowers(queue, dev_points.size());

tests/test_clusterer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TEST_CASE("Test make_cluster interfaces") {
2424
auto truth_ids = truth_data.clusterIndexes();
2525
auto truth_isSeed = truth_data.isSeed();
2626
SUBCASE("Run clustering without passing device points") {
27-
algo.make_clusters(h_points, clue::FlatKernel{.5f}, queue, block_size);
27+
algo.make_clusters(queue, h_points, clue::FlatKernel{.5f}, block_size);
2828
auto clusters = h_points.clusterIndexes();
2929
auto isSeed = h_points.isSeed();
3030

@@ -51,7 +51,7 @@ TEST_CASE("Test make_cluster interfaces") {
5151
}
5252
SUBCASE("Run clustering from device points") {
5353
clue::copyToDevice(queue, d_points, h_points);
54-
algo.make_clusters(d_points, clue::FlatKernel{.5f}, queue, block_size);
54+
algo.make_clusters(queue, d_points, clue::FlatKernel{.5f}, block_size);
5555
clue::copyToHost(queue, h_points, d_points);
5656

5757
auto clusters = h_points.clusterIndexes();

tests/test_clustering.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TEST_CASE("Test clustering on benchmarking datasets") {
3030
const float dc{1.5f}, rhoc{10.f}, outlier{1.5f};
3131
clue::Clusterer<2> algo(queue, dc, rhoc, outlier);
3232

33-
algo.make_clusters(h_points, d_points, clue::FlatKernel{.5f}, queue);
33+
algo.make_clusters(queue, h_points, d_points);
3434
auto clusters = h_points.clusterIndexes();
3535
auto isSeed = h_points.isSeed();
3636

@@ -54,7 +54,7 @@ TEST_CASE("Test clustering on sissa") {
5454
const float dc{20.f}, rhoc{10.f}, outlier{20.f};
5555
clue::Clusterer<2> algo(queue, dc, rhoc, outlier);
5656

57-
algo.make_clusters(h_points, d_points, clue::FlatKernel{.5f}, queue);
57+
algo.make_clusters(queue, h_points, d_points);
5858
auto clusters = h_points.clusterIndexes();
5959
auto isSeed = h_points.isSeed();
6060

@@ -76,7 +76,7 @@ TEST_CASE("Test clustering on toy detector dataset") {
7676
const float dc{4.5f}, rhoc{2.5f}, outlier{4.5f};
7777
clue::Clusterer<2> algo(queue, dc, rhoc, outlier);
7878

79-
algo.make_clusters(h_points, d_points, clue::FlatKernel{.5f}, queue);
79+
algo.make_clusters(queue, h_points, d_points);
8080
auto clusters = h_points.clusterIndexes();
8181
auto isSeed = h_points.isSeed();
8282

@@ -98,7 +98,7 @@ TEST_CASE("Test clustering on blob dataset") {
9898
const float dc{1.f}, rhoc{5.f}, outlier{2.f};
9999
clue::Clusterer<3> algo(queue, dc, rhoc, outlier);
100100

101-
algo.make_clusters(h_points, d_points, clue::FlatKernel{.5f}, queue);
101+
algo.make_clusters(queue, h_points, d_points);
102102
auto clusters = h_points.clusterIndexes();
103103
auto isSeed = h_points.isSeed();
104104

0 commit comments

Comments
 (0)