20 #include <cudf/detail/utilities/assert.cuh>
21 #include <cudf/hashing/detail/hash_functions.cuh>
22 #include <cudf/hashing/detail/hashing.hpp>
27 #include <cuda/std/limits>
28 #include <thrust/equal.h>
29 #include <thrust/execution_policy.h>
30 #include <thrust/iterator/counting_iterator.h>
31 #include <thrust/transform_reduce.h>
33 namespace CUDF_EXPORT
cudf {
58 template <
typename Element>
59 __device__ weak_ordering compare_elements(Element lhs, Element rhs)
62 return weak_ordering::LESS;
63 }
else if (rhs < lhs) {
64 return weak_ordering::GREATER;
66 return weak_ordering::EQUIVALENT;
79 template <
typename Element, std::enable_if_t<std::is_
floating_po
int_v<Element>>* =
nullptr>
82 if (isnan(lhs) and isnan(rhs)) {
83 return weak_ordering::EQUIVALENT;
84 }
else if (isnan(rhs)) {
85 return weak_ordering::LESS;
86 }
else if (isnan(lhs)) {
87 return weak_ordering::GREATER;
90 return detail::compare_elements(lhs, rhs);
103 if (lhs_is_null and rhs_is_null) {
104 return weak_ordering::EQUIVALENT;
105 }
else if (lhs_is_null) {
106 return (null_precedence == null_order::BEFORE) ? weak_ordering::LESS : weak_ordering::GREATER;
107 }
else if (rhs_is_null) {
108 return (null_precedence == null_order::AFTER) ? weak_ordering::LESS : weak_ordering::GREATER;
110 return weak_ordering::EQUIVALENT;
121 template <
typename Element, std::enable_if_t<not std::is_
floating_po
int_v<Element>>* =
nullptr>
122 __device__ weak_ordering relational_compare(Element lhs, Element rhs)
124 return detail::compare_elements(lhs, rhs);
135 template <
typename Element, std::enable_if_t<std::is_
floating_po
int_v<Element>>* =
nullptr>
138 if (isnan(lhs) and isnan(rhs)) {
return true; }
150 template <
typename Element, std::enable_if_t<not std::is_
floating_po
int_v<Element>>* =
nullptr>
151 __device__
bool equality_compare(Element
const lhs, Element
const rhs)
161 template <
typename Nullate>
180 : lhs{lhs}, rhs{rhs}, nulls{
has_nulls}, nulls_are_equal{nulls_are_equal}
191 template <
typename Element,
192 std::enable_if_t<cudf::is_equality_comparable<Element, Element>()>* =
nullptr>
194 size_type rhs_element_index)
const noexcept
197 bool const lhs_is_null{lhs.is_null(lhs_element_index)};
198 bool const rhs_is_null{rhs.is_null(rhs_element_index)};
199 if (lhs_is_null and rhs_is_null) {
200 return nulls_are_equal == null_equality::EQUAL;
201 }
else if (lhs_is_null != rhs_is_null) {
207 rhs.element<Element>(rhs_element_index));
211 template <
typename Element,
212 std::enable_if_t<not cudf::is_equality_comparable<Element, Element>()>* =
nullptr>
215 CUDF_UNREACHABLE(
"Attempted to compare elements of uncomparable types.");
220 column_device_view lhs;
221 column_device_view rhs;
231 template <
typename Nullate>
246 : lhs{lhs}, rhs{rhs}, nulls{
has_nulls}, nulls_are_equal{nulls_are_equal}
267 return thrust::equal(thrust::seq, lhs.begin(), lhs.end(), rhs.begin(), equal_elements);
282 template <
typename Nullate>
300 : lhs{lhs}, rhs{rhs}, nulls{
has_nulls}, null_precedence{null_precedence}
327 template <
typename Element,
328 std::enable_if_t<cudf::is_relationally_comparable<Element, Element>()>* =
nullptr>
330 size_type rhs_element_index)
const noexcept
333 bool const lhs_is_null{lhs.is_null(lhs_element_index)};
334 bool const rhs_is_null{rhs.is_null(rhs_element_index)};
336 if (lhs_is_null or rhs_is_null) {
337 return null_compare(lhs_is_null, rhs_is_null, null_precedence);
342 rhs.element<Element>(rhs_element_index));
346 template <
typename Element,
347 std::enable_if_t<not cudf::is_relationally_comparable<Element, Element>()>* =
nullptr>
350 CUDF_UNREACHABLE(
"Attempted to compare elements of uncomparable types.");
355 column_device_view lhs;
356 column_device_view rhs;
376 template <
typename Nullate>
401 order const* column_order =
nullptr,
406 _column_order{column_order},
407 _null_precedence{null_precedence}
409 CUDF_EXPECTS(_lhs.num_columns() == _rhs.num_columns(),
"Mismatched number of columns.");
423 for (
size_type i = 0; i < _lhs.num_columns(); ++i) {
424 bool ascending = (_column_order ==
nullptr) or (_column_order[i] == order::ASCENDING);
427 _null_precedence ==
nullptr ? null_order::BEFORE : _null_precedence[i];
435 if (state == weak_ordering::EQUIVALENT) {
continue; }
437 return state == (ascending ? weak_ordering::LESS : weak_ordering::GREATER);
447 order const* _column_order{};
456 template <
template <
typename>
class hash_function,
typename Nullate>
467 template <typename T, CUDF_ENABLE_IF(column_device_view::has_element_accessor<T>())>
471 return cuda::std::numeric_limits<hash_value_type>::max();
473 return hash_function<T>{}(col.
element<T>(row_index));
484 template <typename T, CUDF_ENABLE_IF(not column_device_view::has_element_accessor<T>())>
487 CUDF_UNREACHABLE(
"Unsupported type in hash.");
499 template <
template <
typename>
class hash_function,
typename Nullate>
521 : _seed{seed}, _null_hash{null_hash}, _has_nulls{
has_nulls}
533 template <typename T, CUDF_ENABLE_IF(column_device_view::has_element_accessor<T>())>
536 if (_has_nulls && col.
is_null(row_index)) {
return _null_hash; }
537 return hash_function<T>{_seed}(col.
element<T>(row_index));
548 template <typename T, CUDF_ENABLE_IF(not column_device_view::has_element_accessor<T>())>
551 CUDF_UNREACHABLE(
"Unsupported type in hash.");
555 uint32_t _seed{DEFAULT_HASH_SEED};
556 hash_value_type _null_hash{cuda::std::numeric_limits<hash_value_type>::max()};
566 template <
template <
typename>
class hash_function,
typename Nullate>
589 : _table{t}, _seed(seed), _has_nulls{
has_nulls}
602 auto const initial_hash = cudf::hashing::detail::hash_combine(
604 type_dispatcher<dispatch_storage_type>(
605 _table.column(0).type(),
611 auto hasher = [=](
size_type column_index) {
612 return cudf::type_dispatcher<dispatch_storage_type>(
613 _table.column(column_index).type(),
615 _table.column(column_index),
620 return thrust::transform_reduce(
623 thrust::make_counting_iterator(1),
624 thrust::make_counting_iterator(_table.num_columns()),
628 return cudf::hashing::detail::hash_combine(lhs, rhs);
635 uint32_t _seed{DEFAULT_HASH_SEED};
设备数据作为元素列的一个不可变、非拥有的视图,它是可平凡复制且...
T element(size_type element_index) const noexcept
返回指定索引处元素的引用。
CUDF_HOST_DEVICE data_type type() const noexcept
返回元素类型。
bool is_null(size_type element_index) const noexcept
返回指定元素是否为 null。
size_type num_columns() const noexcept
返回列数。
element_equality_comparator(Nullate has_nulls, column_device_view lhs, column_device_view rhs, null_equality nulls_are_equal=null_equality::EQUAL)
构造类型分派函数对象,用于比较两个元素的相等性。
bool operator()(size_type lhs_element_index, size_type rhs_element_index) const noexcept
比较指定元素的相等性。
element_hasher_with_seed(Nullate has_nulls, uint32_t seed)
构造函数对象,用于对给定列中的元素进行哈希计算。
element_hasher_with_seed(Nullate has_nulls, uint32_t seed, hash_value_type null_hash)
构造函数对象,用于对给定列中的元素进行哈希计算。
Nullate has_nulls
一个描述如何检查 null 的 cudf::nullate 类型。
weak_ordering operator()(size_type lhs_element_index, size_type rhs_element_index) const noexcept
对指定元素执行关系比较。
element_relational_comparator(Nullate has_nulls, column_device_view lhs, column_device_view rhs)
构造类型分派函数对象,用于执行两个元素之间的关系比较...
element_relational_comparator(Nullate has_nulls, column_device_view lhs, column_device_view rhs, null_order null_precedence)
构造类型分派函数对象,用于执行两个元素之间的关系比较...
row_equality_comparator(Nullate has_nulls, table_device_view lhs, table_device_view rhs, null_equality nulls_are_equal=null_equality::EQUAL)
构造新的行相等性比较器对象。
bool operator()(size_type lhs_row_index, size_type rhs_row_index) const noexcept
比较指定行的相等性。
CUDF_HOST_DEVICE row_hasher(Nullate has_nulls, table_device_view t, uint32_t seed)
构造带有种子值的 row_hasher 对象。
CUDF_HOST_DEVICE row_hasher(Nullate has_nulls, table_device_view t)
构造 row_hasher 对象。
auto operator()(size_type row_index) const
计算表中 row_index 处行的哈希值
bool operator()(size_type lhs_index, size_type rhs_index) const noexcept
检查 lhs 表中 lhs_index 处的行是否按字典序小于 rhs 表中 rhs_index 处的行...
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)
构造函数对象,用于在两表的行之间执行字典序比较。
uint32_t hash_value_type
哈希值类型。
CUDF_HOST_DEVICE constexpr decltype(auto) __forceinline__ type_dispatcher(cudf::data_type dtype, Functor f, Ts &&... args)
基于指定的 cudf::data_type 的实例化类型调用 operator() 模板...
#define CUDF_EXPECTS(...)
用于检查(前置)条件的宏,条件不满足时抛出异常。
null_order
指示 null 值与所有其他值比较时的顺序。
null_equality
枚举,用于确定两个 null 是否相等或不等。
int32_t size_type
列和表的行索引类型。
bool has_nulls(table_view const &view)
如果表中的任何列包含 null,则返回 True。
weak_ordering
element_relational_comparator 函数对象的返回类型。
@ EQUIVALENT
表示 a 的排序既不在 b 之前也不在 b 之后
auto null_compare(bool lhs_is_null, bool rhs_is_null, null_order null_precedence)
根据 null 顺序比较 null。
weak_ordering relational_compare(Element lhs, Element rhs)
浮点元素类型关系比较的特化,用于派生元素的顺序...
bool equality_compare(Element lhs, Element rhs)
浮点元素类型的特化,用于检查 lhs 是否等价于 rhs...
定义了 cudf::type_id 运行时类型信息与具体 C++ 类型之间的映射。
#define CUDF_HOST_DEVICE
指示函数或方法可在主机和设备上使用。