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 off-by-one error in char-parallel string scalar replace #7502

Merged
merged 2 commits into from
Mar 4, 2021
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
2 changes: 1 addition & 1 deletion cpp/src/strings/replace/replace.cu
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ size_type filter_false_target_positions(rmm::device_uvector<size_type>& target_p
// find the end of the string containing the start of this target
size_type const* offset_ptr = thrust::upper_bound(
thrust::seq, d_offsets_span.begin(), d_offsets_span.end(), target_pos);
return target_pos + target_size >= *offset_ptr;
return target_pos + target_size > *offset_ptr;
});
auto const target_count = cudf::distance(d_target_positions, target_pos_end);
if (target_count == 0) { return 0; }
Expand Down
31 changes: 31 additions & 0 deletions cpp/tests/strings/replace_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,37 @@ TEST_F(StringsReplaceTest, ReplaceNullInput)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, strings);
}

TEST_F(StringsReplaceTest, ReplaceEndOfString)
{
auto strings = build_corpus();
auto strings_view = cudf::strings_column_view(strings);
// replace all occurrences of 'in' with ' '
std::vector<const char*> h_expected{"the quick brown fox jumps over the lazy dog",
"the fat cat lays next to the other accénted cat",
"a slow mov g turtlé cannot catch the bird",
"which can be composéd together to form a more complete",
"The result does not clude the value the sum ",
"",
nullptr};

cudf::test::strings_column_wrapper expected(
h_expected.begin(),
h_expected.end(),
thrust::make_transform_iterator(h_expected.begin(), [](auto str) { return str != nullptr; }));

auto results =
cudf::strings::replace(strings_view, cudf::string_scalar("in"), cudf::string_scalar(" "));
cudf::test::expect_columns_equal(*results, expected);

results = cudf::strings::detail::replace<cudf::strings::detail::replace_algorithm::CHAR_PARALLEL>(
strings_view, cudf::string_scalar("in"), cudf::string_scalar(" "));
cudf::test::expect_columns_equal(*results, expected);

results = cudf::strings::detail::replace<cudf::strings::detail::replace_algorithm::ROW_PARALLEL>(
strings_view, cudf::string_scalar("in"), cudf::string_scalar(" "));
cudf::test::expect_columns_equal(*results, expected);
}

TEST_F(StringsReplaceTest, ReplaceSlice)
{
std::vector<const char*> h_strings{"Héllo", "thesé", nullptr, "ARE THE", "tést strings", ""};
Expand Down