Skip to content

Commit

Permalink
Improved NewSparseVectorFromMap
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 25, 2024
1 parent 468f895 commit 4ae72c9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sparsevec.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ func NewSparseVector(vec []float32) SparseVector {
func NewSparseVectorFromMap(elements map[int32]float32, dim int32) SparseVector {
indices := make([]int32, 0, len(elements))
values := make([]float32, 0, len(elements))
// no need to sort or remove zeros since binary format is not supported
// no need to sort since binary format is not supported
for k, v := range elements {
indices = append(indices, k)
values = append(values, v)
if v != 0 {
indices = append(indices, k)
values = append(values, v)
}
}
return SparseVector{dim: dim, indices: indices, values: values}
}
Expand Down

0 comments on commit 4ae72c9

Please sign in to comment.