Switching between random and sequential sampling

i would like my code to be able to switch easily between using random and sequential sampling with dataloader.

was hoping to do something like the following. based on a user entered parameter (useseq) i can switch from using random to sequential. of course this doesn’t work. there must be a relatively easy way to do this.

can anyone help?

    auto dlisrnd = torch::data::make_data_loader<torch::data::samplers::RandomSampler>(std::move(dsis), cunbs);
    auto dlisseq = torch::data::make_data_loader<torch::data::samplers::SequentialSampler>(std::move(dsis), cunbs);
    auto dlisuse = dlisrnd;
    if (useseq) {
        dlisuse = dlisseq;

I assume the problem is that the returned types of the dataloaders don’t match?
Is there an issue with just passing both dataloaders in a struct, tuple, or other iterable structure and using one or the other? If you must use just a single object, you could e.g., use a Union, create a wrapper class/template, or even use raw pointers and cast them back to the selected dataloader type?

thanks. will try those. appreciate the help.