Skip to content

Commit

Permalink
Add tests and fix one oversight
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasr committed Sep 21, 2023
1 parent 6343098 commit 689ea33
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cpp/src/sort/segmented_sort_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ std::unique_ptr<column> fast_segmented_sorted_order(column_view const& input,
// Unfortunately, CUB's segmented sort functions cannot accept iterators.
// We have to build a pre-filled sequence of indices as input.
auto sorted_indices =
cudf::detail::sequence(input.size(), numeric_scalar<size_type>{0}, stream, mr);
cudf::detail::sequence(input.size(), numeric_scalar<size_type>{0, true, stream}, stream, mr);
auto indices_view = sorted_indices->mutable_view();

cudf::type_dispatcher<dispatch_storage_type>(input.type(),
Expand Down
7 changes: 4 additions & 3 deletions cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -620,14 +620,15 @@ ConfigureTest(
STREAM_IDENTIFICATION_TEST identify_stream_usage/test_default_stream_identification.cu
)

ConfigureTest(STREAM_HASHING_TEST streams/hash_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_COPYING_TEST streams/copying_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_GROUPBY_TEST streams/groupby_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_CONCATENATE_TEST streams/concatenate_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_COPYING_TEST streams/copying_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_FILLING_TEST streams/filling_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_GROUPBY_TEST streams/groupby_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_HASHING_TEST streams/hash_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_REPLACE_TEST streams/replace_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_SEARCH_TEST streams/search_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_STRINGS_TEST streams/strings/case_test.cpp STREAM_MODE testing)
ConfigureTest(STREAM_SORTING_TEST streams/sorting_test.cpp STREAM_MODE testing)

# ##################################################################################################
# Install tests ####################################################################################
Expand Down
132 changes: 132 additions & 0 deletions cpp/tests/streams/sorting_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <cudf/column/column_view.hpp>
#include <cudf/sorting.hpp>

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>

class SortingTest : public cudf::test::BaseFixture {};

TEST_F(SortingTest, SortedOrder)
{
cudf::test::fixed_width_column_wrapper<int32_t> const column{10, 20, 30, 40, 50};
cudf::table_view const tbl{{column}};

cudf::sorted_order(tbl, {}, {}, cudf::test::get_default_stream());
}

TEST_F(SortingTest, StableSortedOrder)
{
cudf::test::fixed_width_column_wrapper<int32_t> const column{10, 20, 30, 40, 50};
cudf::table_view const tbl{{column}};

cudf::stable_sorted_order(tbl, {}, {}, cudf::test::get_default_stream());
}

TEST_F(SortingTest, IsSorted)
{
cudf::test::fixed_width_column_wrapper<int32_t> const column{10, 20, 30, 40, 50};
cudf::table_view const tbl{{column}};

cudf::is_sorted(tbl, {}, {}, cudf::test::get_default_stream());
}

TEST_F(SortingTest, Sort)
{
cudf::test::fixed_width_column_wrapper<int32_t> const column{10, 20, 30, 40, 50};
cudf::table_view const tbl{{column}};

cudf::sort(tbl, {}, {}, cudf::test::get_default_stream());
}

TEST_F(SortingTest, SortByKey)
{
cudf::test::fixed_width_column_wrapper<int32_t> const values_col{10, 20, 30, 40, 50};
cudf::table_view const values{{values_col}};
cudf::test::fixed_width_column_wrapper<int32_t> const keys_col{10, 20, 30, 40, 50};
cudf::table_view const keys{{keys_col}};

cudf::sort_by_key(values, keys, {}, {}, cudf::test::get_default_stream());
}

TEST_F(SortingTest, StableSortByKey)
{
cudf::test::fixed_width_column_wrapper<int32_t> const values_col{10, 20, 30, 40, 50};
cudf::table_view const values{{values_col}};
cudf::test::fixed_width_column_wrapper<int32_t> const keys_col{10, 20, 30, 40, 50};
cudf::table_view const keys{{keys_col}};

cudf::stable_sort_by_key(values, keys, {}, {}, cudf::test::get_default_stream());
}

TEST_F(SortingTest, Rank)
{
cudf::test::fixed_width_column_wrapper<int32_t> const column{10, 20, 30, 40, 50};

cudf::rank(column,
cudf::rank_method::AVERAGE,
cudf::order::ASCENDING,
cudf::null_policy::EXCLUDE,
cudf::null_order::AFTER,
false,
cudf::test::get_default_stream());
}

TEST_F(SortingTest, SegmentedSortedOrder)
{
cudf::test::fixed_width_column_wrapper<int32_t> const keys_col{9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
cudf::table_view const keys{{keys_col}};
cudf::test::fixed_width_column_wrapper<int32_t> const segment_offsets{3, 7};

cudf::segmented_sorted_order(keys, segment_offsets, {}, {}, cudf::test::get_default_stream());
}

TEST_F(SortingTest, StableSegmentedSortedOrder)
{
cudf::test::fixed_width_column_wrapper<int32_t> const keys_col{9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
cudf::table_view const keys{{keys_col}};
cudf::test::fixed_width_column_wrapper<int32_t> const segment_offsets{3, 7};

cudf::stable_segmented_sorted_order(
keys, segment_offsets, {}, {}, cudf::test::get_default_stream());
}

TEST_F(SortingTest, SegmentedSortByKey)
{
cudf::test::fixed_width_column_wrapper<int32_t> const keys_col{9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
cudf::table_view const keys{{keys_col}};
cudf::test::fixed_width_column_wrapper<int32_t> const values_col{7, 6, 9, 3, 4, 5, 1, 2, 0, 4};
cudf::table_view const values{{values_col}};
cudf::test::fixed_width_column_wrapper<int32_t> const segment_offsets{0, 3, 7, 10};

cudf::segmented_sort_by_key(
values, keys, segment_offsets, {}, {}, cudf::test::get_default_stream());
}

TEST_F(SortingTest, StableSegmentedSortByKey)
{
cudf::test::fixed_width_column_wrapper<int32_t> const keys_col{9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
cudf::table_view const keys{{keys_col}};
cudf::test::fixed_width_column_wrapper<int32_t> const values_col{7, 6, 9, 3, 4, 5, 1, 2, 0, 4};
cudf::table_view const values{{values_col}};
cudf::test::fixed_width_column_wrapper<int32_t> const segment_offsets{0, 3, 7, 10};

cudf::stable_segmented_sort_by_key(
values, keys, segment_offsets, {}, {}, cudf::test::get_default_stream());
}

0 comments on commit 689ea33

Please sign in to comment.