Skip to content

Commit

Permalink
Improved SparseVector code
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 20, 2024
1 parent c547f0d commit 8c2869c
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/pgvector/sparse_vector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ defmodule Pgvector.SparseVector do
Creates a new sparse vector from a list, tensor or sparse vector
"""
def new(list) when is_list(list) do
indices =
{values, indices} =
list
|> Enum.with_index()
|> Enum.filter(fn {v, _} -> v != 0 end)
|> Enum.map(fn {_, i} -> i end)
|> Enum.unzip()

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

0 comments on commit 8c2869c

Please sign in to comment.