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!
@tom Many thanks! To clarify, in my function forward, i need to check for (noise.defined()) instead of (noise==None) . But if I want to call my function “forward” with noise undefined, how do i do that without setting a default value for noise in the function? I just do " torch::Tensor noise_dummy;" and pass in noise_dummy?
What this is about is that None in Python maps to an undefined torch::Tensor in C++. The the m.def is on the C++ side already, so the default argument should be the default constructed torch::Tensor().