LeviViana:

torch::Tensor tensor = torch::zeros({2, 2}).to(torch::kInt);


Yes, this approach works, but you have to know the number of your observations (rows), as you have defined it by torch::Tensor tensor = torch::zeros({2, 2}).to(torch::kInt);.
The initial question was looking for a solution when we do not know the number of rows.