Add check for zero-length input in sparsevec. Fix #7507