Fix a bug in dealing with SPD matrix