From 47ddf94f17295246dbfce02ce96d97fc702afd3f Mon Sep 17 00:00:00 2001 From: chenyu Date: Tue, 14 Jul 2026 21:59:15 -0400 Subject: [PATCH] remove InvalidType lt and gt (#17023) not really used --- test/null/test_uops.py | 8 +++++++- tinygrad/dtype.py | 2 -- tinygrad/uop/ops.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/null/test_uops.py b/test/null/test_uops.py index 0ff635bc3b..21ca901f18 100644 --- a/test/null/test_uops.py +++ b/test/null/test_uops.py @@ -3,7 +3,7 @@ import unittest import numpy as np from tinygrad.tensor import Tensor from tinygrad.helpers import Timing, Context, cdiv -from tinygrad.dtype import dtypes, ConstFloat # noqa: F401 +from tinygrad.dtype import dtypes, ConstFloat, Invalid # noqa: F401 from tinygrad.device import Device from tinygrad.uop.ops import Ops, ParamArg, UOp, UPat, exec_alu # noqa: F401 # ParamArg used by eval(str(uop)) roundtrip tests from tinygrad.uop.spec import spec_shared @@ -40,6 +40,12 @@ class TestExecALU(unittest.TestCase): def test_sqrt(self): self.assertEqual(exec_alu(Ops.SQRT, dtypes.float, (0.0,)), 0.0) + def test_invalid_poison(self): + # Invalid poisons any binary op regardless of result dtype: a comparison must not fold to a boolean + self.assertIs(exec_alu(Ops.CMPLT, dtypes.bool, (Invalid, 1)), Invalid) + self.assertIs(exec_alu(Ops.CMPNE, dtypes.bool, (Invalid, 1)), Invalid) + self.assertIs(exec_alu(Ops.ADD, dtypes.index, (Invalid, 1)), Invalid) + def test_div(self): self.assertEqual(exec_alu(Ops.CDIV, dtypes.int8, (8, 2)), 4) self.assertEqual(exec_alu(Ops.CDIV, dtypes.int8, (7, 3)), 2) diff --git a/tinygrad/dtype.py b/tinygrad/dtype.py index efb75eb476..a84521498e 100644 --- a/tinygrad/dtype.py +++ b/tinygrad/dtype.py @@ -27,8 +27,6 @@ class InvalidType: if cls._instance is None: cls._instance = object.__new__(cls) return cls._instance def __eq__(self, other): return self is other - def __lt__(self, other): return self is not other - def __gt__(self, other): return self is not other def __hash__(self): return id(self) def __repr__(self): return "Invalid" def __reduce__(self): return (InvalidType, ()) # unpickle returns the singleton diff --git a/tinygrad/uop/ops.py b/tinygrad/uop/ops.py index 8438e2f147..9aa3d925bf 100644 --- a/tinygrad/uop/ops.py +++ b/tinygrad/uop/ops.py @@ -1201,7 +1201,7 @@ def exec_alu(op:Ops, dtype:DType, operands, truncate_output=True): if any(isinstance(x, tuple) for x in operands): count = max(len(x) for x in operands if isinstance(x, tuple)) return tuple([exec_alu(op, dtype, [x[i] if isinstance(x, tuple) else x for x in operands]) for i in range(count)]) - if dtype==dtypes.index and op in GroupOp.Binary and Invalid in operands: return Invalid + if op in GroupOp.Binary and Invalid in operands: return Invalid alu = python_alu[op](*operands) if truncate_output and (truncate_fxn:=truncate.get(dtype)) is not None: return truncate_fxn(alu) return alu