MCPcopy
hub / github.com/tinygrad/tinygrad / uniform

Method uniform

tinygrad/tensor.py:705–720  ·  view source on GitHub ↗

Creates a tensor with the given shape, filled with random values from a uniform distribution over the interval `[low, high)`. Requires `low < high`. You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor. Additionally, all other key

(*shape, low=0.0, high=1.0, dtype:DTypeLike|None=None, **kwargs)

Source from the content-addressed store, hash-verified

703
704 @staticmethod
705 def uniform(*shape, low=0.0, high=1.0, dtype:DTypeLike|None=None, **kwargs) -> Tensor:
706 """
707 Creates a tensor with the given shape, filled with random values from a uniform distribution over the interval `[low, high)`.
708 Requires `low < high`.
709
710 You can pass in `dtype` and `device` keyword arguments to control the data type and device of the tensor.
711 Additionally, all other keyword arguments are passed to the constructor of the tensor.
712
713 ```python exec="true" source="above" session="tensor" result="python"
714 Tensor.manual_seed(42)
715 print(Tensor.uniform(2, 3, low=2, high=10).numpy())
716 ```
717 """
718 if not all_int(shape:=argfix(*shape)) or not all(s >= 0 for s in shape): raise ValueError(f"invalid input {shape=}")
719 if low >= high: raise ValueError(f"Tensor.uniform requires low < high, got {low=}, {high=}")
720 return ((high-low) * Tensor.rand(*shape, **kwargs)).cast(dtype or dtypes.default_float) + low
721
722 @staticmethod
723 def scaled_uniform(*shape, **kwargs) -> Tensor:

Callers 15

randintMethod · 0.80
scaled_uniformMethod · 0.80
glorot_uniformMethod · 0.80
kaiming_uniformMethod · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
_get_valueFunction · 0.80
backend.pyFile · 0.80
random_resized_cropFunction · 0.80

Calls 4

all_intFunction · 0.90
argfixFunction · 0.90
randMethod · 0.80
castMethod · 0.45

Tested by 15

test_uniform_realizesMethod · 0.64
test_uniform_gradientMethod · 0.64
test_uniformMethod · 0.64
test_scaled_uniformMethod · 0.64
test_glorot_uniformMethod · 0.64
_test_convMethod · 0.64
test_conv2d_winogradMethod · 0.64
get_nextMethod · 0.64
test_quant_128Method · 0.64
test_quantMethod · 0.64