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_s ⇒ Object
Constructor Details
#initialize(data) ⇒ Vector
Returns a new instance of Vector.
3 4 5 |
# File 'lib/pgvector/vector.rb', line 3 def initialize(data) @data = data.to_a.map(&:to_f) end |
Class Method Details
.from_binary(string) ⇒ Object
11 12 13 14 15 |
# File 'lib/pgvector/vector.rb', line 11 def self.from_binary(string) dim, unused = string[0, 4].unpack("nn") raise "expected unused to be 0" if unused != 0 Vector.new(string[4..-1].unpack("g#{dim}")) end |
.from_text(string) ⇒ Object
7 8 9 |
# File 'lib/pgvector/vector.rb', line 7 def self.from_text(string) Vector.new(string[1..-2].split(",").map(&:to_f)) end |
Instance Method Details
#to_a ⇒ Object
21 22 23 |
# File 'lib/pgvector/vector.rb', line 21 def to_a @data end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/pgvector/vector.rb', line 17 def to_s "[#{@data.to_a.map(&:to_f).join(",")}]" end |