Repository: ivy-llc/ivy

Issue:
UnsortedSegmentProd



Discussion:
This issue has been labelled as stale. If you would like to continue working on this issue, then please add another comment or create a PR . If a PR has already been created which refers to this issue, then you should explicitly mention this issue in the relevant PR. For more information please refer to this page in our documentation: https://lets-unify.ai/ivy/contributing/1_the_basics.html#todo-list-issues
Working on this

Resolving patch:
diff --git a/ivy/functional/frontends/tensorflow/raw_ops.py b/ivy/functional/frontends/tensorflow/raw_ops.py
--- a/ivy/functional/frontends/tensorflow/raw_ops.py
+++ b/ivy/functional/frontends/tensorflow/raw_ops.py
@@ -853,6 +853,39 @@ def Unpack(*, value, num, axis=0, name="Unpack"):
     return ivy.unstack(value, axis=axis)[:num]
 
 
+@with_supported_dtypes(
+    {
+        "2.15.0 and below": (
+            "int8",
+            "int16",
+            "int32",
+            "int64",
+            "float32",
+            "float64",
+            "complex64",
+            "complex128",
+        )
+    },
+    "tensorflow",
+)
+@to_ivy_arrays_and_back
+def UnsortedSegmentProd(*, data, segment_ids, num_segments, name=None):
+    data = ivy.array(data)
+    segment_ids = ivy.array(segment_ids)
+
+    ivy.utils.assertions.check_equal(
+        list(segment_ids.shape), [list(data.shape)[0]], as_array=False
+    )
+    ivy.utils.assertions.check_greater(int(num_segments), int(ivy.max(segment_ids)))
+
+    shape = list(ivy.shape(data))
+    shape[0] = int(num_segments)
+    x = ivy.ones(shape, dtype=data.dtype)
+    for i in range((segment_ids).shape[0]):
+        x[segment_ids[i]] = ivy.multiply(x[segment_ids[i]], data[i])
+    return x
+
+
 @to_ivy_arrays_and_back
 def Xdivy(*, x, y, name="Xdivy"):
     if (x == 0).all():


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_raw_ops.py b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_raw_ops.py
--- a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_raw_ops.py
+++ b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_raw_ops.py
@@ -265,6 +265,40 @@ def _reshape_helper(draw):
     return x, dtype, reshape_shape
 
 
+@st.composite
+def _segment_ops_helper(draw):
+    shape_x = draw(st.integers(min_value=3, max_value=100))
+    shape_y = draw(st.integers(min_value=3, max_value=100))
+    max_val = draw(st.integers(min_value=3, max_value=9))
+    s_dtype = draw(
+        st.sampled_from(
+            [
+                "int32",
+                "int64",
+            ]
+        )
+    )
+    data_dtype, data = draw(
+        helpers.dtype_and_values(
+            available_dtypes=helpers.get_dtypes("valid"),
+            num_arrays=1,
+            shape=(shape_x, shape_y),
+            min_value=-max_val,
+            max_value=max_val,
+        )
+    )
+    seg_dtype, segment_ids = draw(
+        helpers.dtype_and_values(
+            available_dtypes=[s_dtype],
+            num_arrays=1,
+            shape=(shape_x,),
+            min_value=0,
+            max_value=max_val,
+        )
+    )
+    return data_dtype + seg_dtype, data, segment_ids, max_val
+
+
 @st.composite
 def _squeeze_helper(draw):
     shape = draw(st.shared(helpers.get_shape(), key="value_shape"))
@@ -4427,6 +4461,34 @@ def test_tensorflow_Unpack(  # NOQA
     )
 
 
+@handle_frontend_test(
+    fn_tree="tensorflow.raw_ops.UnsortedSegmentProd",
+    params=_segment_ops_helper(),
+    test_with_out=st.just(False),
+)
+def test_tensorflow_UnsortedSegmentProd(
+    *,
+    params,
+    frontend,
+    test_flags,
+    fn_tree,
+    backend_fw,
+    on_device,
+):
+    dtypes, data, segment_ids, max_val = params
+    helpers.test_frontend_function(
+        input_dtypes=dtypes,
+        backend_to_test=backend_fw,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        data=data[0],
+        segment_ids=segment_ids[0],
+        num_segments=max_val + 1,
+    )
+
+
 @handle_frontend_test(
     fn_tree="tensorflow.raw_ops.Xdivy",
     dtype_and_x=helpers.dtype_and_values(