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

replace torch.sparse.SparseTensor to torch.sparse_coo_tensor #1909

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions pytorch3d/ops/laplacian_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def laplacian(verts: torch.Tensor, edges: torch.Tensor) -> torch.Tensor:
# A[e0, e1] = 1 & A[e1, e0] = 1
ones = torch.ones(idx.shape[1], dtype=torch.float32, device=verts.device)
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
A = torch.sparse.FloatTensor(idx, ones, (V, V))
A = torch.sparse_coo_tensor(idx, ones, (V, V))

# the sum of i-th row of A gives the degree of the i-th vertex
deg = torch.sparse.sum(A, dim=1).to_dense()
Expand All @@ -63,14 +63,14 @@ def laplacian(verts: torch.Tensor, edges: torch.Tensor) -> torch.Tensor:
deg1 = torch.where(deg1 > 0.0, 1.0 / deg1, deg1)
val = torch.cat([deg0, deg1])
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
L = torch.sparse.FloatTensor(idx, val, (V, V))
L = torch.sparse_coo_tensor(idx, val, (V, V))

# Then we add the diagonal values L[i, i] = -1.
idx = torch.arange(V, device=verts.device)
idx = torch.stack([idx, idx], dim=0)
ones = torch.ones(idx.shape[1], dtype=torch.float32, device=verts.device)
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
L -= torch.sparse.FloatTensor(idx, ones, (V, V))
L -= torch.sparse_coo_tensor(idx, ones, (V, V))

return L

Expand Down Expand Up @@ -127,7 +127,7 @@ def cot_laplacian(
jj = faces[:, [2, 0, 1]]
idx = torch.stack([ii, jj], dim=0).view(2, F * 3)
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
L = torch.sparse.FloatTensor(idx, cot.view(-1), (V, V))
L = torch.sparse_coo_tensor(idx, cot.view(-1), (V, V))

# Make it symmetric; this means we are also setting
# L[v2, v1] = cota
Expand Down Expand Up @@ -176,7 +176,7 @@ def norm_laplacian(

V = verts.shape[0]
# pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
L = torch.sparse.FloatTensor(e01, w01, (V, V))
L = torch.sparse_coo_tensor(e01, w01, (V, V))
L = L + L.t()

return L