MCPcopy
hub / github.com/tinygrad/tinygrad / stack

Method stack

tinygrad/mixin/__init__.py:643–657  ·  view source on GitHub ↗

Concatenates self with other tensors in `args` along a new dimension specified by `dim`. ```python exec="true" source="above" session="tensor" result="python" t0, t1, t2 = Tensor([1, 2]), Tensor([3, 4]), Tensor([5, 6]) print(t0.stack(t1, t2, dim=0).numpy()) ``` ```python ex

(self, *args:Self, dim:int=0)

Source from the content-addressed store, hash-verified

641 return padded[0].usum(*padded[1:])
642
643 def stack(self, *args:Self, dim:int=0) -> Self:
644 """
645 Concatenates self with other tensors in `args` along a new dimension specified by `dim`.
646
647 ```python exec="true" source="above" session="tensor" result="python"
648 t0, t1, t2 = Tensor([1, 2]), Tensor([3, 4]), Tensor([5, 6])
649 print(t0.stack(t1, t2, dim=0).numpy())
650 ```
651 ```python exec="true" source="above" session="tensor" result="python"
652 print(t0.stack(t1, t2, dim=1).numpy())
653 ```
654 """
655 # checks for shapes and number of dimensions delegated to cat
656 unsqueezed = [t.unsqueeze(dim) for t in argfix(self, *args)]
657 return unsqueezed[0].cat(*unsqueezed[1:], dim=dim)
658
659 def _cumalu(self, axis:int, op:Ops) -> Self:
660 assert self.shape[axis] != 0 and op in (Ops.ADD, Ops.MAX, Ops.MUL)

Callers 15

randn_likeMethod · 0.80
nonzeroMethod · 0.80
ctensorMethod · 0.80
bitcastMethod · 0.80
q_to_uint8Function · 0.80
ggml_data_to_tensorFunction · 0.80
_attentionMethod · 0.80
AffineGridFunction · 0.80
attention_contribFunction · 0.80
RotaryEmbeddingFunction · 0.80
NonZeroFunction · 0.80
lower_sink_to_linearFunction · 0.80

Calls 3

argfixFunction · 0.90
unsqueezeMethod · 0.80
catMethod · 0.80

Tested by 15

test_stack_dim0Method · 0.64
test_stack_dim1Method · 0.64
test_stack_3tensorsMethod · 0.64
test_stack_new_lastMethod · 0.64
substituteFunction · 0.64
test_recursive_padMethod · 0.64
test_std_meanMethod · 0.64
test_stack_sliceMethod · 0.64
test_stackMethod · 0.64
test_stack_maxMethod · 0.64
test_zero_foldMethod · 0.64