Bugs in Matrix#rank

S

Sander Land

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[k] == 0

to
exists = true
begin
if (i += 1) > a_row_size - 1
exists = false
break
end
end while a[k] == 0

and

exists = true
begin
if (i += 1) > a_row_size - 1 # line 743
exists = false
break
end
end while a[k] == 0

to

exists = true
begin
if (i += 1) > a_column_size - 1
exists = false
break
end
end while a[k] == 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 1.8.5 (2006-08-25) [i386-mingw32]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,230
Messages
2,571,161
Members
47,794
Latest member
LucretiaEl

Latest Threads

Top