Repository: ivy-llc/ivy

Issue:
blackman_window



Discussion:

Resolving patch:
diff --git a/ivy/functional/backends/jax/experimental/creation.py b/ivy/functional/backends/jax/experimental/creation.py
--- a/ivy/functional/backends/jax/experimental/creation.py
+++ b/ivy/functional/backends/jax/experimental/creation.py
@@ -118,9 +118,10 @@ def blackman_window(
         count = jnp.arange(size) / size
     else:
         count = jnp.linspace(start=0, stop=size, num=size)
-    return (0.42 - 0.5 * jnp.cos(2 * jnp.pi * count)) + (
-        0.08 * jnp.cos(2 * jnp.pi * 2 * count)
-    )
+    return (
+        (0.42 - 0.5 * jnp.cos(2 * jnp.pi * count))
+        + (0.08 * jnp.cos(2 * jnp.pi * 2 * count))
+    ).astype(dtype)
 
 
 def trilu(
diff --git a/ivy/functional/backends/tensorflow/experimental/creation.py b/ivy/functional/backends/tensorflow/experimental/creation.py
--- a/ivy/functional/backends/tensorflow/experimental/creation.py
+++ b/ivy/functional/backends/tensorflow/experimental/creation.py
@@ -107,14 +107,18 @@ def blackman_window(
     out: Optional[Union[tf.Tensor, tf.Variable]] = None,
 ) -> Union[tf.Tensor, tf.Variable]:
     if size < 2:
-        return tf.ones([size], dtype=tf.result_type(size, 0.0))
+        return tf.cast(
+            tf.ones([size], dtype=tf.experimental.numpy.result_type(size, 0.0)),
+            dtype=dtype,
+        )
     if periodic:
-        count = tf.arange(size) / size
+        count = tf.experimental.numpy.arange(size) / size
     else:
         count = tf.linspace(start=0, stop=size, num=size)
-
-    return (0.42 - 0.5 * tf.cos(2 * tf.pi * count)) + (
-        0.08 * tf.cos(2 * tf.pi * 2 * count)
+    return tf.cast(
+        (0.42 - 0.5 * tf.cos(2 * tf.experimental.numpy.pi * count))
+        + (0.08 * tf.cos(2 * tf.experimental.numpy.pi * 2 * count)),
+        dtype=dtype,
     )
 
 
diff --git a/ivy/functional/frontends/torch/spectral_ops.py b/ivy/functional/frontends/torch/spectral_ops.py
--- a/ivy/functional/frontends/torch/spectral_ops.py
+++ b/ivy/functional/frontends/torch/spectral_ops.py
@@ -1,5 +1,6 @@
 import ivy
 from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
+from ivy.func_wrapper import with_supported_dtypes
 
 
 @to_ivy_arrays_and_back
@@ -29,3 +30,17 @@ def bartlett_window(
         )
 
         return res[:-1] if periodic else res
+
+
+@to_ivy_arrays_and_back
+@with_supported_dtypes({"2.51.0 and below": ("float32", "float64")}, "torch")
+def blackman_window(
+    window_length,
+    periodic=True,
+    *,
+    dtype=None,
+    layout=None,
+    device=None,
+    requires_grad=False
+):
+    return ivy.blackman_window(window_length, periodic=periodic, dtype=dtype)


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_torch/test_spectral_ops.py b/ivy_tests/test_ivy/test_frontends/test_torch/test_spectral_ops.py
--- a/ivy_tests/test_ivy/test_frontends/test_torch/test_spectral_ops.py
+++ b/ivy_tests/test_ivy/test_frontends/test_torch/test_spectral_ops.py
@@ -1,5 +1,4 @@
 from hypothesis import strategies as st
-
 import ivy_tests.test_ivy.helpers as helpers
 from ivy_tests.test_ivy.helpers import handle_frontend_test
 
@@ -33,3 +32,35 @@ def test_torch_bartlett_window(
         rtol=1e-02,
         atol=1e-02,
     )
+
+
+@handle_frontend_test(
+    window_length=helpers.ints(min_value=1, max_value=100),
+    dtype=helpers.get_dtypes("float", full=False),
+    fn_tree="torch.blackman_window",
+    periodic=st.booleans(),
+)
+def test_torch_blackman_window(
+    *,
+    window_length,
+    dtype,
+    periodic,
+    on_device,
+    fn_tree,
+    frontend,
+    backend_fw,
+    test_flags,
+):
+    helpers.test_frontend_function(
+        input_dtypes=[],
+        on_device=on_device,
+        frontend=frontend,
+        backend_to_test=backend_fw,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        window_length=window_length,
+        periodic=periodic,
+        dtype=dtype[0],
+        rtol=1e-02,
+        atol=1e-02,
+    )