ATen
ATen copied to clipboard
Improve error messages for undefined tensors
Tensor objects do not have to be defined:
Tensor foo; // undefined tensor reference
auto zeros = CPU(kFloat).zeros({3,4});
// will crash because foo is not defined.
add_out(zeros,zeros,foo);
In the very least, the auto-gen'd operators should check for and report a nice error in this case. Should output-style operators also automatically initialize then Tensor?
what about generating an "undefined" TensorImpl type that just throws exceptions in every function call and the pImpl of current undefined Tensors get assigned to a (static) instance of the new TensorImpl type?
I think that would probably work, assuming writing a Type by hand doesn't force you to implement so many methods that it would become overly verbose (I think it is fine because all the generated stuff has default methods already). The nice thing about this is that .type().cuda()
and other introspection functions can actually work even if the tensor is not defined.