Alternative to clamp

Good afternoon,

I am using the function torch clamp to clip a tensor between its minimum and 1e-10, however it seems to be very slow, would it be an alternative to that? or a better way to do it ?
I am doing :

torch.clamp(dist,torch.min(dist),1e-10)

To save time, don’t take the min! torch.clamp(dist, max=1e-10)
I don’t think you can improve clamp by much (unless fusing it with other pointwise ops, which the jit will do).

Best regards

Thomas

Thanks Thomas.
And compared to a hardthanh operation ?

Can you make that more specific?

Best regards

Thomas