if your “customized loss function” is piecewise constant, as integer indexing implies, you’ll have zeros  for loss derivatives, i.e. there is no “right” direction to minimize loss if you discretize. I don’t know what’s your lookup matrix doing, but maybe you can switch to using loss multipliers, so that float Delta_X doesn’t disappear (akin to delta * table[delta.long()] and the answer above)