Class: Pgvector::Vector
- Inherits:
-
Object
- Object
- Pgvector::Vector
- Defined in:
- lib/pgvector/vector.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Vector
constructor
A new instance of Vector.
- #to_a ⇒ Object
- #to_binary ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Vector
Returns a new instance of Vector.
3 4 5 6 7 8 9 10 11 |
# File 'lib/pgvector/vector.rb', line 3 def initialize(data) # keep as NArray when possible for performance @data = if numo?(data) data.cast_to(Numo::SFloat) else data.to_a.map(&:to_f) end end |
Class Method Details
Instance Method Details
#to_a ⇒ Object
27 28 29 |
# File 'lib/pgvector/vector.rb', line 27 def to_a @data.to_a end |
#to_binary ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/pgvector/vector.rb', line 31 def to_binary if numo?(@data) [@data.shape[0], 0].pack("s>s>") + @data.to_network.to_binary else buffer = [@data.size, 0].pack("s>s>") @data.pack("g*", buffer: buffer) buffer end end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/pgvector/vector.rb', line 23 def to_s "[#{@data.to_a.map(&:to_f).join(",")}]" end |