unary.hpp
前往此文件的文档。
1 /*
2  * Copyright (c) 2018-2025, 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  * https://apache.ac.cn/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/fixed_point/detail/floating_conversion.hpp>
21 #include <cudf/types.hpp>
23 #include <cudf/utilities/export.hpp>
26 
27 #include <memory>
28 
29 namespace CUDF_EXPORT cudf {
51 template <typename Fixed,
52  typename Floating,
53  CUDF_ENABLE_IF(cuda::std::is_floating_point_v<Floating>&& is_fixed_point<Fixed>())>
55 {
56  using Rep = typename Fixed::rep;
57  auto const value = [&]() {
58  if constexpr (Fixed::rad == numeric::Radix::BASE_10) {
59  return numeric::detail::convert_floating_to_integral<Rep>(floating, scale);
60  } else {
61  return static_cast<Rep>(numeric::detail::shift<Rep, Fixed::rad>(floating, scale));
62  }
63  }();
64 
65  return Fixed(numeric::scaled_integer<Rep>{value, scale});
66 }
67 
81 template <typename Floating,
82  typename Fixed,
83  CUDF_ENABLE_IF(cuda::std::is_floating_point_v<Floating>&& is_fixed_point<Fixed>())>
85 {
86  using Rep = typename Fixed::rep;
87  if constexpr (Fixed::rad == numeric::Radix::BASE_10) {
88  return numeric::detail::convert_integral_to_floating<Floating>(fixed.value(), fixed.scale());
89  } else {
90  auto const casted = static_cast<Floating>(fixed.value());
91  auto const scale = numeric::scale_type{-fixed.scale()};
92  return numeric::detail::shift<Rep, Fixed::rad>(casted, scale);
93  }
94 }
95 
104 template <typename Floating,
105  typename Input,
106  CUDF_ENABLE_IF(cuda::std::is_floating_point_v<Floating>)>
108 {
109  if constexpr (is_fixed_point<Input>()) {
110  return convert_fixed_to_floating<Floating>(input);
111  } else {
112  return static_cast<Floating>(input);
113  }
114 }
115 
119 enum class unary_operator : int32_t {
120  SIN,
121  COS,
122  TAN,
123  ARCSIN,
124  ARCCOS,
125  ARCTAN,
126  SINH,
127  COSH,
128  TANH,
129  ARCSINH,
130  ARCCOSH,
131  ARCTANH,
132  EXP,
133  LOG,
134  SQRT,
135  CBRT,
136  CEIL,
137  FLOOR,
138  ABS,
139  RINT,
140  BIT_INVERT,
141  NOT,
142  NEGATE,
143 };
144 
157 std::unique_ptr<cudf::column> unary_operation(
158  cudf::column_view const& input,
162 
174 std::unique_ptr<cudf::column> is_null(
175  cudf::column_view const& input,
178 
190 std::unique_ptr<cudf::column> is_valid(
191  cudf::column_view const& input,
194 
208 std::unique_ptr<column> cast(
209  column_view const& input,
210  data_type out_type,
213 
222 bool is_supported_cast(data_type from, data_type to) noexcept;
223 
237 std::unique_ptr<column> is_nan(
238  cudf::column_view const& input,
241 
256 std::unique_ptr<column> is_not_nan(
257  cudf::column_view const& input,
260  // end of group
262 } // namespace CUDF_EXPORT cudf
一个非拥有、不可变的设备数据视图,作为元素列,其中一些可能为空...
列中元素的逻辑数据类型指示符。
定义: types.hpp:243
定点数据类型的类定义。
rmm::cuda_stream_view const get_default_stream()
获取当前的默认流。
scale_type
fixed_point 的比例类型。
rmm::device_async_resource_ref get_current_device_resource_ref()
获取当前设备内存资源引用。
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
unary_operator
可以对数据执行的一元操作类型。
定义: unary.hpp:119
CUDF_HOST_DEVICE Floating convert_fixed_to_floating(Fixed fixed)
将定点值转换为浮点值。
定义: unary.hpp:84
std::unique_ptr< cudf::column > is_valid(cudf::column_view const &input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
创建一个 type_id::BOOL8 元素列,其中对于输入的每个元素,true 表示该值...
CUDF_HOST_DEVICE Floating convert_to_floating(Input input)
将值转换为浮点值。
定义: unary.hpp:107
std::unique_ptr< cudf::column > is_null(cudf::column_view const &input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
创建一个 type_id::BOOL8 元素列,其中对于输入的每个元素,true 表示该值...
bool is_supported_cast(data_type from, data_type to) noexcept
检查两个数据类型之间的转换是否受支持。
std::unique_ptr< column > is_not_nan(cudf::column_view const &input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
创建一个 type_id::BOOL8 元素列,指示浮点列中不存在 NaN 值...
std::unique_ptr< column > cast(column_view const &input, data_type out_type, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
将指定在输入中的数据类型转换为指定在输出中的数据类型。
CUDF_HOST_DEVICE Fixed convert_floating_to_fixed(Floating floating, numeric::scale_type scale)
将浮点值转换为定点值。
定义: unary.hpp:54
std::unique_ptr< cudf::column > unary_operation(cudf::column_view const &input, cudf::unary_operator op, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
对列中的所有值执行一元操作。
std::unique_ptr< column > is_nan(cudf::column_view const &input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
创建一个 type_id::BOOL8 元素列,指示浮点列中存在 NaN 值...
@ NEGATE
一元取负 (-),仅适用于带符号数值类型和 duration 类型。
#define CUDF_ENABLE_IF(...)
用于 SFINAE 作为无名模板参数的便利宏。
定义: traits.hpp:50
cuDF 接口
定义: host_udf.hpp:37
构造 fixed_point 的辅助结构,当值已移位时使用。
libcudf 的类型声明。
#define CUDF_HOST_DEVICE
指示函数或方法可在主机和设备上使用。
定义: types.hpp:32