xref: /aosp_15_r20/external/pytorch/c10/core/UndefinedTensorImpl.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #include <c10/core/UndefinedTensorImpl.h>
2 #include <c10/util/Exception.h>
3 
4 namespace c10 {
5 
6 // should this use the globalContext?  Can it get a context passed in somehow?
UndefinedTensorImpl()7 UndefinedTensorImpl::UndefinedTensorImpl()
8     : TensorImpl(DispatchKey::Undefined, caffe2::TypeMeta(), std::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 
is_contiguous_custom(MemoryFormat format) const15 bool UndefinedTensorImpl::is_contiguous_custom(MemoryFormat format) const {
16   return is_contiguous_default(format);
17 }
strides_custom() const18 IntArrayRef UndefinedTensorImpl::strides_custom() const {
19   TORCH_CHECK(false, "strides() called on an undefined Tensor");
20 }
sym_strides_custom() const21 SymIntArrayRef UndefinedTensorImpl::sym_strides_custom() const {
22   TORCH_CHECK(false, "sym_strides() called on an undefined Tensor");
23 }
24 
25 #ifdef DEBUG
has_storage() const26 bool 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 
set_storage_offset(int64_t)33 void UndefinedTensorImpl::set_storage_offset(int64_t) {
34   TORCH_CHECK(false, "set_storage_offset() called on an undefined Tensor");
35 }
36 
tensorimpl_type_name() const37 const char* UndefinedTensorImpl::tensorimpl_type_name() const {
38   return "UndefinedTensorImpl";
39 }
40 
41 #ifdef _WIN32
getInstance()42 UndefinedTensorImpl& UndefinedTensorImpl::getInstance() {
43   static UndefinedTensorImpl instance;
44   return instance;
45 }
46 #else
47 UndefinedTensorImpl UndefinedTensorImpl::_singleton;
48 #endif
49 
50 } // namespace c10
51