xref: /aosp_15_r20/external/pytorch/torch/csrc/autograd/variable_info.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #ifndef AT_PER_OPERATOR_HEADERS
2 #include <ATen/Functions.h>
3 #else
4 #include <ATen/ops/zeros.h>
5 #endif
6 
7 #include <torch/csrc/autograd/variable.h>
8 #include <torch/csrc/autograd/variable_info.h>
9 
10 namespace torch::autograd {
11 
VariableInfo(const Variable & var)12 VariableInfo::VariableInfo(const Variable& var)
13     : layout(var.layout()),
14       device(var.device()),
15       scalar_type(var.scalar_type()),
16       size(var.sym_sizes().vec()),
17       requires_grad(var.requires_grad()),
18       is_empty(false) {}
19 
VariableInfo()20 VariableInfo::VariableInfo() : requires_grad(false), is_empty(true) {}
21 
zeros(at::OptionalDeviceGuard & device_guard) const22 Variable VariableInfo::zeros(at::OptionalDeviceGuard& device_guard) const {
23   if (is_empty) {
24     // Return undefined tensor.
25     return at::Tensor();
26   } else {
27     return at::zeros_symint(
28         size, at::TensorOptions(scalar_type).device(device).layout(layout));
29   }
30 }
31 
32 } // namespace torch::autograd
33