About converting for (datum, label) in self.test to C++ in libtorch

Hi, All

I am trying to convert the following python code to C++ in libtorch

The python code is:
d, l = [], []
for (datum, label) in self.test:

When I convert it in C++ code, do I need to obtain the size of the dataset for test please ?
Any suggestion is welcome.


Typicall, when I write

std::vectortorch::Tensor d;
std::vectortorch::Tensor l;
for (auto& datum: test.size())


It gives me an error at “auto& datum: test.size()” saying “Invalid range expression, no viable begin function available”


And I have changed it to:
for (int i=0; i<test.size().value();i++)
torch::Tensor datum=test.get_batch([i]).data;


It is saying “expected lambda body of experession”

Assuming you are creating the data_loader via:

auto data_loader = torch::data::make_data_loader(
      std::move(dataset), ...

then this should work:

for (auto& batch : *data_loader) {

Thanks a lot for your response. I appreciate that.