I’m trying to iterate over a tensor element-wize in C++, which is proving difficult.

I’ve been able to get the number of dimensions of a tensor (torch::Tensor tensor) using tensor.dim(), and I’m able to get the size of each dimension using torch::size(tensor, dim), however I can’t figure out to iterate over a tensor. for (int i = 0; i < sizeof(tensor) / sizeof(tensor[0]); i++) only iterates over each element of the first row.

Is there a way to iterate element-wize over a nth dimensional torch::Tensor?