Contrastive dimension reduction: when and how?