pytorch
e362ee6f - Make it illegal to directly construct _TensorBase (#56150)

Commit
3 years ago
Make it illegal to directly construct _TensorBase (#56150) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/56150 See #56017 for full context; the short story is that by making it illegal to directly construct _TensorBase, we need only write a *single* tp_dealloc function which will work universally for all _TensorBase subclasses, rather than having to write two versions, one for _TensorBase itself, and others for Python subclasses of _TensorBase. This means simpler code. The subtlety here is that we only install our custom `tp_new` for direct subclasses of TensorBase. This is important, because overriding the `tp_new` also overrides any user defined constructor. Fortunately class Tensor(_TensorBase) has no nontrivial constructors and doesn't mind, but other subclasses like Parameter definitely mind! Signed-off-by: Edward Z. Yang <ezyang@fb.com> Test Plan: Imported from OSS Reviewed By: H-Huang Differential Revision: D28028746 Pulled By: ezyang fbshipit-source-id: 3c03a14666ad1ded1145fe676afb0a7623cdb9bb
Author
Parents
Loading