Class: Kwyjibo::SparseMatrix

Inherits:
Matrix
  • Object
show all
Defined in:
lib/kwyjibo.rb

Instance Attribute Summary collapse

Attributes inherited from Matrix

#cols, #rows

Instance Method Summary collapse

Methods inherited from Matrix

#*, #+, #-, #max, #min

Constructor Details

#initialize(rows, cols, h = {}) ⇒ SparseMatrix



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/kwyjibo.rb', line 174

def initialize(rows,cols, h = {})
    @data = Hash.new({})
    for k in h.keys do
        if h[k].is_a? SparseVector
            @data[k] = h[k]
        else
            @data[k] = SparseVector.new(h[k])
        end
    end
    super(rows,cols)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



172
173
174
# File 'lib/kwyjibo.rb', line 172

def data
  @data
end

Instance Method Details

#[](i) ⇒ Object



186
187
188
# File 'lib/kwyjibo.rb', line 186

def [](i)
    @data[i]
end