traits.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2022, 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 #include <cuda/std/type_traits>
26 
27 namespace cudf {
28 
35 template <typename...>
37 using void_t = void;
38 
50 #define CUDF_ENABLE_IF(...) std::enable_if_t<(__VA_ARGS__)>* = nullptr
51 
53 template <typename L, typename R>
54 using less_comparable = decltype(std::declval<L>() < std::declval<R>());
55 
57 template <typename L, typename R>
58 using greater_comparable = decltype(std::declval<L>() > std::declval<R>());
59 
61 template <typename L, typename R>
62 using equality_comparable = decltype(std::declval<L>() == std::declval<R>());
63 
64 namespace detail {
65 template <typename L, typename R, typename = void>
66 struct is_relationally_comparable_impl : std::false_type {
67 };
68 
69 template <typename L, typename R>
70 struct is_relationally_comparable_impl<L,
71  R,
72  void_t<less_comparable<L, R>, greater_comparable<L, R>>>
73  : std::true_type {
74 };
75 
76 template <typename L, typename R, typename = void>
77 struct is_equality_comparable_impl : std::false_type {
78 };
79 
80 template <typename L, typename R>
81 struct is_equality_comparable_impl<L, R, void_t<equality_comparable<L, R>>> : std::true_type {
82 };
83 
84 // has common type
85 template <typename AlwaysVoid, typename... Ts>
86 struct has_common_type_impl : std::false_type {
87 };
88 
89 template <typename... Ts>
90 struct has_common_type_impl<void_t<std::common_type_t<Ts...>>, Ts...> : std::true_type {
91 };
92 } // namespace detail
93 
95 template <typename... Ts>
96 using has_common_type = typename detail::has_common_type_impl<void, Ts...>::type;
97 
99 template <typename... Ts>
100 constexpr inline bool has_common_type_v = detail::has_common_type_impl<void, Ts...>::value;
101 
103 template <typename T>
104 using is_timestamp_t = cuda::std::disjunction<std::is_same<cudf::timestamp_D, T>,
105  std::is_same<cudf::timestamp_s, T>,
106  std::is_same<cudf::timestamp_ms, T>,
107  std::is_same<cudf::timestamp_us, T>,
108  std::is_same<cudf::timestamp_ns, T>>;
109 
111 template <typename T>
112 using is_duration_t = cuda::std::disjunction<std::is_same<cudf::duration_D, T>,
113  std::is_same<cudf::duration_s, T>,
114  std::is_same<cudf::duration_ms, T>,
115  std::is_same<cudf::duration_us, T>,
116  std::is_same<cudf::duration_ns, T>>;
117 
130 template <typename L, typename R>
131 constexpr inline bool is_relationally_comparable()
132 {
133  return detail::is_relationally_comparable_impl<L, R>::value;
134 }
135 
144 
157 template <typename L, typename R>
158 constexpr inline bool is_equality_comparable()
159 {
160  return detail::is_equality_comparable_impl<L, R>::value;
161 }
162 
171 
179 template <typename T>
180 constexpr inline bool is_numeric()
181 {
182  return cuda::std::is_arithmetic<T>();
183 }
184 
197 
209 template <typename T>
210 constexpr inline bool is_index_type()
211 {
212  return std::is_integral_v<T> and not std::is_same_v<T, bool>;
213 }
214 
227 
235 template <typename T>
236 constexpr inline bool is_unsigned()
237 {
238  return std::is_unsigned_v<T>;
239 }
240 
251 
258 template <typename Iterator>
259 constexpr inline bool is_signed_iterator()
260 {
261  return std::is_signed_v<typename std::iterator_traits<Iterator>::value_type>;
262 }
263 
271 template <typename T>
272 constexpr inline bool is_integral()
273 {
274  return cuda::std::is_integral_v<T>;
275 }
276 
287 
295 template <typename T>
296 constexpr inline bool is_floating_point()
297 {
298  return std::is_floating_point_v<T>;
299 }
300 
311 
319 template <typename T>
320 constexpr inline bool is_byte()
321 {
322  return std::is_same_v<std::remove_cv_t<T>, std::byte>;
323 }
324 
332 template <typename T>
333 constexpr inline bool is_boolean()
334 {
335  return std::is_same_v<T, bool>;
336 }
337 
346 
354 template <typename T>
355 constexpr inline bool is_timestamp()
356 {
358 }
359 
370 
378 template <typename T>
379 constexpr inline bool is_fixed_point()
380 {
381  return std::is_same_v<numeric::decimal32, T> || std::is_same_v<numeric::decimal64, T> ||
382  std::is_same_v<numeric::decimal128, T>;
383 }
384 
393 
401 template <typename T>
402 constexpr inline bool is_duration()
403 {
405 }
406 
417 
425 template <typename T>
426 constexpr inline bool is_chrono()
427 {
428  return is_duration<T>() || is_timestamp<T>();
429 }
430 
441 bool is_chrono(data_type type);
442 
455 template <typename T>
456 constexpr bool is_rep_layout_compatible()
457 {
458  return cudf::is_numeric<T>() or cudf::is_chrono<T>() or cudf::is_boolean<T>() or
459  cudf::is_byte<T>();
460 }
461 
469 template <typename T>
470 constexpr inline bool is_dictionary()
471 {
472  return std::is_same_v<dictionary32, T>;
473 }
474 
483 
493 template <typename T>
494 constexpr inline bool is_fixed_width()
495 {
496  // TODO Add fixed width wrapper types
497  // Is a category fixed width?
498  return cudf::is_numeric<T>() || cudf::is_chrono<T>() || cudf::is_fixed_point<T>();
499 }
500 
511 
512 class string_view;
513 
526 template <typename T>
527 constexpr inline bool is_compound()
528 {
529  return std::is_same_v<T, cudf::string_view> or std::is_same_v<T, cudf::dictionary32> or
530  std::is_same_v<T, cudf::list_view> or std::is_same_v<T, cudf::struct_view>;
531 }
532 
546 
558 template <typename T>
559 constexpr inline bool is_nested()
560 {
561  return std::is_same_v<T, cudf::list_view> || std::is_same_v<T, cudf::struct_view>;
562 }
563 
575 bool is_nested(data_type type);
576 
591 
592 template <typename From, typename To>
593 struct is_convertible : std::is_convertible<From, To> {
594 };
595 
596 // This will ensure that timestamps can be promoted to a higher precision. Presently, they can't
597 // do that due to nvcc/gcc compiler issues
598 template <typename Duration1, typename Duration2>
600  : std::is_convertible<typename cudf::detail::time_point<Duration1>::duration,
601  typename cudf::detail::time_point<Duration2>::duration> {
602 };
603 
606 } // namespace cudf
cudf::detail::timestamp
time_point< Duration > timestamp
A wrapper around a column of time_point in varying resolutions.
Definition: timestamps.hpp:38
fixed_point.hpp
Class definition for fixed point data type.
cudf::greater_comparable
decltype(std::declval< L >() > std::declval< R >()) greater_comparable
Checks if two types are comparable using greater operator (i.e. >).
Definition: traits.hpp:58
durations.hpp
Concrete type definitions for int32_t and int64_t durations in varying resolutions.
cudf::is_signed_iterator
constexpr bool is_signed_iterator()
Indicates whether the Iterator value type is unsigned.
Definition: traits.hpp:259
types.hpp
Type declarations for libcudf.
cudf::is_compound
constexpr bool is_compound()
Indicates whether the type T is a compound type.
Definition: traits.hpp:527
cudf::string_view
A non-owning, immutable view of device data that is a variable length char array representing a UTF-8...
Definition: string_view.hpp:44
cudf::is_boolean
constexpr bool is_boolean()
Indicates whether T is a Boolean type.
Definition: traits.hpp:333
cudf::has_common_type
typename detail::has_common_type_impl< void, Ts... >::type has_common_type
Checks if types have a common type.
Definition: traits.hpp:96
cudf::is_rep_layout_compatible
constexpr bool is_rep_layout_compatible()
Indicates whether T is layout compatible with its "representation" type.
Definition: traits.hpp:456
cudf::is_numeric
constexpr bool is_numeric()
Indicates whether the type T is a numeric type.
Definition: traits.hpp:180
cudf::is_integral
constexpr bool is_integral()
Indicates whether the type T is an integral type.
Definition: traits.hpp:272
cudf::has_common_type_v
constexpr bool has_common_type_v
Helper variable template for has_common_type<>::value.
Definition: traits.hpp:100
cudf::less_comparable
decltype(std::declval< L >()< std::declval< R >()) less_comparable
Checks if two types are comparable using less operator (i.e. <).
Definition: traits.hpp:54
cudf::is_byte
constexpr bool is_byte()
Indicates whether T is a std::byte type.
Definition: traits.hpp:320
cudf::is_unsigned
constexpr bool is_unsigned()
Indicates whether the type T is a unsigned numeric type.
Definition: traits.hpp:236
cudf::equality_comparable
decltype(std::declval< L >()==std::declval< R >()) equality_comparable
Checks if two types are comparable using equality operator (i.e. ==).
Definition: traits.hpp:62
cudf::is_floating_point
constexpr bool is_floating_point()
Indicates whether the type T is a floating point type.
Definition: traits.hpp:296
dictionary.hpp
Concrete type definition for dictionary columns.
cudf::is_dictionary
constexpr bool is_dictionary()
Indicates whether the type T is a dictionary type.
Definition: traits.hpp:470
cudf::data_type
Indicator for the logical data type of an element in a column.
Definition: types.hpp:236
cudf::is_index_type
constexpr bool is_index_type()
Indicates whether the type T is a index type.
Definition: traits.hpp:210
cudf
cuDF interfaces
Definition: aggregation.hpp:34
cudf::is_duration_t
cuda::std::disjunction< std::is_same< cudf::duration_D, 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:116
cudf::is_chrono
constexpr bool is_chrono()
Indicates whether the type T is a chrono type.
Definition: traits.hpp:426
cudf::is_fixed_width
constexpr bool is_fixed_width()
Indicates whether elements of type T are fixed-width.
Definition: traits.hpp:494
cudf::is_nested
constexpr bool is_nested()
Indicates whether T is a nested type.
Definition: traits.hpp:559
cudf::is_timestamp_t
cuda::std::disjunction< std::is_same< cudf::timestamp_D, 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:108
cudf::is_convertible
Definition: traits.hpp:593
cudf::is_fixed_point
constexpr bool is_fixed_point()
Indicates whether the type T is a fixed-point type.
Definition: traits.hpp:379
cudf::is_duration
constexpr bool is_duration()
Indicates whether the type T is a duration type.
Definition: traits.hpp:402
timestamps.hpp
Concrete type definitions for int32_t and int64_t timestamps in varying resolutions as durations sinc...
cudf::is_equality_comparable
constexpr bool is_equality_comparable()
Indicates whether objects of types L and R can be compared for equality.
Definition: traits.hpp:158
cudf::is_timestamp
constexpr bool is_timestamp()
Indicates whether the type T is a timestamp type.
Definition: traits.hpp:355
cudf::is_bit_castable
bool is_bit_castable(data_type from, data_type to)
Indicates whether from is bit-castable to to.
cudf::void_t
void void_t
Utility metafunction that maps a sequence of any types to the type void.
Definition: traits.hpp:37
cudf::is_relationally_comparable
constexpr bool is_relationally_comparable()
Indicates whether objects of types L and R can be relationally compared.
Definition: traits.hpp:131