Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
346f6dd9
Unverified
Commit
346f6dd9
authored
Nov 28, 2022
by
Philip Meier
Committed by
GitHub
Nov 28, 2022
Browse files
use bitshifts for int to int in convert_dtype (#6978)
parent
51e8dace
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
9 deletions
+1
-9
torchvision/prototype/transforms/functional/_meta.py
torchvision/prototype/transforms/functional/_meta.py
+1
-9
No files found.
torchvision/prototype/transforms/functional/_meta.py
View file @
346f6dd9
...
@@ -379,15 +379,7 @@ def convert_dtype_image_tensor(image: torch.Tensor, dtype: torch.dtype = torch.f
...
@@ -379,15 +379,7 @@ def convert_dtype_image_tensor(image: torch.Tensor, dtype: torch.dtype = torch.f
if
num_value_bits_input
>
num_value_bits_output
:
if
num_value_bits_input
>
num_value_bits_output
:
return
image
.
bitwise_right_shift
(
num_value_bits_input
-
num_value_bits_output
).
to
(
dtype
)
return
image
.
bitwise_right_shift
(
num_value_bits_input
-
num_value_bits_output
).
to
(
dtype
)
else
:
else
:
# The bitshift kernel is not vectorized
return
image
.
to
(
dtype
).
bitwise_left_shift_
(
num_value_bits_output
-
num_value_bits_input
)
# https://github.com/pytorch/pytorch/blob/703c19008df4700b6a522b0ae5c4b6d5ffc0906f/aten/src/ATen/native/cpu/BinaryOpsKernel.cpp#L315-L322
# This results in the multiplication actually being faster.
# TODO: If the bitshift kernel is optimized in core, replace the computation below with
# `image.to(dtype).bitwise_left_shift_(num_value_bits_output - num_value_bits_input)`
max_value_input
=
float
(
_FT
.
_max_value
(
dtype
))
max_value_output
=
float
(
_FT
.
_max_value
(
image
.
dtype
))
factor
=
int
((
max_value_input
+
1
)
//
(
max_value_output
+
1
))
return
image
.
to
(
dtype
).
mul_
(
factor
)
# We changed the name to align it with the new naming scheme. Still, `convert_image_dtype` is
# We changed the name to align it with the new naming scheme. Still, `convert_image_dtype` is
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment