fn

square

Tensor
square(input: Tensor)
source

Element-wise square.

Computes x2x^2 for each entry. Equivalent to input * input but typically evaluated in a single kernel.

Parameters

inputTensor
Input tensor.

Returns

Tensor

Element-wise result with the same shape as input.

Notes

Mathematical definition:

outi=inputi2\text{out}_i = \text{input}_i^{\,2}

Gradient: 2x2x.

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0])
>>> lucid.square(x)
Tensor([...])