Project

General

Profile

This project is closed and read-only.

Actions

Bug #1517

closed

Matrix[] Performs No Argument Validation, Confusing Some of Its Instance Methods

Bug #1517: Matrix[] Performs No Argument Validation, Confusing Some of Its Instance Methods

Added by runpaint (Run Paint Run Run) over 17 years ago. Updated over 15 years ago.


Description

=begin
The Matrix[] constructor accepts anything as argument. This can cause problems for its instance methods. For example, consider a Fixnum:

 >> m = Matrix[1]
 => Matrix[1]

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:

 >> m.column_size
 => 4

Which leads to:

 >> m.column_vectors
 => [Vector[1], Vector[0], Vector[0], Vector[0]]

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


Related issues 1 (0 open1 closed)

Related to Ruby - Bug #1532: Improved matrix.rb [patch]Closedkeiju (Keiju Ishitsuka)Actions
Actions

Also available in: PDF Atom