Skip to content

Commit 93a7905

Browse files
committed
Switch to if/else impl
1 parent 5112253 commit 93a7905

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

torchvision/transforms/functional_tensor.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ def get_image_num_channels(img: Tensor) -> int:
4545

4646

4747
def _max_value(dtype: torch.dtype) -> int:
48-
return {
49-
torch.uint8: int(2 ** 8) - 1,
50-
torch.int8: int(2 ** 7) - 1,
51-
torch.int16: int(2 ** 15) - 1,
52-
torch.int32: int(2 ** 31) - 1,
53-
torch.int64: int(2 ** 63) - 1,
54-
}.get(dtype, 1)
48+
if dtype == torch.uint8:
49+
return int(2 ** 8) - 1
50+
elif dtype == torch.int8:
51+
return int(2 ** 7) - 1
52+
elif dtype == torch.int16:
53+
return int(2 ** 15) - 1
54+
elif dtype == torch.int32:
55+
return int(2 ** 31) - 1
56+
elif dtype == torch.int64:
57+
return int(2 ** 63) - 1
58+
else:
59+
return 1
5560

5661

5762
def _assert_channels(img: Tensor, permitted: List[int]) -> None:

0 commit comments

Comments
 (0)