torch
torch copied to clipboard
dataset_subset hides dataset subclass
I expected dataset_subset to keep dataset properties, but it hides them. Could we either sort out a way to elevate the dataset to the "top" of that object, or at least give the new dataset a subclass so methods can know to look down a level for "real" dataset properties?
library(torch)
minimal_dataset <- dataset(
"minimal",
initialize = function() {
self$data <- torch_tensor(1:5)
},
.length = function() {
self$data$size()[[1]]
}
)
testing <- minimal_dataset()
class(testing)
#> [1] "minimal" "dataset" "R6"
testing_sub <- dataset_subset(testing, 1:2)
class(testing_sub)
#> [1] "dataset" "R6"
Created on 2022-09-15 with reprex v2.0.2
Indeed! This is a bug, we should keep the same class as the provided dataset!
It isn't just class, anything else the provided dataset has (in my case we have some methods) should come through. After implementing a workaround, I think the best option might be to give it a "dataset_subset" class, so we can make S3 methods for that specifically and then call that generic on the $dataset inside.