Skip to content

Commit

Permalink
fix merge_m2 tests by sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikeyann committed Dec 12, 2023
1 parent f699a94 commit b841fed
Showing 1 changed file with 81 additions and 30 deletions.
111 changes: 81 additions & 30 deletions cpp/tests/groupby/merge_m2_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include "cudf/sorting.hpp"
#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/iterator_utilities.hpp>
Expand Down Expand Up @@ -193,19 +194,29 @@ TYPED_TEST(GroupbyMergeM2TypedTest, SimpleInput)
auto const [final_keys, final_vals] =
merge_M2(vcol_views{*out3_keys, *out4_keys}, vcol_views{*out3_vals, *out4_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}

// One step merging:
{
auto const [final_keys, final_vals] = merge_M2(vcol_views{*out1_keys, *out2_keys, *out3_keys},
vcol_views{*out1_vals, *out2_vals, *out3_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}
}

Expand Down Expand Up @@ -252,19 +263,29 @@ TYPED_TEST(GroupbyMergeM2TypedTest, SimpleInputHavingNegativeValues)
auto const [final_keys, final_vals] =
merge_M2(vcol_views{*out3_keys, *out4_keys}, vcol_views{*out3_vals, *out4_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}

// One step merging:
{
auto const [final_keys, final_vals] = merge_M2(vcol_views{*out1_keys, *out2_keys, *out3_keys},
vcol_views{*out1_vals, *out2_vals, *out3_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}
}

Expand Down Expand Up @@ -312,19 +333,29 @@ TYPED_TEST(GroupbyMergeM2TypedTest, InputHasNulls)
auto const [final_keys, final_vals] =
merge_M2(vcol_views{*out3_keys, *out4_keys}, vcol_views{*out3_vals, *out4_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}

// One step merging:
{
auto const [final_keys, final_vals] = merge_M2(vcol_views{*out1_keys, *out2_keys, *out3_keys},
vcol_views{*out1_vals, *out2_vals, *out3_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}
}

Expand Down Expand Up @@ -377,9 +408,14 @@ TYPED_TEST(GroupbyMergeM2TypedTest, InputHaveNullsAndNaNs)
auto const [final_keys, final_vals] =
merge_M2(vcol_views{*out5_keys, *out6_keys}, vcol_views{*out5_vals, *out6_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}

// One step merging:
Expand All @@ -388,9 +424,14 @@ TYPED_TEST(GroupbyMergeM2TypedTest, InputHaveNullsAndNaNs)
merge_M2(vcol_views{*out1_keys, *out2_keys, *out3_keys, *out4_keys},
vcol_views{*out1_vals, *out2_vals, *out3_vals, *out4_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}
}

Expand Down Expand Up @@ -459,9 +500,14 @@ TYPED_TEST(GroupbyMergeM2TypedTest, SlicedColumnsInput)
auto const [final_keys, final_vals] =
merge_M2(vcol_views{*out5_keys, *out6_keys}, vcol_views{*out5_vals, *out6_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}

// One step merging:
Expand All @@ -470,8 +516,13 @@ TYPED_TEST(GroupbyMergeM2TypedTest, SlicedColumnsInput)
merge_M2(vcol_views{*out1_keys, *out2_keys, *out3_keys, *out4_keys},
vcol_views{*out1_vals, *out2_vals, *out3_vals, *out4_vals});

auto const out_M2s = final_vals->child(2);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, *final_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, out_M2s, verbosity);
auto const out_M2s = final_vals->child(2);
auto const sort_order = cudf::sorted_order(cudf::table_view{{final_keys->view()}});
auto const sorted_out =
cudf::gather(cudf::table_view{{final_keys->view(), out_M2s}}, *sort_order);
auto const [sorted_keys, sorted_vals] =
std::pair{sorted_out->get_column(0), sorted_out->get_column(1)};
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_keys, sorted_keys, verbosity);
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_M2s, sorted_vals, verbosity);
}
}

0 comments on commit b841fed

Please sign in to comment.