Elementwise eager-engine operations.
This file contains scalar-lifted tensor nodes and their runtime/autograd implementation, including arithmetic, comparisons, activations, and loss-adjacent pointwise operations.
Elementwise addition. PyTorch: torch.add / +.
Instances For
Elementwise subtraction. PyTorch: torch.sub / -.
Instances For
Elementwise multiplication. PyTorch: torch.mul / *.
Instances For
Elementwise division. PyTorch: torch.div / /. Backward is the ordinary quotient
rule, valid for nonzero denominators: ∂(a/b)/∂a = 1/b, ∂(a/b)/∂b = −a/b² (mirrors the
CUDA div node; negation subtracts from Tensor.full s 0 as sub does, so no Neg α is
required).
Domain: real calculus does not define the derivative of a/b at b = 0, so this backward is
the genuine quotient rule only where b ≠ 0. The carrier's / (and hence divSpec) may
totalize or be backend-dependent at b = 0, but no real-valued gradient is implied there.
Requires [TorchLean.Storage α] [Context α] like the sibling abs/sqrt/exp nodes (its
divSpec forward rides the carrier's /).
Instances For
Multiply a tensor by a scalar constant. PyTorch: x * c for Python scalar c.
Instances For
Elementwise absolute value.
Backward uses the sign function (signSpec) as a subgradient at 0.
PyTorch comparison: torch.abs.
Instances For
Elementwise square root.
Backward uses 1 / (2 * sqrt(x)) for x > 0 and 0 otherwise (totalized).
PyTorch comparison: torch.sqrt.
Instances For
Elementwise clamp to [minVal, maxVal].
Backward multiplies by an indicator of the open interval (minVal, maxVal) (zero at boundaries).
PyTorch comparison: torch.clamp.
Instances For
Elementwise maximum.
Tie-breaking: when a = b, the upstream gradient is split evenly (0.5) between both inputs.
PyTorch comparison: torch.maximum.
Instances For
Elementwise minimum.
Tie-breaking: when a = b, the upstream gradient is split evenly (0.5) between both inputs.
PyTorch comparison: torch.minimum.
Instances For
Record elementwise sine with the VJP from Spec.sinOp.
The tape retains the input for cos(x) * dLdy, so the backward pass uses the same angle as
the forward pass even when different angles produce the same sine value.
Instances For
Record elementwise cosine with the VJP -sin(x) * dLdy from Spec.cosOp.
Instances For
Elementwise ReLU.
PyTorch comparison: torch.relu(x) / torch.nn.functional.relu(x).