temporary.hpp
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <cudf/types.hpp>
9 
10 #include <cuda/std/limits>
11 #include <cuda/std/type_traits>
12 
13 #include <algorithm>
14 #include <string>
15 
16 namespace CUDF_EXPORT numeric {
17 namespace detail {
18 
19 template <typename T>
20 auto to_string(T value) -> std::string
21 {
22  if constexpr (cuda::std::is_same_v<T, __int128_t>) {
23  auto s = std::string{};
24  auto const sign = value < 0;
25  if (sign) {
26  value += 1; // avoid overflowing if value == _int128_t lowest
27  value *= -1;
28  if (value == cuda::std::numeric_limits<__int128_t>::max())
29  return "-170141183460469231731687303715884105728";
30  value += 1; // can add back the one, no need to avoid overflow anymore
31  }
32  do {
33  s.push_back("0123456789"[value % 10]);
34  value /= 10;
35  } while (value);
36  if (sign) s.push_back('-');
37  std::reverse(s.begin(), s.end());
38  return s;
39  } else {
40  return std::to_string(value);
41  }
42  return std::string{}; // won't ever hit here, need to suppress warning though
43 }
44 
45 template <typename T>
46 CUDF_HOST_DEVICE constexpr auto abs(T value)
47 {
48  return value >= 0 ? value : -value;
49 }
50 
51 template <typename T>
52 CUDF_HOST_DEVICE inline auto min(T lhs, T rhs)
53 {
54  return lhs < rhs ? lhs : rhs;
55 }
56 
57 template <typename T>
58 CUDF_HOST_DEVICE inline auto max(T lhs, T rhs)
59 {
60  return lhs > rhs ? lhs : rhs;
61 }
62 
63 template <typename BaseType>
64 CUDF_HOST_DEVICE constexpr auto exp10(int32_t exponent)
65 {
66  BaseType value = 1;
67  while (exponent > 0)
68  value *= 10, --exponent;
69  return value;
70 }
71 
72 } // namespace detail
73 } // 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:23
Type declarations for libcudf.
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.
Definition: types.hpp:21