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 
103 enum class order : bool {
104  ASCENDING,
105  DESCENDING
106 };
107 
111 enum class null_policy : bool {
112  EXCLUDE,
113  INCLUDE
114 };
115 
119 enum class nan_policy : bool {
120  NAN_IS_NULL,
121  NAN_IS_VALID
122 };
123 
128 enum class nan_equality /*unspecified*/ {
129  ALL_EQUAL,
130  UNEQUAL
131 };
132 
136 enum class null_equality : bool {
137  EQUAL,
138  UNEQUAL
139 };
140 
144 enum class null_order : bool {
145  AFTER,
146  BEFORE
147 };
148 
152 enum class sorted : bool { NO, YES };
153 
157 struct order_info {
161 };
162 
166 enum class mask_state : int32_t {
167  UNALLOCATED,
168  UNINITIALIZED,
169  ALL_VALID,
170  ALL_NULL
171 };
172 
177 enum class interpolation : int32_t {
178  LINEAR,
179  LOWER,
180  HIGHER,
181  MIDPOINT,
182  NEAREST
183 };
184 
188 enum class type_id : int32_t {
189  EMPTY,
190  INT8,
191  INT16,
192  INT32,
193  INT64,
194  UINT8,
195  UINT16,
196  UINT32,
197  UINT64,
198  FLOAT32,
199  FLOAT64,
200  BOOL8,
201  TIMESTAMP_DAYS,
202  TIMESTAMP_SECONDS,
203  TIMESTAMP_MILLISECONDS,
204  TIMESTAMP_MICROSECONDS,
205  TIMESTAMP_NANOSECONDS,
206  DURATION_DAYS,
207  DURATION_SECONDS,
208  DURATION_MILLISECONDS,
209  DURATION_MICROSECONDS,
210  DURATION_NANOSECONDS,
211  DICTIONARY32,
212  STRING,
213  LIST,
214  DECIMAL32,
215  DECIMAL64,
216  DECIMAL128,
217  STRUCT,
218  // `NUM_TYPE_IDS` must be last!
219  NUM_TYPE_IDS
220 };
221 
228 class data_type {
229  public:
230  data_type() = default;
231  ~data_type() = default;
232  data_type(data_type const&) = default;
233  data_type(data_type&&) = default;
234 
240  data_type& operator=(data_type const&) = default;
241 
248 
254  explicit constexpr data_type(type_id id) : _id{id} {}
255 
262  explicit data_type(type_id id, int32_t scale) : _id{id}, _fixed_point_scale{scale}
263  {
264  assert(id == type_id::DECIMAL32 || id == type_id::DECIMAL64 || id == type_id::DECIMAL128);
265  }
266 
272  [[nodiscard]] constexpr type_id id() const noexcept { return _id; }
273 
279  [[nodiscard]] constexpr int32_t scale() const noexcept { return _fixed_point_scale; }
280 
281  private:
282  type_id _id{type_id::EMPTY};
283 
284  // Below is additional type specific metadata. Currently, only _fixed_point_scale is stored.
285 
286  int32_t _fixed_point_scale{}; // numeric::scale_type not available here, use int32_t
287 };
288 
301 constexpr bool operator==(data_type const& lhs, data_type const& rhs)
302 {
303  // use std::tie in the future, breaks JITIFY currently
304  return lhs.id() == rhs.id() && lhs.scale() == rhs.scale();
305 }
306 
319 inline bool operator!=(data_type const& lhs, data_type const& rhs) { return !(lhs == rhs); }
320 
331 std::size_t size_of(data_type t);
332 
334 } // namespace cudf
cudf::nan_policy
nan_policy
Enum to treat NaN floating point value as null or non-null element.
Definition: types.hpp:119
cudf::data_type::id
constexpr type_id id() const noexcept
Returns the type identifier.
Definition: types.hpp:272
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:111
cudf::order_info::null_ordering
null_order null_ordering
Indicates how null values compare against all other values.
Definition: types.hpp:160
cudf::type_id
type_id
Identifies a column's logical element type.
Definition: types.hpp:188
cudf::interpolation
interpolation
Interpolation method to use when the desired quantile lies between two data points i and j.
Definition: types.hpp:177
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:262
cudf::data_type::scale
constexpr int32_t scale() const noexcept
Returns the scale (for fixed_point types)
Definition: types.hpp:279
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:144
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:254
cudf::mask_state
mask_state
Controls the allocation/initialization of a null mask.
Definition: types.hpp:166
cudf::nan_equality
nan_equality
Enum to consider different elements (of floating point types) holding NaN value as equal or unequal.
Definition: types.hpp:128
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:157
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:228
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:152
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:159
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:301
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:136
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:319
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:158
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:103