1#include <c10/core/UndefinedTensorImpl.h>
2#include <c10/util/Exception.h>
3
4namespace c10 {
5
6// should this use the globalContext? Can it get a context passed in somehow?
7UndefinedTensorImpl::UndefinedTensorImpl()
8 : TensorImpl(DispatchKey::Undefined, caffe2::TypeMeta(), c10::nullopt) {
9 set_storage_access_should_throw();
10 // TODO: accessing the sizes on an undefined tensor is not meaningful
11 // and should error too, but empirically it does not!
12 set_custom_sizes_strides(SizesStridesPolicy::CustomStrides);
13}
14
15bool UndefinedTensorImpl::is_contiguous_custom(MemoryFormat format) const {
16 return is_contiguous_default(format);
17}
18IntArrayRef UndefinedTensorImpl::strides_custom() const {
19 TORCH_CHECK(false, "strides() called on an undefined Tensor");
20}
21SymIntArrayRef UndefinedTensorImpl::sym_strides_custom() const {
22 TORCH_CHECK(false, "sym_strides() called on an undefined Tensor");
23}
24
25#ifdef DEBUG
26bool UndefinedTensorImpl::has_storage() const {
27 TORCH_INTERNAL_ASSERT_DEBUG_ONLY(
28 !storage_, "UndefinedTensorImpl assumes that storage_ is never set");
29 return false;
30}
31#endif
32
33void UndefinedTensorImpl::set_storage_offset(int64_t) {
34 TORCH_CHECK(false, "set_storage_offset() called on an undefined Tensor");
35}
36
37const char* UndefinedTensorImpl::tensorimpl_type_name() const {
38 return "UndefinedTensorImpl";
39}
40
41UndefinedTensorImpl UndefinedTensorImpl::_singleton;
42
43} // namespace c10
44