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

Function _uniform

imperative/python/megengine/random/rng.py:92–109  ·  view source on GitHub ↗
(
    low: float,
    high: float,
    size: Optional[Iterable[int]],
    seed: int,
    device: str,
    handle: int,
)

Source from the content-addressed store, hash-verified

90
91
92def _uniform(
93 low: float,
94 high: float,
95 size: Optional[Iterable[int]],
96 seed: int,
97 device: str,
98 handle: int,
99) -> Tensor:
100 assert low < high, "Uniform is not defined when low >= high"
101 if size is None:
102 size = (1,)
103 op = UniformRNG(seed=seed, handle=handle, dtype="float32")
104 _ref = Tensor([], dtype="int32", device=device)
105 shape = utils.astensor1d(size, _ref, dtype="int32", device=device)
106 (output,) = apply(op, shape)
107 if low == 0 and high == 1:
108 return output
109 return low + (high - low) * output
110
111
112def _normal(

Callers 1

uniformMethod · 0.85

Calls 3

UniformRNGClass · 0.85
TensorClass · 0.50
applyFunction · 0.50

Tested by

no test coverage detected