MCPcopy
hub / github.com/tinygrad/tinygrad / repeat

Method repeat

tinygrad/mixin/movement.py:547–565  ·  view source on GitHub ↗

Repeats tensor number of times along each dimension specified by `repeats`. `repeats` can be passed as a tuple or as separate arguments. ```python exec="true" source="above" session="tensor" result="python" t = Tensor([1, 2, 3]) print(t.repeat(4, 2).numpy()) ``` ```pyth

(self, repeats, *args)

Source from the content-addressed store, hash-verified

545 return x
546
547 def repeat(self, repeats, *args) -> Self:
548 """
549 Repeats tensor number of times along each dimension specified by `repeats`.
550 `repeats` can be passed as a tuple or as separate arguments.
551
552 ```python exec="true" source="above" session="tensor" result="python"
553 t = Tensor([1, 2, 3])
554 print(t.repeat(4, 2).numpy())
555 ```
556 ```python exec="true" source="above" session="tensor" result="python"
557 print(t.repeat(4, 2, 1).shape)
558 ```
559 """
560 repeats = argfix(repeats, *args)
561 base_shape = _align_left(self.shape, repeats)[0]
562 unsqueezed_shape = flatten([[s] if r == 1 else [1, s] for r, s in zip(repeats, base_shape)])
563 expanded_shape = flatten([[s] if r == 1 else [r, s] for r, s in zip(repeats, base_shape)])
564 final_shape = [r * s for r, s in zip(repeats, base_shape)]
565 return self.reshape(unsqueezed_shape).expand(expanded_shape).reshape(final_shape)
566
567 # **** pool level ****
568

Callers 15

rollMethod · 0.95
_poolMethod · 0.95
_attentionMethod · 0.80
TileFunction · 0.80
attention_onnxFunction · 0.80
__init__Method · 0.80
_pad_circularMethod · 0.80
_choices_from_argsFunction · 0.80
openNodeMethod · 0.80
test_repeat_basicMethod · 0.80
test_repeat_multidimMethod · 0.80

Calls 5

reshapeMethod · 0.95
argfixFunction · 0.90
_align_leftFunction · 0.90
flattenFunction · 0.90
expandMethod · 0.80

Tested by 14

test_repeat_basicMethod · 0.64
test_repeat_multidimMethod · 0.64
test_repeat_backwardMethod · 0.64
test_repeat_negativeMethod · 0.64
_test_allreduceFunction · 0.64
test_chunkMethod · 0.64
test_repeatMethod · 0.64
test_simple_repeatMethod · 0.64
test_variable_bsMethod · 0.64