diff options
author | Sebastian Messmer <messmer@fb.com> | 2018-12-11 20:40:33 -0800 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2018-12-11 21:01:42 -0800 |
commit | 63db95dd11775b062bb1263c4f8a02e61631c59f (patch) | |
tree | ffc97169c878d05844b8f332aa0af03beed214e5 /c10 | |
parent | 2dfdbef91df0c528ce4021dcd66f0f63619f725b (diff) | |
download | pytorch-63db95dd11775b062bb1263c4f8a02e61631c59f.tar.gz pytorch-63db95dd11775b062bb1263c4f8a02e61631c59f.tar.bz2 pytorch-63db95dd11775b062bb1263c4f8a02e61631c59f.zip |
Move UndefinedTensorImpl to c10 (meh) (#14817)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14817
unfortunately, we still need this.
Reviewed By: ezyang
Differential Revision: D13348041
fbshipit-source-id: e8dcc89f5c71bd1ea2c9813990dac6e58e63b1fd
Diffstat (limited to 'c10')
-rw-r--r-- | c10/core/UndefinedTensorImpl.cpp | 40 | ||||
-rw-r--r-- | c10/core/UndefinedTensorImpl.h | 34 |
2 files changed, 74 insertions, 0 deletions
diff --git a/c10/core/UndefinedTensorImpl.cpp b/c10/core/UndefinedTensorImpl.cpp new file mode 100644 index 0000000000..2e2265397e --- /dev/null +++ b/c10/core/UndefinedTensorImpl.cpp @@ -0,0 +1,40 @@ +#include <c10/core/UndefinedTensorImpl.h> +#include <c10/util/Exception.h> + +namespace c10 { + +// should this use the globalContext? Can it get a context passed in somehow? +UndefinedTensorImpl::UndefinedTensorImpl() +: TensorImpl(UndefinedTensorId(), caffe2::TypeMeta(), nullptr, /* is variable */ false) { +} + +IntList UndefinedTensorImpl::sizes() const { + AT_ERROR("sizes() called on undefined Tensor"); +} + +int64_t UndefinedTensorImpl::size(int64_t d) const { + AT_ERROR("size(dim) called on an undefined Tensor"); +} + +int64_t UndefinedTensorImpl::stride(int64_t d) const { + AT_ERROR("stride(dim) called on an undefined Tensor"); +} + +int64_t UndefinedTensorImpl::dim() const { + AT_ERROR("dim() called on undefined Tensor"); +} + +const Storage& UndefinedTensorImpl::storage() const { + AT_ERROR("storage() called on undefined Tensor"); +} + +int64_t UndefinedTensorImpl::storage_offset() const { + AT_ERROR("storage_offset() called on an undefined Tensor"); +} + +IntList UndefinedTensorImpl::strides() const { + AT_ERROR("strides() called on undefined Tensor"); +} +UndefinedTensorImpl UndefinedTensorImpl::_singleton; + +} diff --git a/c10/core/UndefinedTensorImpl.h b/c10/core/UndefinedTensorImpl.h new file mode 100644 index 0000000000..5d268b7b82 --- /dev/null +++ b/c10/core/UndefinedTensorImpl.h @@ -0,0 +1,34 @@ +#pragma once + +#include <c10/core/TensorImpl.h> + +namespace c10 { + +struct C10_API UndefinedTensorImpl final : public TensorImpl { + public: + // Without this, we get: + // error: identifier "at::UndefinedTensorImpl::_singleton" is undefined in device code + // (ostensibly because the constexpr tricks MSVC into trying to compile this + // function for device as well). +#ifdef _WIN32 + static inline TensorImpl * singleton() { +#else + static constexpr inline TensorImpl * singleton() { +#endif + return &_singleton; + } + IntList sizes() const override; + IntList strides() const override; + int64_t size(int64_t d) const override; + int64_t stride(int64_t d) const override; + int64_t dim() const override; + const Storage& storage() const override; + int64_t storage_offset() const override; +private: + UndefinedTensorImpl(); + static UndefinedTensorImpl _singleton; +public: + friend struct UndefinedType; +}; + +} // namespace c10 |