Repository: ivy-llc/ivy

Issue:
cond



Discussion:
- [ ] #7479 

Resolving patch:
diff --git a/ivy/functional/frontends/torch/linalg.py b/ivy/functional/frontends/torch/linalg.py
--- a/ivy/functional/frontends/torch/linalg.py
+++ b/ivy/functional/frontends/torch/linalg.py
@@ -87,6 +87,12 @@ def slogdet(input, *, out=None):
     return ivy.slogdet(input)
 
 
+@with_unsupported_dtypes({"2.0.0 and below": ("bfloat16", "float16")}, "torch")
+@to_ivy_arrays_and_back
+def cond(input, p=None, *, out=None):
+    return ivy.cond(input, p=p, out=out)
+
+
 @to_ivy_arrays_and_back
 def matrix_power(input, n, *, out=None):
     return ivy.matrix_power(input, n, out=out)
diff --git a/ivy/functional/ivy/control_flow_ops.py b/ivy/functional/ivy/control_flow_ops.py
--- a/ivy/functional/ivy/control_flow_ops.py
+++ b/ivy/functional/ivy/control_flow_ops.py
@@ -135,8 +135,8 @@ def for_loop(
     iterable
         The iterable to loop over.
     body_fn
-        A function to call each iteration, first taking the iterator value and then a tuple of
-        extra parameters.
+        A function to call each iteration, first taking the iterator value
+        and then a tuple of extra parameters.
     vars
         Extra parameters to be passed to body_fn.
 
@@ -159,7 +159,6 @@ def body_fn(k, args):
     >>> 6
     ```
     """
-
     iterator = iterable.__iter__()
 
     vars_dict = _tuple_to_dict(vars)


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_linalg.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_linalg.py
--- a/ivy_tests/test_ivy/test_frontends/test_torch/test_linalg.py
+++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_linalg.py
@@ -28,6 +28,34 @@ def _get_dtype_and_square_matrix(draw):
     return dtype, mat
 
 
+@st.composite
+def _get_dtype_and_matrix_non_singular(draw):
+    while True:
+        matrix = draw(
+            helpers.dtype_and_values(
+                available_dtypes=(
+                    ivy.float64,
+                    ivy.double,
+                ),
+                min_value=-10,
+                max_value=10,
+                min_num_dims=2,
+                max_num_dims=2,
+                min_dim_size=1,
+                max_dim_size=5,
+                shape=st.tuples(st.integers(1, 5), st.integers(1, 5)).filter(
+                    lambda x: x[0] == x[1]
+                ),
+                allow_inf=False,
+                allow_nan=False,
+            )
+        )
+        if np.linalg.det(matrix[1][0]) != 0:
+            break
+
+    return matrix[0], matrix[1]
+
+
 @st.composite
 def _get_dtype_and_matrix(draw):
     arbitrary_dims = draw(helpers.get_shape(max_dim_size=5))
@@ -407,6 +435,27 @@ def test_torch_eigvalsh(
     )
 
 
+@handle_frontend_test(
+    fn_tree="torch.linalg.cond",
+    dtype_and_x=_get_dtype_and_matrix_non_singular(),
+    p=st.sampled_from([None, "fro", "nuc", np.inf, -np.inf, 1, -1, 2, -2]),
+)
+def test_torch_cond(*, dtype_and_x, p, on_device, fn_tree, frontend, test_flags):
+    dtype, x = dtype_and_x
+    helpers.test_frontend_function(
+        input_dtypes=dtype,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        test_values=False,
+        input=x[0],
+        rtol=1e-2,
+        atol=1e-3,
+        p=p,
+    )
+
+
 # matrix_power
 @handle_frontend_test(
     fn_tree="torch.linalg.matrix_power",