as_lazy_tensor | R Documentation |
Convert a object to a lazy_tensor
.
as_lazy_tensor(x, ...)
## S3 method for class 'dataset'
as_lazy_tensor(x, dataset_shapes = NULL, ids = NULL, ...)
x |
(any) |
... |
(any) |
dataset_shapes |
(named |
ids |
( |
iris_ds = dataset("iris",
initialize = function() {
self$iris = iris[, -5]
},
.getbatch = function(i) {
list(x = torch_tensor(as.matrix(self$iris[i, ])))
},
.length = function() nrow(self$iris)
)()
# no need to specify the dataset shapes as they can be inferred from the .getbatch method
# only first 5 observations
as_lazy_tensor(iris_ds, ids = 1:5)
# all observations
head(as_lazy_tensor(iris_ds))
iris_ds2 = dataset("iris",
initialize = function() self$iris = iris[, -5],
.getitem = function(i) list(x = torch_tensor(as.numeric(self$iris[i, ]))),
.length = function() nrow(self$iris)
)()
# if .getitem is implemented we cannot infer the shapes as they might vary,
# so we have to annotate them explicitly
as_lazy_tensor(iris_ds2, dataset_shapes = list(x = c(NA, 4L)))[1:5]
# Convert a matrix
lt = as_lazy_tensor(matrix(rnorm(100), nrow = 20))
materialize(lt[1:5], rbind = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.