I’m converting a python code to C++ and I have to add 2 tensors, one of them (z_vals) shaped [64] and another one (rand_mult) shaped [100, 100, 64]. In python the broadcasting is made automatically, but in C++ I did it manually, converting the first tensor to [100, 100, 64]:
torch::Tensor z_vals_broad = torch::broadcast_to(z_vals, {100, 100, 64});
This way, I should be able to add them up, but every time I try, an exception is called, without much information about what the problem is. It only says Error at memory location.
I’ve tried:
z_vals = z_vals_broad.add(rand_mult);
and
torch::Tensor z_vals_b = torch::add(z_vals_broad, rand_mult);
but none of it works. Am I missing something in the broadcasting part? Or is the problem elsewhere?