Python wrappers
Public Python APIs implemented by this engine symbol.Element-wise conditional selection between two tensors.
Returns x at positions where cond is true, otherwise y.
This is the tensor analogue of the ternary expression
cond ? x : y applied element-wise.
Math
y_i & \text{otherwise}\end{cases}$$ **Shape** On the GPU stream all three operands are broadcast by the MLX backend. On the CPU stream all three must share the same shape.Parameters
condTensorImplPtrBoolean (or 0/1-valued) condition tensor.
xTensorImplPtrValues selected at positions where
cond is true.yTensorImplPtrValues selected at positions where
cond is false.Returns
TensorImplPtrTensor of the broadcast shape and dtype of x/y.
Notes
Backward propagates grad_out masked by cond to x and masked
by ~cond to y. cond itself receives no gradient.