Class: Neighbor::Type::Sparsevec

Inherits:
ActiveRecord::Type::Value
  • Object
show all
Defined in:
lib/neighbor/type/sparsevec.rb

Instance Method Summary collapse

Instance Method Details

#serialize(value) ⇒ Object



8
9
10
11
12
13
# File 'lib/neighbor/type/sparsevec.rb', line 8

def serialize(value)
  if value.is_a?(SparseVector)
    value = "{#{value.indices.zip(value.values).map { |i, v| "#{i.to_i + 1}:#{v.to_f}" }.join(",")}}/#{value.dimensions.to_i}"
  end
  super(value)
end

#typeObject



4
5
6
# File 'lib/neighbor/type/sparsevec.rb', line 4

def type
  :sparsevec
end