Adapt the same kernel to be able to compute both min and max.