libcudf  24.02.00
temporary.hpp
1 /*
2  * Copyright (c) 2021-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 // To avoid https://github.com/NVIDIA/libcudacxx/issues/460
19 // in libcudacxx with CTK 12.0/12.1
20 #include <cuda_runtime.h>
21 
22 #include <cudf/types.hpp>
23 
24 #include <cuda/std/limits>
25 #include <cuda/std/type_traits>
26 
27 #include <algorithm>
28 #include <string>
29 
30 namespace numeric {
31 namespace detail {
32 
33 template <typename T>
34 auto to_string(T value) -> std::string
35 {
36  if constexpr (cuda::std::is_same_v<T, __int128_t>) {
37  auto s = std::string{};
38  auto const sign = value < 0;
39  if (sign) {
40  value += 1; // avoid overflowing if value == _int128_t lowest
41  value *= -1;
42  if (value == cuda::std::numeric_limits<__int128_t>::max())
43  return "-170141183460469231731687303715884105728";
44  value += 1; // can add back the one, no need to avoid overflow anymore
45  }
46  while (value) {
47  s.push_back("0123456789"[value % 10]);
48  value /= 10;
49  }
50  if (sign) s.push_back('-');
51  std::reverse(s.begin(), s.end());
52  return s;
53  } else {
54  return std::to_string(value);
55  }
56  return std::string{}; // won't ever hit here, need to suppress warning though
57 }
58 
59 template <typename T>
60 constexpr auto abs(T value)
61 {
62  return value >= 0 ? value : -value;
63 }
64 
65 template <typename T>
66 CUDF_HOST_DEVICE inline auto min(T lhs, T rhs)
67 {
68  return lhs < rhs ? lhs : rhs;
69 }
70 
71 template <typename T>
72 CUDF_HOST_DEVICE inline auto max(T lhs, T rhs)
73 {
74  return lhs > rhs ? lhs : rhs;
75 }
76 
77 template <typename BaseType>
78 constexpr auto exp10(int32_t exponent)
79 {
80  BaseType value = 1;
81  while (exponent > 0)
82  value *= 10, --exponent;
83  return value;
84 }
85 
86 } // namespace detail
87 } // namespace numeric
std::unique_ptr< table > reverse(table_view const &source_table, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Reverses the rows within a table.
fixed_point and supporting types
Definition: fixed_point.hpp:32
Type declarations for libcudf.
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.
Definition: types.hpp:32