Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for element-wise division with NumPy broadcasting.
Saves both forward inputs because the quotient rule for requires both and . 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, SubBackward, MulBackward
Attributes
kSavesInputsbooltrue (inherited default from BinaryKernel) — both forward inputs are retained for the quotient-rule backward pass.schema_v1OpSchema"div", schema version 1, AmpPolicy::Promote, deterministic.Notes
CPU dispatch uses Accelerate vDSP_vdiv / vDSP_vdivD for F32 / F64.
GPU dispatch uses MLX's broadcast-aware divide primitive. Division
by zero follows IEEE-754 semantics (yields or NaN); no
explicit guard is inserted.
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 (quotient rule).
Math
Parameters
grad_outconst Storage&Returns
std::pair<Storage, Storage>(dA, dB) where dA = grad_out / b_broadcast and dB = -(grad_out * a_broadcast) / b_broadcast^2. Both still at output shape; BinaryKernel::apply performs the broadcast reduction.
Notes
The implementation materialises intermediates (b_sq, g_times_a,
div_by_b_sq) explicitly so each transient storage can be released
as soon as it is no longer needed.
grad_formula_impl
→std::pair<TensorImplPtr, TensorImplPtr>int grad_formula_impl(const int & grad_out, const int & a, const int & b)Graph-mode (TensorImpl) variant of the gradient.
Parameters
grad_outconst TensorImplPtr&a, bconst TensorImplPtr&out_shape_ by BinaryKernel.Returns
std::pair<TensorImplPtr, TensorImplPtr>(grad_out / b, -grad_out * a / b^2).