Skip to content
fn

divide

→Tensor
divide(input: Tensor, other: Tensor | Scalar, rounding_mode: str | None = ...)

Element-wise division — lucid.div under its longer name.

rounding_mode=None is the / operator: integer operands are promoted to a floating dtype. "trunc" rounds the quotient toward zero and "floor" toward negative infinity, keeping an integer dtype.

Parameters

inputTensor
Numerator.
otherTensor | Scalar
Denominator.
rounding_mode(None, trunc, floor)= None
How the quotient is rounded. Default None: not at all.

Returns

Tensor

Element-wise quotient of the broadcast shape of input and other.

Notes

outi=aibi\text{out}_i = \frac{a_i}{b_i}

Division by zero gives ±∞\pm\infty (NaN for 0/0). The gradients are 1/b1/b and −a/b2-a / b^{2}, and zero for a rounded quotient.

Examples

>>> import lucid
>>> lucid.divide(lucid.tensor([6.0, 9.0]), 3.0)
tensor([2., 3.])
>>> lucid.divide(lucid.tensor([7, -7]), 2, rounding_mode="trunc")
tensor([3, -3], dtype=lucid.int64)