Skip to contents

sample_n() and sample_frac() (superseded by slice_sample() in dplyr) on a GPU table. Without weight they draw row indices on the CPU with the exact sample.int() calls dplyr makes, so the same set.seed() gives the same rows, and gather them on the GPU like slice_sample.tbl_gpu(). A weight, a size that reads the data (a column, n()) or draws random numbers, and any call dplyr would raise an error for (e.g. a size larger than a group without replace) run in dplyr on the CPU (see cuplyr-fallback), where dplyr raises the error and consumes the RNG itself.

Usage

# S3 method for class 'tbl_gpu'
sample_n(tbl, size, replace = FALSE, weight = NULL, .env = NULL, ...)

# S3 method for class 'tbl_gpu'
sample_frac(tbl, size = 1, replace = FALSE, weight = NULL, .env = NULL, ...)

Arguments

tbl

A tbl_gpu object.

size

Number of rows (sample_n()) or fraction of rows (sample_frac()) to sample, per group.

replace

Whether to sample with replacement.

weight

Sampling weights; always run on the CPU.

.env

Deprecated, as in dplyr.

...

Passed on to dplyr when the call runs on the CPU.

Value

A tbl_gpu object with the sampled rows, grouped like tbl.