MCPcopy Index your code
hub / github.com/tinygrad/tinygrad / const

Method const

tinygrad/dtype.py:92–100  ·  view source on GitHub ↗
(self, val: tuple[ConstType, ...]|ConstType)

Source from the content-addressed store, hash-verified

90 if dtypes.is_int(self): return 2**(self.scalar().bitsize)-1+self.min
91 return float("inf") if dtypes.is_float(self) else True
92 def const(self, val: tuple[ConstType, ...]|ConstType):
93 if isinstance(val, tuple):
94 assert len(val) == self.count, f"mismatch {val} {self}"
95 return tuple(map(self.const, val))
96 if isinstance(val, InvalidType): return val
97 # NOTE: float('nan') != float('nan'), so we canonicalize here
98 if isinstance(val, float) and math.isnan(val): val = math.nan
99 # int is the default. wrap floats in ConstFloat to distinguish -0.0 from 0.0 in cache
100 return ConstFloat(float(val)) if dtypes.is_float(self) else bool(val) if dtypes.is_bool(self) else int(val)
101
102@dataclass(frozen=True, eq=False)
103class PtrDType(DType):

Callers 15

custom_gemmFunction · 0.45
custom_uop_gemmFunction · 0.45
uopMethod · 0.45
add_signalsFunction · 0.45
lowerFunction · 0.45
bufferize_binaryFunction · 0.45
resolve_getaddrFunction · 0.45
hcq2.pyFile · 0.45
finalize_submitFunction · 0.45
hcq_realizeFunction · 0.45
amd_submit_pm4Function · 0.45
amd_submit_sdmaFunction · 0.45

Calls 4

ConstFloatClass · 0.85
isnanMethod · 0.80
is_floatMethod · 0.80
is_boolMethod · 0.80

Tested by 15

_verify_indices_z3Method · 0.36
test_global_prod_maxMethod · 0.36
check_uop_against_stringFunction · 0.36
uconstFunction · 0.36
test_where_castMethod · 0.36
test_exceptionsMethod · 0.36
test_inf_loopMethod · 0.36