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

Fix cudf::repeat logic when count is zero #13459

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/src/filling/repeat.cu
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ std::unique_ptr<table> repeat(table_view const& input_table,
rmm::cuda_stream_view stream,
rmm::mr::device_memory_resource* mr)
{
if ((input_table.num_rows() == 0) || (count == 0)) { return cudf::empty_like(input_table); }

CUDF_EXPECTS(count >= 0, "count value should be non-negative");
CUDF_EXPECTS(input_table.num_rows() <= std::numeric_limits<size_type>::max() / count,
"The resulting table exceeds the column size limit",
std::overflow_error);

if ((input_table.num_rows() == 0) || (count == 0)) { return cudf::empty_like(input_table); }

auto output_size = input_table.num_rows() * count;
auto map_begin = cudf::detail::make_counting_transform_iterator(
0, [count] __device__(auto i) { return i / count; });
Expand Down
15 changes: 15 additions & 0 deletions cpp/tests/filling/repeat_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ TYPED_TEST(RepeatTypedTestFixture, ZeroSizeInput)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(p_ret->view().column(0), expected);
}

TYPED_TEST(RepeatTypedTestFixture, ZeroCount)
{
using T = TypeParam;
cudf::test::fixed_width_column_wrapper<T, int32_t> input(thrust::make_counting_iterator(0),
thrust::make_counting_iterator(10));

auto expected = cudf::make_empty_column(cudf::type_to_id<T>());

cudf::table_view input_table{{input}};
auto p_ret = cudf::repeat(input_table, 0);

EXPECT_EQ(p_ret->num_columns(), 1);
CUDF_TEST_EXPECT_COLUMNS_EQUAL(p_ret->view().column(0), expected->view());
}

class RepeatStringTestFixture : public cudf::test::BaseFixture,
cudf::test::UniformRandomGenerator<cudf::size_type> {
public:
Expand Down