MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / shuffle

Method shuffle

imperative/python/megengine/random/rng.py:634–663  ·  view source on GitHub ↗

r"""Modify a sequence in-place by shuffling its contents. This function only shuffles the Tensor along the first axis of a multi-dimensional Tensor. The order of sub-Tensors is changed but their contents remains the same. Args: inp: input tensor.

(self, inp: Tensor)

Source from the content-addressed store, hash-verified

632 return _shuffle(inp=n, seed=_seed, handle=self._handle)
633
634 def shuffle(self, inp: Tensor):
635 r"""Modify a sequence in-place by shuffling its contents.
636 This function only shuffles the Tensor along the first axis of a multi-dimensional Tensor.
637 The order of sub-Tensors is changed but their contents remains the same.
638
639 Args:
640 inp: input tensor.
641
642 Returns:
643 None.
644
645 Examples:
646 >>> import numpy as np
647 >>> import megengine.random as rand
648 >>> x = mge.tensor(np.arange(10))
649 >>> rand.shuffle(x)
650 >>> x.numpy() # doctest: +SKIP
651 array([4, 5, 9, 6, 2, 8, 1, 0, 3, 7], dtype=int32)
652 >>> y = mge.tensor(np.arange(18)).reshape(6,3)
653 >>> rand.shuffle(y)
654 >>> y.numpy() # doctest: +SKIP
655 array([[ 3, 4, 5],
656 [ 6, 7, 8],
657 [15, 16, 17],
658 [ 0, 1, 2],
659 [12, 13, 14],
660 [ 9, 10, 11]], dtype=int32)
661 """
662 _seed = self._seed() if callable(self._seed) else self._seed
663 inp._reset(_shuffle(inp=inp, seed=_seed, handle=self._handle))
664
665 def exponential(
666 self, rate: Union[float, Tensor] = 1.0, size: Optional[Iterable[int]] = None

Callers 1

test_ShuffleRNGFunction · 0.95

Calls 2

_shuffleFunction · 0.85
_resetMethod · 0.45

Tested by 1

test_ShuffleRNGFunction · 0.76