MCPcopy
hub / github.com/tinygrad/tinygrad / _apply_uop

Method _apply_uop

tinygrad/tensor.py:147–156  ·  view source on GitHub ↗
(self, fxn:Callable[..., UOp], *x:Tensor, extra_args=(), **kwargs)

Source from the content-addressed store, hash-verified

145 def __del__(self): all_tensors.pop(weakref.ref(self), None)
146
147 def _apply_uop(self, fxn:Callable[..., UOp], *x:Tensor, extra_args=(), **kwargs) -> Tensor:
148 srcs = (self,)+x
149 new_uop: UOp = fxn(*[t.uop for t in srcs], *extra_args, **kwargs)
150 if TRACEMETA >= 1 and (metadata:=_METADATA.get()) is not None: all_metadata[new_uop] = (metadata,)
151 # directly create the Tensor
152 ret = Tensor.__new__(Tensor)
153 ret.uop, ret.grad, ret.is_param = new_uop, None, True
154 # add to all_tensors after construction succeeds
155 all_tensors[weakref.ref(ret)] = None
156 return ret
157
158 # alu and const_like are used by the mixins
159 def alu(self, op: Ops, *src: Tensor) -> Tensor: return self._apply_uop(lambda *u: u[0].alu(op, *u[1:]), *src)

Callers 8

aluMethod · 0.95
_mopMethod · 0.95
_ropMethod · 0.95
__setitem__Method · 0.95
contiguousMethod · 0.95
castMethod · 0.95
bitcastMethod · 0.95
whereMethod · 0.80

Calls 4

fxnFunction · 0.50
getMethod · 0.45
__new__Method · 0.45
refMethod · 0.45

Tested by

no test coverage detected