Project

General

Profile

Bug #1532 ยป e_matrix_enum.diff

marcandre (Marc-Andre Lafortune), 09/17/2009 02:03 PM

View differences:

lib/matrix.rb
277 277
  def row(i, &block) # :yield: e
278 278
    if block_given?
279 279
      @rows[i].each(&block)
280
      self
280 281
    else
281 282
      Vector.elements(@rows[i])
282 283
    end
......
292 293
      row_size.times do |i|
293 294
        yield @rows[i][j]
294 295
      end
296
      self
295 297
    else
296 298
      col = (0 ... row_size).collect {|i|
297 299
        @rows[i][j]
......
308 310
  #        9 16
309 311
  #
310 312
  def collect(&block) # :yield: e
313
    return to_enum(:collect) unless block_given?
311 314
    rows = @rows.collect{|row| row.collect(&block)}
312 315
    new rows, column_size
313 316
  end
......
1091 1094
  #
1092 1095
  def each2(v) # :yield: e1, e2
1093 1096
    Vector.Raise ErrDimensionMismatch if size != v.size
1097
    return to_enum(:each2) unless block_given?
1094 1098
    size.times do |i|
1095 1099
      yield @elements[i], v[i]
1096 1100
    end
......
1102 1106
  #
1103 1107
  def collect2(v) # :yield: e1, e2
1104 1108
    Vector.Raise ErrDimensionMismatch if size != v.size
1109
    return to_enum(:collect2) unless block_given?
1105 1110
    (0 ... size).collect do |i|
1106 1111
      yield @elements[i], v[i]
1107 1112
    end
......
1218 1223
  # Like Array#collect.
1219 1224
  #
1220 1225
  def collect(&block) # :yield: e
1226
    return to_enum(:collect) unless block_given?
1221 1227
    els = @elements.collect(&block)
1222 1228
    Vector.elements(els, false)
1223 1229
  end
......
1227 1233
  # Like Vector#collect2, but returns a Vector instead of an Array.
1228 1234
  #
1229 1235
  def map2(v, &block) # :yield: e1, e2
1236
    return to_enum(:map2) unless block_given?
1230 1237
    els = collect2(v, &block)
1231 1238
    Vector.elements(els, false)
1232 1239
  end