libcudf  24.04.00
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 
27 #include <rmm/mr/device/per_device_resource.hpp>
28 
29 #include <memory>
30 #include <vector>
31 
32 namespace cudf {
33 
48 enum class out_of_bounds_policy : bool {
49  NULLIFY,
50  DONT_CHECK
51 };
52 
84 std::unique_ptr<table> gather(
85  table_view const& source_table,
86  column_view const& gather_map,
88  rmm::cuda_stream_view stream = cudf::get_default_stream(),
89  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
90 
106 std::unique_ptr<table> reverse(
107  table_view const& source_table,
108  rmm::cuda_stream_view stream = cudf::get_default_stream(),
109  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
110 
126 std::unique_ptr<column> reverse(
127  column_view const& source_column,
128  rmm::cuda_stream_view stream = cudf::get_default_stream(),
129  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
130 
173 std::unique_ptr<table> scatter(
174  table_view const& source,
175  column_view const& scatter_map,
176  table_view const& target,
177  rmm::cuda_stream_view stream = cudf::get_default_stream(),
178  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
179 
216 std::unique_ptr<table> scatter(
217  std::vector<std::reference_wrapper<scalar const>> const& source,
218  column_view const& indices,
219  table_view const& target,
220  rmm::cuda_stream_view stream = cudf::get_default_stream(),
221  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
222 
226 enum class mask_allocation_policy : int32_t {
227  NEVER,
228  RETAIN,
229  ALWAYS
230 };
231 
238 std::unique_ptr<column> empty_like(column_view const& input);
239 
246 std::unique_ptr<column> empty_like(scalar const& input);
247 
263 std::unique_ptr<column> allocate_like(
264  column_view const& input,
266  rmm::cuda_stream_view stream = cudf::get_default_stream(),
267  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
268 
285 std::unique_ptr<column> allocate_like(
286  column_view const& input,
287  size_type size,
289  rmm::cuda_stream_view stream = cudf::get_default_stream(),
290  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
291 
302 std::unique_ptr<table> empty_like(table_view const& input_table);
303 
336 void copy_range_in_place(column_view const& source,
337  mutable_column_view& target,
338  size_type source_begin,
339  size_type source_end,
340  size_type target_begin,
341  rmm::cuda_stream_view stream = cudf::get_default_stream());
342 
374 std::unique_ptr<column> copy_range(
375  column_view const& source,
376  column_view const& target,
377  size_type source_begin,
378  size_type source_end,
379  size_type target_begin,
380  rmm::cuda_stream_view stream = cudf::get_default_stream(),
381  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
382 
420 std::unique_ptr<column> shift(
421  column_view const& input,
422  size_type offset,
423  scalar const& fill_value,
424  rmm::cuda_stream_view stream = cudf::get_default_stream(),
425  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
426 
458 std::vector<column_view> slice(column_view const& input,
460  rmm::cuda_stream_view stream = cudf::get_default_stream());
465 std::vector<column_view> slice(column_view const& input,
466  std::initializer_list<size_type> indices,
467  rmm::cuda_stream_view stream = cudf::get_default_stream());
468 
502 std::vector<table_view> slice(table_view const& input,
504  rmm::cuda_stream_view stream = cudf::get_default_stream());
509 std::vector<table_view> slice(table_view const& input,
510  std::initializer_list<size_type> indices,
511  rmm::cuda_stream_view stream = cudf::get_default_stream());
512 
546 std::vector<column_view> split(column_view const& input,
548  rmm::cuda_stream_view stream = cudf::get_default_stream());
553 std::vector<column_view> split(column_view const& input,
554  std::initializer_list<size_type> splits,
555  rmm::cuda_stream_view stream = cudf::get_default_stream());
556 
592 std::vector<table_view> split(table_view const& input,
594  rmm::cuda_stream_view stream = cudf::get_default_stream());
599 std::vector<table_view> split(table_view const& input,
600  std::initializer_list<size_type> splits,
601  rmm::cuda_stream_view stream = cudf::get_default_stream());
602 
623 std::unique_ptr<column> copy_if_else(
624  column_view const& lhs,
625  column_view const& rhs,
626  column_view const& boolean_mask,
627  rmm::cuda_stream_view stream = cudf::get_default_stream(),
628  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
629 
649 std::unique_ptr<column> copy_if_else(
650  scalar const& lhs,
651  column_view const& rhs,
652  column_view const& boolean_mask,
653  rmm::cuda_stream_view stream = cudf::get_default_stream(),
654  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
655 
675 std::unique_ptr<column> copy_if_else(
676  column_view const& lhs,
677  scalar const& rhs,
678  column_view const& boolean_mask,
679  rmm::cuda_stream_view stream = cudf::get_default_stream(),
680  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
681 
699 std::unique_ptr<column> copy_if_else(
700  scalar const& lhs,
701  scalar const& rhs,
702  column_view const& boolean_mask,
703  rmm::cuda_stream_view stream = cudf::get_default_stream(),
704  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
705 
743 std::unique_ptr<table> boolean_mask_scatter(
744  table_view const& input,
745  table_view const& target,
746  column_view const& boolean_mask,
747  rmm::cuda_stream_view stream = cudf::get_default_stream(),
748  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
749 
782 std::unique_ptr<table> boolean_mask_scatter(
783  std::vector<std::reference_wrapper<scalar const>> const& input,
784  table_view const& target,
785  column_view const& boolean_mask,
786  rmm::cuda_stream_view stream = cudf::get_default_stream(),
787  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
788 
803 std::unique_ptr<scalar> get_element(
804  column_view const& input,
805  size_type index,
806  rmm::cuda_stream_view stream = cudf::get_default_stream(),
807  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
808 
812 enum class sample_with_replacement : bool {
813  FALSE,
814  TRUE
815 };
816 
845 std::unique_ptr<table> sample(
846  table_view const& input,
847  size_type const n,
849  int64_t const seed = 0,
850  rmm::cuda_stream_view stream = cudf::get_default_stream(),
851  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
852 
870 bool has_nonempty_nulls(column_view const& input,
871  rmm::cuda_stream_view stream = cudf::get_default_stream());
872 
896 
965 std::unique_ptr<column> purge_nonempty_nulls(
966  column_view const& input,
967  rmm::cuda_stream_view stream = cudf::get_default_stream(),
968  rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
969 
971 } // namespace 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:48
A set of cudf::column_view's of the same size.
Definition: table_view.hpp:187
column view class definitions
std::unique_ptr< column > empty_like(column_view const &input)
Initializes and returns an empty column of the same type as the input.
mask_allocation_policy
Indicates when to allocate a mask, based on an existing mask.
Definition: copying.hpp:226
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::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Gather n samples from given input randomly.
std::unique_ptr< scalar > get_element(column_view const &input, size_type index, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Get the element at specified index from a column.
std::unique_ptr< column > copy_if_else(column_view const &lhs, column_view const &rhs, column_view const &boolean_mask, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::mr::device_memory_resource *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...
std::unique_ptr< column > allocate_like(column_view const &input, mask_allocation_policy mask_alloc=mask_allocation_policy::RETAIN, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Creates an uninitialized new column of the same size and type as the input.
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 > purge_nonempty_nulls(column_view const &input, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
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, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Copies a range of elements out-of-place from one column to another.
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< table > reverse(table_view const &source_table, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Reverses the rows within a table.
out_of_bounds_policy
Policy to account for possible out-of-bounds indices.
Definition: copying.hpp:48
sample_with_replacement
Indicates whether a row can be sampled more than once.
Definition: copying.hpp:812
@ NEVER
Do not allocate a null mask, regardless of input.
@ RETAIN
Allocate a null mask if the input contains one.
@ ALWAYS
Allocate a null mask, regardless of input.
@ 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::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Gathers the specified rows (including null values) of a set of columns.
std::unique_ptr< table > scatter(table_view const &source, column_view const &scatter_map, table_view const &target, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Scatters the rows of the source table into a copy of the target table according to a scatter map.
std::unique_ptr< table > boolean_mask_scatter(table_view const &input, table_view const &target, column_view const &boolean_mask, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Scatters rows from the input table to rows of the output corresponding to true values in a boolean ma...
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::mr::device_memory_resource *mr=rmm::mr::get_current_device_resource())
Creates a new column by shifting all values by an offset.
std::vector< column_view > slice(column_view const &input, host_span< size_type const > indices, rmm::cuda_stream_view stream=cudf::get_default_stream())
Slices a column_view into a set of column_views according to a set of indices.
std::vector< column_view > split(column_view const &input, host_span< size_type const > splits, rmm::cuda_stream_view stream=cudf::get_default_stream())
Splits a column_view into a set of column_views according to a set of indices derived from expected s...
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
int32_t size_type
Row index type for columns and tables.
Definition: types.hpp:93
Class definition for cudf::lists_column_view.
cuDF interfaces
Definition: aggregation.hpp:34
Class definitions for cudf::scalar.
Class definition for cudf::strings_column_view.
C++20 std::span with reduced feature set.
Definition: span.hpp:224
Class definition for cudf::structs_column_view.
Class definition for cudf::table.
Type declarations for libcudf.