fn
eye_
→Tensoreye_(tensor: Tensor)Fill a 2-D tensor in-place with the identity matrix.
Writes ones on the main diagonal and zeros elsewhere. Identity initialisation is useful for square linear layers in residual blocks or for testing — at initialisation the layer is the identity map and gradients propagate untransformed.
Parameters
tensorTensorTwo-dimensional tensor to fill in place. Need not be square; the
identity is written into the leading
min(n, m) diagonal
entries.Returns
Tensortensor (mutated) for chaining.
Raises
ValueErrorIf
tensor.ndim != 2.Notes
For convolution weights that should act as the identity see
dirac_, which is the spatial analogue.
Examples
>>> import lucid
>>> from lucid.nn.init import eye_
>>> w = lucid.empty(4, 4)
>>> eye_(w)