type_lists.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-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 
21 #include <cudf/types.hpp>
27 
28 #include <thrust/host_vector.h>
29 
30 #include <array>
31 #include <tuple>
32 #include <type_traits>
33 
42 namespace cudf {
43 namespace test {
44 namespace detail {
45 template <typename TYPES, std::size_t... Indices>
46 constexpr std::array<cudf::type_id, sizeof...(Indices)> types_to_ids_impl(
47  std::index_sequence<Indices...>)
48 {
49  return {{cudf::type_to_id<GetType<TYPES, Indices>>()...}};
50 }
51 
65 template <typename TYPES>
66 constexpr auto types_to_ids()
67 {
68  constexpr auto N = GetSize<TYPES>;
69  return types_to_ids_impl<TYPES>(std::make_index_sequence<N>());
70 }
71 
72 } // namespace detail
73 
82 template <typename TypeParam, typename T>
83 std::enable_if_t<cudf::is_fixed_width<TypeParam>() && !cudf::is_timestamp_t<TypeParam>::value,
84  thrust::host_vector<TypeParam>>
85 make_type_param_vector(std::initializer_list<T> const& init_list)
86 {
87  std::vector<T> input{init_list};
88  std::vector<TypeParam> vec(init_list.size());
90  std::cbegin(input), std::cend(input), std::begin(vec), [](auto const& e) -> TypeParam {
91  if constexpr (std::is_unsigned_v<TypeParam>) { return static_cast<TypeParam>(std::abs(e)); }
92  return static_cast<TypeParam>(e);
93  });
94  return vec;
95 }
96 
103 template <typename TypeParam, typename T>
104 std::enable_if_t<cudf::is_timestamp_t<TypeParam>::value, thrust::host_vector<TypeParam>>
105 make_type_param_vector(std::initializer_list<T> const& init_list)
106 {
107  thrust::host_vector<TypeParam> vec(init_list.size());
108  std::transform(std::cbegin(init_list), std::cend(init_list), std::begin(vec), [](auto const& e) {
109  return TypeParam{typename TypeParam::duration{e}};
110  });
111  return vec;
112 }
113 
121 template <typename TypeParam, typename T>
122 std::enable_if_t<std::is_same_v<TypeParam, std::string>, thrust::host_vector<std::string>>
123 make_type_param_vector(std::initializer_list<T> const& init_list)
124 {
125  thrust::host_vector<std::string> vec(init_list.size());
126  std::transform(std::cbegin(init_list), std::cend(init_list), std::begin(vec), [](auto const& e) {
127  return std::to_string(e);
128  });
129  return vec;
130 }
131 
143 template <typename TypeParam, typename T>
144 std::enable_if_t<cudf::is_fixed_width<TypeParam>() && !cudf::is_timestamp_t<TypeParam>::value,
145  TypeParam>
146 make_type_param_scalar(T const init_value)
147 {
148  return static_cast<TypeParam>(init_value);
149 }
150 
162 template <typename TypeParam, typename T>
163 std::enable_if_t<cudf::is_timestamp_t<TypeParam>::value, TypeParam> make_type_param_scalar(
164  T const init_value)
165 {
166  return TypeParam{typename TypeParam::duration(init_value)};
167 }
168 
177 template <typename TypeParam, typename T>
178 std::enable_if_t<std::is_same_v<TypeParam, std::string>, TypeParam> make_type_param_scalar(
179  T const init_value)
180 {
181  return std::to_string(init_value);
182 }
183 
188  cudf::test::Types<int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t>;
189 
194 
205 using FloatingPointTypes = cudf::test::Types<float, double>;
206 
218 
230  cudf::test::Types<timestamp_D, timestamp_s, timestamp_ms, timestamp_us, timestamp_ns>;
231 
243  cudf::test::Types<duration_D, duration_s, duration_ms, duration_us, duration_ns>;
244 
255 
266 using StringTypes = cudf::test::Types<string_view>;
267 
278 using ListTypes = cudf::test::Types<list_view>;
279 
291  cudf::test::Types<numeric::decimal32, numeric::decimal64, numeric::decimal128>;
292 
304 
320 
332 
343 
354  cudf::test::Types<cudf::string_view, cudf::dictionary32, cudf::list_view, cudf::struct_view>;
355 
370 
377 static constexpr auto all_type_ids{detail::types_to_ids<AllTypes>()};
378 
385 static constexpr auto numeric_type_ids{detail::types_to_ids<NumericTypes>()};
386 
393 static constexpr std::array<cudf::type_id, 5> timestamp_type_ids{
394  detail::types_to_ids<TimestampTypes>()};
395 
402 static constexpr std::array<cudf::type_id, 5> duration_type_ids{
403  detail::types_to_ids<DurationTypes>()};
404 
411 static constexpr std::array<cudf::type_id, 12> non_numeric_type_ids{
424 
431 static constexpr std::array<cudf::type_id, 2> non_fixed_width_type_ids{cudf::type_id::EMPTY,
433 
434 } // namespace test
435 } // 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:187
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:331
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:85
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:188
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:354
Concat< IntegralTypesNotBool, cudf::test::Types< bool > > IntegralTypes
Type list for all integral types.
Definition: type_lists.hpp:193
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:205
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:230
Concat< NumericTypes, ChronoTypes, FixedPointTypes > FixedWidthTypes
Provides a list of all fixed-width element types for use in GTest typed tests.
Definition: type_lists.hpp:303
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:217
Concat< NumericTypes, ChronoTypes, StringTypes > ComparableTypes
Provides a list of sortable types for use in GTest typed tests.
Definition: type_lists.hpp:342
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:369
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:254
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:146
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:266
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:291
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:319
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:243
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:66
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:278
Type declarations for libcudf.