Project

General

Profile

Bug #1532 » e_matrix_enum.diff

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

View differences:

lib/matrix.rb
def row(i, &block) # :yield: e
if block_given?
@rows[i].each(&block)
self
else
Vector.elements(@rows[i])
end
......
row_size.times do |i|
yield @rows[i][j]
end
self
else
col = (0 ... row_size).collect {|i|
@rows[i][j]
......
# 9 16
#
def collect(&block) # :yield: e
return to_enum(:collect) unless block_given?
rows = @rows.collect{|row| row.collect(&block)}
new rows, column_size
end
......
#
def each2(v) # :yield: e1, e2
Vector.Raise ErrDimensionMismatch if size != v.size
return to_enum(:each2) unless block_given?
size.times do |i|
yield @elements[i], v[i]
end
......
#
def collect2(v) # :yield: e1, e2
Vector.Raise ErrDimensionMismatch if size != v.size
return to_enum(:collect2) unless block_given?
(0 ... size).collect do |i|
yield @elements[i], v[i]
end
......
# Like Array#collect.
#
def collect(&block) # :yield: e
return to_enum(:collect) unless block_given?
els = @elements.collect(&block)
Vector.elements(els, false)
end
......
# Like Vector#collect2, but returns a Vector instead of an Array.
#
def map2(v, &block) # :yield: e1, e2
return to_enum(:map2) unless block_given?
els = collect2(v, &block)
Vector.elements(els, false)
end
(7-7/7)