Skip to content

Commit

Permalink
Use counting_iterator in HLL unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeepyjack committed Jun 11, 2024
1 parent 693698d commit 76d77c9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions tests/distinct_count_estimator/unique_sequence_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
#include <cuco/distinct_count_estimator.cuh>
#include <cuco/hash_functions.cuh>

#include <thrust/device_vector.h>
#include <thrust/sequence.h>
#include <thrust/iterator/counting_iterator.h>

#include <catch2/catch_template_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
Expand Down Expand Up @@ -50,10 +49,8 @@ TEMPLATE_TEST_CASE_SIG("distinct_count_estimator: unique sequence",
double const relative_standard_deviation =
1.04 / std::sqrt(static_cast<double>(1ull << hll_precision));

thrust::device_vector<T> items(num_items);

// Generate `num_items` distinct items
thrust::sequence(items.begin(), items.end(), 0);
// Generates distinct items
auto const items_begin = thrust::counting_iterator<T>(0);

// Initialize the estimator
cuco::distinct_count_estimator<T, cuda::thread_scope_device, Hash> estimator{
Expand All @@ -62,12 +59,12 @@ TEMPLATE_TEST_CASE_SIG("distinct_count_estimator: unique sequence",
REQUIRE(estimator.estimate() == 0);

// Add all items to the estimator
estimator.add(items.begin(), items.end());
estimator.add(items_begin, items_begin + num_items);

auto const estimate = estimator.estimate();

// Adding the same items again should not affect the result
estimator.add(items.begin(), items.begin() + num_items / 2);
estimator.add(items_begin, items_begin + num_items / 2);
REQUIRE(estimator.estimate() == estimate);

// Clearing the estimator should reset the estimate
Expand Down

0 comments on commit 76d77c9

Please sign in to comment.