@@ -47,8 +47,7 @@ def laplacian(verts: torch.Tensor, edges: torch.Tensor) -> torch.Tensor:
47
47
# i.e. A[i, j] = 1 if (i,j) is an edge, or
48
48
# A[e0, e1] = 1 & A[e1, e0] = 1
49
49
ones = torch .ones (idx .shape [1 ], dtype = torch .float32 , device = verts .device )
50
- # pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
51
- A = torch .sparse .FloatTensor (idx , ones , (V , V ))
50
+ A = torch .sparse_coo_tensor (idx , ones , (V , V ), dtype = torch .float32 )
52
51
53
52
# the sum of i-th row of A gives the degree of the i-th vertex
54
53
deg = torch .sparse .sum (A , dim = 1 ).to_dense ()
@@ -62,15 +61,13 @@ def laplacian(verts: torch.Tensor, edges: torch.Tensor) -> torch.Tensor:
62
61
# pyre-fixme[58]: `/` is not supported for operand types `float` and `Tensor`.
63
62
deg1 = torch .where (deg1 > 0.0 , 1.0 / deg1 , deg1 )
64
63
val = torch .cat ([deg0 , deg1 ])
65
- # pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
66
- L = torch .sparse .FloatTensor (idx , val , (V , V ))
64
+ L = torch .sparse_coo_tensor (idx , val , (V , V ), dtype = torch .float32 )
67
65
68
66
# Then we add the diagonal values L[i, i] = -1.
69
67
idx = torch .arange (V , device = verts .device )
70
68
idx = torch .stack ([idx , idx ], dim = 0 )
71
69
ones = torch .ones (idx .shape [1 ], dtype = torch .float32 , device = verts .device )
72
- # pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
73
- L -= torch .sparse .FloatTensor (idx , ones , (V , V ))
70
+ L -= torch .sparse_coo_tensor (idx , ones , (V , V ), dtype = torch .float32 )
74
71
75
72
return L
76
73
@@ -126,8 +123,7 @@ def cot_laplacian(
126
123
ii = faces [:, [1 , 2 , 0 ]]
127
124
jj = faces [:, [2 , 0 , 1 ]]
128
125
idx = torch .stack ([ii , jj ], dim = 0 ).view (2 , F * 3 )
129
- # pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
130
- L = torch .sparse .FloatTensor (idx , cot .view (- 1 ), (V , V ))
126
+ L = torch .sparse_coo_tensor (idx , cot .view (- 1 ), (V , V ), dtype = torch .float32 )
131
127
132
128
# Make it symmetric; this means we are also setting
133
129
# L[v2, v1] = cota
@@ -167,16 +163,15 @@ def norm_laplacian(
167
163
v0 , v1 = edge_verts [:, 0 ], edge_verts [:, 1 ]
168
164
169
165
# Side lengths of each edge, of shape (E,)
170
- w01 = 1.0 / ((v0 - v1 ).norm (dim = 1 ) + eps )
166
+ w01 = torch . reciprocal ((v0 - v1 ).norm (dim = 1 ) + eps )
171
167
172
168
# Construct a sparse matrix by basically doing:
173
169
# L[v0, v1] = w01
174
170
# L[v1, v0] = w01
175
171
e01 = edges .t () # (2, E)
176
172
177
173
V = verts .shape [0 ]
178
- # pyre-fixme[16]: Module `sparse` has no attribute `FloatTensor`.
179
- L = torch .sparse .FloatTensor (e01 , w01 , (V , V ))
174
+ L = torch .sparse_coo_tensor (e01 , w01 , (V , V ), dtype = torch .float32 )
180
175
L = L + L .t ()
181
176
182
177
return L
0 commit comments