Sander Land
2/2/2007 9:06:00 PM
I think I found some bugs in Matrix#rank
>ruby -rmatrix -e'p Matrix[[7,0], [1,0], [2,0]].rank'
.../matrix.rb:761:in `/': nil can't be coerced into Fixnum (TypeError)
>ruby -rmatrix -e'p Matrix[[7,0], [1,0], [2,1]].rank'
.../matrix.rb:761:in `/': nil can't be coerced into Fixnum (TypeError)
Fix (?):
change
exists = true
begin
if (i += 1) > a_column_size - 1 # line 731
exists = false
break
end
end while a[i][k] == 0
to
exists = true
begin
if (i += 1) > a_row_size - 1
exists = false
break
end
end while a[i][k] == 0
and
exists = true
begin
if (i += 1) > a_row_size - 1 # line 743
exists = false
break
end
end while a[k][i] == 0
to
exists = true
begin
if (i += 1) > a_column_size - 1
exists = false
break
end
end while a[k][i] == 0
The error seems to be caused by using loop indices up to row/column
size for column/row indices, which causes some swaps with nil values.
version:
>ruby -v
ruby 1.8.5 (2006-08-25) [i386-mingw32]