type_lists.hpp
1 /*
2  * Copyright (c) 2019-2021, 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 <array>
29 #include <tuple>
30 
39 namespace cudf {
40 namespace test {
41 namespace detail {
42 template <typename TYPES, std::size_t... Indices>
43 constexpr std::array<cudf::type_id, sizeof...(Indices)> types_to_ids_impl(
44  std::index_sequence<Indices...>)
45 {
46  return {{cudf::type_to_id<GetType<TYPES, Indices>>()...}};
47 }
48 
62 template <typename TYPES>
63 constexpr auto types_to_ids()
64 {
65  constexpr auto N = GetSize<TYPES>;
66  return types_to_ids_impl<TYPES>(std::make_index_sequence<N>());
67 }
68 
69 } // namespace detail
70 
79 template <typename TypeParam, typename T>
80 typename std::enable_if<cudf::is_fixed_width<TypeParam>() &&
81  !cudf::is_timestamp_t<TypeParam>::value,
82  std::vector<TypeParam>>::type
83 make_type_param_vector(std::initializer_list<T> const& init_list)
84 {
85  std::vector<TypeParam> vec(init_list.size());
86  std::transform(std::cbegin(init_list), std::cend(init_list), std::begin(vec), [](auto const& e) {
87  if (std::is_unsigned<TypeParam>::value)
88  return static_cast<TypeParam>(std::abs(e));
89  else
90  return static_cast<TypeParam>(e);
91  });
92  return vec;
93 }
94 
95 template <typename TypeParam, typename T>
96 typename std::enable_if<cudf::is_timestamp_t<TypeParam>::value, std::vector<TypeParam>>::type
97 make_type_param_vector(std::initializer_list<T> const& init_list)
98 {
99  std::vector<TypeParam> vec(init_list.size());
100  std::transform(std::cbegin(init_list), std::cend(init_list), std::begin(vec), [](auto const& e) {
101  return TypeParam{typename TypeParam::duration{e}};
102  });
103  return vec;
104 }
105 
117 template <typename TypeParam, typename T>
118 std::enable_if_t<cudf::is_fixed_width<TypeParam>() && !cudf::is_timestamp_t<TypeParam>::value,
119  TypeParam>
120 make_type_param_scalar(T const init_value)
121 {
122  return static_cast<TypeParam>(init_value);
123 }
124 
125 template <typename TypeParam, typename T>
126 std::enable_if_t<cudf::is_timestamp_t<TypeParam>::value, TypeParam> make_type_param_scalar(
127  T const init_value)
128 {
129  return TypeParam{typename TypeParam::duration(init_value)};
130 }
131 
135 using IntegralTypesNotBool =
136  cudf::test::Types<int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t>;
137 
141 using IntegralTypes = Concat<IntegralTypesNotBool, cudf::test::Types<bool>>;
142 
153 using FloatingPointTypes = cudf::test::Types<float, double>;
154 
165 using NumericTypes = Concat<IntegralTypes, FloatingPointTypes>;
166 
177 using TimestampTypes =
178  cudf::test::Types<timestamp_D, timestamp_s, timestamp_ms, timestamp_us, timestamp_ns>;
179 
190 using DurationTypes =
191  cudf::test::Types<duration_D, duration_s, duration_ms, duration_us, duration_ns>;
192 
202 using ChronoTypes = Concat<TimestampTypes, DurationTypes>;
203 
214 using StringTypes = cudf::test::Types<string_view>;
215 
226 using ListTypes = cudf::test::Types<list_view>;
227 
238 using FixedPointTypes = cudf::test::Types<numeric::decimal32, numeric::decimal64>;
239 
250 using FixedWidthTypes = Concat<NumericTypes, ChronoTypes, FixedPointTypes>;
251 
264 using FixedWidthTypesWithoutFixedPoint = Concat<NumericTypes, ChronoTypes>;
265 
275 using ComparableTypes = Concat<NumericTypes, ChronoTypes, StringTypes>;
276 
290 using AllTypes = Concat<NumericTypes, ChronoTypes>;
291 
298 static constexpr auto all_type_ids{detail::types_to_ids<AllTypes>()};
299 
306 static constexpr auto numeric_type_ids{detail::types_to_ids<NumericTypes>()};
307 
314 static constexpr std::array<cudf::type_id, 5> timestamp_type_ids{
315  detail::types_to_ids<TimestampTypes>()};
316 
323 static constexpr std::array<cudf::type_id, 5> duration_type_ids{
324  detail::types_to_ids<DurationTypes>()};
325 
332 static constexpr std::array<cudf::type_id, 12> non_numeric_type_ids{
333  cudf::type_id::EMPTY,
334  cudf::type_id::TIMESTAMP_DAYS,
335  cudf::type_id::TIMESTAMP_SECONDS,
336  cudf::type_id::TIMESTAMP_MILLISECONDS,
337  cudf::type_id::TIMESTAMP_MICROSECONDS,
338  cudf::type_id::TIMESTAMP_NANOSECONDS,
339  cudf::type_id::DURATION_DAYS,
340  cudf::type_id::DURATION_SECONDS,
341  cudf::type_id::DURATION_MILLISECONDS,
342  cudf::type_id::DURATION_MICROSECONDS,
343  cudf::type_id::DURATION_NANOSECONDS,
344  cudf::type_id::STRING};
345 
352 static constexpr std::array<cudf::type_id, 2> non_fixed_width_type_ids{cudf::type_id::EMPTY,
353  cudf::type_id::STRING};
354 
355 } // namespace test
356 } // namespace cudf
fixed_point.hpp
Class definition for fixed point data type.
type_list_utilities.hpp
Utilities for creating type lists for typed tests in Google Test.
durations.hpp
Concrete type definitions for int32_t and int64_t durations in varying resolutions.
string_view.hpp
Class definition for cudf::string_view.
cudf::type_id
type_id
Identifies a column's logical element type.
Definition: types.hpp:196
types.hpp
Type declarations for libcudf.
cudf::transform
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.
cudf
cuDF interfaces
Definition: aggregation.hpp:34
timestamps.hpp
Concrete type definitions for int32_t and int64_t timestamps in varying resolutions as durations sinc...
type_dispatcher.hpp
Defines the mapping between cudf::type_id runtime type information and concrete C++ types.
traits.hpp