Fix contiguous loop for tanh and hardtanh