Skip to content

Commit 5444c53

Browse files
bottlerfacebook-github-bot
authored andcommitted
Avoid plain division involving integers
Summary: To avoid pytorch warnings and future behaviour changes, stop using torch.div and / with tensors of integers. Reviewed By: gkioxari, mruberry Differential Revision: D21857955 fbshipit-source-id: fb9f3000f3d953352cdc721d2a5f73d3a4bbf4b7
1 parent 40b068e commit 5444c53

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

pytorch3d/ops/cubify.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def unravel_index(idx, dims) -> torch.Tensor:
1818
if len(dims) != 4:
1919
raise ValueError("Expects a 4-element list.")
2020
N, H, W, D = dims
21-
n = torch.div(idx, H * W * D)
22-
h = torch.div(idx - n * H * W * D, W * D)
23-
w = torch.div(idx - n * H * W * D - h * W * D, D)
21+
n = idx // (H * W * D)
22+
h = (idx - n * H * W * D) // (W * D)
23+
w = (idx - n * H * W * D - h * W * D) // D
2424
d = idx - n * H * W * D - h * W * D - w * D
2525
return torch.stack((n, h, w, d), dim=1)
2626

pytorch3d/structures/meshes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ def _compute_edges_packed(self, refresh: bool = False):
10311031
unique_mask[1:] = sorted_hash[1:] != sorted_hash[:-1]
10321032
unique_idx = sort_idx[unique_mask]
10331033

1034-
self._edges_packed = torch.stack([u / V, u % V], dim=1)
1034+
self._edges_packed = torch.stack([u // V, u % V], dim=1)
10351035
self._edges_packed_to_mesh_idx = edge_to_mesh[unique_idx]
10361036

10371037
face_to_edge = torch.arange(3 * F).view(3, F).t()

tests/test_rasterizer.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@
2424
def convert_image_to_binary_mask(filename):
2525
with Image.open(filename) as raw_image:
2626
image = torch.from_numpy(np.array(raw_image))
27-
min = image.min()
28-
max = image.max()
29-
image_norm = (image - min) / (max - min)
30-
image_norm[image_norm > 0] == 1.0
31-
image_norm = image_norm.to(torch.int64)
27+
mx = image.max()
28+
image_norm = (image == mx).to(torch.int64)
3229
return image_norm
3330

3431

0 commit comments

Comments
 (0)