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
//! GPU-accelerated reshape operations.
//!
//! Provides interleaving and tiling of [`Table`] columns.
//!
//! # Examples
//!
//! ```rust,no_run
//! use cudf::{Column, Table};
//!
//! let col_a = Column::from_slice(&[1i32, 2]).unwrap();
//! let col_b = Column::from_slice(&[3i32, 4]).unwrap();
//! let table = Table::new(vec![col_a, col_b]).unwrap();
//!
//! let interleaved = table.interleave_columns().unwrap();
//! // Result: [1, 3, 2, 4]
//! ```
use crate::column::Column;
use crate::error::{CudfError, Result};
use crate::table::Table;
use crate::types::checked_i32;
impl Table {
/// Interleave all columns into a single column.
///
/// Columns must all have the same data type. Elements are taken
/// round-robin from each column: `[col0[0], col1[0], col0[1], col1[1], ...]`.
pub fn interleave_columns(&self) -> Result<Column> {
let raw =
cudf_cxx::reshape::ffi::interleave_columns(&self.inner).map_err(CudfError::from_cxx)?;
Ok(Column { inner: raw })
}
/// Tile (repeat) this table's rows the specified number of times.
///
/// Returns a new table with `num_rows * count` rows.
pub fn tile(&self, count: usize) -> Result<Table> {
let raw = cudf_cxx::reshape::ffi::tile(&self.inner, checked_i32(count)?)
.map_err(CudfError::from_cxx)?;
Ok(Table { inner: raw })
}
}
impl Column {
/// Cast column data to lists of bytes.
///
/// Each element becomes a list of `uint8` bytes representing its
/// raw binary data. If `flip_endianness` is true, the byte order
/// is reversed for each element.
pub fn byte_cast(&self, flip_endianness: bool) -> Result<Column> {
let raw = cudf_cxx::reshape::ffi::byte_cast(&self.inner, flip_endianness)
.map_err(CudfError::from_cxx)?;
Ok(Column { inner: raw })
}
}