types.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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 
19 #ifdef __CUDACC__
20 #define CUDF_HOST_DEVICE __host__ __device__
21 #else
22 #define CUDF_HOST_DEVICE
23 #endif
24 
25 #include <cassert>
26 #include <cstddef>
27 #include <cstdint>
28 #include <iterator>
29 
35 // Forward declarations
37 namespace rmm {
38 class device_buffer;
39 namespace mr {
40 class device_memory_resource;
41 device_memory_resource* get_current_device_resource();
42 } // namespace mr
44 
45 } // namespace rmm
46 
47 namespace cudf {
48 // Forward declaration
49 class column;
50 class column_view;
51 class mutable_column_view;
52 class string_view;
53 class list_view;
54 class struct_view;
55 
56 class scalar;
57 
58 // clang-format off
59 class list_scalar;
60 class struct_scalar;
61 class string_scalar;
62 template <typename T> class numeric_scalar;
63 template <typename T> class fixed_point_scalar;
64 template <typename T> class timestamp_scalar;
65 template <typename T> class duration_scalar;
66 
67 class string_scalar_device_view;
68 template <typename T> class numeric_scalar_device_view;
69 template <typename T> class fixed_point_scalar_device_view;
70 template <typename T> class timestamp_scalar_device_view;
71 template <typename T> class duration_scalar_device_view;
72 // clang-format on
73 
74 class table;
75 class table_view;
76 class mutable_table_view;
77 
84 using size_type = int32_t;
85 using bitmask_type = uint32_t;
86 using valid_type = uint8_t;
87 using offset_type = int32_t;
88 using thread_index_type = int64_t;
89 
98 template <typename T>
100 {
101  return static_cast<size_type>(std::distance(f, l));
102 }
103 
110 static constexpr size_type UNKNOWN_NULL_COUNT{-1};
111 
115 enum class order : bool {
116  ASCENDING,
117  DESCENDING
118 };
119 
123 enum class null_policy : bool {
124  EXCLUDE,
125  INCLUDE
126 };
127 
131 enum class nan_policy : bool {
132  NAN_IS_NULL,
133  NAN_IS_VALID
134 };
135 
140 enum class nan_equality /*unspecified*/ {
141  ALL_EQUAL,
142  UNEQUAL
143 };
144 
148 enum class null_equality : bool {
149  EQUAL,
150  UNEQUAL
151 };
152 
156 enum class null_order : bool {
157  AFTER,
158  BEFORE
159 };
160 
164 enum class sorted : bool { NO, YES };
165 
169 struct order_info {
173 };
174 
178 enum class mask_state : int32_t {
179  UNALLOCATED,
180  UNINITIALIZED,
181  ALL_VALID,
182  ALL_NULL
183 };
184 
189 enum class interpolation : int32_t {
190  LINEAR,
191  LOWER,
192  HIGHER,
193  MIDPOINT,
194  NEAREST
195 };
196 
200 enum class type_id : int32_t {
201  EMPTY,
202  INT8,
203  INT16,
204  INT32,
205  INT64,
206  UINT8,
207  UINT16,
208  UINT32,
209  UINT64,
210  FLOAT32,
211  FLOAT64,
212  BOOL8,
213  TIMESTAMP_DAYS,
214  TIMESTAMP_SECONDS,
215  TIMESTAMP_MILLISECONDS,
216  TIMESTAMP_MICROSECONDS,
217  TIMESTAMP_NANOSECONDS,
218  DURATION_DAYS,
219  DURATION_SECONDS,
220  DURATION_MILLISECONDS,
221  DURATION_MICROSECONDS,
222  DURATION_NANOSECONDS,
223  DICTIONARY32,
224  STRING,
225  LIST,
226  DECIMAL32,
227  DECIMAL64,
228  DECIMAL128,
229  STRUCT,
230  // `NUM_TYPE_IDS` must be last!
231  NUM_TYPE_IDS
232 };
233 
240 class data_type {
241  public:
242  data_type() = default;
243  ~data_type() = default;
244  data_type(data_type const&) = default;
245  data_type(data_type&&) = default;
246 
252  data_type& operator=(data_type const&) = default;
253 
260 
266  explicit constexpr data_type(type_id id) : _id{id} {}
267 
274  explicit data_type(type_id id, int32_t scale) : _id{id}, _fixed_point_scale{scale}
275  {
276  assert(id == type_id::DECIMAL32 || id == type_id::DECIMAL64 || id == type_id::DECIMAL128);
277  }
278 
284  [[nodiscard]] constexpr type_id id() const noexcept { return _id; }
285 
291  [[nodiscard]] constexpr int32_t scale() const noexcept { return _fixed_point_scale; }
292 
293  private:
294  type_id _id{type_id::EMPTY};
295 
296  // Below is additional type specific metadata. Currently, only _fixed_point_scale is stored.
297 
298  int32_t _fixed_point_scale{}; // numeric::scale_type not available here, use int32_t
299 };
300 
313 constexpr bool operator==(data_type const& lhs, data_type const& rhs)
314 {
315  // use std::tie in the future, breaks JITIFY currently
316  return lhs.id() == rhs.id() && lhs.scale() == rhs.scale();
317 }
318 
331 inline bool operator!=(data_type const& lhs, data_type const& rhs) { return !(lhs == rhs); }
332 
343 std::size_t size_of(data_type t);
344 
346 } // namespace cudf
cudf::nan_policy
nan_policy
Enum to treat NaN floating point value as null or non-null element.
Definition: types.hpp:131
cudf::data_type::id
constexpr type_id id() const noexcept
Returns the type identifier.
Definition: types.hpp:284
cudf::strings::LOWER
@ LOWER
all lower case characters
Definition: char_types.hpp:46
cudf::data_type::operator=
data_type & operator=(data_type &&)=default
Move assignment operator for data_type.
cudf::interpolation::LINEAR
@ LINEAR
Linear interpolation between i and j.
cudf::size_type
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:84
cudf::null_policy
null_policy
Enum to specify whether to include nulls or exclude nulls.
Definition: types.hpp:123
cudf::order_info::null_ordering
null_order null_ordering
Indicates how null values compare against all other values.
Definition: types.hpp:172
cudf::type_id
type_id
Identifies a column's logical element type.
Definition: types.hpp:200
cudf::interpolation
interpolation
Interpolation method to use when the desired quantile lies between two data points i and j.
Definition: types.hpp:189
rmm
cudf::data_type::data_type
data_type(type_id id, int32_t scale)
Construct a new data_type object for numeric::fixed_point
Definition: types.hpp:274
cudf::data_type::scale
constexpr int32_t scale() const noexcept
Returns the scale (for fixed_point types)
Definition: types.hpp:291
cudf::size_of
std::size_t size_of(data_type t)
Returns the size in bytes of elements of the specified data_type
cudf::valid_type
uint8_t valid_type
Valid type in host memory.
Definition: types.hpp:86
cudf::bitmask_type
uint32_t bitmask_type
Bitmask type stored as 32-bit unsigned integer.
Definition: types.hpp:85
cudf::null_order
null_order
Indicates how null values compare against all other values.
Definition: types.hpp:156
cudf::order::ASCENDING
@ ASCENDING
Elements ordered from small to large.
cudf::data_type::data_type
constexpr data_type(type_id id)
Construct a new data_type object.
Definition: types.hpp:266
cudf::mask_state
mask_state
Controls the allocation/initialization of a null mask.
Definition: types.hpp:178
cudf::nan_equality
nan_equality
Enum to consider different elements (of floating point types) holding NaN value as equal or unequal.
Definition: types.hpp:140
cudf::nan_equality::ALL_EQUAL
@ ALL_EQUAL
All NaNs compare equal, regardless of sign.
cudf::null_order::AFTER
@ AFTER
NULL values ordered after all other values.
cudf::order_info
Indicates how a collection of values has been ordered.
Definition: types.hpp:169
cudf::offset_type
int32_t offset_type
Offset type for column offsets.
Definition: types.hpp:87
cudf::data_type::data_type
data_type(data_type const &)=default
Copy constructor.
cudf::mask_state::UNALLOCATED
@ UNALLOCATED
Null mask not allocated, (all elements are valid)
cudf::data_type
Indicator for the logical data type of an element in a column.
Definition: types.hpp:240
cudf
cuDF interfaces
Definition: aggregation.hpp:34
cudf::nan_policy::NAN_IS_NULL
@ NAN_IS_NULL
treat nans as null elements
cudf::sorted
sorted
Indicates whether a collection of values is known to be sorted.
Definition: types.hpp:164
cudf::thread_index_type
int64_t thread_index_type
Thread index type in kernels.
Definition: types.hpp:88
cudf::order_info::ordering
order ordering
Indicates the order in which the values are sorted.
Definition: types.hpp:171
cudf::null_policy::EXCLUDE
@ EXCLUDE
exclude null elements
cudf::null_equality::EQUAL
@ EQUAL
nulls compare equal
cudf::operator==
constexpr bool operator==(data_type const &lhs, data_type const &rhs)
Compares two data_type objects for equality.
Definition: types.hpp:313
cudf::data_type::data_type
data_type(data_type &&)=default
Move constructor.
cudf::null_equality
null_equality
Enum to consider two nulls as equal or unequal.
Definition: types.hpp:148
cudf::distance
size_type distance(T f, T l)
Similar to std::distance but returns cudf::size_type and performs static_cast
Definition: types.hpp:99
cudf::operator!=
bool operator!=(data_type const &lhs, data_type const &rhs)
Compares two data_type objects for inequality.
Definition: types.hpp:331
cudf::type_id::EMPTY
@ EMPTY
Always null with no underlying data.
get_current_device_resource
device_memory_resource * get_current_device_resource()
cudf::order_info::is_sorted
sorted is_sorted
Indicates whether the collection is sorted.
Definition: types.hpp:170
cudf::data_type::operator=
data_type & operator=(data_type const &)=default
Copy assignment operator for data_type.
cudf::order
order
Indicates the order in which elements should be sorted.
Definition: types.hpp:115