1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once
#include <cudf/copying.hpp>
#include <cudf/column/column.hpp>
#include <cudf/table/table.hpp>
#include <cudf/types.hpp>
#include <memory>
#include <vector>
#include "rust/cxx.h"
#include "column_shim.h"
#include "table_shim.h"
#include "scalar_shim.h"
namespace cudf_shims {
// ── Gather / Scatter ───────────────────────────────────────────
/// Gather rows from table by index column.
std::unique_ptr<OwnedTable> gather(
const OwnedTable& table,
const OwnedColumn& gather_map,
int32_t bounds_policy);
/// Scatter source rows into target at scatter_map positions.
std::unique_ptr<OwnedTable> scatter(
const OwnedTable& source,
const OwnedColumn& scatter_map,
const OwnedTable& target);
// ── Conditional Copy ───────────────────────────────────────────
/// Elementwise: select lhs where mask true, rhs where false.
std::unique_ptr<OwnedColumn> copy_if_else(
const OwnedColumn& lhs,
const OwnedColumn& rhs,
const OwnedColumn& boolean_mask);
// ── Slice / Split ──────────────────────────────────────────────
/// Slice [begin, end) as an owned deep copy.
std::unique_ptr<OwnedTable> slice_table(
const OwnedTable& table,
int32_t begin,
int32_t end);
/// Result of splitting a table into multiple parts.
struct SplitResult {
std::vector<std::unique_ptr<OwnedTable>> parts;
};
/// Split a table at the given indices, returning all parts at once.
std::unique_ptr<SplitResult> split_table_all(
const OwnedTable& table, rust::Slice<const int32_t> splits);
/// Return the number of parts in a split result.
int32_t split_result_count(const SplitResult& result);
/// Move one part out of a split result by index.
std::unique_ptr<OwnedTable> split_result_get(SplitResult& result, int32_t index);
// ── Empty / Allocate ───────────────────────────────────────────
/// Create an empty column (all null) matching col's type and size.
std::unique_ptr<OwnedColumn> empty_like(const OwnedColumn& col);
/// Allocate a column matching col's type and size with given mask policy.
std::unique_ptr<OwnedColumn> allocate_like(
const OwnedColumn& col,
int32_t mask_policy);
// ── In-place Copy ──────────────────────────────────────────────
/// Copy a range from source into target column.
void copy_range(
const OwnedColumn& source,
OwnedColumn& target,
int32_t source_begin,
int32_t source_end,
int32_t target_begin);
// ── Reverse ───────────────────────────────────────────────────
/// Reverse the rows of a table.
std::unique_ptr<OwnedTable> reverse_table(const OwnedTable& table);
/// Reverse the elements of a column.
std::unique_ptr<OwnedColumn> reverse_column(const OwnedColumn& col);
// ── Shift ─────────────────────────────────────────────────────
/// Shift column elements by offset, filling with fill_value.
std::unique_ptr<OwnedColumn> shift_column(
const OwnedColumn& col,
int32_t offset,
const OwnedScalar& fill_value);
// ── Get Element ───────────────────────────────────────────────
/// Get a single element from a column as a scalar.
std::unique_ptr<OwnedScalar> get_element(
const OwnedColumn& col,
int32_t index);
// ── Sample ────────────────────────────────────────────────────
/// Randomly sample n rows from a table.
std::unique_ptr<OwnedTable> sample(
const OwnedTable& table,
int32_t n,
bool with_replacement,
int64_t seed);
// ── Boolean Mask Scatter ──────────────────────────────────────
/// Scatter input rows into target at positions where boolean_mask is true.
std::unique_ptr<OwnedTable> boolean_mask_scatter(
const OwnedTable& input,
const OwnedColumn& boolean_mask,
const OwnedTable& target);
// ── Has Nonempty Nulls ────────────────────────────────────────
/// Check if a column has non-empty null elements.
bool has_nonempty_nulls(const OwnedColumn& col);
/// Elementwise: select lhs_col where mask true, rhs_scalar where false.
std::unique_ptr<OwnedColumn> copy_if_else_col_scalar(
const OwnedColumn& lhs,
const OwnedScalar& rhs,
const OwnedColumn& boolean_mask);
/// Elementwise: select lhs_scalar where mask true, rhs_col where false.
std::unique_ptr<OwnedColumn> copy_if_else_scalar_col(
const OwnedScalar& lhs,
const OwnedColumn& rhs,
const OwnedColumn& boolean_mask);
/// Slice a column by pairs of [begin, end) indices, returning deep copies.
/// The indices vec must contain pairs: [begin0, end0, begin1, end1, ...].
struct ColumnSliceResult {
std::vector<std::unique_ptr<OwnedColumn>> parts;
};
std::unique_ptr<ColumnSliceResult> slice_column(
const OwnedColumn& col, rust::Slice<const int32_t> indices);
int32_t column_slice_result_count(const ColumnSliceResult& result);
std::unique_ptr<OwnedColumn> column_slice_result_get(
ColumnSliceResult& result, int32_t index);
} // namespace cudf_shims