Caffe2 - C++ API
A deep learning, cross platform ML framework
Tensor.cpp
1 #include <ATen/core/Tensor.h>
2 #include <ATen/core/Formatting.h>
3 #include <ATen/core/Type.h>
4 
5 #include <iostream>
6 
7 namespace at {
8 
9 void Tensor::enforce_invariants() {
10  if (impl_.get() == nullptr) {
11  throw std::runtime_error("TensorImpl with nullptr is not supported");
12  }
13  // Following line throws if the method is not a POD data type or is not
14  // supported by ATen
15  scalar_type();
16  if (defined()) {
17  // If it's a variable - we definitely not in C2 land
18  if (!is_variable()) {
19  AT_ASSERTM(
20  impl_->dtype_initialized(),
21  "Partially-initialized tensor not supported by at::Tensor");
22  AT_ASSERTM(
23  impl_->storage_initialized(),
24  "Partially-initialized tensor not supported by at::Tensor");
25  }
26  // Ensure LegacyTypeDispatch is initialized. In ATen it's done in tensor
27  // factory functions, but when we get a tensor from Caffe2 we might bypass
28  // those factory functions.
29  initializeLegacyTypeDispatchFor(*impl_);
30  }
31 }
32 
33 void Tensor::print() const {
34  if (defined()) {
35  std::cerr << "[" << type().toString() << " " << sizes() << "]" << std::endl;
36  } else {
37  std::cerr << "[UndefinedTensor]" << std::endl;
38  }
39 }
40 
41 const char * Tensor::toString() const {
42  return type().toString();
43 }
44 
45 } // namespace at
bool dtype_initialized() const noexcept
True if a tensor is dtype initialized.
Definition: TensorImpl.h:1246
bool is_variable() const noexcept
Returns true if the Tensor is actually a torch::autograd::Variable.
bool storage_initialized() const noexcept
True if a tensor is storage initialized.
Definition: TensorImpl.h:1237
Flush-To-Zero and Denormals-Are-Zero mode.