Skip to content

Commit

Permalink
Replace all_null() and all_valid() by iterator_all_nulls() and …
Browse files Browse the repository at this point in the history
…`iterator_no_null()` in tests (#8437)

This PR does some cleanup for tests in copying and groupby. In particular, it replace the functions `all_null()` and `all_valid()` by `iterator_all_nulls()` and `iterator_no_null()` from `iterator_utilities.hpp`. This is because the former functions (`all_null()` and `all_valid()`) are just duplicated/reimplemented of the latter ones.

There is no other change in this work.

Authors:
  - Nghia Truong (https://github.com/ttnghia)

Approvers:
  - MithunR (https://github.com/mythrocks)
  - Ram (Ramakrishna Prabhu) (https://github.com/rgsl888prabhu)

URL: #8437
  • Loading branch information
ttnghia authored Jun 7, 2021
1 parent 92ed5b3 commit badb501
Show file tree
Hide file tree
Showing 25 changed files with 162 additions and 147 deletions.
14 changes: 6 additions & 8 deletions cpp/tests/copying/get_value_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/cudf_gtest.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/type_list_utilities.hpp>
#include <cudf_test/type_lists.hpp>

Expand Down Expand Up @@ -560,8 +561,8 @@ struct ListGetStructValueTest : public BaseFixture {
// {int: 1, string: NULL, list: NULL}
return this->make_test_structs_column({{1}, {1}},
strings_column_wrapper({"aa"}, {false}),
LCWinner_t({{}}, all_invalid()),
all_valid());
LCWinner_t({{}}, iterator_all_nulls()),
iterator_no_null());
}

/**
Expand All @@ -570,7 +571,7 @@ struct ListGetStructValueTest : public BaseFixture {
SCW row1()
{
// NULL
return this->make_test_structs_column({-1}, {""}, LCWinner_t{-1}, all_invalid());
return this->make_test_structs_column({-1}, {""}, LCWinner_t{-1}, iterator_all_nulls());
}

/**
Expand All @@ -581,8 +582,8 @@ struct ListGetStructValueTest : public BaseFixture {
// {int: 3, string: "xyz", list: [3, 8, 4]}
return this->make_test_structs_column({{3}, {1}},
strings_column_wrapper({"xyz"}, {true}),
LCWinner_t({{3, 8, 4}}, all_valid()),
all_valid());
LCWinner_t({{3, 8, 4}}, iterator_no_null()),
iterator_no_null());
}

/**
Expand All @@ -596,9 +597,6 @@ struct ListGetStructValueTest : public BaseFixture {
// {int: 3, string: "xyz", list: [3, 8, 4]}
return this->concat({row0(), row1(), row2()});
}

auto all_valid() { return thrust::make_constant_iterator(true); }
auto all_invalid() { return thrust::make_constant_iterator(false); }
};

TYPED_TEST_CASE(ListGetStructValueTest, FixedWidthTypes);
Expand Down
13 changes: 7 additions & 6 deletions cpp/tests/groupby/argmax_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/detail/aggregation/aggregation.hpp>
Expand Down Expand Up @@ -58,7 +59,7 @@ TYPED_TEST(groupby_argmax_test, zero_valid_keys)

if (std::is_same<V, bool>::value) return;

fixed_width_column_wrapper<K> keys({1, 2, 3}, all_null());
fixed_width_column_wrapper<K> keys({1, 2, 3}, iterator_all_nulls());
fixed_width_column_wrapper<V> vals({3, 4, 5});

fixed_width_column_wrapper<K> expect_keys{};
Expand All @@ -79,10 +80,10 @@ TYPED_TEST(groupby_argmax_test, zero_valid_values)
if (std::is_same<V, bool>::value) return;

fixed_width_column_wrapper<K> keys{1, 1, 1};
fixed_width_column_wrapper<V> vals({3, 4, 5}, all_null());
fixed_width_column_wrapper<V> vals({3, 4, 5}, iterator_all_nulls());

fixed_width_column_wrapper<K> expect_keys{1};
fixed_width_column_wrapper<R> expect_vals({0}, all_null());
fixed_width_column_wrapper<R> expect_vals({0}, iterator_all_nulls());

auto agg = cudf::make_argmax_aggregation();
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
Expand All @@ -104,7 +105,7 @@ TYPED_TEST(groupby_argmax_test, null_keys_and_values)
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0});

// {1, 1, 2, 2, 2, 3, 3, 4}
fixed_width_column_wrapper<K> expect_keys({1, 2, 3, 4}, all_valid());
fixed_width_column_wrapper<K> expect_keys({1, 2, 3, 4}, iterator_no_null());
// {6, 3, 5, 4, 0, 2, 1, -}
fixed_width_column_wrapper<R> expect_vals({3, 4, 7, 0}, {1, 1, 1, 0});

Expand Down Expand Up @@ -142,10 +143,10 @@ TEST_F(groupby_argmax_string_test, zero_valid_values)
using R = cudf::detail::target_type_t<V, aggregation::ARGMAX>;

fixed_width_column_wrapper<K> keys{1, 1, 1};
strings_column_wrapper vals({"año", "bit", "₹1"}, all_null());
strings_column_wrapper vals({"año", "bit", "₹1"}, iterator_all_nulls());

fixed_width_column_wrapper<K> expect_keys{1};
fixed_width_column_wrapper<R> expect_vals({0}, all_null());
fixed_width_column_wrapper<R> expect_vals({0}, iterator_all_nulls());

auto agg = cudf::make_argmax_aggregation();
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
Expand Down
13 changes: 7 additions & 6 deletions cpp/tests/groupby/argmin_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/detail/aggregation/aggregation.hpp>
Expand Down Expand Up @@ -58,7 +59,7 @@ TYPED_TEST(groupby_argmin_test, zero_valid_keys)

if (std::is_same<V, bool>::value) return;

fixed_width_column_wrapper<K> keys({1, 2, 3}, all_null());
fixed_width_column_wrapper<K> keys({1, 2, 3}, iterator_all_nulls());
fixed_width_column_wrapper<V> vals({3, 4, 5});

fixed_width_column_wrapper<K> expect_keys{};
Expand All @@ -79,10 +80,10 @@ TYPED_TEST(groupby_argmin_test, zero_valid_values)
if (std::is_same<V, bool>::value) return;

fixed_width_column_wrapper<K> keys{1, 1, 1};
fixed_width_column_wrapper<V> vals({3, 4, 5}, all_null());
fixed_width_column_wrapper<V> vals({3, 4, 5}, iterator_all_nulls());

fixed_width_column_wrapper<K> expect_keys{1};
fixed_width_column_wrapper<R> expect_vals({0}, all_null());
fixed_width_column_wrapper<R> expect_vals({0}, iterator_all_nulls());

auto agg = cudf::make_argmin_aggregation();
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
Expand All @@ -104,7 +105,7 @@ TYPED_TEST(groupby_argmin_test, null_keys_and_values)
{1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0});

// { 1, 1, 2, 2, 2, 3, 3, 4}
fixed_width_column_wrapper<K> expect_keys({1, 2, 3, 4}, all_valid());
fixed_width_column_wrapper<K> expect_keys({1, 2, 3, 4}, iterator_no_null());
// { 9, 6, 8, 5, 0, 7, 1, -}
fixed_width_column_wrapper<R> expect_vals({3, 9, 8, 0}, {1, 1, 1, 0});

Expand Down Expand Up @@ -143,10 +144,10 @@ TEST_F(groupby_argmin_string_test, zero_valid_values)
using R = cudf::detail::target_type_t<V, aggregation::ARGMIN>;

fixed_width_column_wrapper<K> keys{1, 1, 1};
strings_column_wrapper vals({"año", "bit", "₹1"}, all_null());
strings_column_wrapper vals({"año", "bit", "₹1"}, iterator_all_nulls());

fixed_width_column_wrapper<K> expect_keys{1};
fixed_width_column_wrapper<R> expect_vals({0}, all_null());
fixed_width_column_wrapper<R> expect_vals({0}, iterator_all_nulls());

auto agg = cudf::make_argmin_aggregation();
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
Expand Down
7 changes: 4 additions & 3 deletions cpp/tests/groupby/count_scan_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/detail/aggregation/aggregation.hpp>
Expand Down Expand Up @@ -84,7 +85,7 @@ TYPED_TEST(groupby_count_scan_test, zero_valid_keys)
using result_wrapper = typename TestFixture::result_wrapper;

// clang-format off
key_wrapper keys( {1, 2, 3}, all_null());
key_wrapper keys( {1, 2, 3}, iterator_all_nulls());
value_wrapper vals{3, 4, 5};

key_wrapper expect_keys{};
Expand All @@ -102,7 +103,7 @@ TYPED_TEST(groupby_count_scan_test, zero_valid_values)

// clang-format off
key_wrapper keys {1, 1, 1};
value_wrapper vals({3, 4, 5}, all_null());
value_wrapper vals({3, 4, 5}, iterator_all_nulls());

key_wrapper expect_keys{1, 1, 1};
result_wrapper expect_vals{0, 1, 2};
Expand All @@ -122,7 +123,7 @@ TYPED_TEST(groupby_count_scan_test, null_keys_and_values)
value_wrapper vals({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4}, {0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0});

// {1, 1, 1, 2, 2, 2, 2, 3, _, 3, 4}
key_wrapper expect_keys( {1, 1, 1, 2, 2, 2, 2, 3, 3, 4}, all_valid());
key_wrapper expect_keys( {1, 1, 1, 2, 2, 2, 2, 3, 3, 4}, iterator_no_null());
// {0, 3, 6, 1, 4, _, 9, 2, 7, 8, -}
result_wrapper expect_vals{0, 1, 2, 0, 1, 2, 3, 0, 1, 0};
// clang-format on
Expand Down
7 changes: 4 additions & 3 deletions cpp/tests/groupby/count_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/detail/aggregation/aggregation.hpp>
Expand Down Expand Up @@ -75,7 +76,7 @@ TYPED_TEST(groupby_count_test, zero_valid_keys)
using V = TypeParam;
using R = cudf::detail::target_type_t<V, aggregation::COUNT_VALID>;

fixed_width_column_wrapper<K> keys({1, 2, 3}, all_null());
fixed_width_column_wrapper<K> keys({1, 2, 3}, iterator_all_nulls());
fixed_width_column_wrapper<V> vals{3, 4, 5};

fixed_width_column_wrapper<K> expect_keys{};
Expand All @@ -97,7 +98,7 @@ TYPED_TEST(groupby_count_test, zero_valid_values)
using R = cudf::detail::target_type_t<V, aggregation::COUNT_VALID>;

fixed_width_column_wrapper<K> keys{1, 1, 1};
fixed_width_column_wrapper<V> vals({3, 4, 5}, all_null());
fixed_width_column_wrapper<V> vals({3, 4, 5}, iterator_all_nulls());

fixed_width_column_wrapper<K> expect_keys{1};
fixed_width_column_wrapper<R> expect_vals{0};
Expand Down Expand Up @@ -125,7 +126,7 @@ TYPED_TEST(groupby_count_test, null_keys_and_values)

// clang-format off
// {1, 1, 2, 2, 2, 3, 3, 4}
fixed_width_column_wrapper<K> expect_keys({1, 2, 3, 4}, all_valid());
fixed_width_column_wrapper<K> expect_keys({1, 2, 3, 4}, iterator_no_null());
// {3, 6, 1, 4, 9, 2, 8, -}
fixed_width_column_wrapper<R> expect_vals({2, 3, 2, 0});
// clang-format on
Expand Down
12 changes: 0 additions & 12 deletions cpp/tests/groupby/groupby_test_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,5 @@ inline void test_single_scan(column_view const& keys,
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expect_vals, *result.second[0].results[0], true);
}

inline auto all_valid()
{
auto all_valid = cudf::detail::make_counting_transform_iterator(0, [](auto i) { return true; });
return all_valid;
}

inline auto all_null()
{
auto all_null = cudf::detail::make_counting_transform_iterator(0, [](auto i) { return false; });
return all_null;
}

} // namespace test
} // namespace cudf
5 changes: 3 additions & 2 deletions cpp/tests/groupby/groups_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/types.hpp>
Expand Down Expand Up @@ -57,7 +58,7 @@ TEST_F(groupby_group_keys_test, all_null_keys)
{
using K = int32_t;

fixed_width_column_wrapper<K> keys({1, 1, 2, 3, 1, 2}, all_null());
fixed_width_column_wrapper<K> keys({1, 1, 2, 3, 1, 2}, iterator_all_nulls());
fixed_width_column_wrapper<K> expect_grouped_keys{};
std::vector<size_type> expect_group_offsets = {0};
test_groups(keys, expect_grouped_keys, expect_group_offsets);
Expand All @@ -82,7 +83,7 @@ TYPED_TEST(groupby_group_keys_and_values_test, some_nulls)
using V = TypeParam;

fixed_width_column_wrapper<K> keys({1, 1, 3, 2, 1, 2}, {1, 0, 1, 0, 0, 1});
fixed_width_column_wrapper<K> expect_grouped_keys({1, 2, 3}, all_valid());
fixed_width_column_wrapper<K> expect_grouped_keys({1, 2, 3}, iterator_no_null());
fixed_width_column_wrapper<V> values({1, 2, 3, 4, 5, 6});
fixed_width_column_wrapper<V> expect_grouped_values({1, 6, 3});
std::vector<size_type> expect_group_offsets = {0, 1, 2, 3};
Expand Down
7 changes: 4 additions & 3 deletions cpp/tests/groupby/keys_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/detail/aggregation/aggregation.hpp>
Expand Down Expand Up @@ -58,7 +59,7 @@ TYPED_TEST(groupby_keys_test, zero_valid_keys)
using R = cudf::detail::target_type_t<V, aggregation::COUNT_VALID>;

// clang-format off
fixed_width_column_wrapper<K> keys ( { 1, 2, 3}, all_null() );
fixed_width_column_wrapper<K> keys ( { 1, 2, 3}, iterator_all_nulls() );
fixed_width_column_wrapper<V> vals { 3, 4, 5};

fixed_width_column_wrapper<K> expect_keys { };
Expand All @@ -81,7 +82,7 @@ TYPED_TEST(groupby_keys_test, some_null_keys)
fixed_width_column_wrapper<V> vals { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4};

// { 1, 1, 1, 2, 2, 2, 2, 3, 3, 4}
fixed_width_column_wrapper<K> expect_keys({ 1, 2, 3, 4}, all_valid());
fixed_width_column_wrapper<K> expect_keys({ 1, 2, 3, 4}, iterator_no_null() );
// { 0, 3, 6, 1, 4, 5, 9, 2, 8, -}
fixed_width_column_wrapper<R> expect_vals { 3, 4, 2, 1};
// clang-format on
Expand Down Expand Up @@ -180,7 +181,7 @@ TYPED_TEST(groupby_keys_test, pre_sorted_keys_nullable)
{ 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1});
fixed_width_column_wrapper<V> vals { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 4};

fixed_width_column_wrapper<K> expect_keys({ 1, 2, 3, 4}, all_valid());
fixed_width_column_wrapper<K> expect_keys({ 1, 2, 3, 4}, iterator_no_null() );
fixed_width_column_wrapper<R> expect_vals { 3, 15, 17, 4};
// clang-format on

Expand Down
9 changes: 5 additions & 4 deletions cpp/tests/groupby/max_scan_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/detail/aggregation/aggregation.hpp>
Expand Down Expand Up @@ -77,7 +78,7 @@ TYPED_TEST(groupby_max_scan_test, zero_valid_keys)
using result_wrapper = typename TestFixture::result_wrapper;

// clang-format off
key_wrapper keys( {1, 2, 3}, all_null());
key_wrapper keys( {1, 2, 3}, iterator_all_nulls());
value_wrapper vals({3, 4, 5});

key_wrapper expect_keys{};
Expand All @@ -95,10 +96,10 @@ TYPED_TEST(groupby_max_scan_test, zero_valid_values)

// clang-format off
key_wrapper keys {1, 1, 1};
value_wrapper vals({3, 4, 5}, all_null());
value_wrapper vals({3, 4, 5}, iterator_all_nulls());

key_wrapper expect_keys {1, 1, 1};
result_wrapper expect_vals({-1, -1, -1}, all_null());
result_wrapper expect_vals({-1, -1, -1}, iterator_all_nulls());
// clang-format on

auto agg = cudf::make_max_aggregation();
Expand All @@ -115,7 +116,7 @@ TYPED_TEST(groupby_max_scan_test, null_keys_and_values)
value_wrapper vals({5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 4}, {0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0});

// {1, 1, 1, 2, 2, 2, 2, 3, _, 3, 4}
key_wrapper expect_keys( {1, 1, 1, 2, 2, 2, 2, 3, 3, 4}, all_valid());
key_wrapper expect_keys( {1, 1, 1, 2, 2, 2, 2, 3, 3, 4}, iterator_no_null() );
// { -, 3, 6, 1, 4, -, 9, 2, _, 8, -}
result_wrapper expect_vals({-1, 8, 8, 6, 9, -1, 9, 7, 7, -1},
{ 0, 1, 1, 1, 1, 0, 1, 1, 1, 0});
Expand Down
13 changes: 7 additions & 6 deletions cpp/tests/groupby/max_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/type_lists.hpp>

#include <cudf/detail/aggregation/aggregation.hpp>
Expand Down Expand Up @@ -73,7 +74,7 @@ TYPED_TEST(groupby_max_test, zero_valid_keys)
using V = TypeParam;
using R = cudf::detail::target_type_t<V, aggregation::MAX>;

fixed_width_column_wrapper<K> keys({1, 2, 3}, all_null());
fixed_width_column_wrapper<K> keys({1, 2, 3}, iterator_all_nulls());
fixed_width_column_wrapper<V> vals({3, 4, 5});

fixed_width_column_wrapper<K> expect_keys{};
Expand All @@ -92,10 +93,10 @@ TYPED_TEST(groupby_max_test, zero_valid_values)
using R = cudf::detail::target_type_t<V, aggregation::MAX>;

fixed_width_column_wrapper<K> keys{1, 1, 1};
fixed_width_column_wrapper<V> vals({3, 4, 5}, all_null());
fixed_width_column_wrapper<V> vals({3, 4, 5}, iterator_all_nulls());

fixed_width_column_wrapper<K> expect_keys{1};
fixed_width_column_wrapper<R> expect_vals({0}, all_null());
fixed_width_column_wrapper<R> expect_vals({0}, iterator_all_nulls());

auto agg = cudf::make_max_aggregation();
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
Expand All @@ -115,7 +116,7 @@ TYPED_TEST(groupby_max_test, null_keys_and_values)
{1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0});

// { 1, 1, 2, 2, 2, 3, 3, 4}
fixed_width_column_wrapper<K> expect_keys({1, 2, 3, 4}, all_valid());
fixed_width_column_wrapper<K> expect_keys({1, 2, 3, 4}, iterator_no_null());
// { 0, 3, 1, 4, 5, 2, 8, -}
fixed_width_column_wrapper<R> expect_vals({3, 5, 8, 0}, {1, 1, 1, 0});

Expand Down Expand Up @@ -147,10 +148,10 @@ TEST_F(groupby_max_string_test, basic)
TEST_F(groupby_max_string_test, zero_valid_values)
{
fixed_width_column_wrapper<K> keys{1, 1, 1};
strings_column_wrapper vals({"año", "bit", "₹1"}, all_null());
strings_column_wrapper vals({"año", "bit", "₹1"}, iterator_all_nulls());

fixed_width_column_wrapper<K> expect_keys{1};
strings_column_wrapper expect_vals({""}, all_null());
strings_column_wrapper expect_vals({""}, iterator_all_nulls());

auto agg = cudf::make_max_aggregation();
test_single_agg(keys, vals, expect_keys, expect_vals, std::move(agg));
Expand Down
Loading

0 comments on commit badb501

Please sign in to comment.