Skip to content

Commit

Permalink
Final update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sameerk22 committed Sep 6, 2023
1 parent 43f4291 commit 4d15c73
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ivy/functional/frontends/paddle/nn/functional/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@
from ivy.utils.assertions import check_equal


@to_ivy_arrays_and_back
def pixel_unshuffle(x, downscale_factor, data_format="NCHW"):
input_shape = ivy.shape(x)

if data_format == "NCHW":
b, c, h, w = input_shape
else:
b, h, w, c = input_shape

check_equal(
c % (downscale_factor ** 2),
0,
message=(
"pixel unshuffle expects input channel to be divisible by square of downscale"
" factor, but got input with size {}, downscale factor={}, and"
" self.size(1)={}, is not divisible by {}".format(
input_shape, downscale_factor, c, downscale_factor ** 2
)
),
as_array=False,
)

oc = c // (downscale_factor ** 2)
oh = h // downscale_factor
ow = w // downscale_factor

if data_format == "NCHW":
x_reshaped = ivy.reshape(x, (b, oc, downscale_factor, downscale_factor, oh, ow))
else:
x_reshaped = ivy.reshape(x, (b, oh, ow, downscale_factor, downscale_factor, oc))

if data_format == "NCHW":
return ivy.reshape(
ivy.permute_dims(x_reshaped, (0, 1, 4, 2, 5, 3)), (b, oc, oh, ow)
)
return ivy.reshape(
ivy.permute_dims(x_reshaped, (0, 4, 1, 5, 2, 3)), (b, oh, ow, oc)
)

@to_ivy_arrays_and_back
@with_unsupported_dtypes({"2.5.1 and below": ("float16", "bfloat16")}, "paddle")
def affine_grid(theta, out_shape, align_corners=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,47 @@
# --- Helpers --- #
# --------------- #

#pixel_unshuffle
@handle_frontend_test(
fn_tree="paddle.nn.functional.pixel_unshuffle",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=["float32", "float64"],
min_value=0,
min_num_dims=4,
max_num_dims=4,
min_dim_size=3,
),
downscale_factor=helpers.ints(min_value=1),
data_format=st.sampled_from(["NCHW", "NHWC"]),
)

def test_paddle_pixel_unshuffle(
*,
dtype_and_x,
downscale_factor,
data_format,
on_device,
fn_tree,
frontend,
test_flags,
backend_fw,
):
input_dtype, x = dtype_and_x
if data_format == "NCHW":
assume(ivy.shape(x[0])[1] % (downscale_factor**2) == 0)
else:
assume(ivy.shape(x[0])[3] % (downscale_factor**2) == 0)
helpers.test_frontend_function(
input_dtypes=input_dtype,
frontend=frontend,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
x=x[0],
downscale_factor=downscale_factor,
data_format=data_format,
backend_to_test=backend_fw,
)

@st.composite
def _affine_grid_helper(draw):
Expand Down

0 comments on commit 4d15c73

Please sign in to comment.