class Hal4R::Matrix
Constants
- DEFAULT_STEP
Attributes
step[RW]
Public Class Methods
new(step = nil)
click to toggle source
# File lib/hal4r/matrix.rb, line 42 def initialize(step = nil) @matrix = matrix(@step = step || DEFAULT_STEP) end
Public Instance Methods
each_col(&block)
click to toggle source
# File lib/hal4r/matrix.rb, line 60 def each_col(&block) block ? @matrix.each_col(&block) : enum_for(:each_col) end
get(index)
click to toggle source
# File lib/hal4r/matrix.rb, line 48 def get(index) expand unless index < size @matrix.row(index) end
inspect()
click to toggle source
# File lib/hal4r/matrix.rb, line 64 def inspect '#<%s:0x%x @step=%p, @size=%p>' % [ self.class, object_id, step, size ] end
vector(index, size = size(), norm = false)
click to toggle source
# File lib/hal4r/matrix.rb, line 53 def vector(index, size = size(), norm = false) vector = @matrix.subrow(index, 0, size) .concat(@matrix.subcolumn(index, 0, size)) Vector.new(norm ? vector.to_f.normalize : vector) end
Private Instance Methods
expand(new_size = size + step)
click to toggle source
# File lib/hal4r/matrix.rb, line 72 def expand(new_size = size + step) @matrix = matrix(new_size).set(range = 0 .. size - 1, range, @matrix) end
matrix(size)
click to toggle source
# File lib/hal4r/matrix.rb, line 76 def matrix(size) GSL::Matrix::Int.zeros(size) end