Class: Spark::Mllib::DenseMatrix

Inherits:
MatrixBase show all
Defined in:
lib/spark/mllib/matrix.rb

Overview

DenseMatrix

DenseMatrix.new(2, 3, [[1,2,3], [4,5,6]]).values
# => [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MatrixAdapter

new, #original_initialize, #shape, #values

Constructor Details

#initialize(rows, cols, values) ⇒ DenseMatrix

Returns a new instance of DenseMatrix.



43
44
45
# File 'lib/spark/mllib/matrix.rb', line 43

def initialize(rows, cols, values)
  super(:dense, rows, cols, values.to_a)
end

Class Method Details

.from_java(object) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/spark/mllib/matrix.rb', line 51

def self.from_java(object)
  rows = object.numRows
  cols = object.numCols
  values = object.values

  DenseMatrix.new(rows, cols, values)
end

Instance Method Details

#to_javaObject



47
48
49
# File 'lib/spark/mllib/matrix.rb', line 47

def to_java
  JDenseMatrix.new(shape[0], shape[1], values.flatten)
end