Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion mlx/backend/metal/kernels/reduction/reduce_row.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ template <

// lid.x * N_READS breaks the per_thread_row_reduce interface a bit. Maybe it
// needs a small refactor.
in += elem_to_loc<IdxT>(out_idx, shape, strides, ndim) + lid.x * N_READS;
in +=
elem_to_loc<IdxT>(out_idx, shape, strides, ndim) + IdxT(lid.x) * N_READS;

LoopedElemToLoc<NDIMS, IdxT, (NDIMS > 2)> loop(reduce_ndim);
const device T* row;
Expand Down
11 changes: 11 additions & 0 deletions python/tests/test_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def test_expand_sums(self):
np.allclose(z_npy, np.array(z_mlx), atol=1e-4)
)

@unittest.skipIf(not mx.metal.is_available(), "Metal is not available")
Comment thread
FU-max-boop marked this conversation as resolved.
Outdated
def test_row_reduce_negative_stride(self):
x_npy = np.arange(1, 131).reshape(2, 65)[::-1]
x_mlx = mx.arange(1, 131).reshape(2, 65)[::-1]

for op in ["sum", "max", "min", "mean", "var"]:
with self.subTest(op=op):
expected = getattr(np, op)(x_npy, axis=-1)
actual = getattr(mx, op)(x_mlx, axis=-1, stream=mx.gpu)
self.assertTrue(np.allclose(expected, actual))

def test_dtypes(self):
int_dtypes = [
"int8",
Expand Down