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

Method uniform

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

r"""Random variable with uniform distribution :math:`U(low, high)`. Args: low(float): lower range. Default: 0. high(float): upper range. Default: 1. size(Optional[Iterable[int]]): the size of output tensor. Default: None. Returns: Ret

(
        self, low: float = 0, high: float = 1, size: Optional[Iterable[int]] = None
    )

Source from the content-addressed store, hash-verified

313 self._device = None
314
315 def uniform(
316 self, low: float = 0, high: float = 1, size: Optional[Iterable[int]] = None
317 ):
318 r"""Random variable with uniform distribution :math:`U(low, high)`.
319
320 Args:
321 low(float): lower range. Default: 0.
322 high(float): upper range. Default: 1.
323 size(Optional[Iterable[int]]): the size of output tensor. Default: None.
324
325 Returns:
326 Return type: tensor. The random variable with uniform distribution.
327
328 Examples:
329 >>> import megengine.random as rand
330 >>> x = rand.uniform(size=(2, 2))
331 >>> x.numpy() # doctest: +SKIP
332 array([[0.28603864, 0.3156649 ],
333 [0.42066026, 0.9805052 ]], dtype=float32)
334 """
335 _seed = self._seed() if callable(self._seed) else self._seed
336 return _uniform(
337 low=low,
338 high=high,
339 size=size,
340 seed=_seed,
341 device=self._device,
342 handle=self._handle,
343 )
344
345 def normal(
346 self, mean: float = 0, std: float = 1, size: Optional[Iterable[int]] = None

Callers 15

test_UniformRNGFunction · 0.95
test_NormalRNGFunction · 0.95
test_GammaRNGFunction · 0.95
test_BetaRNGFunction · 0.95
test_PermutationRNGFunction · 0.95
make_data_given_descFunction · 0.80
benchmark_op.pyFile · 0.80
__init__Method · 0.80
_get_shapeMethod · 0.80
_get_coordMethod · 0.80
_apply_imageMethod · 0.80
_apply_imageMethod · 0.80

Calls 1

_uniformFunction · 0.85

Tested by 15

test_UniformRNGFunction · 0.76
test_NormalRNGFunction · 0.76
test_GammaRNGFunction · 0.76
test_BetaRNGFunction · 0.76
test_PermutationRNGFunction · 0.76
fnFunction · 0.64
fwdFunction · 0.64
test_grou_normFunction · 0.64
test_instance_normFunction · 0.64
test_funcFunction · 0.64
runFunction · 0.64
gen_elemadd_dataFunction · 0.64