Bug #1532 » f_matrix_access.diff
lib/matrix.rb | ||
---|---|---|
# Returns element (+i+,+j+) of the matrix. That is: row +i+, column +j+.
|
||
#
|
||
def [](i, j)
|
||
@rows[i][j]
|
||
@rows.fetch(i){return nil}[j]
|
||
end
|
||
alias element []
|
||
alias component []
|
||
... | ... | |
#
|
||
def row(i, &block) # :yield: e
|
||
if block_given?
|
||
@rows[i].each(&block)
|
||
@rows.fetch(i){return self}.each(&block)
|
||
self
|
||
else
|
||
Vector.elements(@rows[i])
|
||
Vector.elements(@rows.fetch(i){return nil})
|
||
end
|
||
end
|
||
... | ... | |
if block_given?
|
||
row_size.times do |i|
|
||
yield @rows[i][j]
|
||
end
|
||
end unless j >= column_size
|
||
self
|
||
else
|
||
return nil if j >= column_size
|
||
col = (0 ... row_size).collect {|i|
|
||
@rows[i][j]
|
||
}
|
||
... | ... | |
Matrix.Raise ArgumentError, param.inspect
|
||
end
|
||
return nil if from_row > row_size || from_col > column_size
|
||
rows = @rows[from_row, size_row].collect{|row|
|
||
row[from_col, size_col]
|
||
}
|