copying.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/scalar/scalar.hpp>
24 #include <cudf/table/table.hpp>
25 #include <cudf/types.hpp>
26 #include <cudf/utilities/export.hpp>
27 
29 #include <rmm/resource_ref.hpp>
30 
31 #include <memory>
32 #include <vector>
33 
34 namespace CUDF_EXPORT cudf {
35 
50 enum class out_of_bounds_policy : bool {
51  NULLIFY,
52  DONT_CHECK
53 };
54 
86 std::unique_ptr<table> gather(
87  table_view const& source_table,
88  column_view const& gather_map,
89  out_of_bounds_policy bounds_policy = out_of_bounds_policy::DONT_CHECK,
92 
108 std::unique_ptr<table> reverse(
109  table_view const& source_table,
112 
128 std::unique_ptr<column> reverse(
129  column_view const& source_column,
132 
175 std::unique_ptr<table> scatter(
176  table_view const& source,
177  column_view const& scatter_map,
178  table_view const& target,
181 
218 std::unique_ptr<table> scatter(
219  std::vector<std::reference_wrapper<scalar const>> const& source,
220  column_view const& indices,
221  table_view const& target,
224 
228 enum class mask_allocation_policy : int32_t {
229  NEVER,
230  RETAIN,
231  ALWAYS
232 };
233 
240 std::unique_ptr<column> empty_like(column_view const& input);
241 
248 std::unique_ptr<column> empty_like(scalar const& input);
249 
267 std::unique_ptr<column> allocate_like(
268  column_view const& input,
269  mask_allocation_policy mask_alloc = mask_allocation_policy::RETAIN,
272 
289 std::unique_ptr<column> allocate_like(
290  column_view const& input,
291  size_type size,
292  mask_allocation_policy mask_alloc = mask_allocation_policy::RETAIN,
295 
306 std::unique_ptr<table> empty_like(table_view const& input_table);
307 
340 void copy_range_in_place(column_view const& source,
341  mutable_column_view& target,
342  size_type source_begin,
343  size_type source_end,
344  size_type target_begin,
346 
379 std::unique_ptr<column> copy_range(
380  column_view const& source,
381  column_view const& target,
382  size_type source_begin,
383  size_type source_end,
384  size_type target_begin,
387 
425 std::unique_ptr<column> shift(
426  column_view const& input,
427  size_type offset,
428  scalar const& fill_value,
431 
463 std::vector<column_view> slice(column_view const& input,
470 std::vector<column_view> slice(column_view const& input,
471  std::initializer_list<size_type> indices,
473 
507 std::vector<table_view> slice(table_view const& input,
514 std::vector<table_view> slice(table_view const& input,
515  std::initializer_list<size_type> indices,
517 
551 std::vector<column_view> split(column_view const& input,
558 std::vector<column_view> split(column_view const& input,
559  std::initializer_list<size_type> splits,
561 
597 std::vector<table_view> split(table_view const& input,
604 std::vector<table_view> split(table_view const& input,
605  std::initializer_list<size_type> splits,
607 
628 std::unique_ptr<column> copy_if_else(
629  column_view const& lhs,
630  column_view const& rhs,
631  column_view const& boolean_mask,
634 
654 std::unique_ptr<column> copy_if_else(
655  scalar const& lhs,
656  column_view const& rhs,
657  column_view const& boolean_mask,
660 
680 std::unique_ptr<column> copy_if_else(
681  column_view const& lhs,
682  scalar const& rhs,
683  column_view const& boolean_mask,
686 
704 std::unique_ptr<column> copy_if_else(
705  scalar const& lhs,
706  scalar const& rhs,
707  column_view const& boolean_mask,
710 
748 std::unique_ptr<table> boolean_mask_scatter(
749  table_view const& input,
750  table_view const& target,
751  column_view const& boolean_mask,
754 
787 std::unique_ptr<table> boolean_mask_scatter(
788  std::vector<std::reference_wrapper<scalar const>> const& input,
789  table_view const& target,
790  column_view const& boolean_mask,
793 
808 std::unique_ptr<scalar> get_element(
809  column_view const& input,
810  size_type index,
813 
817 enum class sample_with_replacement : bool {
818  FALSE,
819  TRUE
820 };
821 
850 std::unique_ptr<table> sample(
851  table_view const& input,
852  size_type const n,
853  sample_with_replacement replacement = sample_with_replacement::FALSE,
854  int64_t const seed = 0,
857 
875 bool has_nonempty_nulls(column_view const& input,
877 
901 
970 std::unique_ptr<column> purge_nonempty_nulls(
971  column_view const& input,
974 
976 } // 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...
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:49
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:200
column view class definitions
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, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Gather n samples from given input randomly.
mask_allocation_policy
Indicates when to allocate a mask, based on an existing mask.
Definition: copying.hpp:228
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, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Copies a range of elements out-of-place from one column to another.
std::unique_ptr< column > purge_nonempty_nulls(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())
Copy input into output while purging any non-empty null rows in the column or its descendants.
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, rmm::cuda_stream_view 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, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Creates an uninitialized new column of the specified size and same type as the input.
std::unique_ptr< column > reverse(column_view const &source_column, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Reverses the elements of a column.
std::unique_ptr< scalar > get_element(column_view const &input, size_type index, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Get the element at specified index from a column.
bool has_nonempty_nulls(column_view const &input, rmm::cuda_stream_view stream=cudf::get_default_stream())
Checks if a column or its descendants have non-empty null rows.
std::unique_ptr< column > copy_if_else(scalar const &lhs, scalar const &rhs, column_view const &boolean_mask, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
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:50
sample_with_replacement
Indicates whether a row can be sampled more than once.
Definition: copying.hpp:817
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
@ RETAIN
Allocate a null mask if the input contains one.
@ 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=out_of_bounds_policy::DONT_CHECK, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Gathers the specified rows (including null values) of a set of columns.
std::unique_ptr< table > scatter(std::vector< std::reference_wrapper< scalar const >> const &source, column_view const &indices, table_view const &target, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
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, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
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, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
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, rmm::cuda_stream_view 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, rmm::cuda_stream_view 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...
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
@ ALWAYS
Use dictionary regardless of impact on compression.
Definition: io/types.hpp:228
@ NEVER
Never use dictionary encoding.
Definition: io/types.hpp:226
cuda::mr::async_resource_ref< cuda::mr::device_accessible > device_async_resource_ref
device_memory_resource * get_current_device_resource()
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:95
Class definition for cudf::lists_column_view.
cuDF interfaces
Definition: aggregation.hpp:35
Class definitions for cudf::scalar.
Class definition for cudf::strings_column_view.
C++20 std::span with reduced feature set.
Definition: span.hpp:231
Class definition for cudf::structs_column_view.
Class definition for cudf::table.
Type declarations for libcudf.