zdevito / ATen

ATen: A TENsor library for C++11
683 stars 125 forks source link

Improve error messages for undefined tensors #6

Open zdevito opened 7 years ago

zdevito commented 7 years ago

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?

gchanan commented 7 years ago

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?

zdevito commented 7 years ago

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.