if (torch_is_installed()) {
ids <- iterable_dataset(
name = "hello",
initialize = function(n = 5) {
self$n <- n
self$i <- 0
},
.iter = function() {
i <- 0
function() {
i <<- i + 1
if (i > self$n) {
coro::exhausted()
} else {
i
}
}
}
)
coro::collect(ids()$.iter())
}
Run the code above in your browser using DataLab