Contrastive Learning Can Find An Optimal Basis For Approximately View-Invariant Functions