Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid automatic min_coordinate calculation for SparseTensor.dense #570

Open
matthewdm0816 opened this issue Dec 4, 2023 · 0 comments
Open

Comments

@matthewdm0816
Copy link

Document on SparseTensor indicates that, min_coordinate will be automatically computed if 0 is given. But it seems that the first assertion will throw error for any non-torch tensor inputs. There are correct codes below but will never be used under the first assert.

if min_coordinate is not None:
assert isinstance(min_coordinate, torch.IntTensor)
assert min_coordinate.numel() == self._D
if shape is not None:
assert isinstance(shape, torch.Size)
assert len(shape) == self._D + 2 # batch and channel
if shape[1] != self._F.size(1):
shape = torch.Size([shape[0], self._F.size(1), *[s for s in shape[2:]]])
# Exception handling for empty tensor
if self.__len__() == 0:
assert shape is not None, "shape is required to densify an empty tensor"
return (
torch.zeros(shape, dtype=self.dtype, device=self.device),
torch.zeros(self._D, dtype=torch.int32, device=self.device),
self.tensor_stride,
)
# Use int tensor for all operations
tensor_stride = torch.IntTensor(self.tensor_stride).to(self.device)
# New coordinates
batch_indices = self.C[:, 0]
if min_coordinate is None:
min_coordinate, _ = self.C.min(0, keepdim=True)
min_coordinate = min_coordinate[:, 1:]
if not torch.all(min_coordinate >= 0):
raise ValueError(
f"Coordinate has a negative value: {min_coordinate}. Please provide min_coordinate argument"
)
coords = self.C[:, 1:]
elif isinstance(min_coordinate, int) and min_coordinate == 0:
coords = self.C[:, 1:]
else:
min_coordinate = min_coordinate.to(self.device)
if min_coordinate.ndim == 1:
min_coordinate = min_coordinate.unsqueeze(0)
coords = self.C[:, 1:] - min_coordinate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant