Use local_device() to temporarily switch devices within the current
function.
Usage
with_device(device, code)
local_device(device, .local_envir = parent.frame())Arguments
- device
"gpu","cpu", or anmlx_streamcreated viamlx_new_stream().- code
Expression to evaluate while
deviceis active.- .local_envir
Environment to bind the restoration to. Defaults to the calling environment.
Examples
with_device("cpu", x <- mlx_vector(1:10))
local_device("cpu")
# code here runs on CPU, then the previous default is restored