We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
blackman_window


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ivy/functional/backends/jax/experimental/creation.py`
Content:
```
1 # global
2 from typing import Optional, Tuple
3 import math
4 import jax
5 import jax.numpy as jnp
6 import jaxlib.xla_extension
7 
8 # local
9 from ivy.functional.backends.jax import JaxArray
10 import ivy
11 
12 # Array API Standard #
13 # ------------------ #
14 
15 
16 def vorbis_window(
17     window_length: JaxArray,
18     *,
19     dtype: jnp.dtype = jnp.float32,
20     out: Optional[JaxArray] = None,
21 ) -> JaxArray:
22     return jnp.array(
23         [
24             round(
25                 math.sin(
26                     (ivy.pi / 2) * (math.sin(ivy.pi * (i) / (window_length * 2)) ** 2)
27                 ),
28                 8,
29             )
30             for i in range(1, window_length * 2)[0::2]
31         ],
32         dtype=dtype,
33     )
34 
35 
36 def hann_window(
37     size: int,
38     /,
39     *,
40     periodic: bool = True,
41     dtype: Optional[jnp.dtype] = None,
42     out: Optional[JaxArray] = None,
43 ) -> JaxArray:
44     if size < 2:
45         return jnp.ones([size], dtype=dtype)
46     if periodic:
47         count = jnp.arange(size) / size
48     else:
49         count = jnp.linspace(start=0, stop=size, num=size)
50     return (0.5 - 0.5 * jnp.cos(2 * jnp.pi * count)).astype(dtype)
51 
52 
53 def kaiser_window(
54     window_length: int,
55     periodic: bool = True,
56     beta: float = 12.0,
57     *,
58     dtype: Optional[jnp.dtype] = None,
59     out: Optional[JaxArray] = None,
60 ) -> JaxArray:
61     if window_length < 2:
62         return jnp.ones([window_length], dtype=dtype)
63     if periodic is False:
64         return jnp.kaiser(M=window_length, beta=beta).astype(dtype)
65     else:
66         return jnp.kaiser(M=window_length + 1, beta=beta)[:-1].astype(dtype)
67 
68 
69 def tril_indices(
70     n_rows: int,
71     n_cols: Optional[int] = None,
72     k: int = 0,
73     /,
74     *,
75     device: jaxlib.xla_extension.Device,
76 ) -> Tuple[JaxArray, ...]:
77     return jnp.tril_indices(n=n_rows, k=k, m=n_cols)
78 
79 
80 def unsorted_segment_min(
81     data: JaxArray,
82     segment_ids: JaxArray,
83     num_segments: int,
84 ) -> JaxArray:
85     # added this check to keep the same behaviour as tensorflow
86     ivy.utils.assertions.check_unsorted_segment_min_valid_params(
87         data, segment_ids, num_segments
88     )
89     return jax.ops.segment_min(data, segment_ids, num_segments)
90 
91 
92 def unsorted_segment_sum(
93     data: JaxArray,
94     segment_ids: JaxArray,
95     num_segments: int,
96 ) -> JaxArray:
97     # Used the same check which is used for unsorted_segment_min as
98     # the check should be same
99     # Might require to change the assertion function name to
100     # check_unsorted_segment_valid_params
101     ivy.utils.assertions.check_unsorted_segment_min_valid_params(
102         data, segment_ids, num_segments
103     )
104     return jax.ops.segment_sum(data, segment_ids, num_segments)
105 
106 
107 def blackman_window(
108     size: int,
109     /,
110     *,
111     periodic: bool = True,
112     dtype: Optional[jnp.dtype] = None,
113     out: Optional[JaxArray] = None,
114 ) -> JaxArray:
115     if size < 2:
116         return jnp.ones([size], dtype=dtype)
117     if periodic:
118         count = jnp.arange(size) / size
119     else:
120         count = jnp.linspace(start=0, stop=size, num=size)
121     return (0.42 - 0.5 * jnp.cos(2 * jnp.pi * count)) + (
122         0.08 * jnp.cos(2 * jnp.pi * 2 * count)
123     )
124 
125 
126 def trilu(
127     x: JaxArray, /, *, k: int = 0, upper: bool = True, out: Optional[JaxArray] = None
128 ) -> JaxArray:
129     if upper:
130         return jnp.triu(x, k)
131     return jnp.tril(x, k)
132 
133 
134 def mel_weight_matrix(
135     num_mel_bins: int,
136     dft_length: int,
137     sample_rate: int,
138     lower_edge_hertz: float = 0.0,
139     upper_edge_hertz: float = 3000.0,
140 ):
141     lower_edge_hertz = jnp.array(lower_edge_hertz)
142     upper_edge_hertz = jnp.array(upper_edge_hertz)
143     zero = jnp.array(0.0)
144     hz_to_mel = lambda f: 2595 * jnp.log10(1 + f / 700)
145     nyquist_hz = sample_rate / 2
146     linear_freqs = jnp.linspace(0, nyquist_hz, dft_length, dtype=jnp.float32)[1:]
147     spec_bin_mels = hz_to_mel(linear_freqs)[..., None]
148     mel_edges = jnp.linspace(
149         hz_to_mel(lower_edge_hertz),
150         hz_to_mel(upper_edge_hertz),
151         num_mel_bins + 2,
152         dtype=jnp.float32,
153     )
154     mel_edges = jnp.stack([mel_edges[i : i + 3] for i in range(num_mel_bins)])
155     lower_edge_mel, center_mel, upper_edge_mel = [
156         t.reshape((1, num_mel_bins)) for t in jnp.split(mel_edges, 3, axis=1)
157     ]
158     lower_slopes = (spec_bin_mels - lower_edge_mel) / (center_mel - lower_edge_mel)
159     upper_slopes = (upper_edge_mel - spec_bin_mels) / (upper_edge_mel - center_mel)
160     mel_weights = jnp.maximum(zero, jnp.minimum(lower_slopes, upper_slopes))
161     return jnp.pad(mel_weights, [[1, 0], [0, 0]])
162
```

Path: `ivy/functional/backends/tensorflow/experimental/creation.py`
Content:
```
1 # global
2 
3 from typing import Union, Optional, Tuple
4 import tensorflow as tf
5 
6 # local
7 from ivy.func_wrapper import with_unsupported_device_and_dtypes, with_unsupported_dtypes
8 from .. import backend_version
9 
10 
11 # Array API Standard #
12 # -------------------#
13 
14 
15 @with_unsupported_device_and_dtypes(
16     {"2.13.0 and below": {"cpu": ("bfloat16",)}},
17     backend_version,
18 )
19 def kaiser_window(
20     window_length: int,
21     periodic: bool = True,
22     beta: float = 12.0,
23     *,
24     dtype: Optional[tf.DType] = None,
25     out: Optional[Union[tf.Tensor, tf.Variable]] = None,
26 ) -> Union[tf.Tensor, tf.Variable]:
27     if window_length < 2:
28         return tf.ones([window_length], dtype=dtype)
29     if periodic is False:
30         return tf.signal.kaiser_window(window_length, beta, dtype=dtype)
31     else:
32         return tf.signal.kaiser_window(window_length + 1, beta, dtype=dtype)[:-1]
33 
34 
35 def kaiser_bessel_derived_window(
36     window_length: int,
37     beta: float = 12.0,
38     *,
39     dtype: Optional[tf.DType] = None,
40     out: Optional[Union[tf.Tensor, tf.Variable]] = None,
41 ) -> Union[tf.Tensor, tf.Variable]:
42     return tf.signal.kaiser_bessel_derived_window(window_length, beta, dtype)
43 
44 
45 def vorbis_window(
46     window_length: Union[tf.Tensor, tf.Variable],
47     *,
48     dtype: tf.DType = tf.dtypes.float32,
49     out: Optional[Union[tf.Tensor, tf.Variable]] = None,
50 ) -> Union[tf.Tensor, tf.Variable]:
51     return tf.signal.vorbis_window(window_length, dtype=dtype, name=None)
52 
53 
54 def hann_window(
55     size: int,
56     /,
57     *,
58     periodic: bool = True,
59     dtype: Optional[tf.DType] = None,
60     out: Optional[Union[tf.Tensor, tf.Variable]] = None,
61 ) -> Union[tf.Tensor, tf.Variable]:
62     if size < 2:
63         return tf.ones([size], dtype=dtype)
64     if periodic:
65         return tf.signal.hann_window(size + 1, periodic=False, dtype=dtype)[:-1]
66     else:
67         return tf.signal.hann_window(size, periodic=False, dtype=dtype)
68 
69 
70 def tril_indices(
71     n_rows: int,
72     n_cols: Optional[int] = None,
73     k: int = 0,
74     /,
75     *,
76     device: str,
77 ) -> Tuple[Union[tf.Tensor, tf.Variable], ...]:
78     n_cols = n_rows if n_cols is None else n_cols
79 
80     if n_rows < 0 or n_cols < 0:
81         n_rows, n_cols = 0, 0
82 
83     ret = [[], []]
84 
85     for i in range(-min(k, 0), n_rows, 1):
86         for j in range(0, min(n_cols, k + i + 1), 1):
87             ret[0].append(i)
88             ret[1].append(j)
89 
90     return tuple(tf.convert_to_tensor(ret, dtype=tf.int64))
91 
92 
93 def unsorted_segment_min(
94     data: tf.Tensor,
95     segment_ids: tf.Tensor,
96     num_segments: Union[int, tf.Tensor],
97 ) -> tf.Tensor:
98     return tf.math.unsorted_segment_min(data, segment_ids, num_segments)
99 
100 
101 def blackman_window(
102     size: int,
103     /,
104     *,
105     periodic: bool = True,
106     dtype: Optional[tf.DType] = None,
107     out: Optional[Union[tf.Tensor, tf.Variable]] = None,
108 ) -> Union[tf.Tensor, tf.Variable]:
109     if size < 2:
110         return tf.ones([size], dtype=tf.result_type(size, 0.0))
111     if periodic:
112         count = tf.arange(size) / size
113     else:
114         count = tf.linspace(start=0, stop=size, num=size)
115 
116     return (0.42 - 0.5 * tf.cos(2 * tf.pi * count)) + (
117         0.08 * tf.cos(2 * tf.pi * 2 * count)
118     )
119 
120 
121 def unsorted_segment_sum(
122     data: tf.Tensor,
123     segment_ids: tf.Tensor,
124     num_segments: Union[int, tf.Tensor],
125 ) -> tf.Tensor:
126     return tf.math.unsorted_segment_sum(data, segment_ids, num_segments)
127 
128 
129 @with_unsupported_dtypes({"2.13.0 and below": ("bool",)}, backend_version)
130 def trilu(
131     x: Union[tf.Tensor, tf.Variable],
132     /,
133     *,
134     k: int = 0,
135     upper: bool = True,
136     out: Optional[Union[tf.Tensor, tf.Variable]] = None,
137 ) -> Union[tf.Tensor, tf.Variable]:
138     if upper:
139         return tf.experimental.numpy.triu(x, k)
140     return tf.experimental.numpy.tril(x, k)
141 
142 
143 def mel_weight_matrix(
144     num_mel_bins: int,
145     dft_length: int,
146     sample_rate: int,
147     lower_edge_hertz: float = 125.0,
148     upper_edge_hertz: float = 3000.0,
149 ):
150     return tf.signal.linear_to_mel_weight_matrix(
151         num_mel_bins,
152         dft_length,
153         sample_rate,
154         lower_edge_hertz=lower_edge_hertz,
155         upper_edge_hertz=upper_edge_hertz,
156     )
157
```

Path: `ivy/functional/frontends/torch/spectral_ops.py`
Content:
```
1 import ivy
2 from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
3 
4 
5 @to_ivy_arrays_and_back
6 def bartlett_window(
7     window_length,
8     periodic=True,
9     *,
10     dtype=None,
11     layout=None,
12     device=None,
13     requires_grad=False
14 ):
15     # this implementation is based on scipy.signal.windows.bartlett
16     # https://github.com/scipy/scipy/blob/v1.11.2/scipy/signal/windows/_windows.py#L625-L721
17     if int(window_length) != window_length or window_length < 0:
18         raise ValueError("Window length must be a non-negative integer")
19     elif window_length == 1:
20         return ivy.ones(window_length)
21     else:
22         N = window_length + 1 if periodic else window_length
23 
24         res = ivy.arange(0, N, dtype=dtype)
25         res = ivy.where(
26             ivy.less_equal(res, (N - 1) / 2.0),
27             2.0 * res / (N - 1),
28             2.0 - 2.0 * res / (N - 1),
29         )
30 
31         return res[:-1] if periodic else res
32
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
         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 @@
     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 @@
         )
 
         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)

{"golden_diff": "diff --git a/ivy/functional/backends/jax/experimental/creation.py b/ivy/functional/backends/jax/experimental/creation.py\n--- a/ivy/functional/backends/jax/experimental/creation.py\n+++ b/ivy/functional/backends/jax/experimental/creation.py\n@@ -118,9 +118,10 @@\n         count = jnp.arange(size) / size\n     else:\n         count = jnp.linspace(start=0, stop=size, num=size)\n-    return (0.42 - 0.5 * jnp.cos(2 * jnp.pi * count)) + (\n-        0.08 * jnp.cos(2 * jnp.pi * 2 * count)\n-    )\n+    return (\n+        (0.42 - 0.5 * jnp.cos(2 * jnp.pi * count))\n+        + (0.08 * jnp.cos(2 * jnp.pi * 2 * count))\n+    ).astype(dtype)\n \n \n def trilu(\ndiff --git a/ivy/functional/backends/tensorflow/experimental/creation.py b/ivy/functional/backends/tensorflow/experimental/creation.py\n--- a/ivy/functional/backends/tensorflow/experimental/creation.py\n+++ b/ivy/functional/backends/tensorflow/experimental/creation.py\n@@ -107,14 +107,18 @@\n     out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n ) -> Union[tf.Tensor, tf.Variable]:\n     if size < 2:\n-        return tf.ones([size], dtype=tf.result_type(size, 0.0))\n+        return tf.cast(\n+            tf.ones([size], dtype=tf.experimental.numpy.result_type(size, 0.0)),\n+            dtype=dtype,\n+        )\n     if periodic:\n-        count = tf.arange(size) / size\n+        count = tf.experimental.numpy.arange(size) / size\n     else:\n         count = tf.linspace(start=0, stop=size, num=size)\n-\n-    return (0.42 - 0.5 * tf.cos(2 * tf.pi * count)) + (\n-        0.08 * tf.cos(2 * tf.pi * 2 * count)\n+    return tf.cast(\n+        (0.42 - 0.5 * tf.cos(2 * tf.experimental.numpy.pi * count))\n+        + (0.08 * tf.cos(2 * tf.experimental.numpy.pi * 2 * count)),\n+        dtype=dtype,\n     )\n \n \ndiff --git a/ivy/functional/frontends/torch/spectral_ops.py b/ivy/functional/frontends/torch/spectral_ops.py\n--- a/ivy/functional/frontends/torch/spectral_ops.py\n+++ b/ivy/functional/frontends/torch/spectral_ops.py\n@@ -1,5 +1,6 @@\n import ivy\n from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back\n+from ivy.func_wrapper import with_supported_dtypes\n \n \n @to_ivy_arrays_and_back\n@@ -29,3 +30,17 @@\n         )\n \n         return res[:-1] if periodic else res\n+\n+\n+@to_ivy_arrays_and_back\n+@with_supported_dtypes({\"2.51.0 and below\": (\"float32\", \"float64\")}, \"torch\")\n+def blackman_window(\n+    window_length,\n+    periodic=True,\n+    *,\n+    dtype=None,\n+    layout=None,\n+    device=None,\n+    requires_grad=False\n+):\n+    return ivy.blackman_window(window_length, periodic=periodic, dtype=dtype)\n", "issue": "blackman_window\n\n", "before_files": [{"content": "# global\nfrom typing import Optional, Tuple\nimport math\nimport jax\nimport jax.numpy as jnp\nimport jaxlib.xla_extension\n\n# local\nfrom ivy.functional.backends.jax import JaxArray\nimport ivy\n\n# Array API Standard #\n# ------------------ #\n\n\ndef vorbis_window(\n    window_length: JaxArray,\n    *,\n    dtype: jnp.dtype = jnp.float32,\n    out: Optional[JaxArray] = None,\n) -> JaxArray:\n    return jnp.array(\n        [\n            round(\n                math.sin(\n                    (ivy.pi / 2) * (math.sin(ivy.pi * (i) / (window_length * 2)) ** 2)\n                ),\n                8,\n            )\n            for i in range(1, window_length * 2)[0::2]\n        ],\n        dtype=dtype,\n    )\n\n\ndef hann_window(\n    size: int,\n    /,\n    *,\n    periodic: bool = True,\n    dtype: Optional[jnp.dtype] = None,\n    out: Optional[JaxArray] = None,\n) -> JaxArray:\n    if size < 2:\n        return jnp.ones([size], dtype=dtype)\n    if periodic:\n        count = jnp.arange(size) / size\n    else:\n        count = jnp.linspace(start=0, stop=size, num=size)\n    return (0.5 - 0.5 * jnp.cos(2 * jnp.pi * count)).astype(dtype)\n\n\ndef kaiser_window(\n    window_length: int,\n    periodic: bool = True,\n    beta: float = 12.0,\n    *,\n    dtype: Optional[jnp.dtype] = None,\n    out: Optional[JaxArray] = None,\n) -> JaxArray:\n    if window_length < 2:\n        return jnp.ones([window_length], dtype=dtype)\n    if periodic is False:\n        return jnp.kaiser(M=window_length, beta=beta).astype(dtype)\n    else:\n        return jnp.kaiser(M=window_length + 1, beta=beta)[:-1].astype(dtype)\n\n\ndef tril_indices(\n    n_rows: int,\n    n_cols: Optional[int] = None,\n    k: int = 0,\n    /,\n    *,\n    device: jaxlib.xla_extension.Device,\n) -> Tuple[JaxArray, ...]:\n    return jnp.tril_indices(n=n_rows, k=k, m=n_cols)\n\n\ndef unsorted_segment_min(\n    data: JaxArray,\n    segment_ids: JaxArray,\n    num_segments: int,\n) -> JaxArray:\n    # added this check to keep the same behaviour as tensorflow\n    ivy.utils.assertions.check_unsorted_segment_min_valid_params(\n        data, segment_ids, num_segments\n    )\n    return jax.ops.segment_min(data, segment_ids, num_segments)\n\n\ndef unsorted_segment_sum(\n    data: JaxArray,\n    segment_ids: JaxArray,\n    num_segments: int,\n) -> JaxArray:\n    # Used the same check which is used for unsorted_segment_min as\n    # the check should be same\n    # Might require to change the assertion function name to\n    # check_unsorted_segment_valid_params\n    ivy.utils.assertions.check_unsorted_segment_min_valid_params(\n        data, segment_ids, num_segments\n    )\n    return jax.ops.segment_sum(data, segment_ids, num_segments)\n\n\ndef blackman_window(\n    size: int,\n    /,\n    *,\n    periodic: bool = True,\n    dtype: Optional[jnp.dtype] = None,\n    out: Optional[JaxArray] = None,\n) -> JaxArray:\n    if size < 2:\n        return jnp.ones([size], dtype=dtype)\n    if periodic:\n        count = jnp.arange(size) / size\n    else:\n        count = jnp.linspace(start=0, stop=size, num=size)\n    return (0.42 - 0.5 * jnp.cos(2 * jnp.pi * count)) + (\n        0.08 * jnp.cos(2 * jnp.pi * 2 * count)\n    )\n\n\ndef trilu(\n    x: JaxArray, /, *, k: int = 0, upper: bool = True, out: Optional[JaxArray] = None\n) -> JaxArray:\n    if upper:\n        return jnp.triu(x, k)\n    return jnp.tril(x, k)\n\n\ndef mel_weight_matrix(\n    num_mel_bins: int,\n    dft_length: int,\n    sample_rate: int,\n    lower_edge_hertz: float = 0.0,\n    upper_edge_hertz: float = 3000.0,\n):\n    lower_edge_hertz = jnp.array(lower_edge_hertz)\n    upper_edge_hertz = jnp.array(upper_edge_hertz)\n    zero = jnp.array(0.0)\n    hz_to_mel = lambda f: 2595 * jnp.log10(1 + f / 700)\n    nyquist_hz = sample_rate / 2\n    linear_freqs = jnp.linspace(0, nyquist_hz, dft_length, dtype=jnp.float32)[1:]\n    spec_bin_mels = hz_to_mel(linear_freqs)[..., None]\n    mel_edges = jnp.linspace(\n        hz_to_mel(lower_edge_hertz),\n        hz_to_mel(upper_edge_hertz),\n        num_mel_bins + 2,\n        dtype=jnp.float32,\n    )\n    mel_edges = jnp.stack([mel_edges[i : i + 3] for i in range(num_mel_bins)])\n    lower_edge_mel, center_mel, upper_edge_mel = [\n        t.reshape((1, num_mel_bins)) for t in jnp.split(mel_edges, 3, axis=1)\n    ]\n    lower_slopes = (spec_bin_mels - lower_edge_mel) / (center_mel - lower_edge_mel)\n    upper_slopes = (upper_edge_mel - spec_bin_mels) / (upper_edge_mel - center_mel)\n    mel_weights = jnp.maximum(zero, jnp.minimum(lower_slopes, upper_slopes))\n    return jnp.pad(mel_weights, [[1, 0], [0, 0]])\n", "path": "ivy/functional/backends/jax/experimental/creation.py"}, {"content": "# global\n\nfrom typing import Union, Optional, Tuple\nimport tensorflow as tf\n\n# local\nfrom ivy.func_wrapper import with_unsupported_device_and_dtypes, with_unsupported_dtypes\nfrom .. import backend_version\n\n\n# Array API Standard #\n# -------------------#\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.13.0 and below\": {\"cpu\": (\"bfloat16\",)}},\n    backend_version,\n)\ndef kaiser_window(\n    window_length: int,\n    periodic: bool = True,\n    beta: float = 12.0,\n    *,\n    dtype: Optional[tf.DType] = None,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    if window_length < 2:\n        return tf.ones([window_length], dtype=dtype)\n    if periodic is False:\n        return tf.signal.kaiser_window(window_length, beta, dtype=dtype)\n    else:\n        return tf.signal.kaiser_window(window_length + 1, beta, dtype=dtype)[:-1]\n\n\ndef kaiser_bessel_derived_window(\n    window_length: int,\n    beta: float = 12.0,\n    *,\n    dtype: Optional[tf.DType] = None,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    return tf.signal.kaiser_bessel_derived_window(window_length, beta, dtype)\n\n\ndef vorbis_window(\n    window_length: Union[tf.Tensor, tf.Variable],\n    *,\n    dtype: tf.DType = tf.dtypes.float32,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    return tf.signal.vorbis_window(window_length, dtype=dtype, name=None)\n\n\ndef hann_window(\n    size: int,\n    /,\n    *,\n    periodic: bool = True,\n    dtype: Optional[tf.DType] = None,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    if size < 2:\n        return tf.ones([size], dtype=dtype)\n    if periodic:\n        return tf.signal.hann_window(size + 1, periodic=False, dtype=dtype)[:-1]\n    else:\n        return tf.signal.hann_window(size, periodic=False, dtype=dtype)\n\n\ndef tril_indices(\n    n_rows: int,\n    n_cols: Optional[int] = None,\n    k: int = 0,\n    /,\n    *,\n    device: str,\n) -> Tuple[Union[tf.Tensor, tf.Variable], ...]:\n    n_cols = n_rows if n_cols is None else n_cols\n\n    if n_rows < 0 or n_cols < 0:\n        n_rows, n_cols = 0, 0\n\n    ret = [[], []]\n\n    for i in range(-min(k, 0), n_rows, 1):\n        for j in range(0, min(n_cols, k + i + 1), 1):\n            ret[0].append(i)\n            ret[1].append(j)\n\n    return tuple(tf.convert_to_tensor(ret, dtype=tf.int64))\n\n\ndef unsorted_segment_min(\n    data: tf.Tensor,\n    segment_ids: tf.Tensor,\n    num_segments: Union[int, tf.Tensor],\n) -> tf.Tensor:\n    return tf.math.unsorted_segment_min(data, segment_ids, num_segments)\n\n\ndef blackman_window(\n    size: int,\n    /,\n    *,\n    periodic: bool = True,\n    dtype: Optional[tf.DType] = None,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    if size < 2:\n        return tf.ones([size], dtype=tf.result_type(size, 0.0))\n    if periodic:\n        count = tf.arange(size) / size\n    else:\n        count = tf.linspace(start=0, stop=size, num=size)\n\n    return (0.42 - 0.5 * tf.cos(2 * tf.pi * count)) + (\n        0.08 * tf.cos(2 * tf.pi * 2 * count)\n    )\n\n\ndef unsorted_segment_sum(\n    data: tf.Tensor,\n    segment_ids: tf.Tensor,\n    num_segments: Union[int, tf.Tensor],\n) -> tf.Tensor:\n    return tf.math.unsorted_segment_sum(data, segment_ids, num_segments)\n\n\n@with_unsupported_dtypes({\"2.13.0 and below\": (\"bool\",)}, backend_version)\ndef trilu(\n    x: Union[tf.Tensor, tf.Variable],\n    /,\n    *,\n    k: int = 0,\n    upper: bool = True,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    if upper:\n        return tf.experimental.numpy.triu(x, k)\n    return tf.experimental.numpy.tril(x, k)\n\n\ndef mel_weight_matrix(\n    num_mel_bins: int,\n    dft_length: int,\n    sample_rate: int,\n    lower_edge_hertz: float = 125.0,\n    upper_edge_hertz: float = 3000.0,\n):\n    return tf.signal.linear_to_mel_weight_matrix(\n        num_mel_bins,\n        dft_length,\n        sample_rate,\n        lower_edge_hertz=lower_edge_hertz,\n        upper_edge_hertz=upper_edge_hertz,\n    )\n", "path": "ivy/functional/backends/tensorflow/experimental/creation.py"}, {"content": "import ivy\nfrom ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back\n\n\n@to_ivy_arrays_and_back\ndef bartlett_window(\n    window_length,\n    periodic=True,\n    *,\n    dtype=None,\n    layout=None,\n    device=None,\n    requires_grad=False\n):\n    # this implementation is based on scipy.signal.windows.bartlett\n    # https://github.com/scipy/scipy/blob/v1.11.2/scipy/signal/windows/_windows.py#L625-L721\n    if int(window_length) != window_length or window_length < 0:\n        raise ValueError(\"Window length must be a non-negative integer\")\n    elif window_length == 1:\n        return ivy.ones(window_length)\n    else:\n        N = window_length + 1 if periodic else window_length\n\n        res = ivy.arange(0, N, dtype=dtype)\n        res = ivy.where(\n            ivy.less_equal(res, (N - 1) / 2.0),\n            2.0 * res / (N - 1),\n            2.0 - 2.0 * res / (N - 1),\n        )\n\n        return res[:-1] if periodic else res\n", "path": "ivy/functional/frontends/torch/spectral_ops.py"}], "after_files": [{"content": "# global\nfrom typing import Optional, Tuple\nimport math\nimport jax\nimport jax.numpy as jnp\nimport jaxlib.xla_extension\n\n# local\nfrom ivy.functional.backends.jax import JaxArray\nimport ivy\n\n# Array API Standard #\n# ------------------ #\n\n\ndef vorbis_window(\n    window_length: JaxArray,\n    *,\n    dtype: jnp.dtype = jnp.float32,\n    out: Optional[JaxArray] = None,\n) -> JaxArray:\n    return jnp.array(\n        [\n            round(\n                math.sin(\n                    (ivy.pi / 2) * (math.sin(ivy.pi * (i) / (window_length * 2)) ** 2)\n                ),\n                8,\n            )\n            for i in range(1, window_length * 2)[0::2]\n        ],\n        dtype=dtype,\n    )\n\n\ndef hann_window(\n    size: int,\n    /,\n    *,\n    periodic: bool = True,\n    dtype: Optional[jnp.dtype] = None,\n    out: Optional[JaxArray] = None,\n) -> JaxArray:\n    if size < 2:\n        return jnp.ones([size], dtype=dtype)\n    if periodic:\n        count = jnp.arange(size) / size\n    else:\n        count = jnp.linspace(start=0, stop=size, num=size)\n    return (0.5 - 0.5 * jnp.cos(2 * jnp.pi * count)).astype(dtype)\n\n\ndef kaiser_window(\n    window_length: int,\n    periodic: bool = True,\n    beta: float = 12.0,\n    *,\n    dtype: Optional[jnp.dtype] = None,\n    out: Optional[JaxArray] = None,\n) -> JaxArray:\n    if window_length < 2:\n        return jnp.ones([window_length], dtype=dtype)\n    if periodic is False:\n        return jnp.kaiser(M=window_length, beta=beta).astype(dtype)\n    else:\n        return jnp.kaiser(M=window_length + 1, beta=beta)[:-1].astype(dtype)\n\n\ndef tril_indices(\n    n_rows: int,\n    n_cols: Optional[int] = None,\n    k: int = 0,\n    /,\n    *,\n    device: jaxlib.xla_extension.Device,\n) -> Tuple[JaxArray, ...]:\n    return jnp.tril_indices(n=n_rows, k=k, m=n_cols)\n\n\ndef unsorted_segment_min(\n    data: JaxArray,\n    segment_ids: JaxArray,\n    num_segments: int,\n) -> JaxArray:\n    # added this check to keep the same behaviour as tensorflow\n    ivy.utils.assertions.check_unsorted_segment_min_valid_params(\n        data, segment_ids, num_segments\n    )\n    return jax.ops.segment_min(data, segment_ids, num_segments)\n\n\ndef unsorted_segment_sum(\n    data: JaxArray,\n    segment_ids: JaxArray,\n    num_segments: int,\n) -> JaxArray:\n    # Used the same check which is used for unsorted_segment_min as\n    # the check should be same\n    # Might require to change the assertion function name to\n    # check_unsorted_segment_valid_params\n    ivy.utils.assertions.check_unsorted_segment_min_valid_params(\n        data, segment_ids, num_segments\n    )\n    return jax.ops.segment_sum(data, segment_ids, num_segments)\n\n\ndef blackman_window(\n    size: int,\n    /,\n    *,\n    periodic: bool = True,\n    dtype: Optional[jnp.dtype] = None,\n    out: Optional[JaxArray] = None,\n) -> JaxArray:\n    if size < 2:\n        return jnp.ones([size], dtype=dtype)\n    if periodic:\n        count = jnp.arange(size) / size\n    else:\n        count = jnp.linspace(start=0, stop=size, num=size)\n    return (\n        (0.42 - 0.5 * jnp.cos(2 * jnp.pi * count))\n        + (0.08 * jnp.cos(2 * jnp.pi * 2 * count))\n    ).astype(dtype)\n\n\ndef trilu(\n    x: JaxArray, /, *, k: int = 0, upper: bool = True, out: Optional[JaxArray] = None\n) -> JaxArray:\n    if upper:\n        return jnp.triu(x, k)\n    return jnp.tril(x, k)\n\n\ndef mel_weight_matrix(\n    num_mel_bins: int,\n    dft_length: int,\n    sample_rate: int,\n    lower_edge_hertz: float = 0.0,\n    upper_edge_hertz: float = 3000.0,\n):\n    lower_edge_hertz = jnp.array(lower_edge_hertz)\n    upper_edge_hertz = jnp.array(upper_edge_hertz)\n    zero = jnp.array(0.0)\n    hz_to_mel = lambda f: 2595 * jnp.log10(1 + f / 700)\n    nyquist_hz = sample_rate / 2\n    linear_freqs = jnp.linspace(0, nyquist_hz, dft_length, dtype=jnp.float32)[1:]\n    spec_bin_mels = hz_to_mel(linear_freqs)[..., None]\n    mel_edges = jnp.linspace(\n        hz_to_mel(lower_edge_hertz),\n        hz_to_mel(upper_edge_hertz),\n        num_mel_bins + 2,\n        dtype=jnp.float32,\n    )\n    mel_edges = jnp.stack([mel_edges[i : i + 3] for i in range(num_mel_bins)])\n    lower_edge_mel, center_mel, upper_edge_mel = [\n        t.reshape((1, num_mel_bins)) for t in jnp.split(mel_edges, 3, axis=1)\n    ]\n    lower_slopes = (spec_bin_mels - lower_edge_mel) / (center_mel - lower_edge_mel)\n    upper_slopes = (upper_edge_mel - spec_bin_mels) / (upper_edge_mel - center_mel)\n    mel_weights = jnp.maximum(zero, jnp.minimum(lower_slopes, upper_slopes))\n    return jnp.pad(mel_weights, [[1, 0], [0, 0]])\n", "path": "ivy/functional/backends/jax/experimental/creation.py"}, {"content": "# global\n\nfrom typing import Union, Optional, Tuple\nimport tensorflow as tf\n\n# local\nfrom ivy.func_wrapper import with_unsupported_device_and_dtypes, with_unsupported_dtypes\nfrom .. import backend_version\n\n\n# Array API Standard #\n# -------------------#\n\n\n@with_unsupported_device_and_dtypes(\n    {\"2.13.0 and below\": {\"cpu\": (\"bfloat16\",)}},\n    backend_version,\n)\ndef kaiser_window(\n    window_length: int,\n    periodic: bool = True,\n    beta: float = 12.0,\n    *,\n    dtype: Optional[tf.DType] = None,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    if window_length < 2:\n        return tf.ones([window_length], dtype=dtype)\n    if periodic is False:\n        return tf.signal.kaiser_window(window_length, beta, dtype=dtype)\n    else:\n        return tf.signal.kaiser_window(window_length + 1, beta, dtype=dtype)[:-1]\n\n\ndef kaiser_bessel_derived_window(\n    window_length: int,\n    beta: float = 12.0,\n    *,\n    dtype: Optional[tf.DType] = None,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    return tf.signal.kaiser_bessel_derived_window(window_length, beta, dtype)\n\n\ndef vorbis_window(\n    window_length: Union[tf.Tensor, tf.Variable],\n    *,\n    dtype: tf.DType = tf.dtypes.float32,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    return tf.signal.vorbis_window(window_length, dtype=dtype, name=None)\n\n\ndef hann_window(\n    size: int,\n    /,\n    *,\n    periodic: bool = True,\n    dtype: Optional[tf.DType] = None,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    if size < 2:\n        return tf.ones([size], dtype=dtype)\n    if periodic:\n        return tf.signal.hann_window(size + 1, periodic=False, dtype=dtype)[:-1]\n    else:\n        return tf.signal.hann_window(size, periodic=False, dtype=dtype)\n\n\ndef tril_indices(\n    n_rows: int,\n    n_cols: Optional[int] = None,\n    k: int = 0,\n    /,\n    *,\n    device: str,\n) -> Tuple[Union[tf.Tensor, tf.Variable], ...]:\n    n_cols = n_rows if n_cols is None else n_cols\n\n    if n_rows < 0 or n_cols < 0:\n        n_rows, n_cols = 0, 0\n\n    ret = [[], []]\n\n    for i in range(-min(k, 0), n_rows, 1):\n        for j in range(0, min(n_cols, k + i + 1), 1):\n            ret[0].append(i)\n            ret[1].append(j)\n\n    return tuple(tf.convert_to_tensor(ret, dtype=tf.int64))\n\n\ndef unsorted_segment_min(\n    data: tf.Tensor,\n    segment_ids: tf.Tensor,\n    num_segments: Union[int, tf.Tensor],\n) -> tf.Tensor:\n    return tf.math.unsorted_segment_min(data, segment_ids, num_segments)\n\n\ndef blackman_window(\n    size: int,\n    /,\n    *,\n    periodic: bool = True,\n    dtype: Optional[tf.DType] = None,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    if size < 2:\n        return tf.cast(\n            tf.ones([size], dtype=tf.experimental.numpy.result_type(size, 0.0)),\n            dtype=dtype,\n        )\n    if periodic:\n        count = tf.experimental.numpy.arange(size) / size\n    else:\n        count = tf.linspace(start=0, stop=size, num=size)\n    return tf.cast(\n        (0.42 - 0.5 * tf.cos(2 * tf.experimental.numpy.pi * count))\n        + (0.08 * tf.cos(2 * tf.experimental.numpy.pi * 2 * count)),\n        dtype=dtype,\n    )\n\n\ndef unsorted_segment_sum(\n    data: tf.Tensor,\n    segment_ids: tf.Tensor,\n    num_segments: Union[int, tf.Tensor],\n) -> tf.Tensor:\n    return tf.math.unsorted_segment_sum(data, segment_ids, num_segments)\n\n\n@with_unsupported_dtypes({\"2.13.0 and below\": (\"bool\",)}, backend_version)\ndef trilu(\n    x: Union[tf.Tensor, tf.Variable],\n    /,\n    *,\n    k: int = 0,\n    upper: bool = True,\n    out: Optional[Union[tf.Tensor, tf.Variable]] = None,\n) -> Union[tf.Tensor, tf.Variable]:\n    if upper:\n        return tf.experimental.numpy.triu(x, k)\n    return tf.experimental.numpy.tril(x, k)\n\n\ndef mel_weight_matrix(\n    num_mel_bins: int,\n    dft_length: int,\n    sample_rate: int,\n    lower_edge_hertz: float = 125.0,\n    upper_edge_hertz: float = 3000.0,\n):\n    return tf.signal.linear_to_mel_weight_matrix(\n        num_mel_bins,\n        dft_length,\n        sample_rate,\n        lower_edge_hertz=lower_edge_hertz,\n        upper_edge_hertz=upper_edge_hertz,\n    )\n", "path": "ivy/functional/backends/tensorflow/experimental/creation.py"}, {"content": "import ivy\nfrom ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back\nfrom ivy.func_wrapper import with_supported_dtypes\n\n\n@to_ivy_arrays_and_back\ndef bartlett_window(\n    window_length,\n    periodic=True,\n    *,\n    dtype=None,\n    layout=None,\n    device=None,\n    requires_grad=False\n):\n    # this implementation is based on scipy.signal.windows.bartlett\n    # https://github.com/scipy/scipy/blob/v1.11.2/scipy/signal/windows/_windows.py#L625-L721\n    if int(window_length) != window_length or window_length < 0:\n        raise ValueError(\"Window length must be a non-negative integer\")\n    elif window_length == 1:\n        return ivy.ones(window_length)\n    else:\n        N = window_length + 1 if periodic else window_length\n\n        res = ivy.arange(0, N, dtype=dtype)\n        res = ivy.where(\n            ivy.less_equal(res, (N - 1) / 2.0),\n            2.0 * res / (N - 1),\n            2.0 - 2.0 * res / (N - 1),\n        )\n\n        return res[:-1] if periodic else res\n\n\n@to_ivy_arrays_and_back\n@with_supported_dtypes({\"2.51.0 and below\": (\"float32\", \"float64\")}, \"torch\")\ndef blackman_window(\n    window_length,\n    periodic=True,\n    *,\n    dtype=None,\n    layout=None,\n    device=None,\n    requires_grad=False\n):\n    return ivy.blackman_window(window_length, periodic=periodic, dtype=dtype)\n", "path": "ivy/functional/frontends/torch/spectral_ops.py"}]}