Fast mean for sparse matrices along dimensions. (#7788)