MCPcopy
hub / github.com/tinygrad/tinygrad / randperm

Method randperm

tinygrad/tensor.py:787–796  ·  view source on GitHub ↗

Returns a tensor with a random permutation of integers from `0` to `n-1`. ```python exec="true" source="above" session="tensor" result="python" Tensor.manual_seed(42) print(Tensor.randperm(6).numpy()) ```

(n:int, device=None, dtype=dtypes.int32, **kwargs)

Source from the content-addressed store, hash-verified

785
786 @staticmethod
787 def randperm(n:int, device=None, dtype=dtypes.int32, **kwargs) -> Tensor:
788 """
789 Returns a tensor with a random permutation of integers from `0` to `n-1`.
790
791 ```python exec="true" source="above" session="tensor" result="python"
792 Tensor.manual_seed(42)
793 print(Tensor.randperm(6).numpy())
794 ```
795 """
796 return Tensor.rand(n, device=device, **kwargs).argsort().cast(dtype)
797
798 def multinomial(self:Tensor, num_samples:int = 1, replacement:bool = False) -> Tensor:
799 """

Callers 5

randperm_generatorFunction · 0.80
test_randpermMethod · 0.80
augmentationsFunction · 0.80
beautiful_cifar.pyFile · 0.80

Calls 3

argsortMethod · 0.80
randMethod · 0.80
castMethod · 0.45

Tested by 2

test_randpermMethod · 0.64