I’m a fresher on PyTorch and I found the following code in aten/src/ATen/native/TensorFactories.cpp:254
Tensor empty_cpu(IntArrayRef size, c10::optional<ScalarType> dtype_opt, c10::optional<Layout> layout_opt,
c10::optional<Device> device_opt, c10::optional<bool> pin_memory_opt, c10::optional<c10::MemoryFormat> memory_format_opt) {
return at::detail::empty_cpu(size, dtype_opt, layout_opt, device_opt, pin_memory_opt, memory_format_opt);
}
My question is that: This function returns a Tensor object and it seems that the return value of “at::detail::empty_cpu()” is TensorBase which is base class of Tensor. (e.g. at::detail::empty_cpu() returns a base-class object and pass it to a subclass variable)
aten/src/ATen/EmptyTensor.cpp:239
TensorBase empty_cpu(
IntArrayRef size,
c10::optional<ScalarType> dtype_opt,
c10::optional<Layout> layout_opt,
c10::optional<Device> device_opt,
c10::optional<bool> pin_memory_opt,
c10::optional<c10::MemoryFormat> memory_format_opt) {
TORCH_INTERNAL_ASSERT_DEBUG_ONLY(device_or_default(device_opt).type() == DeviceType::CPU);
TORCH_INTERNAL_ASSERT_DEBUG_ONLY(layout_or_default(layout_opt) == Layout::Strided);
auto pin_memory = pinned_memory_or_default(pin_memory_opt);
auto dtype = dtype_or_default(dtype_opt);
return empty_cpu(size, dtype, pin_memory, memory_format_opt);
}
Why that works? Any suggestions would be appreciated