Repository: ivy-llc/ivy

Issue:
normalize_moments



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/tensorflow/nn.py b/ivy/functional/frontends/tensorflow/nn.py
--- a/ivy/functional/frontends/tensorflow/nn.py
+++ b/ivy/functional/frontends/tensorflow/nn.py
@@ -318,6 +318,27 @@ def moments(x, axes, shift=None, keepdims=False, name=None):
     )
 
 
+@with_unsupported_dtypes({"2.12.0 and below":(
+            "int8",
+            "int16",
+            "int32",
+            "int64",
+            "bool",
+        )}, "tensorflow")
+@to_ivy_arrays_and_back
+def normalize_moments( counts, mean_ss, variance_ss, shift=None, name=None):
+    divisor = ivy.reciprocal(counts)
+    if shift is not None:
+        shifted_mean = ivy.multiply(mean_ss,divisor)
+        mean = ivy.add(shifted_mean,shift)
+    else:
+        shifted_mean = ivy.multiply(mean_ss,divisor)
+        mean = shifted_mean
+        
+    variance = ivy.subtract(ivy.multiply(variance_ss,divisor), ivy.square(shifted_mean))
+    return mean, variance
+
+
 @to_ivy_arrays_and_back
 def bias_add(value, bias, data_format=None, name=None):
     if data_format is None:


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_nn.py b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_nn.py
--- a/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_nn.py
+++ b/ivy_tests/test_ivy/test_frontends/test_tensorflow/test_nn.py
@@ -1166,6 +1166,84 @@ def test_tensorflow_moments(
         keepdims=keepdims,
     )
 
+# Normalize Moments
+@st.composite
+def _normalize_moments_helper(draw):
+    shape1, shape2, shape3 = draw(helpers.mutually_broadcastable_shapes(3))
+    counts_dtype, counts = draw(
+        helpers.dtype_and_values(
+            available_dtypes=helpers.get_dtypes("float"),
+            max_value=999,
+            min_value=-1001,
+            max_num_dims=1,
+            max_dim_size=1,
+            min_dim_size=1,
+        )
+    )
+    _, mean = draw(
+        helpers.dtype_and_values(
+            available_dtypes=counts_dtype,
+            shape=shape1,
+            min_value=1,
+            max_num_dims=1,
+            max_dim_size=1,
+            min_dim_size=1,
+        )
+    )
+    _, variance = draw(
+        helpers.dtype_and_values(
+            available_dtypes=counts_dtype,
+            shape=shape2,
+            min_value=1,
+            max_num_dims=1,
+            max_dim_size=1,
+            min_dim_size=1,
+            )
+    )
+    _,shift = draw(
+        helpers.dtype_and_values(
+            available_dtypes=counts_dtype,
+            shape=shape3,
+            min_value=1,
+            max_num_dims=1,
+            max_dim_size=1,
+            min_dim_size=1,
+        )
+    )
+
+    return counts_dtype, counts[0], mean[0], variance[0], shift[0]
+
+
+@handle_frontend_test(
+    fn_tree="tensorflow.nn.normalize_moments",
+    data=_normalize_moments_helper(),
+)
+
+def test_tensorflow_normalize_moments(
+    *,
+    data,
+    frontend,
+    test_flags,
+    fn_tree,
+    on_device,
+):
+ 
+    counts_dtype, counts, mean, variance, shift = data
+    helpers.test_frontend_function(
+        input_dtypes=counts_dtype,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        rtol=1e-1,
+        atol=1e-1,
+        counts=counts,
+        mean_ss=mean,
+        variance_ss=variance,
+        shift=shift,
+    )
+
+
 
 @st.composite
 def _generate_bias_data(draw):