I defined a forward function in a module. The forward function checks if the noise input parameter is None or not, if None then create its own noise; if not None, then just use the input noise. However, this could not be achieved using the following code, c10::optional<at::Tensor> could not be converted to torch::Tensor through " mynoise = noise;". What is the best way to pass in a tensor that could optionally be None to a function? Thanks!
torch::Tensor forward(torch::Tensor  image, c10::optional <at::Tensor> noise){
torch::Tensor mynoise;
if(noise == None){
auto batch = image.size(0);// , height, width = image.shape
auto height = image.size(2);
auto width = image.size(3);
mynoise = image.new_empty({batch, 1, height, width}).normal();
}else{
mynoise = noise;
}
return image + weight *  mynoise;
}