Skip to content

Commit

Permalink
refactor(tests): Added new pre-commit hook for ordering functions (iv…
Browse files Browse the repository at this point in the history
  • Loading branch information
NripeshN authored and iababio committed Sep 8, 2023
1 parent 5882204 commit 0b37cdb
Show file tree
Hide file tree
Showing 57 changed files with 1,807 additions and 3,493 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ repos:
# Exclude everything in frontends except __init__.py, and func_wrapper.py
exclude: 'ivy/functional/(frontends|backends)/(?!.*/func_wrapper\.py$).*(?!__init__\.py$)'
- repo: https://github.com/unifyai/lint-hook
rev: 956eb831454d5a4fc3138467b85aedbf634140f0
rev: a90659d806c6d65f20ec41095a2da8e8920cc96f
hooks:
- id: ivy-lint
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
# --------------- #


# --- Helpers --- #
# --------------- #


def _swap_direction(norm):
try:
return _SWAP_DIRECTION_MAP[norm]
Expand Down
9 changes: 5 additions & 4 deletions ivy/functional/frontends/numpy/ma/MaskedArray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import ivy.functional.frontends.numpy as np_frontend
import numpy as np

masked = True
masked_print_options = "--"
nomask = False

Expand Down Expand Up @@ -194,10 +193,12 @@ def _array_in_str(self):
def _is_masked_array(x):
return isinstance(x, (np.ma.MaskedArray, np_frontend.ma.MaskedArray))

# Instance Methods #
# ---------------- #

# TODO
masked = True
# Instance Methods #
# ---------------- #

# TODO


# masked_array (alias)
Expand Down
8 changes: 5 additions & 3 deletions ivy/functional/frontends/tensorflow/raw_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

Acos = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.acos))
Acosh = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.acosh))
Add = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.add))
AddN = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.add_n))
AddV2 = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.add))
ArgMax = to_ivy_arrays_and_back(
Expand Down Expand Up @@ -220,7 +219,6 @@
)
Sin = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.sin))
Size = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.general_functions.size))
Slice = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.slice))
Softmax = to_ivy_arrays_and_back(
with_unsupported_dtypes(
{
Expand Down Expand Up @@ -253,7 +251,6 @@
Squeeze = to_ivy_arrays_and_back(
map_raw_ops_alias(tf_frontend.general_functions.squeeze)
)
Sub = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.subtract))
Tan = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.tan))
Tanh = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.tanh))
Xlogy = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.xlogy))
Expand Down Expand Up @@ -831,3 +828,8 @@ def Xlog1py(*, x, y, name="Xlog1py"):
@to_ivy_arrays_and_back
def ZerosLike(*, x, name="ZerosLike"):
return ivy.zeros_like(x)


Add = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.add))
Slice = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.slice))
Sub = to_ivy_arrays_and_back(map_raw_ops_alias(tf_frontend.math.subtract))
4 changes: 2 additions & 2 deletions ivy/functional/frontends/torch/comparison_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ def topk(input, k, dim=None, largest=True, sorted=True, *, out=None):
return ivy.top_k(input, k, axis=dim, largest=largest, sorted=sorted, out=out)


ge = greater_equal
gt = greater
ne = not_equal
ge = greater_equal
le = less_equal
lt = less
ne = not_equal
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ def test_jax_elu(
fn_tree="jax.nn.gelu",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float_and_complex"),
large_abs_safety_factor=1,
small_abs_safety_factor=1,
safety_factor_scale="linear",
min_value=-1e4,
max_value=1e4,
abs_smallest_val=1e-3,
),
approximate=st.booleans(),
test_with_out=st.just(False),
Expand All @@ -125,7 +127,7 @@ def test_jax_gelu(
):
input_dtype, x = dtype_and_x
# As erf function doesn't support complex dtype
if "complex" in input_dtype[0]:
if "complex" in str(x[0].dtype):
approximate = True
helpers.test_frontend_function(
input_dtypes=input_dtype,
Expand All @@ -134,8 +136,8 @@ def test_jax_gelu(
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
rtol=1e-2,
atol=1e-2,
rtol=1e-02,
atol=1e-02,
x=x[0],
approximate=approximate,
)
Expand Down Expand Up @@ -315,9 +317,7 @@ def test_jax_hard_tanh(
small_abs_safety_factor=2,
safety_factor_scale="linear",
),
negative_slope=helpers.floats(
min_value=0.0, max_value=1.0, small_abs_safety_factor=16
),
negative_slope=helpers.floats(min_value=0.0, max_value=1.0),
test_with_out=st.just(False),
)
def test_jax_leaky_relu(
Expand Down Expand Up @@ -735,9 +735,9 @@ def test_jax_soft_sign(
@handle_frontend_test(
fn_tree="jax.nn.softmax",
dtype_x_axis=helpers.dtype_values_axis(
available_dtypes=helpers.get_dtypes("float_and_complex"),
available_dtypes=helpers.get_dtypes("float"),
min_num_dims=2,
max_axes_size=2,
max_axes_size=1,
force_int_axis=True,
valid_axis=True,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,46 +543,6 @@ def test_jax_ceil(
)


# clip
@handle_frontend_test(
fn_tree="jax.numpy.clip",
dtype_and_x=helpers.dtype_and_values(
available_dtypes=helpers.get_dtypes("float_and_integer"),
min_value=-1e3,
max_value=1e3,
max_dim_size=10,
max_num_dims=4,
min_dim_size=1,
min_num_dims=1,
),
a_min=st.integers(min_value=0, max_value=5),
a_max=st.integers(min_value=5, max_value=10),
)
def test_jax_clip(
*,
dtype_and_x,
a_min,
a_max,
on_device,
fn_tree,
frontend,
backend_fw,
test_flags,
):
input_dtype, x = dtype_and_x
helpers.test_frontend_function(
input_dtypes=input_dtype,
frontend=frontend,
backend_to_test=backend_fw,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
a=x[0],
a_min=a_min,
a_max=a_max,
)


# conj
@handle_frontend_test(
fn_tree="jax.numpy.conj",
Expand Down Expand Up @@ -1486,49 +1446,6 @@ def test_jax_gcd(
)


# gradient
@handle_frontend_test(
fn_tree="jax.numpy.gradient",
dtype_input_axis=helpers.dtype_values_axis(
available_dtypes=("float32", "float16", "float64"),
min_num_dims=1,
max_num_dims=3,
min_dim_size=2,
max_dim_size=4,
valid_axis=True,
force_int_axis=True,
),
varargs=helpers.ints(
min_value=-3,
max_value=3,
),
)
def test_jax_gradient(
dtype_input_axis,
varargs,
frontend,
backend_fw,
test_flags,
fn_tree,
on_device,
):
input_dtype, x, axis = dtype_input_axis
test_flags.num_positional_args = 2
kw = {}
kw["varargs"] = varargs
kw["axis"] = axis
helpers.test_frontend_function(
input_dtypes=input_dtype,
frontend=frontend,
backend_to_test=backend_fw,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
f=x[0],
**kw,
)


# heaviside
@handle_frontend_test(
fn_tree="jax.numpy.heaviside",
Expand Down
56 changes: 0 additions & 56 deletions ivy_tests/test_ivy/test_frontends/test_jax/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,62 +820,6 @@ def call():
assert u.shape == v.shape


@pytest.mark.xfail
@handle_frontend_test(
fn_tree="jax.random.logistic",
dtype_key=helpers.dtype_and_values(
available_dtypes=["uint32"],
min_value=0,
max_value=2000,
min_num_dims=1,
max_num_dims=1,
min_dim_size=2,
max_dim_size=2,
),
shape=helpers.get_shape(allow_none=False, min_num_dims=1, min_dim_size=1),
dtype=helpers.get_dtypes("float", full=False),
test_with_out=st.just(False),
)
def test_jax_logistic(
*,
dtype_key,
shape,
dtype,
on_device,
fn_tree,
frontend,
backend_fw,
test_flags,
):
input_dtype, key = dtype_key

def call():
return helpers.test_frontend_function(
input_dtypes=input_dtype,
frontend=frontend,
backend_to_test=backend_fw,
test_flags=test_flags,
fn_tree=fn_tree,
on_device=on_device,
key=key[0],
shape=shape,
dtype=dtype[0],
test_values=False,
)

ret = call()

if not ivy.exists(ret):
return

ret_np, ret_from_np = ret
ret_np = helpers.flatten_and_to_np(ret=ret_np, backend=backend_fw)
ret_from_np = helpers.flatten_and_to_np(ret=ret_from_np, backend=backend_fw)
for u, v in zip(ret_np, ret_from_np):
assert u.dtype == v.dtype
assert u.shape == v.shape


@pytest.mark.xfail
@handle_frontend_test(
fn_tree="jax.random.maxwell",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,52 +665,6 @@ def test_mindspore_log_softmax(
# )


# max_pool3d
@pytest.mark.skip("Testing pipeline not yet implemented")
@handle_frontend_test(
fn_tree="mindspore.ops.function.nn_func.max_pool3d",
x_k_s_p=helpers.arrays_for_pooling(
min_dims=5,
max_dims=5,
min_side=1,
max_side=4,
only_explicit_padding=True,
return_dilation=True,
data_format="channel_first",
),
test_with_out=st.just(False),
ceil_mode=st.sampled_from([True, False]),
)
def test_mindspore_max_pool3d(
x_k_s_p,
ceil_mode,
*,
test_flags,
frontend,
backend_fw,
fn_tree,
on_device,
):
input_dtypes, x, kernel_size, stride, padding, dilation = x_k_s_p

padding = (padding[0][0], padding[1][0], padding[2][0])

helpers.test_frontend_function(
input_dtypes=input_dtypes,
backend_to_test=backend_fw,
test_flags=test_flags,
frontend=frontend,
fn_tree=fn_tree,
on_device=on_device,
input=x[0],
kernel_size=kernel_size,
stride=stride,
padding=padding,
dilation=dilation,
ceil_mode=ceil_mode,
)


# pad
@pytest.mark.skip("Testing pipeline not yet implemented")
@handle_frontend_test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import ivy_tests.test_ivy.helpers as helpers
from ivy_tests.test_ivy.helpers import handle_frontend_test
from ivy_tests.test_ivy.test_functional.test_experimental.test_nn.test_layers import (
_x_and_ifft,
_x_and_rfftn,
x_and_ifft,
x_and_rfftn,
)


Expand Down Expand Up @@ -90,7 +90,7 @@ def test_numpy_fftshift(

@handle_frontend_test(
fn_tree="numpy.fft.ifft",
dtype_and_x=_x_and_ifft(),
dtype_and_x=x_and_ifft(),
)
def test_numpy_ifft(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device):
input_dtype, x, dim, norm, n = dtype_and_x
Expand All @@ -111,7 +111,7 @@ def test_numpy_ifft(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_d

@handle_frontend_test(
fn_tree="numpy.fft.ifftn",
dtype_and_x=_x_and_ifft(),
dtype_and_x=x_and_ifft(),
)
def test_numpy_ifftn(dtype_and_x, backend_fw, frontend, test_flags, fn_tree, on_device):
input_dtype, x, dim, norm, n = dtype_and_x
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_numpy_rfftfreq(

@handle_frontend_test(
fn_tree="numpy.fft.rfftn",
dtype_and_x=_x_and_rfftn(),
dtype_and_x=x_and_rfftn(),
)
def test_numpy_rfftn(dtype_and_x, frontend, backend_fw, test_flags, fn_tree, on_device):
dtype, x, s, axes, norm = dtype_and_x
Expand Down
Loading

0 comments on commit 0b37cdb

Please sign in to comment.