refactor the sparse inner product and added tests