type_lists.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2024, 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 
23 #include <cudf/types.hpp>
28 
29 #include <thrust/host_vector.h>
30 
31 #include <array>
32 #include <tuple>
33 #include <type_traits>
34 
43 namespace cudf {
44 namespace test {
45 namespace detail {
46 template <typename TYPES, std::size_t... Indices>
47 constexpr std::array<cudf::type_id, sizeof...(Indices)> types_to_ids_impl(
48  std::index_sequence<Indices...>)
49 {
50  return {{cudf::type_to_id<GetType<TYPES, Indices>>()...}};
51 }
52 
66 template <typename TYPES>
67 constexpr auto types_to_ids()
68 {
69  constexpr auto N = GetSize<TYPES>;
70  return types_to_ids_impl<TYPES>(std::make_index_sequence<N>());
71 }
72 
73 } // namespace detail
74 
83 template <typename TypeParam, typename T>
84 std::enable_if_t<cudf::is_fixed_width<TypeParam>() && !cudf::is_timestamp_t<TypeParam>::value,
85  thrust::host_vector<TypeParam>>
86 make_type_param_vector(std::initializer_list<T> const& init_list)
87 {
88  std::vector<T> input{init_list};
89  std::vector<TypeParam> vec(init_list.size());
91  std::cbegin(input), std::cend(input), std::begin(vec), [](auto const& e) -> TypeParam {
92  if constexpr (std::is_unsigned_v<TypeParam>) { return static_cast<TypeParam>(std::abs(e)); }
93  return static_cast<TypeParam>(e);
94  });
95  return vec;
96 }
97 
104 template <typename TypeParam, typename T>
105 std::enable_if_t<cudf::is_timestamp_t<TypeParam>::value, thrust::host_vector<TypeParam>>
106 make_type_param_vector(std::initializer_list<T> const& init_list)
107 {
108  thrust::host_vector<TypeParam> vec(init_list.size());
109  std::transform(std::cbegin(init_list), std::cend(init_list), std::begin(vec), [](auto const& e) {
110  return TypeParam{typename TypeParam::duration{e}};
111  });
112  return vec;
113 }
114 
122 template <typename TypeParam, typename T>
123 std::enable_if_t<std::is_same_v<TypeParam, std::string>, thrust::host_vector<std::string>>
124 make_type_param_vector(std::initializer_list<T> const& init_list)
125 {
126  thrust::host_vector<std::string> vec(init_list.size());
127  std::transform(std::cbegin(init_list), std::cend(init_list), std::begin(vec), [](auto const& e) {
128  return std::to_string(e);
129  });
130  return vec;
131 }
132 
144 template <typename TypeParam, typename T>
145 std::enable_if_t<cudf::is_fixed_width<TypeParam>() && !cudf::is_timestamp_t<TypeParam>::value,
146  TypeParam>
147 make_type_param_scalar(T const init_value)
148 {
149  return static_cast<TypeParam>(init_value);
150 }
151 
163 template <typename TypeParam, typename T>
164 std::enable_if_t<cudf::is_timestamp_t<TypeParam>::value, TypeParam> make_type_param_scalar(
165  T const init_value)
166 {
167  return TypeParam{typename TypeParam::duration(init_value)};
168 }
169 
178 template <typename TypeParam, typename T>
179 std::enable_if_t<std::is_same_v<TypeParam, std::string>, TypeParam> make_type_param_scalar(
180  T const init_value)
181 {
182  return std::to_string(init_value);
183 }
184 
189  cudf::test::Types<int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t>;
190 
195 
206 using FloatingPointTypes = cudf::test::Types<float, double>;
207 
219 
231  cudf::test::Types<timestamp_D, timestamp_s, timestamp_ms, timestamp_us, timestamp_ns>;
232 
244  cudf::test::Types<duration_D, duration_s, duration_ms, duration_us, duration_ns>;
245 
256 
267 using StringTypes = cudf::test::Types<string_view>;
268 
279 using ListTypes = cudf::test::Types<list_view>;
280 
292  cudf::test::Types<numeric::decimal32, numeric::decimal64, numeric::decimal128>;
293 
305 
321 
333 
344 
355  cudf::test::Types<cudf::string_view, cudf::dictionary32, cudf::list_view, cudf::struct_view>;
356 
371 
378 static constexpr auto all_type_ids{detail::types_to_ids<AllTypes>()};
379 
386 static constexpr auto numeric_type_ids{detail::types_to_ids<NumericTypes>()};
387 
394 static constexpr std::array<cudf::type_id, 5> timestamp_type_ids{
395  detail::types_to_ids<TimestampTypes>()};
396 
403 static constexpr std::array<cudf::type_id, 5> duration_type_ids{
404  detail::types_to_ids<DurationTypes>()};
405 
412 static constexpr std::array<cudf::type_id, 12> non_numeric_type_ids{
425 
432 static constexpr std::array<cudf::type_id, 2> non_fixed_width_type_ids{cudf::type_id::EMPTY,
434 
435 } // namespace test
436 } // namespace cudf
Concrete type definitions for int32_t and int64_t durations in varying resolutions.
Class definition for fixed point data type.
std::unique_ptr< column > transform(column_view const &input, std::string const &unary_udf, data_type output_type, bool is_ptx, rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Creates a new column by applying a unary function against every element of an input column.
type_id
Identifies a column's logical element type.
Definition: types.hpp:201
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:102
@ DURATION_MILLISECONDS
time interval of milliseconds in int64
@ TIMESTAMP_MILLISECONDS
point in time in milliseconds since Unix Epoch in int64
@ DURATION_NANOSECONDS
time interval of nanoseconds in int64
@ STRING
String elements.
@ DURATION_DAYS
time interval of days in int32
@ TIMESTAMP_MICROSECONDS
point in time in microseconds since Unix Epoch in int64
@ DURATION_SECONDS
time interval of seconds in int64
@ DURATION_MICROSECONDS
time interval of microseconds in int64
@ EMPTY
Always null with no underlying data.
@ TIMESTAMP_SECONDS
point in time in seconds since Unix Epoch in int64
@ TIMESTAMP_NANOSECONDS
point in time in nanoseconds since Unix Epoch in int64
@ TIMESTAMP_DAYS
point in time in days since Unix Epoch in int32
cuDF interfaces
Definition: aggregation.hpp:34
Class definition for cudf::string_view.
Concrete type definitions for int32_t and int64_t timestamps in varying resolutions as durations sinc...
Defines the mapping between cudf::type_id runtime type information and concrete C++ types.
Utilities for creating type lists for typed tests in Google Test.
typename ConcatImpl< T... >::type Concat
Concatenates compile-time lists of types into a single type list.
Concat< NumericTypes, FixedPointTypes > FixedWidthTypesWithoutChrono
Provides a list of all fixed-width element types except for the chrono types for use in GTest typed t...
Definition: type_lists.hpp:332
std::enable_if_t< cudf::is_fixed_width< TypeParam >) &&!cudf::is_timestamp_t< TypeParam >::value, thrust::host_vector< TypeParam > > make_type_param_vector(std::initializer_list< T > const &init_list)
Convert numeric values of type T to numeric vector of type TypeParam.
Definition: type_lists.hpp:86
cudf::test::Types< int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t > IntegralTypesNotBool
Type list for all integral types except type bool.
Definition: type_lists.hpp:189
cudf::test::Types< cudf::string_view, cudf::dictionary32, cudf::list_view, cudf::struct_view > CompoundTypes
Provides a list of all compound types for use in GTest typed tests.
Definition: type_lists.hpp:355
Concat< IntegralTypesNotBool, cudf::test::Types< bool > > IntegralTypes
Type list for all integral types.
Definition: type_lists.hpp:194
cudf::test::Types< float, double > FloatingPointTypes
Provides a list of all floating point types supported in libcudf for use in a GTest typed test.
Definition: type_lists.hpp:206
cudf::test::Types< timestamp_D, timestamp_s, timestamp_ms, timestamp_us, timestamp_ns > TimestampTypes
Provides a list of all timestamp types supported in libcudf for use in a GTest typed test.
Definition: type_lists.hpp:231
Concat< NumericTypes, ChronoTypes, FixedPointTypes > FixedWidthTypes
Provides a list of all fixed-width element types for use in GTest typed tests.
Definition: type_lists.hpp:304
Concat< IntegralTypes, FloatingPointTypes > NumericTypes
Provides a list of all numeric types supported in libcudf for use in a GTest typed test.
Definition: type_lists.hpp:218
Concat< NumericTypes, ChronoTypes, StringTypes > ComparableTypes
Provides a list of sortable types for use in GTest typed tests.
Definition: type_lists.hpp:343
Concat< NumericTypes, ChronoTypes, FixedPointTypes > AllTypes
Provides a list of all types supported in libcudf for use in a GTest typed test.
Definition: type_lists.hpp:370
Concat< TimestampTypes, DurationTypes > ChronoTypes
Provides a list of all chrono types supported in libcudf for use in a GTest typed test.
Definition: type_lists.hpp:255
std::enable_if_t< cudf::is_fixed_width< TypeParam >) &&!cudf::is_timestamp_t< TypeParam >::value, TypeParam > make_type_param_scalar(T const init_value)
Convert the numeric value of type T to a fixed width type of type TypeParam.
Definition: type_lists.hpp:147
cudf::test::Types< string_view > StringTypes
Provides a list of all string types supported in libcudf for use in a GTest typed test.
Definition: type_lists.hpp:267
cudf::test::Types< numeric::decimal32, numeric::decimal64, numeric::decimal128 > FixedPointTypes
Provides a list of all fixed-point element types for use in GTest typed tests.
Definition: type_lists.hpp:292
Concat< NumericTypes, ChronoTypes > FixedWidthTypesWithoutFixedPoint
Provides a list of all fixed-width element types except for the fixed-point types for use in GTest ty...
Definition: type_lists.hpp:320
cudf::test::Types< duration_D, duration_s, duration_ms, duration_us, duration_ns > DurationTypes
Provides a list of all duration types supported in libcudf for use in a GTest typed test.
Definition: type_lists.hpp:244
constexpr auto types_to_ids()
Converts a Types list of types into a std::array of the corresponding cudf::type_ids for each type in...
Definition: type_lists.hpp:67
cudf::test::Types< list_view > ListTypes
Provides a list of all list types supported in libcudf for use in a GTest typed test.
Definition: type_lists.hpp:279
Type declarations for libcudf.