Implement mlx.core.blackman (#3136)

This commit is contained in:
willem adnet
2026-02-25 13:42:40 -08:00
committed by GitHub
parent 6304c285d3
commit a8ba5ac3e0
4 changed files with 66 additions and 0 deletions
+24
View File
@@ -1475,6 +1475,30 @@ void init_ops(nb::module_& m) {
appears only if the number of samples is odd).
)pbdoc");
m.def(
"blackman",
&mlx::core::blackman,
"M"_a,
nb::kw_only(),
"stream"_a = nb::none(),
nb::sig(
"def blackman(M: int, *, stream: Union[None, Stream, Device] = None) -> array"), // <--- J'ai rajouté ça
R"pbdoc(
Return the Blackman window.
The Blackman window is a taper formed by using the first three terms of a summation of cosines.
.. math::
w(n) = 0.42 - 0.5 \cos\left(\frac{2\pi n}{M-1}\right) + 0.08 \cos\left(\frac{4\pi n}{M-1}\right)
\qquad 0 \le n \le M-1
Args:
M (int): Number of points in the output window.
Returns:
array: The window, with the maximum value normalized to one (the value one
appears only if the number of samples is odd).
)pbdoc");
m.def(
"linspace",
[](Scalar start,
Scalar stop,
+12
View File
@@ -1474,6 +1474,18 @@ class TestOps(mlx_tests.MLXTestCase):
self.assertEqual(a.size, 0)
self.assertEqual(a.dtype, mx.float32)
def test_blackman_general(self):
a = mx.blackman(10)
expected = np.blackman(10)
self.assertTrue(np.allclose(a, expected, atol=1e-5))
a = mx.blackman(1)
self.assertEqual(a.item(), 1.0)
a = mx.blackman(0)
self.assertEqual(a.size, 0)
self.assertEqual(a.dtype, mx.float32)
def test_unary_ops(self):
def test_ops(npop, mlxop, x, y, atol, rtol):
r_np = npop(x)