Class: Spark::Mllib::SparseMatrix

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

Overview

SparseMatrix

Arguments:

rows

Number of rows.

cols

Number of columns.

col_pointers

The index corresponding to the start of a new column.

row_indices

The row index of the entry. They must be in strictly increasing order for each column.

values

Nonzero matrix entries in column major.

Examples:

SparseMatrix.new(3, 3, [0, 2, 3, 6], [0, 2, 1, 0, 1, 2], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).values

# => [
#      [1.0, 0.0, 4.0],
#      [0.0, 3.0, 5.0],
#      [2.0, 0.0, 6.0]
#    ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from MatrixAdapter

new, #original_initialize, #shape, #values

Constructor Details

#initialize(rows, cols, col_pointers, row_indices, values) ⇒ SparseMatrix

Returns a new instance of SparseMatrix.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/spark/mllib/matrix.rb', line 99

def initialize(rows, cols, col_pointers, row_indices, values)
  super(:sparse, rows, cols)

  @col_pointers = col_pointers
  @row_indices = row_indices
  @values = values

  j = 0
  while j < cols
    idx = col_pointers[j]
    idx_end = col_pointers[j+1]
    while idx < idx_end
      self[row_indices[idx], j] = values[idx]
      idx += 1
    end
    j += 1
  end
end

Instance Attribute Details

#col_pointersObject (readonly)

Returns the value of attribute col_pointers.



97
98
99
# File 'lib/spark/mllib/matrix.rb', line 97

def col_pointers
  @col_pointers
end

#row_indicesObject (readonly)

Returns the value of attribute row_indices.



97
98
99
# File 'lib/spark/mllib/matrix.rb', line 97

def row_indices
  @row_indices
end