Skip to content

Commit 8c2869c

Browse files
committed
Improved SparseVector code
1 parent c547f0d commit 8c2869c

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/pgvector/sparse_vector.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ defmodule Pgvector.SparseVector do
99
Creates a new sparse vector from a list, tensor or sparse vector
1010
"""
1111
def new(list) when is_list(list) do
12-
indices =
12+
{values, indices} =
1313
list
1414
|> Enum.with_index()
1515
|> Enum.filter(fn {v, _} -> v != 0 end)
16-
|> Enum.map(fn {_, i} -> i end)
16+
|> Enum.unzip()
1717

18-
values = list |> Enum.filter(fn v -> v != 0 end)
1918
dim = list |> length()
2019
nnz = indices |> length()
2120
indices = for v <- indices, into: "", do: <<v::signed-32>>

0 commit comments

Comments
 (0)