Repository: ivy-llc/ivy

Issue:
Fix averages_and_variances.test_numpy_cov
|   |   |
|---|---|
|paddle|<a href="https://github.com/unifyai/ivy/actions/runs/6219910913"><img src=https://img.shields.io/badge/-failure-red></a>
|numpy|<a href="https://github.com/unifyai/ivy/actions/runs/6219910913"><img src=https://img.shields.io/badge/-failure-red></a>
|jax|<a href="https://github.com/unifyai/ivy/actions/runs/6219910913"><img src=https://img.shields.io/badge/-failure-red></a>
|tensorflow|<a href="https://github.com/unifyai/ivy/actions/runs/6219910913"><img src=https://img.shields.io/badge/-failure-red></a>
|torch|<a href="https://github.com/unifyai/ivy/actions/runs/6219910913"><img src=https://img.shields.io/badge/-failure-red></a>



Discussion:
start working

Resolving patch:
diff --git a/ivy/functional/frontends/numpy/statistics/averages_and_variances.py b/ivy/functional/frontends/numpy/statistics/averages_and_variances.py
--- a/ivy/functional/frontends/numpy/statistics/averages_and_variances.py
+++ b/ivy/functional/frontends/numpy/statistics/averages_and_variances.py
@@ -173,56 +173,28 @@ def nanstd(
 
 
 @to_ivy_arrays_and_back
-def cov(x, y=None, bias=False, dtype=None, fweights=None, aweights=None, ddof=None):
-    # check if inputs are valid
-    input_check = ivy.valid_dtype(dtype) and x.ndim in [0, 1]
-
-    if input_check:
-        x = ivy.array(x)
-        x = x.stack([], axis=0)
-        # if two input arrays are given
-        if ivy.exists(y) and y.ndim > 0:
-            x = x.stack(ivy.array(y), axis=0)
-
-        # compute the weights array
-        w = None
-        # if weights are 1D and positive
-        if ivy.exists(fweights):
-            if fweights.ndim < 2 and not fweights.min(keepdims=True)[0] > 0:
-                w = ivy.array(fweights)
-        if ivy.exists(aweights):
-            if aweights.ndim < 2 and not aweights.min(keepdims=True)[0] > 0:
-                w = w.multiply(aweights) if ivy.exists(w) else ivy.array(aweights)
-
-            # if w exists, use weighted average
-            xw = x.multiply(w)
-            w_sum = ivy.sum(w)
-            average = ivy.stable_divide(ivy.sum(xw, axis=1), w_sum)
-        else:
-            # else compute arithmetic average
-            average = ivy.mean(x, axis=1)
-
-        # compute the normalization
-        if ddof is None:
-            ddof = 1 if bias == 0 else 0
-
-        if w is None:
-            norm = x.shape[0] - ddof
-        elif ddof == 0:
-            norm = w_sum
-        elif aweights is None:
-            norm = w_sum - ddof
-        else:
-            norm = w_sum - ivy.stable_divide(ddof * ivy.sum(w * aweights), w_sum)
-
-        # compute residuals from average
-        x -= average[:]
-        # compute transpose matrix
-        x_t = ivy.matrix_transpose(x * w) if ivy.exists(w) else ivy.matrix_transpose(x)
-        # compute covariance matrix
-        c = ivy.stable_divide(ivy.matmul(x, x_t), norm).astype(dtype)
-
-        return c
+def cov(
+    m,
+    y=None,
+    /,
+    *,
+    rowVar=True,
+    bias=False,
+    ddof=None,
+    fweights=None,
+    aweights=None,
+    dtype=None,
+):
+    return ivy.cov(
+        m,
+        y,
+        rowVar=rowVar,
+        bias=bias,
+        ddof=ddof,
+        fweights=fweights,
+        aweights=aweights,
+        dtype=dtype,
+    )
 
 
 @handle_numpy_out


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_numpy/test_statistics/test_averages_and_variances.py b/ivy_tests/test_ivy/test_frontends/test_numpy/test_statistics/test_averages_and_variances.py
--- a/ivy_tests/test_ivy/test_frontends/test_numpy/test_statistics/test_averages_and_variances.py
+++ b/ivy_tests/test_ivy/test_frontends/test_numpy/test_statistics/test_averages_and_variances.py
@@ -241,36 +241,135 @@ def test_numpy_nanstd(
     )
 
 
+@st.composite
+def _get_dtype_value1_value2_cov(
+    draw,
+    available_dtypes,
+    min_num_dims,
+    max_num_dims,
+    min_dim_size,
+    max_dim_size,
+    abs_smallest_val=None,
+    min_value=None,
+    max_value=None,
+    allow_inf=False,
+    exclude_min=False,
+    exclude_max=False,
+    large_abs_safety_factor=4,
+    small_abs_safety_factor=4,
+    safety_factor_scale="log",
+):
+    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,
+        )
+    )
+
+    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]
+
+    # modifiers: rowVar, bias, ddof
+    rowVar = draw(st.booleans())
+    bias = draw(st.booleans())
+    ddof = draw(helpers.ints(min_value=0, max_value=1))
+
+    numVals = None
+    if rowVar is False:
+        numVals = -1 if numVals == 0 else 0
+    else:
+        numVals = 0 if len(shape) == 1 else -1
+
+    fweights = draw(
+        helpers.array_values(
+            dtype="int64",
+            shape=shape[numVals],
+            abs_smallest_val=1,
+            min_value=1,
+            max_value=10,
+            allow_inf=False,
+        )
+    )
+
+    aweights = draw(
+        helpers.array_values(
+            dtype="float64",
+            shape=shape[numVals],
+            abs_smallest_val=1,
+            min_value=1,
+            max_value=10,
+            allow_inf=False,
+            small_abs_safety_factor=1,
+        )
+    )
+
+    return [dtype], value1, value2, rowVar, bias, ddof, fweights, aweights
+
+
 # cov
 @handle_frontend_test(
     fn_tree="numpy.cov",
-    dtype_and_x=_statistical_dtype_values(function="cov"),
-    dtype=helpers.get_dtypes("float", full=False, none=True),
-    keep_dims=st.booleans(),
+    dtype_x1_x2_cov=_get_dtype_value1_value2_cov(
+        available_dtypes=helpers.get_dtypes("float"),
+        min_num_dims=1,
+        max_num_dims=2,
+        min_dim_size=2,
+        max_dim_size=5,
+        min_value=1,
+        max_value=1e10,
+        abs_smallest_val=0.01,
+        large_abs_safety_factor=2,
+        safety_factor_scale="log",
+    ),
     test_with_out=st.just(False),
 )
 def test_numpy_cov(
-    dtype_and_x,
-    dtype,
-    frontend,
+    dtype_x1_x2_cov,
     test_flags,
+    frontend,
     fn_tree,
     on_device,
 ):
-    input_dtypes, x, axis = dtype_and_x
-    if isinstance(axis, tuple):
-        axis = axis[0]
-
+    dtype, x1, x2, rowVar, bias, ddof, fweights, aweights = dtype_x1_x2_cov
     np_frontend_helpers.test_frontend_function(
-        input_dtypes=input_dtypes,
+        input_dtypes=[dtype[0], dtype[0], "int64", "float64"],
         frontend=frontend,
         test_flags=test_flags,
         fn_tree=fn_tree,
         on_device=on_device,
-        x=x[0],
-        axis=axis,
-        dtype=dtype[0],
-        test_values=False,
+        rtol=1e-2,
+        atol=1e-2,
+        m=x1,
+        y=x2,
+        rowvar=rowVar,
+        bias=bias,
+        ddof=ddof,
+        fweights=fweights,
+        aweights=aweights,
     )