fix a bug for the sparse case