copying.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
10 #include <cudf/scalar/scalar.hpp>
13 #include <cudf/table/table.hpp>
14 #include <cudf/types.hpp>
15 #include <cudf/utilities/export.hpp>
17 
18 #include <memory>
19 #include <span>
20 #include <vector>
21 
27 namespace CUDF_EXPORT cudf {
28 
37 enum class out_of_bounds_policy : bool {
38  NULLIFY,
39  DONT_CHECK
40 };
41 
45 enum class negative_index_policy : bool {
46  ALLOWED,
48 };
49 
81 std::unique_ptr<table> gather(table_view const& source_table,
82  column_view const& gather_map,
83  out_of_bounds_policy bounds_policy = out_of_bounds_policy::DONT_CHECK,
84  cuda::stream_ref stream = cudf::get_default_stream(),
86 
117 std::unique_ptr<table> gather(table_view const& source_table,
118  column_view const& gather_map,
119  out_of_bounds_policy bounds_policy,
120  negative_index_policy neg_indices,
121  cuda::stream_ref stream = cudf::get_default_stream(),
123 
139 std::unique_ptr<table> reverse(
140  table_view const& source_table,
141  cuda::stream_ref stream = cudf::get_default_stream(),
143 
159 std::unique_ptr<column> reverse(
160  column_view const& source_column,
161  cuda::stream_ref stream = cudf::get_default_stream(),
163 
206 std::unique_ptr<table> scatter(
207  table_view const& source,
208  column_view const& scatter_map,
209  table_view const& target,
210  cuda::stream_ref stream = cudf::get_default_stream(),
212 
249 std::unique_ptr<table> scatter(
250  std::vector<std::reference_wrapper<scalar const>> const& source,
251  column_view const& indices,
252  table_view const& target,
253  cuda::stream_ref stream = cudf::get_default_stream(),
255 
259 enum class mask_allocation_policy : int32_t {
260  NEVER,
261  RETAIN,
262  ALWAYS
263 };
264 
271 std::unique_ptr<column> empty_like(column_view const& input);
272 
279 std::unique_ptr<column> empty_like(scalar const& input);
280 
298 std::unique_ptr<column> allocate_like(
299  column_view const& input,
300  mask_allocation_policy mask_alloc = mask_allocation_policy::RETAIN,
301  cuda::stream_ref stream = cudf::get_default_stream(),
303 
320 std::unique_ptr<column> allocate_like(
321  column_view const& input,
322  size_type size,
323  mask_allocation_policy mask_alloc = mask_allocation_policy::RETAIN,
324  cuda::stream_ref stream = cudf::get_default_stream(),
326 
337 std::unique_ptr<table> empty_like(table_view const& input_table);
338 
371 void copy_range_in_place(column_view const& source,
372  mutable_column_view& target,
373  size_type source_begin,
374  size_type source_end,
375  size_type target_begin,
376  cuda::stream_ref stream = cudf::get_default_stream());
377 
410 std::unique_ptr<column> copy_range(
411  column_view const& source,
412  column_view const& target,
413  size_type source_begin,
414  size_type source_end,
415  size_type target_begin,
416  cuda::stream_ref stream = cudf::get_default_stream(),
418 
456 std::unique_ptr<column> shift(
457  column_view const& input,
458  size_type offset,
459  scalar const& fill_value,
460  cuda::stream_ref stream = cudf::get_default_stream(),
462 
494 std::vector<column_view> slice(column_view const& input,
495  std::span<size_type const> indices,
496  cuda::stream_ref stream = cudf::get_default_stream());
501 std::vector<column_view> slice(column_view const& input,
502  std::initializer_list<size_type> indices,
503  cuda::stream_ref stream = cudf::get_default_stream());
504 
538 std::vector<table_view> slice(table_view const& input,
539  std::span<size_type const> indices,
540  cuda::stream_ref stream = cudf::get_default_stream());
545 std::vector<table_view> slice(table_view const& input,
546  std::initializer_list<size_type> indices,
547  cuda::stream_ref stream = cudf::get_default_stream());
548 
582 std::vector<column_view> split(column_view const& input,
583  std::span<size_type const> splits,
584  cuda::stream_ref stream = cudf::get_default_stream());
589 std::vector<column_view> split(column_view const& input,
590  std::initializer_list<size_type> splits,
591  cuda::stream_ref stream = cudf::get_default_stream());
592 
628 std::vector<table_view> split(table_view const& input,
629  std::span<size_type const> splits,
630  cuda::stream_ref stream = cudf::get_default_stream());
635 std::vector<table_view> split(table_view const& input,
636  std::initializer_list<size_type> splits,
637  cuda::stream_ref stream = cudf::get_default_stream());
638 
659 std::unique_ptr<column> copy_if_else(
660  column_view const& lhs,
661  column_view const& rhs,
662  column_view const& boolean_mask,
663  cuda::stream_ref stream = cudf::get_default_stream(),
665 
685 std::unique_ptr<column> copy_if_else(
686  scalar const& lhs,
687  column_view const& rhs,
688  column_view const& boolean_mask,
689  cuda::stream_ref stream = cudf::get_default_stream(),
691 
711 std::unique_ptr<column> copy_if_else(
712  column_view const& lhs,
713  scalar const& rhs,
714  column_view const& boolean_mask,
715  cuda::stream_ref stream = cudf::get_default_stream(),
717 
735 std::unique_ptr<column> copy_if_else(
736  scalar const& lhs,
737  scalar const& rhs,
738  column_view const& boolean_mask,
739  cuda::stream_ref stream = cudf::get_default_stream(),
741 
779 std::unique_ptr<table> boolean_mask_scatter(
780  table_view const& input,
781  table_view const& target,
782  column_view const& boolean_mask,
783  cuda::stream_ref stream = cudf::get_default_stream(),
785 
818 std::unique_ptr<table> boolean_mask_scatter(
819  std::vector<std::reference_wrapper<scalar const>> const& input,
820  table_view const& target,
821  column_view const& boolean_mask,
822  cuda::stream_ref stream = cudf::get_default_stream(),
824 
839 std::unique_ptr<scalar> get_element(
840  column_view const& input,
841  size_type index,
842  cuda::stream_ref stream = cudf::get_default_stream(),
844 
848 enum class sample_with_replacement : bool {
849  FALSE,
850  TRUE
851 };
852 
882 std::unique_ptr<table> sample(
883  table_view const& input,
884  size_type const n,
885  sample_with_replacement replacement = sample_with_replacement::FALSE,
886  int64_t const seed = 0,
887  cuda::stream_ref stream = cudf::get_default_stream(),
889 
907 bool has_nonempty_nulls(column_view const& input,
908  cuda::stream_ref stream = cudf::get_default_stream());
909 
933 
1002 std::unique_ptr<column> purge_nonempty_nulls(
1003  column_view const& input,
1004  cuda::stream_ref stream = cudf::get_default_stream(),
1006 
1008 } // 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...
Non-owning references to the memory resources used by a cuDF operation.
A non-owning, mutable view of device data as a column of elements, some of which may be null as indic...
An owning class to represent a singular value.
Definition: scalar.hpp:42
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:206
column view class definitions
mask_allocation_policy
Indicates when to allocate a mask, based on an existing mask.
Definition: copying.hpp:259
std::unique_ptr< column > purge_nonempty_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())
Copy input into output while purging any non-empty null rows in the column or its descendants.
std::unique_ptr< column > copy_range(column_view const &source, column_view const &target, size_type source_begin, size_type source_end, size_type target_begin, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Copies a range of elements out-of-place from one column to another.
bool may_have_nonempty_nulls(column_view const &input)
Approximates if a column or its descendants may have non-empty null elements.
void copy_range_in_place(column_view const &source, mutable_column_view &target, size_type source_begin, size_type source_end, size_type target_begin, cuda::stream_ref stream=cudf::get_default_stream())
Copies a range of elements in-place from one column to another.
std::unique_ptr< column > allocate_like(column_view const &input, size_type size, mask_allocation_policy mask_alloc=mask_allocation_policy::RETAIN, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Creates an uninitialized new column of the specified size and same type as the input.
std::unique_ptr< table > sample(table_view const &input, size_type const n, sample_with_replacement replacement=sample_with_replacement::FALSE, int64_t const seed=0, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Gather n samples from given input randomly.
negative_index_policy
Policy to recognize negative indices as relative to the end of the source.
Definition: copying.hpp:45
std::unique_ptr< column > reverse(column_view const &source_column, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Reverses the elements of a column.
std::unique_ptr< column > copy_if_else(scalar const &lhs, scalar const &rhs, column_view const &boolean_mask, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Returns a new column, where each element is selected from either lhs or rhs based on the value of the...
out_of_bounds_policy
Policy to account for possible out-of-bounds indices.
Definition: copying.hpp:37
sample_with_replacement
Indicates whether a row can be sampled more than once.
Definition: copying.hpp:848
std::unique_ptr< scalar > get_element(column_view const &input, size_type index, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Get the element at specified index from a column.
std::unique_ptr< table > empty_like(table_view const &input_table)
Creates a table of empty columns with the same types as the input_table
bool has_nonempty_nulls(column_view const &input, cuda::stream_ref stream=cudf::get_default_stream())
Checks if a column or its descendants have non-empty null rows.
@ RETAIN
Allocate a null mask if the input contains one.
@ NOT_ALLOWED
Negative indices are not allowed and result in undefined behavior.
@ ALLOWED
Negative indices are allowed and result in wrapping behavior.
@ DONT_CHECK
No bounds checking is performed, better performance.
@ NULLIFY
Output values corresponding to out-of-bounds indices are null.
@ FALSE
A row can be sampled only once.
@ TRUE
A row can be sampled more than once.
std::unique_ptr< table > gather(table_view const &source_table, column_view const &gather_map, out_of_bounds_policy bounds_policy, negative_index_policy neg_indices, cuda::stream_ref stream=cudf::get_default_stream(), cudf::memory_resources mr=cudf::get_current_device_resource_ref())
Gathers the specified rows of a set of columns according to a gather map.
std::unique_ptr< table > scatter(std::vector< std::reference_wrapper< scalar const >> const &source, column_view const &indices, table_view const &target, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Scatters a row of scalar values into a copy of the target table according to a scatter map.
std::unique_ptr< table > boolean_mask_scatter(std::vector< std::reference_wrapper< scalar const >> const &input, table_view const &target, column_view const &boolean_mask, cuda::stream_ref stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=cudf::get_current_device_resource_ref())
Scatters scalar values to rows of the output corresponding to true values in a boolean mask.
std::unique_ptr< column > shift(column_view const &input, size_type offset, scalar const &fill_value, 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 shifting all values by an offset.
std::vector< table_view > slice(table_view const &input, std::initializer_list< size_type > indices, cuda::stream_ref stream=cudf::get_default_stream())
Slices a table_view into a set of table_views according to a set of indices.
std::vector< table_view > split(table_view const &input, std::initializer_list< size_type > splits, cuda::stream_ref stream=cudf::get_default_stream())
Splits a table_view into a set of table_views according to a set of indices derived from expected spl...
cuda::stream_ref const get_default_stream()
Get the current default stream.
@ ALWAYS
Use dictionary regardless of impact on compression.
Definition: types.hpp:217
@ NEVER
Never use dictionary encoding.
Definition: types.hpp:215
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
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:76
Class definition for cudf::lists_column_view.
APIs for getting and setting the current device memory resource.
cuDF interfaces
Definition: host_udf.hpp:27
Class definitions for cudf::scalar.
Class definition for cudf::strings_column_view.
Class definition for cudf::structs_column_view.
Class definition for cudf::table.
Type declarations for libcudf.