Use pseudo-inverse if singular matrix.
Fix bug when using precomputed kernel and sample weights.