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