Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for element-wise addition with NumPy broadcasting.
Inherits forward dispatch, broadcasting logic, and the apply() trampoline from BinaryOp<AddBackward> (alias for BinaryKernel<AddBackward>); only the backend hook and the gradient formula are defined locally. No forward inputs are saved because the gradient is a pass-through: the upstream gradient is delivered unchanged to each operand (modulo broadcast reduction).
Math
When or was broadcast against the other operand, the corresponding
branch is reduced back to the original input shape via sum_to_shape
inside BinaryKernel::apply.
Shape
Inputs follow NumPy broadcasting; output has the broadcasted shape. Each gradient is then reduced to the original input's shape.
See Also
SubBackward, MulBackward, DivBackward
Attributes
kSavesInputsboolfalse — the additive gradient is independent of input values, so no Storage is retained.schema_v1OpSchema"add", schema version 1, AmpPolicy::Promote (operands are up-cast to the wider dtype), deterministic.Notes
CPU dispatch routes to Accelerate vDSP_vadd / vDSP_vaddD for F32 /
F64. GPU dispatch uses MLX's broadcast-aware add primitive.
Static methods
1dispatch
→Storageint dispatch(backend::IBackend & be, const int & a, const int & b, const int & shape, Dtype dt)Forward dispatch hook called by BinaryKernel::forward.
Parameters
bebackend::IBackend&a, bconst Storage&shape.shapeconst Shape&dtDtypeReturns
StorageNewly allocated output storage holding .
Methods
2Compute the storage-level gradients for both operands.
Math
Parameters
grad_outconst Storage&Returns
std::pair<Storage, Storage>(dA, dB) where both equal grad_out (still at output shape; BinaryKernel::apply performs the broadcast reduction).
grad_formula_impl
→std::pair<TensorImplPtr, TensorImplPtr>int grad_formula_impl(const int & grad_out, const int &, const int &)Graph-mode (TensorImpl) variant of the gradient.
Used when autograd is built as a dataflow graph rather than executed eagerly on storages. Returns the upstream gradient unchanged for both branches — broadcast reduction is handled by the caller.
Parameters
grad_outconst TensorImplPtr&a, bconst TensorImplPtr&Returns
std::pair<TensorImplPtr, TensorImplPtr>(grad_out, grad_out) — identity in graph form.