unary.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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 
21 #include <cudf/types.hpp>
23 #include <cudf/utilities/export.hpp>
25 
27 #include <rmm/resource_ref.hpp>
28 
29 #include <memory>
30 
31 namespace CUDF_EXPORT cudf {
53 template <typename Fixed,
54  typename Floating,
55  CUDF_ENABLE_IF(cuda::std::is_floating_point_v<Floating>&& is_fixed_point<Fixed>())>
57 {
58  using Rep = typename Fixed::rep;
59  auto const value = [&]() {
60  if constexpr (Fixed::rad == numeric::Radix::BASE_10) {
61  return numeric::detail::convert_floating_to_integral<Rep>(floating, scale);
62  } else {
63  return static_cast<Rep>(numeric::detail::shift<Rep, Fixed::rad>(floating, scale));
64  }
65  }();
66 
67  return Fixed(numeric::scaled_integer<Rep>{value, scale});
68 }
69 
83 template <typename Floating,
84  typename Fixed,
85  CUDF_ENABLE_IF(cuda::std::is_floating_point_v<Floating>&& is_fixed_point<Fixed>())>
87 {
88  using Rep = typename Fixed::rep;
89  if constexpr (Fixed::rad == numeric::Radix::BASE_10) {
90  return numeric::detail::convert_integral_to_floating<Floating>(fixed.value(), fixed.scale());
91  } else {
92  auto const casted = static_cast<Floating>(fixed.value());
93  auto const scale = numeric::scale_type{-fixed.scale()};
94  return numeric::detail::shift<Rep, Fixed::rad>(casted, scale);
95  }
96 }
97 
106 template <typename Floating,
107  typename Input,
108  CUDF_ENABLE_IF(cuda::std::is_floating_point_v<Floating>)>
110 {
111  if constexpr (is_fixed_point<Input>()) {
112  return convert_fixed_to_floating<Floating>(input);
113  } else {
114  return static_cast<Floating>(input);
115  }
116 }
117 
121 enum class unary_operator : int32_t {
122  SIN,
123  COS,
124  TAN,
125  ARCSIN,
126  ARCCOS,
127  ARCTAN,
128  SINH,
129  COSH,
130  TANH,
131  ARCSINH,
132  ARCCOSH,
133  ARCTANH,
134  EXP,
135  LOG,
136  SQRT,
137  CBRT,
138  CEIL,
139  FLOOR,
140  ABS,
141  RINT,
142  BIT_INVERT,
143  NOT,
144 };
145 
158 std::unique_ptr<cudf::column> unary_operation(
159  cudf::column_view const& input,
163 
175 std::unique_ptr<cudf::column> is_null(
176  cudf::column_view const& input,
179 
191 std::unique_ptr<cudf::column> is_valid(
192  cudf::column_view const& input,
195 
209 std::unique_ptr<column> cast(
210  column_view const& input,
211  data_type out_type,
214 
223 bool is_supported_cast(data_type from, data_type to) noexcept;
224 
238 std::unique_ptr<column> is_nan(
239  cudf::column_view const& input,
242 
257 std::unique_ptr<column> is_not_nan(
258  cudf::column_view const& input,
261  // end of group
263 } // namespace CUDF_EXPORT cudf
A non-owning, immutable view of device data as a column of elements, some of which may be null as ind...
Indicator for the logical data type of an element in a column.
Definition: types.hpp:243
Class definition for fixed point data type.
fixed_point <--> floating-point conversion functions.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
scale_type
The scale type for fixed_point.
Definition: fixed_point.hpp:43
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
device_memory_resource * get_current_device_resource()
unary_operator
Types of unary operations that can be performed on data.
Definition: unary.hpp:121
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=rmm::mr::get_current_device_resource())
Performs unary op on all values in column.
CUDF_HOST_DEVICE Floating convert_fixed_to_floating(Fixed fixed)
Convert a fixed-point value to floating point.
Definition: unary.hpp:86
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=rmm::mr::get_current_device_resource())
Creates a column of type_id::BOOL8 elements where for every element in input true indicates the value...
CUDF_HOST_DEVICE Floating convert_to_floating(Input input)
Convert a value to floating point.
Definition: unary.hpp:109
bool is_supported_cast(data_type from, data_type to) noexcept
Check if a cast between two datatypes is supported.
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=rmm::mr::get_current_device_resource())
Casts data from dtype specified in input to dtype specified in output.
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=rmm::mr::get_current_device_resource())
Creates a column of type_id::BOOL8 elements where for every element in input true indicates the value...
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=rmm::mr::get_current_device_resource())
Creates a column of type_id::BOOL8 elements indicating the presence of NaN values in a column of floa...
CUDF_HOST_DEVICE Fixed convert_floating_to_fixed(Floating floating, numeric::scale_type scale)
Convert a floating-point value to fixed point.
Definition: unary.hpp:56
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=rmm::mr::get_current_device_resource())
Creates a column of type_id::BOOL8 elements indicating the absence of NaN values in a column of float...
#define CUDF_ENABLE_IF(...)
Convenience macro for SFINAE as an unnamed template parameter.
Definition: traits.hpp:50
cuDF interfaces
Definition: aggregation.hpp:35
Helper struct for constructing fixed_point when value is already shifted.
Type declarations for libcudf.
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.
Definition: types.hpp:32