ATen icon indicating copy to clipboard operation
ATen copied to clipboard

Improve error messages for undefined tensors

Open zdevito opened this issue 7 years ago • 2 comments

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?

zdevito avatar Jun 21 '17 17:06 zdevito

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?

gchanan avatar Sep 20 '17 15:09 gchanan

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.

zdevito avatar Sep 20 '17 16:09 zdevito