class Spark::Mllib::VectorAdapter

Public Class Methods

new(*args) click to toggle source
# File lib/spark/mllib/ruby_matrix/vector_adapter.rb, line 15
def self.new(*args)
  object = self.allocate
  object.__send__(:initialize, *args)
  object
end
new(*args) click to toggle source
Calls superclass method
# File lib/spark/mllib/ruby_matrix/vector_adapter.rb, line 21
def initialize(*args)
  case args.shift
  when :dense
    values = args.shift.dup
  when :sparse
    values = [0.0] * args.shift.to_i
  else
    raise Spark::MllibError, 'Unknow vector type.'
  end

  super(values)
end

Public Instance Methods

[]=(index, value) click to toggle source
# File lib/spark/mllib/ruby_matrix/vector_adapter.rb, line 34
def []=(index, value)
  @elements[index] = value
end
dot(other) click to toggle source
# File lib/spark/mllib/ruby_matrix/vector_adapter.rb, line 38
def dot(other)
  if other.is_a?(Spark::Mllib::MatrixBase)
    other * self
  else
    inner_product(other)
  end
end
squared_distance(other) click to toggle source
# File lib/spark/mllib/ruby_matrix/vector_adapter.rb, line 46
def squared_distance(other)
  diff = self - other
  diff.dot(diff)
end
values() click to toggle source
# File lib/spark/mllib/ruby_matrix/vector_adapter.rb, line 51
def values
  @values || to_a
end