All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
traits.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2025, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
20 #include <cudf/types.hpp>
24 
25 namespace CUDF_EXPORT cudf {
26 
34 template <typename...>
35 using void_t = void;
36 
48 #define CUDF_ENABLE_IF(...) std::enable_if_t<(__VA_ARGS__)>* = nullptr
49 
51 template <typename L, typename R>
52 using less_comparable = decltype(std::declval<L>() < std::declval<R>());
53 
55 template <typename L, typename R>
56 using greater_comparable = decltype(std::declval<L>() > std::declval<R>());
57 
59 template <typename L, typename R>
60 using equality_comparable = decltype(std::declval<L>() == std::declval<R>());
61 
62 namespace detail {
63 template <typename L, typename R, typename = void>
64 struct is_relationally_comparable_impl : std::false_type {};
65 
66 template <typename L, typename R>
67 struct is_relationally_comparable_impl<L,
68  R,
69  void_t<less_comparable<L, R>, greater_comparable<L, R>>>
70  : std::true_type {};
71 
72 template <typename L, typename R, typename = void>
73 struct is_equality_comparable_impl : std::false_type {};
74 
75 template <typename L, typename R>
76 struct is_equality_comparable_impl<L, R, void_t<equality_comparable<L, R>>> : std::true_type {};
77 
78 // has common type
79 template <typename AlwaysVoid, typename... Ts>
80 struct has_common_type_impl : std::false_type {};
81 
82 template <typename... Ts>
83 struct has_common_type_impl<void_t<std::common_type_t<Ts...>>, Ts...> : std::true_type {};
84 } // namespace detail
85 
87 template <typename... Ts>
88 using has_common_type = typename detail::has_common_type_impl<void, Ts...>::type;
89 
91 template <typename... Ts>
92 constexpr inline bool has_common_type_v = detail::has_common_type_impl<void, Ts...>::value;
93 
95 template <typename T>
96 using is_timestamp_t = cuda::std::disjunction<std::is_same<cudf::timestamp_D, T>,
97  std::is_same<cudf::timestamp_h, T>,
98  std::is_same<cudf::timestamp_m, T>,
99  std::is_same<cudf::timestamp_s, T>,
100  std::is_same<cudf::timestamp_ms, T>,
101  std::is_same<cudf::timestamp_us, T>,
102  std::is_same<cudf::timestamp_ns, T>>;
103 
105 template <typename T>
106 using is_duration_t = cuda::std::disjunction<std::is_same<cudf::duration_D, T>,
107  std::is_same<cudf::duration_h, T>,
108  std::is_same<cudf::duration_m, T>,
109  std::is_same<cudf::duration_s, T>,
110  std::is_same<cudf::duration_ms, T>,
111  std::is_same<cudf::duration_us, T>,
112  std::is_same<cudf::duration_ns, T>>;
113 
126 template <typename L, typename R>
127 constexpr inline bool is_relationally_comparable()
128 {
129  return detail::is_relationally_comparable_impl<L, R>::value;
130 }
131 
140 
153 template <typename L, typename R>
154 constexpr inline bool is_equality_comparable()
155 {
156  return detail::is_equality_comparable_impl<L, R>::value;
157 }
158 
167 
175 template <typename T>
176 CUDF_HOST_DEVICE constexpr inline bool is_numeric()
177 {
178  return cuda::std::is_arithmetic<T>();
179 }
180 
193 
205 template <typename T>
206 constexpr inline bool is_index_type()
207 {
208  return std::is_integral_v<T> and not std::is_same_v<T, bool>;
209 }
210 
223 
230 template <typename T>
231 constexpr inline bool is_signed()
232 {
233  return std::is_signed_v<T>;
234 }
235 
245 bool is_signed(data_type type);
246 
254 template <typename T>
255 constexpr inline bool is_unsigned()
256 {
257  return std::is_unsigned_v<T>;
258 }
259 
270 
277 template <typename Iterator>
278 CUDF_HOST_DEVICE constexpr inline bool is_signed_iterator()
279 {
280  return cuda::std::is_signed_v<typename cuda::std::iterator_traits<Iterator>::value_type>;
281 }
282 
290 template <typename T>
291 constexpr inline bool is_integral()
292 {
293  return cuda::std::is_integral_v<T>;
294 }
295 
306 
314 template <typename T>
315 constexpr inline bool is_integral_not_bool()
316 {
317  return cuda::std::is_integral_v<T> and not std::is_same_v<T, bool>;
318 }
319 
330 
338 template <typename T>
339 constexpr inline bool is_numeric_not_bool()
340 {
341  return cudf::is_numeric<T>() and not std::is_same_v<T, bool>;
342 }
343 
354 
362 template <typename T>
363 CUDF_HOST_DEVICE constexpr inline bool is_floating_point()
364 {
365  return cuda::std::is_floating_point_v<T>;
366 }
367 
378 
386 template <typename T>
387 constexpr inline bool is_byte()
388 {
389  return std::is_same_v<std::remove_cv_t<T>, std::byte>;
390 }
391 
399 template <typename T>
400 constexpr inline bool is_boolean()
401 {
402  return std::is_same_v<T, bool>;
403 }
404 
413 
421 template <typename T>
422 CUDF_HOST_DEVICE constexpr inline bool is_timestamp()
423 {
425 }
426 
437 
445 template <typename T>
446 CUDF_HOST_DEVICE constexpr inline bool is_fixed_point()
447 {
448  return cuda::std::is_same_v<numeric::decimal32, T> ||
449  cuda::std::is_same_v<numeric::decimal64, T> ||
450  cuda::std::is_same_v<numeric::decimal128, T> ||
451  cuda::std::is_same_v<numeric::fixed_point<int32_t, numeric::Radix::BASE_2>, T> ||
452  cuda::std::is_same_v<numeric::fixed_point<int64_t, numeric::Radix::BASE_2>, T> ||
453  cuda::std::is_same_v<numeric::fixed_point<__int128_t, numeric::Radix::BASE_2>, T>;
454 }
455 
464 
472 template <typename T>
473 CUDF_HOST_DEVICE constexpr inline bool is_duration()
474 {
476 }
477 
488 
496 template <typename T>
497 CUDF_HOST_DEVICE constexpr inline bool is_chrono()
498 {
499  return is_duration<T>() || is_timestamp<T>();
500 }
501 
512 bool is_chrono(data_type type);
513 
526 template <typename T>
527 constexpr bool is_rep_layout_compatible()
528 {
529  return cudf::is_numeric<T>() or cudf::is_chrono<T>() or cudf::is_boolean<T>() or
530  cudf::is_byte<T>();
531 }
532 
540 template <typename T>
541 constexpr inline bool is_dictionary()
542 {
543  return std::is_same_v<dictionary32, T>;
544 }
545 
554 
564 template <typename T>
565 CUDF_HOST_DEVICE constexpr inline bool is_fixed_width()
566 {
567  // TODO Add fixed width wrapper types
568  // Is a category fixed width?
569  return cudf::is_numeric<T>() || cudf::is_chrono<T>() || cudf::is_fixed_point<T>();
570 }
571 
582 
583 class string_view;
584 
597 template <typename T>
598 CUDF_HOST_DEVICE constexpr inline bool is_compound()
599 {
600  return cuda::std::is_same_v<T, cudf::string_view> or
601  cuda::std::is_same_v<T, cudf::dictionary32> or cuda::std::is_same_v<T, cudf::list_view> or
602  cuda::std::is_same_v<T, cudf::struct_view>;
603 }
604 
618 
630 template <typename T>
631 CUDF_HOST_DEVICE constexpr inline bool is_nested()
632 {
633  return cuda::std::is_same_v<T, cudf::list_view> || cuda::std::is_same_v<T, cudf::struct_view>;
634 }
635 
647 bool is_nested(data_type type);
648 
663 
664 template <typename From, typename To>
665 struct is_convertible : std::is_convertible<From, To> {};
666 
667 // This will ensure that timestamps can be promoted to a higher precision. Presently, they can't
668 // do that due to nvcc/gcc compiler issues
669 template <typename Duration1, typename Duration2>
671  : std::is_convertible<typename cudf::detail::time_point<Duration1>::duration,
672  typename cudf::detail::time_point<Duration2>::duration> {};
673 
676 } // namespace CUDF_EXPORT cudf
Indicator for the logical data type of an element in a column.
Definition: types.hpp:243
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
Definition: string_view.hpp:44
Concrete type definition for dictionary columns.
Concrete type definitions for int32_t and int64_t durations in varying resolutions.
Class definition for fixed point data type.
bool is_dictionary(data_type type)
Indicates whether type is a dictionary data_type.
decltype(std::declval< L >() > std::declval< R >()) greater_comparable
Checks if two types are comparable using greater operator (i.e. >).
Definition: traits.hpp:56
constexpr bool is_byte()
Indicates whether T is a std::byte type.
Definition: traits.hpp:387
bool is_duration(data_type type)
Indicates whether type is a duration data_type.
bool is_numeric(data_type type)
Indicates whether type is a numeric data_type.
bool is_integral(data_type type)
Indicates whether type is a integral data_type.
decltype(std::declval< L >()==std::declval< R >()) equality_comparable
Checks if two types are comparable using equality operator (i.e. ==).
Definition: traits.hpp:60
typename detail::has_common_type_impl< void, Ts... >::type has_common_type
Checks if types have a common type.
Definition: traits.hpp:88
bool is_equality_comparable(data_type type)
Checks whether data_type type supports equality comparisons.
bool is_index_type(data_type type)
Indicates whether the type type is a index type.
bool is_numeric_not_bool(data_type type)
Indicates whether type is a numeric data_type but not BOOL8.
bool is_relationally_comparable(data_type type)
Checks whether data_type type supports relational comparisons.
decltype(std::declval< L >()< std::declval< R >()) less_comparable
Checks if two types are comparable using less operator (i.e. <).
Definition: traits.hpp:52
cuda::std::disjunction< std::is_same< cudf::timestamp_D, T >, std::is_same< cudf::timestamp_h, T >, std::is_same< cudf::timestamp_m, T >, std::is_same< cudf::timestamp_s, T >, std::is_same< cudf::timestamp_ms, T >, std::is_same< cudf::timestamp_us, T >, std::is_same< cudf::timestamp_ns, T > > is_timestamp_t
Checks if a type is a timestamp type.
Definition: traits.hpp:102
bool is_boolean(data_type type)
Indicates whether type is a Boolean data_type.
bool is_bit_castable(data_type from, data_type to)
Indicates whether from is bit-castable to to.
bool is_compound(data_type type)
Indicates whether elements of type are compound.
constexpr bool is_rep_layout_compatible()
Indicates whether T is layout compatible with its "representation" type.
Definition: traits.hpp:527
bool is_signed(data_type type)
Indicates whether type is a signed numeric data_type.
bool is_nested(data_type type)
Indicates whether type is a nested type.
void void_t
Utility metafunction that maps a sequence of any types to the type void.
Definition: traits.hpp:35
bool is_timestamp(data_type type)
Indicates whether type is a timestamp data_type.
bool is_floating_point(data_type type)
Indicates whether type is a floating point data_type.
bool is_unsigned(data_type type)
Indicates whether type is a unsigned numeric data_type.
constexpr bool has_common_type_v
Helper variable template for has_common_type<>::value.
Definition: traits.hpp:92
cuda::std::disjunction< std::is_same< cudf::duration_D, T >, std::is_same< cudf::duration_h, T >, std::is_same< cudf::duration_m, T >, std::is_same< cudf::duration_s, T >, std::is_same< cudf::duration_ms, T >, std::is_same< cudf::duration_us, T >, std::is_same< cudf::duration_ns, T > > is_duration_t
Checks if a type is a duration type.
Definition: traits.hpp:112
bool is_integral_not_bool(data_type type)
Indicates whether type is a integral data_type and not BOOL8.
bool is_chrono(data_type type)
Indicates whether type is a chrono data_type.
bool is_fixed_point(data_type type)
Indicates whether type is a fixed point data_type.
bool is_fixed_width(data_type type)
Indicates whether elements of type are fixed-width.
constexpr CUDF_HOST_DEVICE bool is_signed_iterator()
Indicates whether the Iterator value type is unsigned.
Definition: traits.hpp:278
cuDF interfaces
Definition: host_udf.hpp:37
Concrete type definitions for int32_t and int64_t timestamps in varying resolutions as durations sinc...
time_point< Duration > timestamp
A wrapper around a column of time_point in varying resolutions.
Definition: timestamps.hpp:39
Type declarations for libcudf.
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.
Definition: types.hpp:32