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 
20 #include <cudf/types.hpp>
23 
24 #include <rmm/mr/device/per_device_resource.hpp>
25 #include <rmm/resource_ref.hpp>
26 
27 #include <memory>
28 
29 namespace cudf {
51 template <typename Fixed,
52  typename Floating,
53  typename cuda::std::enable_if_t<is_fixed_point<Fixed>() &&
54  cuda::std::is_floating_point_v<Floating>>* = nullptr>
56 {
57  using Rep = typename Fixed::rep;
58  auto const shifted = numeric::detail::shift<Rep, Fixed::rad>(floating, scale);
59  numeric::scaled_integer<Rep> scaled{static_cast<Rep>(shifted), scale};
60  return Fixed(scaled);
61 }
62 
76 template <typename Floating,
77  typename Fixed,
78  typename cuda::std::enable_if_t<cuda::std::is_floating_point_v<Floating> &&
79  is_fixed_point<Fixed>()>* = nullptr>
81 {
82  using Rep = typename Fixed::rep;
83  auto const casted = static_cast<Floating>(fixed.value());
84  auto const scale = numeric::scale_type{-fixed.scale()};
85  return numeric::detail::shift<Rep, Fixed::rad>(casted, scale);
86 }
87 
96 template <typename Floating,
97  typename Input,
98  typename cuda::std::enable_if_t<cuda::std::is_floating_point_v<Floating>>* = nullptr>
100 {
101  if constexpr (is_fixed_point<Input>()) {
102  return convert_fixed_to_floating<Floating>(input);
103  } else {
104  return static_cast<Floating>(input);
105  }
106 }
107 
111 enum class unary_operator : int32_t {
112  SIN,
113  COS,
114  TAN,
115  ARCSIN,
116  ARCCOS,
117  ARCTAN,
118  SINH,
119  COSH,
120  TANH,
121  ARCSINH,
122  ARCCOSH,
123  ARCTANH,
124  EXP,
125  LOG,
126  SQRT,
127  CBRT,
128  CEIL,
129  FLOOR,
130  ABS,
131  RINT,
132  BIT_INVERT,
133  NOT,
134 };
135 
148 std::unique_ptr<cudf::column> unary_operation(
149  cudf::column_view const& input,
151  rmm::cuda_stream_view stream = cudf::get_default_stream(),
152  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
153 
165 std::unique_ptr<cudf::column> is_null(
166  cudf::column_view const& input,
167  rmm::cuda_stream_view stream = cudf::get_default_stream(),
168  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
169 
181 std::unique_ptr<cudf::column> is_valid(
182  cudf::column_view const& input,
183  rmm::cuda_stream_view stream = cudf::get_default_stream(),
184  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
185 
199 std::unique_ptr<column> cast(
200  column_view const& input,
201  data_type out_type,
202  rmm::cuda_stream_view stream = cudf::get_default_stream(),
203  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
204 
218 std::unique_ptr<column> is_nan(
219  cudf::column_view const& input,
220  rmm::cuda_stream_view stream = cudf::get_default_stream(),
221  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
222 
237 std::unique_ptr<column> is_not_nan(
238  cudf::column_view const& input,
239  rmm::cuda_stream_view stream = cudf::get_default_stream(),
240  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
241  // end of group
243 } // namespace 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:241
Class definition for fixed point data type.
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
unary_operator
Types of unary operations that can be performed on data.
Definition: unary.hpp:111
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:80
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:99
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:55
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...
@ NOT
Logical Not (!)
@ TANH
Hyperbolic tangent.
@ CBRT
Cube-root (x^(1.0/3))
@ ARCSINH
Hyperbolic sine inverse.
@ SQRT
Square-root (x^0.5)
@ LOG
Natural Logarithm (base e)
@ FLOOR
largest integer value not greater than arg
@ ARCTAN
Trigonometric tangent inverse.
@ SIN
Trigonometric sine.
@ CEIL
Smallest integer value not less than arg.
@ ARCSIN
Trigonometric sine inverse.
@ RINT
Rounds the floating-point argument arg to an integer value.
@ BIT_INVERT
Bitwise Not (~)
@ TAN
Trigonometric tangent.
@ ARCCOS
Trigonometric cosine inverse.
@ ABS
Absolute value.
@ ARCTANH
Hyperbolic tangent inverse.
@ EXP
Exponential (base e, Euler number)
@ SINH
Hyperbolic sine.
@ COSH
Hyperbolic cosine.
@ ARCCOSH
Hyperbolic cosine inverse.
@ COS
Trigonometric cosine.
cuDF interfaces
Definition: aggregation.hpp:34
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