Class: Spark::Mllib::MatrixAdapter
- Inherits:
-
Matrix
- Object
- Matrix
- Spark::Mllib::MatrixAdapter
- Defined in:
- lib/spark/mllib/ruby_matrix/matrix_adapter.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, rows, cols, values = nil) ⇒ MatrixAdapter
constructor
A new instance of MatrixAdapter.
- #original_initialize ⇒ Object
- #shape ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(type, rows, cols, values = nil) ⇒ MatrixAdapter
Returns a new instance of MatrixAdapter.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/spark/mllib/ruby_matrix/matrix_adapter.rb', line 23 def initialize(type, rows, cols, values=nil) case type when :dense values = values.dup if rows * cols == values.size # Values are on one row # 2x2 => [1,2,3,4] values = values.each_slice(cols).to_a else # 2x2 => [[1,2], [3,4]] end when :sparse values = Array.new(rows) { Array.new(cols) { 0.0 } } else raise Spark::MllibError, 'Unknow vector type.' end super(values, cols) end |
Class Method Details
.new(*args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/spark/mllib/ruby_matrix/matrix_adapter.rb', line 7 def self.new(*args) object = self.allocate if args.size == 2 # Matrix is initialized from Matrix # Arguments: rows, column count object.__send__(:original_initialize, *args) else object.__send__(:initialize, *args) end object end |
Instance Method Details
#original_initialize ⇒ Object
21 |
# File 'lib/spark/mllib/ruby_matrix/matrix_adapter.rb', line 21 alias_method :original_initialize, :initialize |
#shape ⇒ Object
43 44 45 |
# File 'lib/spark/mllib/ruby_matrix/matrix_adapter.rb', line 43 def shape [row_count, column_count] end |
#values ⇒ Object
47 48 49 |
# File 'lib/spark/mllib/ruby_matrix/matrix_adapter.rb', line 47 def values @values || to_a end |