Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aten/src/ATen/Declarations.cwrap
Original file line number Diff line number Diff line change
Expand Up @@ -3885,7 +3885,7 @@
aten_custom_call: |
if (self_->isScalar()) {
// Empty tensor
return self_->type().toScalarType(kLong).tensor({0});
return toBackend(toDense(backend())).toScalarType(kLong).tensor({0});
}
]]

Expand Down
6 changes: 6 additions & 0 deletions test/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@ def test_factory_size_check(self):
with self.assertRaisesRegex(RuntimeError, "values and sizes are inconsistent"):
self.SparseTensor(indices, values, sizes)

def test_factory_empty_indices(self):
device = 'cuda' if self.is_cuda else 'cpu'
tensor = torch.sparse_coo_tensor([], [], torch.Size([]), device=device)
expected_indices = torch.tensor([], dtype=torch.long, device=device)
self.assertEqual(tensor._indices(), expected_indices)

@cpu_only
def test_factory_type_inference(self):
t = torch.sparse_coo_tensor(torch.tensor(([0], [2])), torch.tensor([1.], dtype=torch.float32))
Expand Down