Module: JBLAS::MatrixEnumMixin
Overview
Mixin for collecting enumerable operations.
Collected in MatrixMixin.
Instance Method Summary collapse
-
#each ⇒ Object
Each iterates over each element, going down rows first.
-
#each_column ⇒ Object
Iterate over columns.
-
#each_row ⇒ Object
Iterate over rows.
-
#map(&block) ⇒ Object
Map each element.
-
#map!(&block) ⇒ Object
Map each element and store the result in the matrix.
Methods included from Enumerable
Instance Method Details
#each ⇒ Object
Each iterates over each element, going down rows first.
57 58 59 60 61 |
# File 'lib/jblas/mixin_enum.rb', line 57 def each (0...length).each do |i| yield get(i) end end |
#each_column ⇒ Object
Iterate over columns.
50 51 52 53 54 |
# File 'lib/jblas/mixin_enum.rb', line 50 def each_column (0...columns).each do |j| yield column(j) end end |
#each_row ⇒ Object
Iterate over rows.
43 44 45 46 47 |
# File 'lib/jblas/mixin_enum.rb', line 43 def each_row (0...rows).each do |i| yield row(i) end end |
#map(&block) ⇒ Object
Map each element.
Returns a new matrix of the same type. This means that the block must return something which can again be stored in the matrix.
67 68 69 |
# File 'lib/jblas/mixin_enum.rb', line 67 def map(&block) return dup.map!(&block) end |
#map!(&block) ⇒ Object
Map each element and store the result in the matrix.
Note that the result must be again something which can be stored in the matrix. Otherwise you should do an to_a first.
76 77 78 79 80 81 |
# File 'lib/jblas/mixin_enum.rb', line 76 def map!(&block) (0...length).each do |i| put(i, block.call(get(i))) end self end |