Skip to content
class

NextafterBackward

NextafterBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Return the next representable floating-point value after a toward b.

Computes element-wise IEEE-754 nextafter: for each element pair (a_k, b_k) returns the float bit-adjacent to a_k in the direction of b_k. If a_k == b_k the result is b_k. NaN propagates.

Math

a_k & \text{if } a_k = b_k \\ \mathrm{succ}(a_k) & \text{if } a_k < b_k \\ \mathrm{pred}(a_k) & \text{if } a_k > b_k \end{cases}$$ where $\mathrm{succ}$ / $\mathrm{pred}$ are the IEEE-754 next- / previous- representable functions.

Parameters

aTensorImplPtr
Source values. Floating-point dtype (F32 or F64).
bTensorImplPtr
Direction values. Must match a in dtype and broadcast-compatible shape.

Raises

ValueError
If a and b differ in dtype, or the dtype is not F32 / F64.
Autograd node for ``nextafter(a, b)``.
The result is ``a`` moved by one unit in the last place, so within a
the
gradient is the incoming one for ``a`` and zero for ``b`` — the reference
framework's rule. The op used to return a detached tensor, dropping the
gradient to ``a`` without a word.

Notes

Non-differentiable: the output is piecewise constant in a (the step is always one ULP regardless of magnitude). No backward is registered.

On the GPU stream, the F32 fast path operates entirely on int32 views of the floating bits (sign-magnitude adjusted to two's complement) and avoids a CPU round-trip. F64 inputs always traverse the CPU stream because MLX does not provide F64 buffers.

Instance methods

2
fn

apply_for_graph

int apply_for_graph(const int & grad_out)