class Matrix

Matrix extensions

Public Class Methods

ones(*dims) click to toggle source

Build an array of 1's

# File lib/epitools/core_ext/matrix.rb, line 25
def self.ones(*dims)
  build(*dims) { 1 }
end
random(*dims) click to toggle source

Create a matrix of the specified size full of random numbers.

# File lib/epitools/core_ext/matrix.rb, line 32
def self.random(*dims)
  build(*dims) { rand }
end

Public Instance Methods

blit!(submatrix, top, left) click to toggle source

Overlay one matrix onto another

# File lib/epitools/core_ext/matrix.rb, line 83
def blit!(submatrix, top, left)
  submatrix.each_row.with_index do |row, y|
    row.each.with_index do |elem, x|
      self[top+y,left+x] = elem
    end
  end
end
Also aliased as: overlay!
draw(header=true, separator=" ")
Alias for: print
each_row() { |row(num)| ... } click to toggle source

Iterate over rows (takes a block or returns an Enumerator)

# File lib/epitools/core_ext/matrix.rb, line 46
def each_row
  return to_enum(:each_row) unless block_given?

  (0...row_count).each do |num|
    yield row(num)
  end
end
overlay!(submatrix, top, left)
Alias for: blit!
print(header=true, separator=" ") click to toggle source

Print the matrix to the STDOUT.

Also aliased as: draw
size() click to toggle source

The size of the matrix, returned as `[rows, columns]`.

# File lib/epitools/core_ext/matrix.rb, line 39
def size
  [row_size, column_size]
end