Validate num_splits in split (#3234)
Co-authored-by: KD2YCU <[email protected]>
This commit is contained in:
@@ -1328,6 +1328,25 @@ class TestOps(mlx_tests.MLXTestCase):
|
||||
self.assertEqual(y.tolist(), [1, 2, 3, 4])
|
||||
self.assertEqual(z.tolist(), [5, 6, 7])
|
||||
|
||||
def test_split_invalid_num_splits(self):
|
||||
"""Regression: split with num_splits <= 0 should raise, not crash."""
|
||||
a = mx.arange(6)
|
||||
|
||||
# num_splits = 0: should raise cleanly (was UB via divide-by-zero)
|
||||
with self.assertRaises(ValueError):
|
||||
mx.split(a, 0)
|
||||
|
||||
# num_splits = -1: should raise cleanly (was SIGBUS via huge allocation)
|
||||
with self.assertRaises(ValueError):
|
||||
mx.split(a, -1)
|
||||
|
||||
# Also check with explicit axis
|
||||
b = mx.zeros((4, 6))
|
||||
with self.assertRaises(ValueError):
|
||||
mx.split(b, 0, axis=1)
|
||||
with self.assertRaises(ValueError):
|
||||
mx.split(b, -2, axis=0)
|
||||
|
||||
def test_arange_overload_dispatch(self):
|
||||
with self.assertRaises(ValueError):
|
||||
a = mx.arange(float("nan"), 1, 5)
|
||||
|
||||
Reference in New Issue
Block a user