31 #include <cudf/detail/row_operator/common_utils.cuh>
32 #include <cudf/detail/row_operator/row_operators.cuh>
33 #include <cudf/detail/utilities/assert.cuh>
34 #include <cudf/hashing/detail/hash_functions.cuh>
35 #include <cudf/hashing/detail/hashing.hpp>
40 #include <cuda/std/limits>
41 #include <thrust/equal.h>
42 #include <thrust/execution_policy.h>
43 #include <thrust/iterator/counting_iterator.h>
44 #include <thrust/transform_reduce.h>
46 namespace CUDF_EXPORT
cudf {
69 template <
typename Element>
85 template <
typename Element>
116 template <
typename Element>
130 template <
typename Nullate>
149 : lhs{lhs}, rhs{rhs}, nulls{
has_nulls}, nulls_are_equal{nulls_are_equal}
160 template <
typename Element>
162 size_type rhs_element_index)
const noexcept
163 requires(cudf::is_equality_comparable<Element, Element>())
166 bool const lhs_is_null{lhs.is_null(lhs_element_index)};
167 bool const rhs_is_null{rhs.is_null(rhs_element_index)};
168 if (lhs_is_null and rhs_is_null) {
169 return nulls_are_equal == null_equality::EQUAL;
170 }
else if (lhs_is_null != rhs_is_null) {
176 rhs.element<Element>(rhs_element_index));
180 template <
typename Element>
182 requires(not cudf::is_equality_comparable<Element, Element>())
184 CUDF_UNREACHABLE(
"Attempted to compare elements of uncomparable types.");
189 column_device_view lhs;
190 column_device_view rhs;
203 template <
typename Nullate>
218 : lhs{lhs}, rhs{rhs}, nulls{
has_nulls}, nulls_are_equal{nulls_are_equal}
240 return thrust::equal(thrust::seq, lhs.begin(), lhs.end(), rhs.begin(), equal_elements);
258 template <
typename Nullate>
276 : lhs{lhs}, rhs{rhs}, nulls{
has_nulls}, null_precedence{null_precedence}
303 template <
typename Element>
305 size_type rhs_element_index)
const noexcept
306 requires(cudf::is_relationally_comparable<Element, Element>())
309 bool const lhs_is_null{lhs.is_null(lhs_element_index)};
310 bool const rhs_is_null{rhs.is_null(rhs_element_index)};
312 if (lhs_is_null or rhs_is_null) {
318 rhs.element<Element>(rhs_element_index));
322 template <
typename Element>
325 requires(not cudf::is_relationally_comparable<Element, Element>())
327 CUDF_UNREACHABLE(
"Attempted to compare elements of uncomparable types.");
332 column_device_view lhs;
333 column_device_view rhs;
356 template <
typename Nullate>
381 order const* column_order =
nullptr,
386 _column_order{column_order},
387 _null_precedence{null_precedence}
389 CUDF_EXPECTS(_lhs.num_columns() == _rhs.num_columns(),
"Mismatched number of columns.");
403 for (
size_type i = 0; i < _lhs.num_columns(); ++i) {
404 bool ascending = (_column_order ==
nullptr) or (_column_order[i] == order::ASCENDING);
407 _null_precedence ==
nullptr ? null_order::BEFORE : _null_precedence[i];
415 if (state == cudf::detail::weak_ordering::EQUIVALENT) {
continue; }
418 (ascending ? cudf::detail::weak_ordering::LESS : cudf::detail::weak_ordering::GREATER);
428 order const* _column_order{};
440 template <
template <
typename>
class hash_function,
typename Nullate>
451 template <typename T, CUDF_ENABLE_IF(column_device_view::has_element_accessor<T>())>
455 return cuda::std::numeric_limits<hash_value_type>::max();
457 return hash_function<T>{}(col.
element<T>(row_index));
468 template <typename T, CUDF_ENABLE_IF(not column_device_view::has_element_accessor<T>())>
471 CUDF_UNREACHABLE(
"Unsupported type in hash.");
486 template <
template <
typename>
class hash_function,
typename Nullate>
508 : _seed{seed}, _null_hash{null_hash}, _has_nulls{
has_nulls}
520 template <typename T, CUDF_ENABLE_IF(column_device_view::has_element_accessor<T>())>
523 if (_has_nulls && col.
is_null(row_index)) {
return _null_hash; }
524 return hash_function<T>{_seed}(col.
element<T>(row_index));
535 template <typename T, CUDF_ENABLE_IF(not column_device_view::has_element_accessor<T>())>
538 CUDF_UNREACHABLE(
"Unsupported type in hash.");
542 uint32_t _seed{DEFAULT_HASH_SEED};
543 hash_value_type _null_hash{cuda::std::numeric_limits<hash_value_type>::max()};
556 template <
template <
typename>
class hash_function,
typename Nullate>
579 : _table{t}, _seed(seed), _has_nulls{
has_nulls}
592 auto const initial_hash = cudf::hashing::detail::hash_combine(
594 type_dispatcher<dispatch_storage_type>(
595 _table.column(0).type(),
601 auto hasher = [row_index,
this](
size_type column_index) {
602 return cudf::type_dispatcher<dispatch_storage_type>(
603 _table.column(column_index).type(),
605 _table.column(column_index),
610 return thrust::transform_reduce(
613 thrust::make_counting_iterator(1),
614 thrust::make_counting_iterator(_table.num_columns()),
618 return cudf::hashing::detail::hash_combine(lhs, rhs);
625 uint32_t _seed{DEFAULT_HASH_SEED};
An immutable, non-owning view of device data as a column of elements that is trivially copyable and u...
T element(size_type element_index) const noexcept
Returns a copy of the element at the specified index.
bool is_null(size_type element_index) const noexcept
Returns whether the specified element is null.
size_type num_columns() const noexcept
Returns the number of columns.
Performs an equality comparison between two elements in two columns.
bool operator()(size_type lhs_element_index, size_type rhs_element_index) const noexcept requires(cudf
Compares the specified elements for equality.
element_equality_comparator(Nullate has_nulls, column_device_view lhs, column_device_view rhs, null_equality nulls_are_equal=null_equality::EQUAL)
Construct type-dispatched function object for comparing equality between two elements.
Function object for computing the hash value of a row in a column.
element_hasher_with_seed(Nullate has_nulls, uint32_t seed)
Constructs a function object for hashing an element in the given column.
element_hasher_with_seed(Nullate has_nulls, uint32_t seed, hash_value_type null_hash)
Constructs a function object for hashing an element in the given column.
Computes the hash value of an element in the given column.
Nullate has_nulls
A cudf::nullate type describing how to check for nulls.
Performs a relational comparison between two elements in two columns.
element_relational_comparator(Nullate has_nulls, column_device_view lhs, column_device_view rhs)
Construct type-dispatched function object for performing a relational comparison between two elements...
element_relational_comparator(Nullate has_nulls, column_device_view lhs, column_device_view rhs, null_order null_precedence)
Construct type-dispatched function object for performing a relational comparison between two elements...
cudf::detail::weak_ordering operator()(size_type lhs_element_index, size_type rhs_element_index) const noexcept requires(cudf
Performs a relational comparison between the specified elements.
Performs a relational comparison between two elements in two tables.
row_equality_comparator(Nullate has_nulls, table_device_view lhs, table_device_view rhs, null_equality nulls_are_equal=null_equality::EQUAL)
Construct a new row equality comparator object.
bool operator()(size_type lhs_row_index, size_type rhs_row_index) const noexcept
Compares the specified rows for equality.
Computes the hash value of a row in the given table.
CUDF_HOST_DEVICE row_hasher(Nullate has_nulls, table_device_view t, uint32_t seed)
Constructs a row_hasher object with a seed value.
CUDF_HOST_DEVICE row_hasher(Nullate has_nulls, table_device_view t)
Constructs a row_hasher object.
auto operator()(size_type row_index) const
Computes the hash value of the row at row_index in the table
Computes whether one row is lexicographically less than another row.
bool operator()(size_type lhs_index, size_type rhs_index) const noexcept
Checks whether the row at lhs_index in the lhs table compares lexicographically less than the row at ...
row_lexicographic_comparator(Nullate has_nulls, table_device_view lhs, table_device_view rhs, order const *column_order=nullptr, null_order const *null_precedence=nullptr)
Construct a function object for performing a lexicographic comparison between the rows of two tables.
Table device view that is usable in device memory.
Column device view class definitions.
uint32_t hash_value_type
Type of hash value.
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ type_dispatcher(cudf::data_type dtype, Functor f, Ts &&... args)
Invokes an operator() template with the type instantiation based on the specified cudf::data_type's i...
#define CUDF_EXPECTS(...)
Macro for checking (pre-)conditions that throws an exception when a condition is violated.
null_order
Indicates how null values compare against all other values.
null_equality
Enum to consider two nulls as equal or unequal.
int32_t size_type
Row index type for columns and tables.
order
Indicates the order in which elements should be sorted.
bool has_nulls(table_view const &view)
Returns True if the table has nulls in any of its columns.
weak_ordering compare_elements(Element lhs, Element rhs)
Alias for backward compatibility with legacy row operators.
bool equality_compare(Element lhs, Element rhs)
Alias for backward compatibility with legacy row operators.
auto null_compare(bool lhs_is_null, bool rhs_is_null, null_order null_precedence)
Alias for backward compatibility with legacy row operators.
cudf::detail::weak_ordering weak_ordering
Alias for backward compatibility with legacy row operators.
weak_ordering relational_compare(Element lhs, Element rhs)
Alias for backward compatibility with legacy row operators.
Table device view class definitions.
Defines the mapping between cudf::type_id runtime type information and concrete C++ types.
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.