ENH sparse matrix support in pairwise + optimizations