Skip to content

Commit

Permalink
fixed asarray for paddle backend and other frontend methods tests (iv…
Browse files Browse the repository at this point in the history
…y-llc#21176)

Added a check at paddle backend to not clone empty tensors, and fixed complex errors in max and min functions of the paddle backend, fixed other ndarray frontend tests along the way.
  • Loading branch information
fnhirwa authored Aug 2, 2023
1 parent 0a7a0cb commit b91ea4d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
9 changes: 7 additions & 2 deletions ivy/functional/backends/paddle/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ def asarray(
device = ivy.as_native_dev(device)
if isinstance(obj, paddle.Tensor):
if copy:
ret = obj.clone().detach()
ret.stop_gradient = obj.stop_gradient
# Checking if the tensor is not empty
# As clone is not supported for empty tensors
if all(obj.shape):
ret = obj.clone().detach()
ret.stop_gradient = obj.stop_gradient
else:
ret = obj
else:
ret = obj
return to_device(ret, device).astype(dtype)
Expand Down
12 changes: 6 additions & 6 deletions ivy/functional/backends/paddle/statistical.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def min(
paddle.int16,
paddle.uint8,
paddle.float16,
paddle.bfloat16,
paddle.complex64,
paddle.complex128,
paddle.bool,
]:
if paddle.is_complex(x):
real = paddle.amin(x.real(), axis=axis, keepdim=keepdims)
masked_x = paddle_backend.greater_equal(x, paddle.amin(x.real())) * x
imag = paddle.amin(masked_x.imag(), axis=axis, keepdim=keepdims)
imag = paddle.amin(x.imag(), axis=axis, keepdim=keepdims)
ret = paddle.complex(real, imag)
else:
ret = paddle.amin(x.cast("float32"), axis=axis, keepdim=keepdims)
Expand Down Expand Up @@ -67,16 +67,16 @@ def max(
paddle.int8,
paddle.int16,
paddle.uint8,
paddle.bfloat16,
paddle.float16,
paddle.complex64,
paddle.complex128,
paddle.bool,
]:
if paddle.is_complex(x):
real = paddle.amax(x.real(), axis=axis, keepdim=keepdims)
masked_x = paddle_backend.greater_equal(x, paddle.amax(x.real())) * x
imag = paddle.amax(masked_x.imag(), axis=axis, keepdim=keepdims)
ret = paddle.complex(real, imag)
real_part = paddle.amax(x.real(), axis=axis, keepdim=keepdims)
imag_part = paddle.amax(x.imag(), axis=axis, keepdim=keepdims)
ret = paddle.complex(real_part, imag_part)
else:
ret = paddle.amax(x.cast("float32"), axis=axis, keepdim=keepdims)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3275,6 +3275,9 @@ def test_numpy_view(
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float"),
num_arrays=2,
large_abs_safety_factor=2,
small_abs_safety_factor=2,
safety_factor_scale="log",
min_value=0,
exclude_min=True,
),
Expand Down Expand Up @@ -3304,6 +3307,8 @@ def test_numpy___mod__(
init_flags=init_flags,
method_flags=method_flags,
on_device=on_device,
rtol_=1e-5,
atol_=1e-5,
)


Expand Down Expand Up @@ -3399,14 +3404,21 @@ def _item_helper(draw):
args_kwargs=_item_helper(),
)
def test_numpy_instance_item(
args_kwargs, frontend_method_data, init_flags, method_flags, frontend, on_device
args_kwargs,
frontend_method_data,
init_flags,
method_flags,
frontend,
on_device,
backend_fw,
):
input_dtype, x, method_all_as_kwargs_np, num_positional_args = args_kwargs
method_flags.num_positional_args = num_positional_args
helpers.test_frontend_method(
init_input_dtypes=input_dtype,
init_all_as_kwargs_np={"object": x},
method_input_dtypes=input_dtype,
backend_to_test=backend_fw,
method_all_as_kwargs_np=method_all_as_kwargs_np,
frontend=frontend,
frontend_method_data=frontend_method_data,
Expand Down

0 comments on commit b91ea4d

Please sign in to comment.