class Matrix

Public Class Methods

new() click to toggle source
# File lib/generic/matrix.rb, line 2
def initialize()
  @mat = []
  @n = 0
end

Public Instance Methods

get(at) click to toggle source
# File lib/generic/matrix.rb, line 22
def get(at)
  i = at[0]
  j = at[1]
  @mat[i][j]
end
m_size() click to toggle source
# File lib/generic/matrix.rb, line 11
def m_size
  @mat.size
end
n_size() click to toggle source
# File lib/generic/matrix.rb, line 7
def n_size
  @n
end
set(at, value) click to toggle source
# File lib/generic/matrix.rb, line 15
def set(at, value)
  expand(at)
  i = at[0]
  j = at[1]
  @mat[i][j] = value
end
to_s() click to toggle source
# File lib/generic/matrix.rb, line 28
  def to_s
    p @mat
#    print "["
#    print @mat.join(",\n")
#    print "]\n"
  end

Private Instance Methods

expand(by) click to toggle source
# File lib/generic/matrix.rb, line 37
def expand(by)
  _m_size = by[0] + 1
  _n_size = by[1] + 1

  if _m_size > m_size
    expand_m(_m_size)
  end

  if _n_size > n_size
    expand_n(_n_size)
  end

end
expand_m(to) click to toggle source
# File lib/generic/matrix.rb, line 51
def expand_m(to)
  (to-m_size).times do
    @mat << Array.new(n_size)
  end
end
expand_n(to) click to toggle source
# File lib/generic/matrix.rb, line 57
def expand_n(to)
  @mat.each do |x|
    n = x.size
    (to-n).times do
      x << nil
    end
  end
  @n = to
end