Class: Hal4R::Matrix
- Inherits:
-
Object
- Object
- Hal4R::Matrix
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/hal4r/matrix.rb
Constant Summary collapse
- DEFAULT_STEP =
512
Instance Attribute Summary collapse
-
#step ⇒ Object
Returns the value of attribute step.
Instance Method Summary collapse
- #each_col(&block) ⇒ Object
- #get(index) ⇒ Object
-
#initialize(step = nil) ⇒ Matrix
constructor
A new instance of Matrix.
- #inspect ⇒ Object
- #vector(index, size = size(), norm = false) ⇒ Object
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
#step ⇒ Object
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) unless index < size @matrix.row(index) end |
#inspect ⇒ Object
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 |