mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-02-08 21:55:14 -05:00
Misc rewrite perf improvements (#6500)
* Make UOp a normal class and use __slots__
* Use __slots__ in UPat
* Cache dtypes.{min,max}
* Use faster iterables in ops.py
* extend is a lot faster than nested listcomp
Co-authored-by: Roelof van Dijk <3604013+roelofvandijk@users.noreply.github.com>
---------
Co-authored-by: Roelof van Dijk <3604013+roelofvandijk@users.noreply.github.com>
This commit is contained in:
@@ -62,10 +62,12 @@ class dtypes:
|
||||
return tuple(dtypes.as_const(x, dtype) for x in val)
|
||||
return int(val) if dtypes.is_int(dtype) else float(val) if dtypes.is_float(dtype) else bool(val)
|
||||
@staticmethod
|
||||
@functools.lru_cache(None)
|
||||
def min(dtype:DType):
|
||||
if dtypes.is_int(dtype): return 0 if dtypes.is_unsigned(dtype) else -2**(dtype.itemsize*8-1)
|
||||
return -float("inf") if dtypes.is_float(dtype) else False
|
||||
@staticmethod
|
||||
@functools.lru_cache(None)
|
||||
def max(dtype:DType):
|
||||
if dtypes.is_int(dtype): return (2**(dtype.itemsize*8-(0 if dtypes.is_unsigned(dtype) else 1)))-1
|
||||
return float("inf") if dtypes.is_float(dtype) else True
|
||||
|
||||
Reference in New Issue
Block a user