Skip to content

Commit

Permalink
Fix cudf::repeat logic when count is zero (#13459)
Browse files Browse the repository at this point in the history
Fixes logic in `cudf::repeat` to check for `count==0` before using it to check for possible out-of-bounds output size result.
Added a specific gtest for this as well.

Closes #13458 

Authors:
   - David Wendt (https://github.com/davidwendt)

Approvers:
   - Karthikeyan (https://github.com/karthikeyann)
   - Bradley Dice (https://github.com/bdice)
   - Vukasin Milovanovic (https://github.com/vuule)
   - Jason Lowe (https://github.com/jlowe)
   - Mike Wilson (https://github.com/hyperbolic2346)
  • Loading branch information
davidwendt authored May 30, 2023
1 parent e159c01 commit 5541e64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 5541e64

Please sign in to comment.