diff --git a/cpp/include/cudf/table/row_operators.cuh b/cpp/include/cudf/table/row_operators.cuh index 6ff4833cb14..b5d46935fe8 100644 --- a/cpp/include/cudf/table/row_operators.cuh +++ b/cpp/include/cudf/table/row_operators.cuh @@ -356,12 +356,13 @@ class row_lexicographic_comparator { * @brief Construct a function object for performing a lexicographic * comparison between the rows of two tables. * + * Behavior is undefined if called with incomparable column types. + * * @throws cudf::logic_error if `lhs.num_columns() != rhs.num_columns()` - * @throws cudf::logic_error if column types of `lhs` and `rhs` are not comparable. * + * @param has_nulls Indicates if either input table contains columns with nulls. * @param lhs The first table * @param rhs The second table (may be the same table as `lhs`) - * @param has_nulls Indicates if either input table contains columns with nulls. * @param column_order Optional, device array the same length as a row that * indicates the desired ascending/descending order of each column in a row. * If `nullptr`, it is assumed all columns are sorted in ascending order. @@ -382,8 +383,6 @@ class row_lexicographic_comparator { _null_precedence{null_precedence} { CUDF_EXPECTS(_lhs.num_columns() == _rhs.num_columns(), "Mismatched number of columns."); - CUDF_EXPECTS(detail::is_relationally_comparable(_lhs, _rhs), - "Attempted to compare elements of uncomparable types."); } /** diff --git a/cpp/include/cudf/table/table_device_view.cuh b/cpp/include/cudf/table/table_device_view.cuh index ce61e8853b6..3ed18099463 100644 --- a/cpp/include/cudf/table/table_device_view.cuh +++ b/cpp/include/cudf/table/table_device_view.cuh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. + * Copyright (c) 2019-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -150,10 +150,4 @@ auto contiguous_copy_column_device_views(HostTableView source_view, rmm::cuda_st return std::make_tuple(std::move(descendant_storage), d_columns); } -namespace detail { -extern template bool is_relationally_comparable(table_device_view const& lhs, - table_device_view const& rhs); -extern template bool is_relationally_comparable( - mutable_table_device_view const& lhs, mutable_table_device_view const& rhs); -} // namespace detail } // namespace cudf diff --git a/cpp/src/table/table_device_view.cu b/cpp/src/table/table_device_view.cu index 859a6be3bb0..5f17574bb89 100644 --- a/cpp/src/table/table_device_view.cu +++ b/cpp/src/table/table_device_view.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. + * Copyright (c) 2019-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,6 @@ #include -#include - namespace cudf { namespace detail { template @@ -54,45 +52,5 @@ template class table_device_view_base; // Explicit instantiation for a device table of mutable views template class table_device_view_base; -namespace { -struct is_relationally_comparable_functor { - template - constexpr bool operator()() - { - return cudf::is_relationally_comparable(); - } -}; -} // namespace - -template -bool is_relationally_comparable(TableView const& lhs, TableView const& rhs) -{ - return thrust::all_of(thrust::counting_iterator(0), - thrust::counting_iterator(lhs.num_columns()), - [lhs, rhs] __device__(auto const i) { - // Simplified this for compile time. (Ideally use double_type_dispatcher) - // TODO: possible to implement without double type dispatcher. - return lhs.column(i).type() == rhs.column(i).type() and - type_dispatcher(lhs.column(i).type(), - is_relationally_comparable_functor{}); - }); -} - -// Explicit extern template instantiation for a table of immutable views -extern template bool is_relationally_comparable(table_view const& lhs, - table_view const& rhs); - -// Explicit extern template instantiation for a table of mutable views -extern template bool is_relationally_comparable(mutable_table_view const& lhs, - mutable_table_view const& rhs); - -// Explicit extern template instantiation for a device table of immutable views -template bool is_relationally_comparable(table_device_view const& lhs, - table_device_view const& rhs); - -// Explicit extern template instantiation for a device table of mutable views -template bool is_relationally_comparable( - mutable_table_device_view const& lhs, mutable_table_device_view const& rhs); - } // namespace detail } // namespace cudf diff --git a/cpp/src/table/table_view.cpp b/cpp/src/table/table_view.cpp index abd909f8cfc..365ff67263c 100644 --- a/cpp/src/table/table_view.cpp +++ b/cpp/src/table/table_view.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019, NVIDIA CORPORATION. + * Copyright (c) 2018-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -96,4 +96,35 @@ table_view scatter_columns(table_view const& source, return table_view{updated_columns}; } +namespace detail { +namespace { +struct is_relationally_comparable_functor { + template + constexpr bool operator()() + { + return cudf::is_relationally_comparable(); + } +}; +} // namespace + +template +bool is_relationally_comparable(TableView const& lhs, TableView const& rhs) +{ + return std::all_of(thrust::counting_iterator(0), + thrust::counting_iterator(lhs.num_columns()), + [lhs, rhs](auto const i) { + return lhs.column(i).type() == rhs.column(i).type() and + type_dispatcher(lhs.column(i).type(), + is_relationally_comparable_functor{}); + }); +} + +// Explicit template instantiation for a table of immutable views +template bool is_relationally_comparable(table_view const& lhs, table_view const& rhs); + +// Explicit template instantiation for a table of mutable views +template bool is_relationally_comparable(mutable_table_view const& lhs, + mutable_table_view const& rhs); + +} // namespace detail } // namespace cudf