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
153
154
155
156
157
158
159
160
161
162
//! Bridge definitions for libcudf copying operations.
//!
//! Provides GPU-accelerated gather, scatter, slice, split, and copy operations
//! for tables and columns.
#[cxx::bridge(namespace = "cudf_shims")]
pub mod ffi {
unsafe extern "C++" {
include!("copying_shim.h");
include!("column_shim.h");
include!("table_shim.h");
include!("scalar_shim.h");
type OwnedColumn = crate::column::ffi::OwnedColumn;
type OwnedTable = crate::table::ffi::OwnedTable;
// ── Gather / Scatter ───────────────────────────────────────
/// Gather rows from `table` according to `gather_map` (index column).
/// `bounds_policy`: 0=DONT_CHECK, 1=NULLIFY.
fn gather(
table: &OwnedTable,
gather_map: &OwnedColumn,
bounds_policy: i32,
) -> Result<UniquePtr<OwnedTable>>;
/// Scatter rows from `source` into `target` at positions in `scatter_map`.
fn scatter(
source: &OwnedTable,
scatter_map: &OwnedColumn,
target: &OwnedTable,
) -> Result<UniquePtr<OwnedTable>>;
// ── Conditional Copy ───────────────────────────────────────
/// Elementwise: select from `lhs` where mask is true, `rhs` where false.
fn copy_if_else(
lhs: &OwnedColumn,
rhs: &OwnedColumn,
boolean_mask: &OwnedColumn,
) -> Result<UniquePtr<OwnedColumn>>;
// ── Slice / Split ──────────────────────────────────────────
/// Extract a contiguous slice [begin, end) as an owned deep copy.
fn slice_table(table: &OwnedTable, begin: i32, end: i32) -> Result<UniquePtr<OwnedTable>>;
/// Opaque result of splitting a table into multiple parts.
type SplitResult;
/// Split a table at the given indices, returning all parts at once.
fn split_table_all(table: &OwnedTable, splits: &[i32]) -> Result<UniquePtr<SplitResult>>;
/// Return the number of parts in a split result.
fn split_result_count(result: &SplitResult) -> i32;
/// Move one part out of a split result by index.
fn split_result_get(
result: Pin<&mut SplitResult>,
index: i32,
) -> Result<UniquePtr<OwnedTable>>;
// ── Empty / Allocate ───────────────────────────────────────
/// Create an empty column with the same type and size as `col`, all nulls.
fn empty_like(col: &OwnedColumn) -> Result<UniquePtr<OwnedColumn>>;
/// Create a column with the same type and size as `col`, with allocated
/// but uninitialized data.
/// `mask_policy`: 0=NEVER, 1=ALWAYS, 2=RETAIN.
fn allocate_like(col: &OwnedColumn, mask_policy: i32) -> Result<UniquePtr<OwnedColumn>>;
// ── In-place Copy ──────────────────────────────────────────
/// Copy a range from `source` into `target` column (in-place).
fn copy_range(
source: &OwnedColumn,
target: Pin<&mut OwnedColumn>,
source_begin: i32,
source_end: i32,
target_begin: i32,
) -> Result<()>;
// ── Reverse ───────────────────────────────────────────────
/// Reverse the rows of a table.
fn reverse_table(table: &OwnedTable) -> Result<UniquePtr<OwnedTable>>;
/// Reverse the elements of a column.
fn reverse_column(col: &OwnedColumn) -> Result<UniquePtr<OwnedColumn>>;
// ── Shift ─────────────────────────────────────────────────
type OwnedScalar = crate::scalar::ffi::OwnedScalar;
/// Shift column elements by offset, filling with fill_value.
fn shift_column(
col: &OwnedColumn,
offset: i32,
fill_value: &OwnedScalar,
) -> Result<UniquePtr<OwnedColumn>>;
// ── Get Element ───────────────────────────────────────────
/// Get a single element from a column as a scalar.
fn get_element(col: &OwnedColumn, index: i32) -> Result<UniquePtr<OwnedScalar>>;
// ── Sample ────────────────────────────────────────────────
/// Randomly sample n rows from a table.
fn sample(
table: &OwnedTable,
n: i32,
with_replacement: bool,
seed: i64,
) -> Result<UniquePtr<OwnedTable>>;
// ── Boolean Mask Scatter ──────────────────────────────────
/// Scatter input rows into target at positions where boolean_mask is true.
fn boolean_mask_scatter(
input: &OwnedTable,
boolean_mask: &OwnedColumn,
target: &OwnedTable,
) -> Result<UniquePtr<OwnedTable>>;
// ── Has Nonempty Nulls ────────────────────────────────────
/// Check if a column has non-empty null elements.
fn has_nonempty_nulls(col: &OwnedColumn) -> Result<bool>;
/// Elementwise: select lhs_col where mask true, rhs_scalar where false.
fn copy_if_else_col_scalar(
lhs: &OwnedColumn,
rhs: &OwnedScalar,
boolean_mask: &OwnedColumn,
) -> Result<UniquePtr<OwnedColumn>>;
/// Elementwise: select lhs_scalar where mask true, rhs_col where false.
fn copy_if_else_scalar_col(
lhs: &OwnedScalar,
rhs: &OwnedColumn,
boolean_mask: &OwnedColumn,
) -> Result<UniquePtr<OwnedColumn>>;
/// Opaque result of slicing a column.
type ColumnSliceResult;
/// Slice a column by pairs of [begin, end) indices.
fn slice_column(col: &OwnedColumn, indices: &[i32])
-> Result<UniquePtr<ColumnSliceResult>>;
/// Return the number of parts in a column slice result.
fn column_slice_result_count(result: &ColumnSliceResult) -> i32;
/// Move one part out of a column slice result by index.
fn column_slice_result_get(
result: Pin<&mut ColumnSliceResult>,
index: i32,
) -> Result<UniquePtr<OwnedColumn>>;
}
}