If you want a boolean mask (e.g., as returned by lt), that is not floating type so you won’t be able to compute gradient of it wrt to anything. If you do something like clamp_max, you could get gradients wrt R and r_max, but not sure if that’s what you need.