Class: Hal4R::Matrix

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/hal4r/matrix.rb

Constant Summary collapse

DEFAULT_STEP =
512

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step = nil) ⇒ Matrix

Returns a new instance of Matrix.



42
43
44
# File 'lib/hal4r/matrix.rb', line 42

def initialize(step = nil)
  @matrix = matrix(@step = step || DEFAULT_STEP)
end

Instance Attribute Details

#stepObject

Returns the value of attribute step.



46
47
48
# File 'lib/hal4r/matrix.rb', line 46

def step
  @step
end

Instance Method Details

#each_col(&block) ⇒ Object



60
61
62
# File 'lib/hal4r/matrix.rb', line 60

def each_col(&block)
  block ? @matrix.each_col(&block) : enum_for(:each_col)
end

#get(index) ⇒ Object



48
49
50
51
# File 'lib/hal4r/matrix.rb', line 48

def get(index)
  expand unless index < size
  @matrix.row(index)
end

#inspectObject



64
65
66
67
68
# 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) ⇒ Object



53
54
55
56
57
58
# 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