Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for element-wise subtraction with NumPy broadcasting.
Inherits forward dispatch, broadcasting logic, and the apply() trampoline
from BinaryOp<SubBackward>. No forward inputs are saved because the
gradient depends only on the upstream gradient: receives it unchanged
and receives it negated. Broadcast-reduces each branch back to the
original input shape via sum_to_shape inside
BinaryKernel::apply.
Math
Shape
Inputs follow NumPy broadcasting; output has the broadcasted shape. Each gradient is then reduced to the original input's shape.
See Also
AddBackward, MulBackward, DivBackward
Attributes
kSavesInputsboolfalse — gradient is value-independent.schema_v1OpSchema"sub", schema version 1, AmpPolicy::Promote, deterministic.Notes
CPU dispatch uses Accelerate vDSP_vsub / vDSP_vsubD for F32 / F64.
GPU dispatch uses MLX's broadcast-aware subtract 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
StorageOutput storage holding .
Methods
2Compute the storage-level gradients for both operands.
Math
Parameters
grad_outconst Storage&Returns
std::pair<Storage, Storage>(dA, dB) where dA is a clone of grad_out and dB is its element-wise negation.
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.
Parameters
grad_outconst TensorImplPtr&a, bconst TensorImplPtr&Returns
std::pair<TensorImplPtr, TensorImplPtr>(grad_out, -grad_out).