Optim: small optimizations

On the digits example, on my computer, these changes improve the run time
of t-SNE from 22s to 18s.