types.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2023, 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;
40 
41 } // namespace rmm
42 
43 namespace cudf {
44 // Forward declaration
45 class column;
46 class column_view;
47 class mutable_column_view;
48 class string_view;
49 class list_view;
50 class struct_view;
51 
52 class scalar;
53 
54 // clang-format off
55 class list_scalar;
56 class struct_scalar;
57 class string_scalar;
58 template <typename T> class numeric_scalar;
59 template <typename T> class fixed_point_scalar;
60 template <typename T> class timestamp_scalar;
61 template <typename T> class duration_scalar;
62 
63 class string_scalar_device_view;
64 template <typename T> class numeric_scalar_device_view;
65 template <typename T> class fixed_point_scalar_device_view;
66 template <typename T> class timestamp_scalar_device_view;
67 template <typename T> class duration_scalar_device_view;
68 // clang-format on
69 
70 class table;
71 class table_view;
72 class mutable_table_view;
73 
80 using size_type = int32_t;
81 using bitmask_type = uint32_t;
82 using valid_type = uint8_t;
83 using offset_type = int32_t;
84 using thread_index_type = int64_t;
85 
94 template <typename T>
96 {
97  return static_cast<size_type>(std::distance(f, l));
98 }
99 
106 static constexpr size_type UNKNOWN_NULL_COUNT{-1};
107 
111 enum class order : bool {
112  ASCENDING,
113  DESCENDING
114 };
115 
119 enum class null_policy : bool {
120  EXCLUDE,
121  INCLUDE
122 };
123 
127 enum class nan_policy : bool {
128  NAN_IS_NULL,
129  NAN_IS_VALID
130 };
131 
136 enum class nan_equality /*unspecified*/ {
137  ALL_EQUAL,
138  UNEQUAL
139 };
140 
144 enum class null_equality : bool {
145  EQUAL,
146  UNEQUAL
147 };
148 
152 enum class null_order : bool {
153  AFTER,
154  BEFORE
155 };
156 
160 enum class sorted : bool { NO, YES };
161 
165 struct order_info {
169 };
170 
174 enum class mask_state : int32_t {
175  UNALLOCATED,
176  UNINITIALIZED,
177  ALL_VALID,
178  ALL_NULL
179 };
180 
185 enum class interpolation : int32_t {
186  LINEAR,
187  LOWER,
188  HIGHER,
189  MIDPOINT,
190  NEAREST
191 };
192 
196 enum class type_id : int32_t {
197  EMPTY,
198  INT8,
199  INT16,
200  INT32,
201  INT64,
202  UINT8,
203  UINT16,
204  UINT32,
205  UINT64,
206  FLOAT32,
207  FLOAT64,
208  BOOL8,
209  TIMESTAMP_DAYS,
210  TIMESTAMP_SECONDS,
211  TIMESTAMP_MILLISECONDS,
212  TIMESTAMP_MICROSECONDS,
213  TIMESTAMP_NANOSECONDS,
214  DURATION_DAYS,
215  DURATION_SECONDS,
216  DURATION_MILLISECONDS,
217  DURATION_MICROSECONDS,
218  DURATION_NANOSECONDS,
219  DICTIONARY32,
220  STRING,
221  LIST,
222  DECIMAL32,
223  DECIMAL64,
224  DECIMAL128,
225  STRUCT,
226  // `NUM_TYPE_IDS` must be last!
227  NUM_TYPE_IDS
228 };
229 
236 class data_type {
237  public:
238  data_type() = default;
239  ~data_type() = default;
240  data_type(data_type const&) = default;
241  data_type(data_type&&) = default;
242 
248  data_type& operator=(data_type const&) = default;
249 
256 
262  explicit constexpr data_type(type_id id) : _id{id} {}
263 
270  explicit data_type(type_id id, int32_t scale) : _id{id}, _fixed_point_scale{scale}
271  {
272  assert(id == type_id::DECIMAL32 || id == type_id::DECIMAL64 || id == type_id::DECIMAL128);
273  }
274 
280  [[nodiscard]] constexpr type_id id() const noexcept { return _id; }
281 
287  [[nodiscard]] constexpr int32_t scale() const noexcept { return _fixed_point_scale; }
288 
289  private:
290  type_id _id{type_id::EMPTY};
291 
292  // Below is additional type specific metadata. Currently, only _fixed_point_scale is stored.
293 
294  int32_t _fixed_point_scale{}; // numeric::scale_type not available here, use int32_t
295 };
296 
309 constexpr bool operator==(data_type const& lhs, data_type const& rhs)
310 {
311  // use std::tie in the future, breaks JITIFY currently
312  return lhs.id() == rhs.id() && lhs.scale() == rhs.scale();
313 }
314 
327 inline bool operator!=(data_type const& lhs, data_type const& rhs) { return !(lhs == rhs); }
328 
339 std::size_t size_of(data_type t);
340 
342 } // namespace cudf
cudf::nan_policy
nan_policy
Enum to treat NaN floating point value as null or non-null element.
Definition: types.hpp:127
cudf::data_type::id
constexpr type_id id() const noexcept
Returns the type identifier.
Definition: types.hpp:280
cudf::strings::LOWER
@ LOWER
all lower case characters
Definition: char_types_enum.hpp:45
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:80
cudf::null_policy
null_policy
Enum to specify whether to include nulls or exclude nulls.
Definition: types.hpp:119
cudf::order_info::null_ordering
null_order null_ordering
Indicates how null values compare against all other values.
Definition: types.hpp:168
cudf::type_id
type_id
Identifies a column's logical element type.
Definition: types.hpp:196
cudf::interpolation
interpolation
Interpolation method to use when the desired quantile lies between two data points i and j.
Definition: types.hpp:185
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:270
cudf::data_type::scale
constexpr int32_t scale() const noexcept
Returns the scale (for fixed_point types)
Definition: types.hpp:287
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:82
cudf::bitmask_type
uint32_t bitmask_type
Bitmask type stored as 32-bit unsigned integer.
Definition: types.hpp:81
cudf::null_order
null_order
Indicates how null values compare against all other values.
Definition: types.hpp:152
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:262
cudf::mask_state
mask_state
Controls the allocation/initialization of a null mask.
Definition: types.hpp:174
cudf::nan_equality
nan_equality
Enum to consider different elements (of floating point types) holding NaN value as equal or unequal.
Definition: types.hpp:136
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:165
cudf::offset_type
int32_t offset_type
Offset type for column offsets.
Definition: types.hpp:83
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:236
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:160
cudf::thread_index_type
int64_t thread_index_type
Thread index type in kernels.
Definition: types.hpp:84
cudf::order_info::ordering
order ordering
Indicates the order in which the values are sorted.
Definition: types.hpp:167
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:309
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:144
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:95
cudf::operator!=
bool operator!=(data_type const &lhs, data_type const &rhs)
Compares two data_type objects for inequality.
Definition: types.hpp:327
cudf::type_id::EMPTY
@ EMPTY
Always null with no underlying data.
cudf::order_info::is_sorted
sorted is_sorted
Indicates whether the collection is sorted.
Definition: types.hpp:166
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:111