About create a random noise tensor with the same size of existing tensor in C++

Hi, All

I have an inquiry about creating a random noise tensor with the same size of existing tensor.

the python code is:
noise1=torch.randn(x.size())*0.3

but in C++, I cannot write like
torch::Tensor noise = torch::randn({x.size()}) * 0.3; it does not allow to have x.size()

as the size of tensor x is varying, I cannot explicit write down all the dimensions of x, is there a better way to handle it please ?

Any comments are welcome.

Thanks.

I’m unsure what the right approach to pass the size() to the c’tor would be, but this should work as well:

auto noise = torch::empty_like(x)
noise.normal_(0., 0.3);

Thanks a lot.

That is very helpful.