This project is closed and read-only.
Actions
Bug #1517
closedMatrix[] Performs No Argument Validation, Confusing Some of Its Instance Methods
Bug #1517:
Matrix[] Performs No Argument Validation, Confusing Some of Its Instance Methods
Status:
Closed
Assignee:
Description
=begin
The Matrix[] constructor accepts anything as argument. This can cause problems for its instance methods. For example, consider a Fixnum:
This works as you'd expect. But then:
>> m.row(0)
TypeError: can't dup Fixnum
from /usr/lib/ruby/1.9.0/matrix.rb:1132:in `dup'
from /usr/lib/ruby/1.9.0/matrix.rb:1132:in `init_elements'
from /usr/lib/ruby/1.9.0/matrix.rb:1124:in `initialize'
from /usr/lib/ruby/1.9.0/matrix.rb:1117:in `new'
from /usr/lib/ruby/1.9.0/matrix.rb:1117:in `elements'
from /usr/lib/ruby/1.9.0/matrix.rb:303:in `row'
from (irb):20
from /usr/bin/irb1.9:12:in `<main>'
Or:
Which leads to:
If such arguments are accepted, Matrix should coerce them into a matrix. Presumably, the easiest approach would be to have Matrix[1] == Matrix[[1]]. Otherwise, Matrix[] should raise an ArgumentError if it doesn't receive an Array. Ideally, you should only be able to create matrices of Arrays of Numeric-like objects. The current behaviour is non-intuitive, and invites bugs.
=end
Updated by marcandre (Marc-Andre Lafortune) almost 17 years ago
- Category set to lib
- Assignee set to keiju (Keiju Ishitsuka)
=begin
=end
Updated by keiju (Keiju Ishitsuka) almost 17 years ago
- Status changed from Open to Closed
=begin
=end
Actions