Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mlx/backend/cpu/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void scan_dispatch(
auto op = [](U y, T x) {
if constexpr (is_floating_point_v<U>) {
if (std::isnan(y) || std::isnan(static_cast<U>(x))) {
return std::numeric_limits<U>::quiet_NaN();
return static_cast<U>(std::numeric_limits<float>::quiet_NaN());
}
}
return x < y ? x : y;
Expand All @@ -242,7 +242,7 @@ void scan_dispatch(
auto op = [](U y, T x) {
if constexpr (is_floating_point_v<U>) {
if (std::isnan(y) || std::isnan(static_cast<U>(x))) {
return std::numeric_limits<U>::quiet_NaN();
return static_cast<U>(std::numeric_limits<float>::quiet_NaN());
}
}
return x < y ? y : x;
Expand Down
14 changes: 14 additions & 0 deletions python/tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2989,6 +2989,20 @@ def test_cummax_cummin_nan(self):
msg=f"{op} reverse={reverse} inclusive={inclusive} "
f"arr={arr}\ngot={got}\nexp={expected}",
)
for dtype in (mx.float16, mx.bfloat16):
got = getattr(mx, op)(
a_mx.astype(dtype), reverse=reverse, inclusive=inclusive
)
self.assertEqual(got.dtype, dtype)
self.assertTrue(
np.array_equal(
np.array(got.astype(mx.float32)),
expected,
equal_nan=True,
),
msg=f"{op} {dtype} reverse={reverse} "
f"inclusive={inclusive} arr={arr}",
)

def test_diff(self):
a = mx.array([1, 2, 4, 7, 0])
Expand Down
Loading