TypeID ID() const override;
Tensor empty(IntList size, const TensorOptions & options) const override {
- // TODO: Upstream this
- int64_t numel = 1;
- for (auto s : size) {
- numel *= s;
- }
- Storage s{c10::make_intrusive<StorageImpl>(
- scalarTypeToTypeMeta(ScalarType::ComplexFloat),
- numel,
- getCPUAllocator(),
- /* resizable */ true)};
- Tensor t{c10::make_intrusive<TensorImpl, UndefinedTensorImpl>(
- std::move(s),
- at::CPUTensorId(),
- /* is_variable */ false)};
- return t;
+ // Delegate to the appropriate cpu tensor factory
+ const DeviceGuard device_guard(options.device());
+ return at::native::empty_cpu(/* actuals */ size, options);
}
};
verbose=True,
)
- torch.empty(2, 2, dtype=torch.complex64)
+ # Make sure that the empty tensor is of the desired shape and type
+ # Refer to https://github.com/pytorch/pytorch/issues/14829
+ t = torch.empty(2, 2, dtype=torch.complex64)
+ self.assertEqual(t.size(), torch.Size([2, 2]))
+ self.assertEqual(t.type(), 'torch.ComplexFloatTensor')
@unittest.skipIf(not TEST_CUDA, "CUDA not found")
def test_half_support(self):