transform.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
9 #include <cudf/column/scalar_column_view.hpp>
10 #include <cudf/types.hpp>
11 #include <cudf/utilities/export.hpp>
13 
14 #include <memory>
15 #include <optional>
16 #include <variant>
17 #include <vector>
18 
24 namespace CUDF_EXPORT cudf {
25 
35 using transform_input = std::variant<column_view, scalar_column_view>;
36 
43  data_type type = data_type{type_id::EMPTY};
44 
45  output_nullability nullability =
46  output_nullability::PRESERVE;
48 };
49 
68 [[deprecated("Use transform instead")]] std::unique_ptr<column> transform_extended(
69  std::span<transform_input const> inputs,
70  std::string const& udf,
71  data_type output_type,
72  udf_source_type source_type,
73  std::optional<void*> user_data = std::nullopt,
74  null_aware is_null_aware = null_aware::NO,
75  std::optional<size_type> row_size = std::nullopt,
76  output_nullability null_policy = output_nullability::PRESERVE,
77  cuda::stream_ref stream = cudf::get_default_stream(),
79 
121 std::unique_ptr<table> transform(
122  std::string const& udf,
123  udf_source_type source_type,
124  null_aware is_null_aware,
125  std::optional<void*> user_data,
126  std::span<transform_input const> inputs,
127  std::span<transform_output const> outputs,
128  std::vector<std::unique_ptr<column>>&& string_offsets,
129  std::optional<size_type> row_size,
130  cuda::stream_ref stream = cudf::get_default_stream(),
132 
151 [[deprecated("Use transform instead")]] std::unique_ptr<table> multi_transform(
152  std::string const& udf,
153  udf_source_type source_type,
154  null_aware is_null_aware,
155  std::optional<void*> user_data,
156  std::span<transform_input const> inputs,
157  std::span<transform_output const> outputs,
158  std::vector<std::unique_ptr<column>>&& string_offsets,
159  std::optional<size_type> row_size,
160  cuda::stream_ref stream = cudf::get_default_stream(),
162 
166 enum class lto_binary_type : uint8_t {
167  LTO_IR, //< LTO-IR binary
168  FATBIN //< FATBIN binary
169 };
170 
209 std::unique_ptr<table> transform_lto(
210  std::span<uint8_t const> udf,
211  lto_binary_type binary_type,
212  null_aware is_null_aware,
213  std::optional<void*> user_data,
214  std::span<transform_input const> inputs,
215  std::span<transform_output const> outputs,
216  std::vector<std::unique_ptr<column>>&& string_offsets,
217  std::optional<size_type> row_size,
218  cuda::stream_ref stream = cudf::get_default_stream(),
220 
235 [[deprecated]] std::pair<std::unique_ptr<rmm::device_buffer>, size_type> nans_to_nulls(
236  column_view const& input,
237  cuda::stream_ref stream = cudf::get_default_stream(),
239 
251 std::unique_ptr<column> column_nans_to_nulls(
252  column_view const& input,
253  cuda::stream_ref stream = cudf::get_default_stream(),
255 
274 std::unique_ptr<column> compute_column(
275  table_view const& table,
276  ast::expression const& expr,
277  cuda::stream_ref stream = cudf::get_default_stream(),
279 
299 std::unique_ptr<column> compute_column_jit(
300  table_view const& table,
301  ast::expression const& expr,
302  cuda::stream_ref stream = cudf::get_default_stream(),
304 
321 std::pair<std::unique_ptr<rmm::device_buffer>, cudf::size_type> bools_to_mask(
322  column_view const& input,
323  cuda::stream_ref stream = cudf::get_default_stream(),
325 
351 std::pair<std::unique_ptr<cudf::table>, std::unique_ptr<cudf::column>> encode(
352  cudf::table_view const& input,
353  cuda::stream_ref stream = cudf::get_default_stream(),
355 
384 std::pair<std::unique_ptr<column>, table_view> one_hot_encode(
385  column_view const& input,
386  column_view const& categories,
387  cuda::stream_ref stream = cudf::get_default_stream(),
389 
412 std::unique_ptr<column> mask_to_bools(
413  bitmask_type const* bitmask,
414  size_type begin_bit,
415  size_type end_bit,
416  cuda::stream_ref stream = cudf::get_default_stream(),
418 
445 std::unique_ptr<column> row_bit_count(
446  table_view const& t,
447  cuda::stream_ref stream = cudf::get_default_stream(),
449 
469 std::unique_ptr<column> segmented_row_bit_count(
470  table_view const& t,
471  size_type segment_length,
472  cuda::stream_ref stream = cudf::get_default_stream(),
474  // end of group
476 } // 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:279
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
A set of cudf::column's of the same size.
Definition: table.hpp:31
Class definitions for building and evaluating abstract syntax tree expressions.
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
rmm::device_async_resource_ref get_current_device_resource_ref()
Get the current device memory resource reference.
cuda::mr::resource_ref< cuda::mr::device_accessible > device_async_resource_ref
std::unique_ptr< table > multi_transform(std::string const &udf, udf_source_type source_type, null_aware is_null_aware, std::optional< void * > user_data, std::span< transform_input const > inputs, std::span< transform_output const > outputs, std::vector< std::unique_ptr< column >> &&string_offsets, std::optional< size_type > row_size, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new table by applying a transform function against every element of the input columns.
std::unique_ptr< column > row_bit_count(table_view const &t, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns an approximate cumulative size in bits of all columns in the table_view for each row.
std::unique_ptr< column > transform_extended(std::span< transform_input const > inputs, std::string const &udf, data_type output_type, udf_source_type source_type, std::optional< void * > user_data=std::nullopt, null_aware is_null_aware=null_aware::NO, std::optional< size_type > row_size=std::nullopt, output_nullability null_policy=output_nullability::PRESERVE, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new column by applying a transform function against every element of the input columns.
std::pair< std::unique_ptr< rmm::device_buffer >, size_type > nans_to_nulls(column_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a null_mask from input by converting NaN to null and preserving existing null values and also...
std::unique_ptr< table > transform_lto(std::span< uint8_t const > udf, lto_binary_type binary_type, null_aware is_null_aware, std::optional< void * > user_data, std::span< transform_input const > inputs, std::span< transform_output const > outputs, std::vector< std::unique_ptr< column >> &&string_offsets, std::optional< size_type > row_size, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new table by applying a transform function against every element of the input columns.
std::unique_ptr< table > transform(std::string const &udf, udf_source_type source_type, null_aware is_null_aware, std::optional< void * > user_data, std::span< transform_input const > inputs, std::span< transform_output const > outputs, std::vector< std::unique_ptr< column >> &&string_offsets, std::optional< size_type > row_size, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a new table by applying a transform function against every element of the input columns.
std::unique_ptr< column > column_nans_to_nulls(column_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a null_mask from input by converting NaN elements to null rows and preserving existing null v...
std::unique_ptr< column > segmented_row_bit_count(table_view const &t, size_type segment_length, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns an approximate cumulative size in bits of all columns in the table_view for each segment of r...
std::unique_ptr< column > compute_column_jit(table_view const &table, ast::expression const &expr, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Compute a new column by evaluating an expression tree on a table using a JIT-compiled kernel.
std::variant< column_view, scalar_column_view > transform_input
Typedef for inputs to the transform function. Each input can be either a column or a scalar column.
Definition: transform.hpp:35
std::pair< std::unique_ptr< column >, table_view > one_hot_encode(column_view const &input, column_view const &categories, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Encodes input by generating a new column for each value in categories indicating the presence of that...
std::unique_ptr< column > mask_to_bools(bitmask_type const *bitmask, size_type begin_bit, size_type end_bit, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a boolean column from given bitmask.
std::pair< std::unique_ptr< cudf::table >, std::unique_ptr< cudf::column > > encode(cudf::table_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Encode the rows of the given table as integers.
lto_binary_type
The type of LTO Binary.
Definition: transform.hpp:166
std::pair< std::unique_ptr< rmm::device_buffer >, cudf::size_type > bools_to_mask(column_view const &input, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates a bitmask from a column of boolean elements.
std::unique_ptr< column > compute_column(table_view const &table, ast::expression const &expr, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Compute a new column by evaluating an expression tree on a table.
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:76
null_policy
Enum to specify whether to include nulls or exclude nulls.
Definition: types.hpp:107
uint32_t bitmask_type
Bitmask type stored as 32-bit unsigned integer.
Definition: types.hpp:77
output_nullability
Indicates the null output policy of a function.
Definition: types.hpp:250
null_aware
A function is null-aware if its output value uses the input validity.
Definition: types.hpp:224
udf_source_type
Indicates the source language of a user defined function (UDF) to be used in JIT APIs.
Definition: types.hpp:268
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
A generic expression that can be evaluated to return a value.
Definition: expressions.hpp:69
Specification for the outputs of the transform function. This includes the output type and nullabilit...
Definition: transform.hpp:42
Type declarations for libcudf.