Repository: ivy-llc/ivy

Issue:
cross



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/numpy/__init__.py b/ivy/functional/frontends/numpy/__init__.py
--- a/ivy/functional/frontends/numpy/__init__.py
+++ b/ivy/functional/frontends/numpy/__init__.py
@@ -500,6 +500,7 @@ def promote_types_of_numpy_inputs(
     # einsum,
     # einsum_path,
     kron,
+    cross,
 )
 
 from .linalg.decompositions import cholesky, qr, svd
diff --git a/ivy/functional/frontends/numpy/linalg/matrix_and_vector_products.py b/ivy/functional/frontends/numpy/linalg/matrix_and_vector_products.py
--- a/ivy/functional/frontends/numpy/linalg/matrix_and_vector_products.py
+++ b/ivy/functional/frontends/numpy/linalg/matrix_and_vector_products.py
@@ -58,6 +58,11 @@ def kron(a, b):
     return ivy.kron(a, b)
 
 
+@to_ivy_arrays_and_back
+def cross(a, b, *, axisa=-1, axisb=-1, axisc=-1, axis=None):
+    return ivy.cross(a, b, axisa=axisa, axisb=axisb, axisc=axisc, axis=axis)
+
+
 @with_unsupported_dtypes({"2.0.0 and below": ("float16",)}, "torch")
 @handle_numpy_out
 @to_ivy_arrays_and_back


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/helpers.py b/ivy_tests/test_ivy/test_frontends/test_numpy/helpers.py
--- a/ivy_tests/test_ivy/test_frontends/test_numpy/helpers.py
+++ b/ivy_tests/test_ivy/test_frontends/test_numpy/helpers.py
@@ -29,6 +29,68 @@ def dtype_x_bounded_axis(draw, **kwargs):
     return dtype, x, axis
 
 
+@st.composite
+def dtype_value1_value2_axis(
+    draw,
+    available_dtypes,
+    abs_smallest_val=None,
+    min_value=None,
+    max_value=None,
+    allow_inf=False,
+    exclude_min=False,
+    exclude_max=False,
+    min_num_dims=1,
+    max_num_dims=10,
+    min_dim_size=1,
+    max_dim_size=10,
+    specific_dim_size=3,
+    large_abs_safety_factor=4,
+    small_abs_safety_factor=4,
+    safety_factor_scale="log",
+):
+    # Taken from functional helpers
+    # For cross product, a dim with size 3 is required
+    shape = draw(
+        helpers.get_shape(
+            allow_none=False,
+            min_num_dims=min_num_dims,
+            max_num_dims=max_num_dims,
+            min_dim_size=min_dim_size,
+            max_dim_size=max_dim_size,
+        )
+    )
+    axis = draw(helpers.ints(min_value=0, max_value=len(shape)))
+    # make sure there is a dim with specific dim size
+    shape = list(shape)
+    shape = shape[:axis] + [specific_dim_size] + shape[axis:]
+    shape = tuple(shape)
+
+    dtype = draw(st.sampled_from(draw(available_dtypes)))
+
+    values = []
+    for i in range(2):
+        values.append(
+            draw(
+                helpers.array_values(
+                    dtype=dtype,
+                    shape=shape,
+                    abs_smallest_val=abs_smallest_val,
+                    min_value=min_value,
+                    max_value=max_value,
+                    allow_inf=allow_inf,
+                    exclude_min=exclude_min,
+                    exclude_max=exclude_max,
+                    large_abs_safety_factor=large_abs_safety_factor,
+                    small_abs_safety_factor=small_abs_safety_factor,
+                    safety_factor_scale=safety_factor_scale,
+                )
+            )
+        )
+
+    value1, value2 = values[0], values[1]
+    return [dtype], value1, value2, axis
+
+
 @st.composite
 def _array_and_axes_permute_helper(
     draw,
diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_linear_algebra/test_matrix_and_vector_products.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_linear_algebra/test_matrix_and_vector_products.py
--- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_linear_algebra/test_matrix_and_vector_products.py
+++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_linear_algebra/test_matrix_and_vector_products.py
@@ -78,6 +78,45 @@ def test_numpy_inner(
     )
 
 
+# cross
+@handle_frontend_test(
+    fn_tree="numpy.cross",
+    dtype_x1_x2_axis=np_frontend_helpers.dtype_value1_value2_axis(
+        available_dtypes=helpers.get_dtypes("numeric"),
+        min_num_dims=1,
+        max_num_dims=5,
+        min_dim_size=3,
+        max_dim_size=3,
+        min_value=-1e5,
+        max_value=1e5,
+        abs_smallest_val=0.01,
+        safety_factor_scale="log",
+    ),
+    test_with_out=st.just(True),
+)
+def test_numpy_cross(
+    *,
+    dtype_x1_x2_axis,
+    frontend,
+    test_flags,
+    fn_tree,
+    on_device,
+):
+    dtypes, x1, x2, axis = dtype_x1_x2_axis
+    helpers.test_frontend_function(
+        input_dtypes=dtypes,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        rtol=1e-3,
+        atol=1e-3,
+        a=x1,
+        b=x2,
+        axis=axis,
+    )
+
+
 # matmul
 @handle_frontend_test(
     fn_tree="numpy.matmul",