Class: Neighbor::Type::Sparsevec
- Inherits:
-
ActiveRecord::Type::Value
- Object
- ActiveRecord::Type::Value
- Neighbor::Type::Sparsevec
- 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 |
#type ⇒ Object
4 5 6 |
# File 'lib/neighbor/type/sparsevec.rb', line 4 def type :sparsevec end |