materialize {mlr3torch} | R Documentation |
Materialize Lazy Tensor Columns
Description
This will materialize a lazy_tensor()
or a data.frame()
/ list()
containing – among other things –
lazy_tensor()
columns.
I.e. the data described in the underlying DataDescriptor
s is loaded for the indices in the lazy_tensor()
,
is preprocessed and then put unto the specified device.
Because not all elements in a lazy tensor must have the same shape, a list of tensors is returned by default.
If all elements have the same shape, these tensors can also be rbinded into a single tensor (parameter rbind
).
Usage
materialize(x, device = "cpu", rbind = FALSE, ...)
## S3 method for class 'list'
materialize(x, device = "cpu", rbind = FALSE, cache = "auto", ...)
Arguments
x |
(any) |
device |
( |
rbind |
( |
... |
(any) |
cache |
( |
Details
Materializing a lazy tensor consists of:
Loading the data from the internal dataset of the
DataDescriptor
.Processing these batches in the preprocessing
Graph
s.Returning the result of the
PipeOp
pointed to by theDataDescriptor
(pointer
).
With multiple lazy_tensor
columns we can benefit from caching because:
a) Output(s) from the dataset might be input to multiple graphs.
b) Different lazy tensors might be outputs from the same graph.
For this reason it is possible to provide a cache environment. The hash key for a) is the hash of the indices and the dataset. The hash key for b) is the hash of the indices, dataset and preprocessing graph.
Value
(list()
of lazy_tensor
s or a lazy_tensor
)
Examples
lt1 = as_lazy_tensor(torch_randn(10, 3))
materialize(lt1, rbind = TRUE)
materialize(lt1, rbind = FALSE)
lt2 = as_lazy_tensor(torch_randn(10, 4))
d = data.table::data.table(lt1 = lt1, lt2 = lt2)
materialize(d, rbind = TRUE)
materialize(d, rbind = FALSE)