nn.init.uniform

lucid.nn.init.uniform(tensor: Tensor, a: int | float | complex = 0, b: int | float | complex = 1) None

The uniform function fills the input tensor with values sampled from a uniform distribution \(U(a, b)\), where \(a\) and \(b\) are the lower and upper bounds of the distribution.

Function Signature

def uniform(tensor: Tensor, a: _Scalar = 0, b: _Scalar = 1) -> None

Parameters

  • tensor (Tensor): The tensor to be initialized.

  • a (_Scalar, optional): The lower bound of the uniform distribution. Defaults to 0.

  • b (_Scalar, optional): The upper bound of the uniform distribution. Defaults to 1.

Returns

  • None: The function modifies the tensor in-place with new values sampled from the uniform distribution.

Examples

>>> import lucid
>>> from lucid.nn.init import uniform
>>> tensor = lucid.zeros((3, 3))
>>> uniform(tensor, a=-1, b=1)
>>> print(tensor)
Tensor([[ 0.423, -0.234,  0.678],
        [-0.123,  0.654, -0.543],
        [ 0.543, -0.345,  0.234]], requires_grad=False)