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 
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 };
143 
156 std::unique_ptr<cudf::column> unary_operation(
157  cudf::column_view const& input,
161 
173 std::unique_ptr<cudf::column> is_null(
174  cudf::column_view const& input,
177 
189 std::unique_ptr<cudf::column> is_valid(
190  cudf::column_view const& input,
193 
207 std::unique_ptr<column> cast(
208  column_view const& input,
209  data_type out_type,
212 
221 bool is_supported_cast(data_type from, data_type to) noexcept;
222 
236 std::unique_ptr<column> is_nan(
237  cudf::column_view const& input,
240 
255 std::unique_ptr<column> is_not_nan(
256  cudf::column_view const& input,
259  // end of group
261 } // 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.
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
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
unary_operator
Types of unary operations that can be performed on data.
Definition: unary.hpp:119
CUDF_HOST_DEVICE Floating convert_fixed_to_floating(Fixed fixed)
Convert a fixed-point value to floating point.
Definition: 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())
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: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())
Creates a column of type_id::BOOL8 elements where for every element in input true indicates the value...
bool is_supported_cast(data_type from, data_type to) noexcept
Check if a cast between two datatypes is supported.
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())
Creates a column of type_id::BOOL8 elements indicating the absence of NaN values in a column of float...
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())
Casts data from dtype specified in input to dtype specified in output.
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: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())
Performs unary op on all values in column.
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())
Creates a column of type_id::BOOL8 elements indicating the presence of NaN values in a column of floa...
#define CUDF_ENABLE_IF(...)
Convenience macro for SFINAE as an unnamed template parameter.
Definition: traits.hpp:48
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