MCPcopy
hub / github.com/tinygrad/tinygrad / full_like

Method full_like

tinygrad/tensor.py:603–617  ·  view source on GitHub ↗

Creates a tensor with the same shape as `self`, filled with the given value. If `dtype` is not specified, the dtype of `self` is used. You can pass in the `device` keyword argument to control device of the tensor. ```python exec="true" source="above" session="tensor" result="pytho

(self, fill_value:ConstType, dtype=None, device=None)

Source from the content-addressed store, hash-verified

601 return Tensor(stacked.multi(self.uop.axis))
602
603 def full_like(self, fill_value:ConstType, dtype=None, device=None) -> Tensor:
604 """
605 Creates a tensor with the same shape as `self`, filled with the given value.
606 If `dtype` is not specified, the dtype of `self` is used.
607
608 You can pass in the `device` keyword argument to control device of the tensor.
609
610 ```python exec="true" source="above" session="tensor" result="python"
611 t = Tensor.ones(2, 3)
612 print(Tensor.full_like(t, 42).numpy())
613 ```
614 """
615 if device is None: return super().full_like(fill_value, dtype)
616 if isinstance(self.device, tuple): raise RuntimeError("cannot specify `device` on `full_like` of a multi device tensor")
617 return Tensor.full(self.shape, fill_value, dtype=dtype or self.dtype, device=device)
618
619 def rand_like(self, **kwargs) -> Tensor:
620 """

Callers 12

test_assign_other_jitMethod · 0.95
backend.pyFile · 0.45
test_full_likeMethod · 0.45
test_const_reduceMethod · 0.45
rfMethod · 0.45
sampleFunction · 0.45
generateFunction · 0.45

Calls 1

fullMethod · 0.80