Use local_default_device() to temporarily switch devices within the current
function.
Usage
with_default_device(device, code)
local_default_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_default_device("cpu", x <- mlx_vector(1:10))
local_default_device("cpu")
# code here runs on CPU, then the previous default is restored