From a19d689481b19b05ee7a2c9625708eeb7fb174ee Mon Sep 17 00:00:00 2001 From: Sieds Lykles <93992551+S-Lykles@users.noreply.github.com> Date: Mon, 1 Sep 2025 03:24:07 +0200 Subject: [PATCH] fix vec dtype _min_max (#11944) --- test/unit/test_dtype_spec.py | 7 ++++++- tinygrad/dtype.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/test/unit/test_dtype_spec.py b/test/unit/test_dtype_spec.py index da690a8170..36e91e1111 100644 --- a/test/unit/test_dtype_spec.py +++ b/test/unit/test_dtype_spec.py @@ -100,6 +100,11 @@ class TestHelpers(unittest.TestCase): np.testing.assert_equal(dt.min, False) np.testing.assert_equal(dt.max, True) + def test_dtype_range_vec(self): + for dt in core_dtypes: + self.assertEqual(dt.min, dt.vec(4).min) + self.assertEqual(dt.max, dt.vec(4).max) + def test_truncate_fp16(self): self.assertEqual(truncate_fp16(1), 1) self.assertEqual(truncate_fp16(65504), 65504) @@ -613,4 +618,4 @@ class TestAutoCastType(unittest.TestCase): np.testing.assert_allclose(out.numpy(), tt.log_softmax(0).numpy(), rtol=1e-3) out = t.log_softmax(0, dtype=dtypes.float) self.assertEqual(out.dtype, dtypes.float) - np.testing.assert_allclose(out.numpy(), tt.log_softmax(0, dtype=torch.float).numpy(), rtol=1e-3) \ No newline at end of file + np.testing.assert_allclose(out.numpy(), tt.log_softmax(0, dtype=torch.float).numpy(), rtol=1e-3) diff --git a/tinygrad/dtype.py b/tinygrad/dtype.py index 2ae836e742..2e2716c426 100644 --- a/tinygrad/dtype.py +++ b/tinygrad/dtype.py @@ -112,12 +112,12 @@ class dtypes: @staticmethod @functools.cache def min(dtype:DType): - if dtypes.is_int(dtype): return 0 if dtypes.is_unsigned(dtype) else -2**(dtype.itemsize*8-1) + if dtypes.is_int(dtype): return 0 if dtypes.is_unsigned(dtype) else -2**(dtype.scalar().itemsize*8-1) return -float("inf") if dtypes.is_float(dtype) else False @staticmethod @functools.cache def max(dtype:DType): - if dtypes.is_int(dtype): return 2**(dtype.itemsize*8)-1+dtypes.min(dtype) + if dtypes.is_int(dtype): return 2**(dtype.scalar().itemsize*8)-1+dtypes.min(dtype) return float("inf") if dtypes.is_float(dtype) else True @staticmethod def finfo(dtype:DType) -> tuple[int, int]: