# [Bug:trunk] three bugs of Matrix::Scalar

e\$BO"Ej\$9\$_\$^\$;\$s!#e(B
[ruby-dev:40149] e\$B\$HA4\$/F1\$8FbMF\$G\$9\$,!"e(Bsubject e\$B\$Ke(B
[Bug:trunk] e\$B\$re(B
e\$B\$D\$1K:\$l\$?\$N\$G:FAw\$7\$^\$9!#e(B

=====

e\$B1sF#\$G\$9!#e(B

Matrix::Scalar e\$B\$NDj5A\$Ke(B 3 e\$B\$D\$*\$+\$7\$\$\$H\$3\$m\$r8+\$D\$1\$^\$7\$?!#e(B
nodoc e\$B\$J%/%i%9\$G\$9\$,!"\$I\$l\$bC1=c\$JLdBj\$@\$H;W\$&\$N\$GJs9p\$7\$^\$9!#e(B

e\$B!{e(B WrongArgType e\$B\$,L\$Dj5Ae(B
\$ ./ruby -rmatrix -e ‘Matrix[[0]].coerce(1).first + Matrix[[0]]’
/home/mame/work/ruby/lib/matrix.rb:979:in `+': uninitialized constant Matrix::Scalar::WrongArgType (NameError) from -e:1:in`

e\$B\$?\$@\$NDj5AK:\$l\$@\$H;W\$\$\$^\$9!#e(B

e\$B!{e(B Matrix#powered_by e\$B\$,L\$Dj5Ae(B
\$ ./ruby -rmatrix -e ‘2 ** Matrix[[1]]’
/home/mame/work/ruby/lib/matrix.rb:1032:in `**': undefined method`powered_by’ for Matrix[[1]]:Matrix (NoMethodError)
from -e:1:in `**' from -e:1:in`

e\$B\$=\$b\$=\$be(B 2 ** Matrix[[1]]
e\$B\$K0UL#\$O\$J\$\$\$H;W\$&\$N\$G!"e(BMatrix::Scalar#** e\$B\$Oe(B
e\$B0z?t\$,e(B Matrix e\$B\$@\$C\$?\$iNc30\$K\$9\$Y\$-\$G\$O\$J\$\$\$G\$7\$g\$&\$+!#e(B

e\$B!{e(B when Numeric e\$B\$N8e\$Ke(B when Scalar e\$B\$,\$"\$ke(B
Scalar e\$B\$Oe(B Numeric e\$B\$N%5%V%/%i%9\$J\$N\$G!"e(Bwhen Scalar
e\$B\$O<B9T\$5\$l\$^\$;\$s!#e(B
e\$B\$b\$7<B9T\$5\$l\$k\$h\$&\$K\$J\$C\$?\$H\$7\$F\$b!“e(Bother.value
e\$B\$H\$\$\$&5-=R\$,\$”\$j!"e(B
Scalar e\$B\$Oe(B value e\$B\$H\$\$\$&%a%=%C%I\$rDs6!\$7\$F\$\$\$J\$\$\$N\$Ge(B
NoMethodError e\$B\$K\$J\$ke(B
e\$B\$H;W\$\$\$^\$9!#e(B

— a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -27,6 +27,7 @@ module ExceptionForMatrix # :nodoc:
def_exception(“ErrDimensionMismatch”, “#{self.name} dimension
mismatch”)
def_exception(“ErrNotRegular”, “Not Regular Matrix”)
def_exception(“ErrOperationNotDefined”, “This operation(%s) can\'t
defined”)

• def_exception(“WrongArgType”, “wrong argument type %s (expected %s)”)
end

@@ -977,8 +978,6 @@ class Matrix
Scalar.new(@value + other)
when Vector, Matrix
Scalar.Raise WrongArgType, other.class, “Numeric or Scalar”

• `````` when Scalar
``````
• ``````   Scalar.new(@value + other.value)
else
x, y = other.coerce(self)
x + y
``````

@@ -991,8 +990,6 @@ class Matrix
Scalar.new(@value - other)
when Vector, Matrix
Scalar.Raise WrongArgType, other.class, “Numeric or Scalar”

• `````` when Scalar
``````
• ``````   Scalar.new(@value - other.value)
else
x, y = other.coerce(self)
x - y
``````

@@ -1029,10 +1026,8 @@ class Matrix
case other
when Numeric
Scalar.new(@value ** other)

• `````` when Vector
``````
• ``````   Scalar.Raise WrongArgType, other.class, "Numeric or Scalar or
``````

Matrix"

• `````` when Matrix
``````
• ``````   other.powered_by(self)
``````
• `````` when Vector, Matrix
``````
• ``````   Scalar.Raise WrongArgType, other.class, "Numeric or Scalar"
else
x, y = other.coerce(self)
x ** y``````

e\$BK-J!\$G\$9!#e(B

On Tue, 26 Jan 2010 00:32:45 +0900
Yusuke ENDOH [email protected] wrote:

e\$B!{e(B Matrix#powered_by e\$B\$,L\$Dj5Ae(B

e\$B\$=\$b\$=\$be(B 2 ** Matrix[[1]] e\$B\$K0UL#\$O\$J\$\$\$H;W\$&\$N\$G!"e(BMatrix::Scalar#** e\$B\$Oe(B
e\$B0z?t\$,e(B Matrix e\$B\$@\$C\$?\$iNc30\$K\$9\$Y\$-\$G\$O\$J\$\$\$G\$7\$g\$&\$+!#e(B

e\$B4WOC!#e(B
| Subject: [ruby-dev:1989] Re: coerce
| From: keiju rational.com (Keiju ISHITSUKA)
| Date: Mon, 30 Mar 1998 15:24:46 +0900
|
| >>>e\$B\$^\$5\$+e(B exp(M) e\$B\$r7W;;\$7\$FJV\$=\$&\$H!&!&!&e(B
| >> e\$BB?J,\$=\$NDL\$j\$G\$9e(B. jordane\$BI8=`7A\$,5a\$^\$l\$Pe(Bexp(M)e\$B\$O5a\$^\$j\$^\$9\$7e(B…
| >
| > e\$BH>J,>iCL\$N\$D\$b\$j\$G=q\$\$\$?\$N\$G\$9\$,K\Ev\$K\$=\$N\$D\$b\$je(B
| >e\$B\$@\$C\$?\$H\$O!&!&!&!#e(B
|
| # e\$B\$=\$&\$\$\$&\$3\$H\$O7k9=9%\$-\$J\$s\$G\$9e(B(^^;;;

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

In [ruby-dev:40153] the message: “[ruby-dev:40153] [Bug:trunk] three
bugs of Matrix::Scalar”, on Jan/26 00:32(JST) Yusuke ENDOH writes:

e\$BO"Ej\$9\$_\$^\$;\$s!#e(B
[ruby-dev:40149] e\$B\$HA4\$/F1\$8FbMF\$G\$9\$,!"e(Bsubject e\$B\$Ke(B [Bug:trunk] e\$B\$re(B
e\$B\$D\$1K:\$l\$?\$N\$G:FAw\$7\$^\$9!#e(B

e\$B\$"!<e(B.
e\$B\$3\$C\$A\$K%j%W%i%\$\$7\$J\$/\$A\$c9T\$1\$J\$+\$C\$?\$s\$G\$9\$Me(B…

e\$B0lO"\$N%a%\$%k\$r\$^\$H\$a\$k\$H0J2<\$N%Q%C%A\$G\$O\$\$\$+\$,\$G\$7\$g\$&e(B?

e\$B:XF#\$5\$s\$Ne(B [ruby-dev:40176] e\$B\$Ge(B

• `````` Vector.Raise WrongArgType, x.class, "Numeric or Matrix"
``````

e\$B\$NOC\$,\$"\$j\$^\$7\$?\$,e(B, e\$B85!9e(B WrongArgType
e\$B\$,Dj5A\$5\$l\$F\$\$\$J\$\$e(B. e\$B\$^\$?e(B, Matrix
e\$BEy\$G\$Oe(B, ErrOperationNotDefined
e\$B\$r;H\$C\$F\$\$\$?\$N\$G\$3\$A\$i\$KE}0l\$7\$^\$7\$?e(B.

e\$B\$"\$He(B, e\$B:XF#\$5\$s\$Ne(B
e\$B%a%C%;!<%8\$,IT?F@Z\$H\$N;XE&\$r9MN8\$7%(%i!<%a%C%;!<%8\$be(B
e\$B>/\$7=\$@5\$7\$^\$7\$?e(B.

e\$B0[O@\$,\$J\$1\$l\$P%3%_%C%H\$7\$?\$\$\$H;W\$\$\$^\$9e(B.

diff --git a/matrix.rb b/matrix.rb
index 90e393c…f417323 100644
— a/matrix.rb
+++ b/matrix.rb
@@ -26,7 +26,8 @@ module ExceptionForMatrix # :nodoc:

def_exception(“ErrDimensionMismatch”, “#{self.name} dimension
mismatch”)
def_exception(“ErrNotRegular”, “Not Regular Matrix”)

• def_exception(“ErrOperationNotDefined”, “This operation(%s) can\'t
defined”)
• def_exception(“ErrOperationNotDefined”, “Operation(%s) can\'t be
defined: %s op %s”)
• def_exception(“ErrOperationNotImplement”, “Sorry, Operation(%s) not
implemented: %s op %s”)
end

@@ -497,7 +498,7 @@ class Matrix
def +(m)
case m
when Numeric

• `````` Matrix.Raise ErrOperationNotDefined, "+"
``````
• `````` Matrix.Raise ErrOperationNotDefined, "+", self.class, m.class
``````
when Vector
m = Matrix.column_vector(m)
when Matrix
@@ -525,7 +526,7 @@ class Matrix
def -(m)
case m
when Numeric
• `````` Matrix.Raise ErrOperationNotDefined, "-"
``````
• `````` Matrix.Raise ErrOperationNotDefined, "-", self.class, m.class
``````
when Vector
m = Matrix.column_vector(m)
when Matrix
@@ -649,9 +650,9 @@ class Matrix
x *= x
end
elsif other.kind_of?(Float) || defined?(Rational) &&
other.kind_of?(Rational)
• `````` Matrix.Raise ErrOperationNotDefined, "**"
``````
• `````` Matrix.Raise ErrOperationNotImplement, "**", self.class,
``````

other.class
else

• `````` Matrix.Raise ErrOperationNotDefined, "**"
``````
• `````` Matrix.Raise ErrOperationNotDefined, "**", self.class,
``````

other.class
end
end

@@ -976,9 +977,7 @@ class Matrix
when Numeric
Scalar.new(@value + other)
when Vector, Matrix

• ``````   Scalar.Raise TypeError, other.class, "Numeric or Scalar"
``````
• `````` when Scalar
``````
• ``````   Scalar.new(@value + other.value)
``````
• ``````   Scalar.Raise ErrOperationNotDefined, "+", @value.class,
``````

other.class
else
x, y = other.coerce(self)
x + y
@@ -990,9 +989,7 @@ class Matrix
when Numeric
Scalar.new(@value - other)
when Vector, Matrix

• ``````   Scalar.Raise WrongArgType, other.class, "Numeric or Scalar"
``````
• `````` when Scalar
``````
• ``````   Scalar.new(@value - other.value)
``````
• ``````   Scalar.Raise ErrOperationNotDefined, "-", @value.class,
``````

other.class
else
x, y = other.coerce(self)
x - y
@@ -1016,7 +1013,7 @@ class Matrix
when Numeric
Scalar.new(@value / other)
when Vector

• ``````   Scalar.Raise WrongArgType, other.class, "Numeric or Scalar or
``````

Matrix"

• ``````   Scalar.Raise ErrOperationNotDefined, "/", @value.class,
``````

other.class
when Matrix
self * other.inverse
else
@@ -1030,9 +1027,10 @@ class Matrix
when Numeric
Scalar.new(@value ** other)
when Vector

• ``````   Scalar.Raise WrongArgType, other.class, "Numeric or Scalar or
``````

Matrix"

• ``````   Scalar.Raise ErrOperationNotDefined, "**", @value.class,
``````

other.class
when Matrix

• ``````   other.powered_by(self)
``````
• ``````   #other.powered_by(self)
``````
• ``````   Scalar.Raise ErrOperationNotImplement, "**", @value.class,
``````

other.class
else
x, y = other.coerce(self)
x ** y
@@ -1214,6 +1212,8 @@ class Vector
Vector.elements(els, false)
when Matrix
Matrix.column_vector(self) * x

• when Vector

• `````` Vector.Raise ErrOperationNotDefined, "*", self.class, x.class
``````

else
s, x = x.coerce(self)
s * x
@@ -1258,6 +1258,22 @@ class Vector
end
end

• # Vector division.

• def /(x)

• case x

• when Numeric

• `````` els = @elements.collect{|e| e / x}
``````
• `````` Vector.elements(els, false)
``````
• when Matrix, Vector

• `````` Vector.Raise ErrOperationNotDefined, "/", self.class, x.class
``````
• else

• `````` s, x = x.coerce(self)
``````
• `````` s / x
``````
• end

• end

• #–

# VECTOR FUNCTIONS

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#++
__
---------------------------------------------------->> e\$B@PDMe(B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

In [ruby-dev:40189] the message: “[ruby-dev:40189] Re: [Bug:trunk]
three bugs of Matrix::Scalar”, on Jan/27 22:51(JST) Yusuke ENDOH
writes:

e\$B1sF#\$G\$9!#e(B

e\$B\$\$\$\$\$H;W\$\$\$^\$7\$?!#e(B

e\$B\$O\$\$e(B.

e\$B\$R\$H\$D\$@\$15\$\$K\$J\$C\$?\$3\$H!#e(BErrOperationNotImplement e\$B\$h\$j\$Oe(B
ErrOperationNotImplemented e\$B\$NJ}\$,\$h\$/\$J\$\$\$G\$7\$g\$&\$+!#e(B

e\$B\$=\$&\$G\$9\$Me(B. e\$B=\$@5\$7\$^\$7\$?e(B.
e\$B%3%_%C%H\$7\$^\$7\$?e(B.

e\$B\$3\$l\$,%3%%C%H\$5\$l\$?\$i!"0J2<\$N%F%9%H\$r%3%%C%H\$7\$?\$\$\$H;W\$\$\$^\$9!#e(B

e\$B\$"!<e(B. e\$B\$3\$N7oK:\$l\$F\$\$\$^\$7\$?e(B…

• def test_compare_by_row_vectors
• assert(@m1.compare_by_row_vectors([[1, 2, 3], [4, 5, 6]]))
• end

e\$B\$b\$H\$b\$He(B, Matrix#compare_by_row_vectors e\$B\$C\$Fe(B
Matrixe\$BF1;N\$NHf3S\$N\$?\$a\$Je(B
e\$B\$N\$Ge(B, e\$B\$3\$&8@\$C\$?\$3\$H\$OA[Dj\$7\$F\$\$\$J\$+\$C\$?\$s\$G\$9\$h\$M\$'e(B…

__
---------------------------------------------------->> e\$B@PDMe(B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e\$B1sF#\$G\$9!#e(B

2010e\$BG/e(B1e\$B7ne(B27e\$BF|e(B19:50 e\$B@PDM7=<ye(B
[email protected]:

e\$B0lO"\$N%a%\$%k\$r\$^\$H\$a\$k\$H0J2<\$N%Q%C%A\$G\$O\$\$\$+\$,\$G\$7\$g\$&e(B?

e\$B\$\$\$\$\$H;W\$\$\$^\$7\$?!#e(B

e\$B\$R\$H\$D\$@\$15\$\$K\$J\$C\$?\$3\$H!#e(BErrOperationNotImplement e\$B\$h\$j\$Oe(B
ErrOperationNotImplemented e\$B\$NJ}\$,\$h\$/\$J\$\$\$G\$7\$g\$&\$+!#e(B

e\$B\$3\$l\$,%3%%C%H\$5\$l\$?\$i!"0J2<\$N%F%9%H\$r%3%%C%H\$7\$?\$\$\$H;W\$\$\$^\$9!#e(B

diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb
index 6b9b587…526d7a3 100644
— a/test/matrix/test_matrix.rb
+++ b/test/matrix/test_matrix.rb
@@ -10,6 +10,15 @@ class TestMatrix < Test::Unit::TestCase
@n1 = Matrix[[2,3,4], [5,6,7]]
end

• def test_matrix
• assert_equal(1, @m1[0, 0])
• assert_equal(2, @m1[0, 1])
• assert_equal(3, @m1[0, 2])
• assert_equal(4, @m1[1, 0])
• assert_equal(5, @m1[1, 1])
• assert_equal(6, @m1[1, 2])
• end
• def test_identity
assert_same @m1, @m1
assert_not_same @m1, @m2
@@ -153,4 +162,297 @@ class TestMatrix < Test::Unit::TestCase
assert_equal(45, Matrix[[7,6], [3,9]].determinant)
assert_equal(-18, Matrix[[2,0,1],[0,-2,2],[1,2,3]].determinant)
end
• def test_new_matrix
• assert_raise(TypeError) { Matrix[Object.new] }
• o = Object.new
• def o.to_ary; [1,2,3]; end
• assert_equal(@m1, Matrix[o, [4,5,6]])
• end
• def test_rows
• assert_equal(@m1, Matrix.rows([[1, 2, 3], [4, 5, 6]]))
• end
• def test_columns
• assert_equal(@m1, Matrix.columns([[1, 4], [2, 5], [3, 6]]))
• end
• def test_diagonal
• assert_equal(Matrix[[3,0,0],[0,2,0],[0,0,1]], Matrix.diagonal(3, 2,
1))
• assert_equal(Matrix[[4,0,0,0],[0,3,0,0],[0,0,2,0],[0,0,0,1]],
Matrix.diagonal(4, 3, 2, 1))
• end
• def test_scalar
• assert_equal(Matrix[[2,0,0],[0,2,0],[0,0,2]], Matrix.scalar(3, 2))
• assert_equal(Matrix[[2,0,0,0],[0,2,0,0],[0,0,2,0],[0,0,0,2]],
Matrix.scalar(4, 2))
• end
• def test_identity2
• assert_equal(Matrix[[1,0,0],[0,1,0],[0,0,1]], Matrix.identity(3))
• assert_equal(Matrix[[1,0,0],[0,1,0],[0,0,1]], Matrix.unit(3))
• assert_equal(Matrix[[1,0,0],[0,1,0],[0,0,1]], Matrix.I(3))
• assert_equal(Matrix[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],
Matrix.identity(4))
• end
• def test_zero
• assert_equal(Matrix[[0,0,0],[0,0,0],[0,0,0]], Matrix.zero(3))
• assert_equal(Matrix[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],
Matrix.zero(4))
• assert_equal(Matrix[[0]], Matrix.zero(1))
• end
• def test_row_vector
• assert_equal(Matrix[[1,2,3,4]], Matrix.row_vector([1,2,3,4]))
• end
• def test_column_vector
• assert_equal(Matrix[[1],[2],[3],[4]],
Matrix.column_vector([1,2,3,4]))
• end
• def test_empty
• m = Matrix.empty(2, 0)
• assert_equal(Matrix[ [], [] ], m)
• n = Matrix.empty(0, 3)
• assert_equal(Matrix.columns([ [], [], [] ]), n)
• assert_equal(Matrix[[0, 0, 0], [0, 0, 0]], m * n)
• end
• def test_row
• assert_equal(Vector[1, 2, 3], @m1.row(0))
• assert_equal(Vector[4, 5, 6], @m1.row(1))
• a = []; @m1.row(0) {|x| a << x }
• assert_equal([1, 2, 3], a)
• end
• def test_column
• assert_equal(Vector[1, 4], @m1.column(0))
• assert_equal(Vector[2, 5], @m1.column(1))
• assert_equal(Vector[3, 6], @m1.column(2))
• a = []; @m1.column(0) {|x| a << x }
• assert_equal([1, 4], a)
• end
• def test_collect
• assert_equal(Matrix[[1, 4, 9], [16, 25, 36]], @m1.collect {|x| x **
2 })
• end
• def test_minor
• assert_equal(Matrix[[1, 2], [4, 5]], @m1.minor(0…1, 0…1))
• assert_equal(Matrix[[2], [5]], @m1.minor(0…1, 1…1))
• assert_equal(Matrix[[4, 5]], @m1.minor(1…1, 0…1))
• assert_equal(Matrix[[1, 2], [4, 5]], @m1.minor(0, 2, 0, 2))
• assert_equal(Matrix[[4, 5]], @m1.minor(1, 1, 0, 2))
• assert_equal(Matrix[[2], [5]], @m1.minor(0, 2, 1, 1))
• assert_raise(ArgumentError) { @m1.minor(0) }
• end
• def test_regular?
• assert(Matrix[[1, 0], [0, 1]].regular?)
• assert(Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]].regular?)
• assert(!Matrix[[1, 0, 0], [0, 0, 1], [0, 0, 1]].regular?)
• assert(!Matrix[[1, 0, 0], [0, 1, 0]].regular?)
• end
• def test_singular?
• assert(!Matrix[[1, 0], [0, 1]].singular?)
• assert(!Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]].singular?)
• assert(Matrix[[1, 0, 0], [0, 0, 1], [0, 0, 1]].singular?)
• assert(Matrix[[1, 0, 0], [0, 1, 0]].singular?)
• end
• def test_square?
• assert(Matrix[[1, 0], [0, 1]].square?)
• assert(Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]].square?)
• assert(Matrix[[1, 0, 0], [0, 0, 1], [0, 0, 1]].square?)
• assert(!Matrix[[1, 0, 0], [0, 1, 0]].square?)
• end
• def test_compare_by_row_vectors
• assert(@m1.compare_by_row_vectors([[1, 2, 3], [4, 5, 6]]))
• end
• def test_mul
• assert_equal(Matrix[[2,4],[6,8]], Matrix[[2,4],[6,8]] *
Matrix.I(2))
• assert_equal(Matrix[[4,8],[12,16]], Matrix[[2,4],[6,8]] * 2)
• assert_equal(Matrix[[4,8],[12,16]], 2 * Matrix[[2,4],[6,8]])
• assert_equal(Matrix[[14,32],[32,77]], @m1 * @m1.transpose)
• assert_equal(Matrix[[17,22,27],[22,29,36],[27,36,45]],
@m1.transpose * @m1)
• assert_equal(Vector[14,32], @m1 * Vector[1,2,3])
• o = Object.new
• def o.coerce(m)
• `````` [m, m.transpose]
``````
• end
• assert_equal(Matrix[[14,32],[32,77]], @m1 * o)
• end
• assert_equal(Matrix[[6,0],[-4,12]], Matrix.scalar(2,5) +
Matrix[[1,0],[-4,7]])
• assert_equal(Matrix[[3,5,7],[9,11,13]], @m1 + @n1)
• assert_equal(Matrix[[3,5,7],[9,11,13]], @n1 + @m1)
• assert_equal(Matrix[[2],[4],[6]], Matrix[[1],[2],[3]] +
Vector[1,2,3])
• assert_raise(Matrix::ErrOperationNotDefined) { @m1 + 1 }
• o = Object.new
• def o.coerce(m)
• `````` [m, m]
``````
• end
• assert_equal(Matrix[[2,4,6],[8,10,12]], @m1 + o)
• end
• def test_sub
• assert_equal(Matrix[[4,0],[4,-2]], Matrix.scalar(2,5) -
Matrix[[1,0],[-4,7]])
• assert_equal(Matrix[[-1,-1,-1],[-1,-1,-1]], @m1 - @n1)
• assert_equal(Matrix[[1,1,1],[1,1,1]], @n1 - @m1)
• assert_equal(Matrix[[0],[0],[0]], Matrix[[1],[2],[3]] -
Vector[1,2,3])
• assert_raise(Matrix::ErrOperationNotDefined) { @m1 - 1 }
• o = Object.new
• def o.coerce(m)
• `````` [m, m]
``````
• end
• assert_equal(Matrix[[0,0,0],[0,0,0]], @m1 - o)
• end
• def test_div
• assert_equal(Matrix[[0,1,1],[2,2,3]], @m1 / 2)
• assert_equal(Matrix[[1,1],[1,1]], Matrix[[2,2],[2,2]] /
Matrix.scalar(2,2))
• o = Object.new
• def o.coerce(m)
• `````` [m, Matrix.scalar(2,2)]
``````
• end
• assert_equal(Matrix[[1,1],[1,1]], Matrix[[2,2],[2,2]] / o)
• end
• def test_exp
• assert_equal(Matrix[[67,96],[48,99]], Matrix[[7,6],[3,9]] ** 2)
• assert_equal(Matrix.I(5), Matrix.I(5) ** -1)
• assert_raise(Matrix::ErrOperationNotImplemented) { Matrix.I(5) **
1.0 }
• assert_raise(Matrix::ErrOperationNotDefined) { Matrix.I(5) **
Object.new }
• end
• def test_det
• assert_in_delta(45.0, Matrix[[7,6],[3,9]].det, 0.0001)
• assert_in_delta(0.0, Matrix[[0,0],[0,0]].det, 0.0001)
• assert_in_delta(-7.0, Matrix[[0,0,1],[0,7,6],[1,3,9]].det, 0.0001)
• assert_in_delta(0,0, @m1.det, 0.0001)
• end
• def test_det_e
• assert_equal(45, Matrix[[7,6],[3,9]].det_e)
• assert_equal(0, Matrix[[0,0],[0,0]].det_e)
• assert_equal(-7, Matrix[[0,0,1],[0,7,6],[1,3,9]].det_e)
• assert_equal(0, @m1.det_e)
• end
• def test_rank2
• assert_equal(2, Matrix[[7,6],[3,9]].rank)
• assert_equal(0, Matrix[[0,0],[0,0]].rank)
• assert_equal(3, Matrix[[0,0,1],[0,7,6],[1,3,9]].rank)
• assert_equal(2, @m1.rank)
• end
• def test_rank_e
• assert_equal(2, Matrix[[7,6],[3,9]].rank_e)
• assert_equal(0, Matrix[[0,0],[0,0]].rank_e)
• assert_equal(3, Matrix[[0,0,1],[0,7,6],[1,3,9]].rank_e)
• assert_equal(2, @m1.rank_e)
• end
• def test_trace
• assert_equal(1+5+9, Matrix[[1,2,3],[4,5,6],[7,8,9]].trace)
• end
• def test_transpose
• assert_equal(Matrix[[1,4],[2,5],[3,6]], @m1.transpose)
• end
• def test_row_vectors
• assert_equal([Vector[1,2,3], Vector[4,5,6]], @m1.row_vectors)
• end
• def test_column_vectors
• assert_equal([Vector[1,4], Vector[2,5], Vector[3,6]],
@m1.column_vectors)
• end
• def test_elements_to_f
• assert_equal(Matrix[[0.5,1.0,1.5],[2.0,2.5,3.0]], @m1.elements_to_f
/ 2)
• end
• def test_elements_to_i
• assert_equal(Matrix[[0,1,1],[2,2,3]], (@m1.elements_to_f /
2).elements_to_i)
• end
• def test_elements_to_r
• assert_equal(@m1.collect {|x| Rational(x, 2) }, @m1.elements_to_r /
• end
• def test_to_s
• assert_equal(“Matrix[[1, 2, 3], [4, 5, 6]]”, @m1.to_s)
• assert_equal(“Matrix.empty(0, 0)”, Matrix[].to_s)
• assert_equal(“Matrix.empty(1, 0)”, Matrix[[]].to_s)
• end
• def test_inspect
• assert_equal(“Matrix[[1, 2, 3], [4, 5, 6]]”, @m1.inspect)
• assert_equal(“Matrix.empty(0, 0)”, Matrix[].inspect)
• assert_equal(“Matrix.empty(1, 0)”, Matrix[[]].inspect)
• end
• s1 = @m1.coerce(1).first
• assert_equal(Matrix[[1]], (s1 + 0) * Matrix[[1]])
• assert_raise(Matrix::ErrOperationNotDefined) { s1 + Vector[0] }
• assert_raise(Matrix::ErrOperationNotDefined) { s1 + Matrix[[0]] }
• o = Object.new
• def o.coerce(x)
• `````` [1, 1]
``````
• end
• assert_equal(2, s1 + o)
• end
• def test_scalar_sub
• s1 = @m1.coerce(1).first
• assert_equal(Matrix[[1]], (s1 - 0) * Matrix[[1]])
• assert_raise(Matrix::ErrOperationNotDefined) { s1 - Vector[0] }
• assert_raise(Matrix::ErrOperationNotDefined) { s1 - Matrix[[0]] }
• o = Object.new
• def o.coerce(x)
• `````` [1, 1]
``````
• end
• assert_equal(0, s1 - o)
• end
• def test_scalar_mul
• s1 = @m1.coerce(1).first
• assert_equal(Matrix[[1]], (s1 * 1) * Matrix[[1]])
• assert_equal(Vector[2], s1 * Vector[2])
• assert_equal(Matrix[[2]], s1 * Matrix[[2]])
• o = Object.new
• def o.coerce(x)
• `````` [1, 1]
``````
• end
• assert_equal(1, s1 * o)
• end
• def test_scalar_div
• s1 = @m1.coerce(1).first
• assert_equal(Matrix[[1]], (s1 / 1) * Matrix[[1]])
• assert_raise(Matrix::ErrOperationNotDefined) { s1 / Vector[0] }
• assert_equal(Matrix[[Rational(1,2)]], s1 / Matrix[[2]])
• o = Object.new
• def o.coerce(x)
• `````` [1, 1]
``````
• end
• assert_equal(1, s1 / o)
• end
• def test_scalar_pow
• s1 = @m1.coerce(1).first
• assert_equal(Matrix[[1]], (s1 ** 1) * Matrix[[1]])
• assert_raise(Matrix::ErrOperationNotDefined) { s1 ** Vector[0] }
• assert_raise(Matrix::ErrOperationNotImplemented) { s1 **
Matrix[[1]] }
• o = Object.new
• def o.coerce(x)
• `````` [1, 1]
``````
• end
• assert_equal(1, s1 ** o)
• end
end
diff --git a/test/matrix/test_vector.rb b/test/matrix/test_vector.rb
index 95a3969…9be54af 100644
— a/test/matrix/test_vector.rb
+++ b/test/matrix/test_vector.rb
@@ -46,4 +46,106 @@ class TestVector < Test::Unit::TestCase
assert_equal @v1.hash, @v2.hash
assert_equal @v1.hash, @v3.hash
end
• def test_aref
• assert_equal(1, @v1[0])
• assert_equal(2, @v1[1])
• assert_equal(3, @v1[2])
• assert_equal(3, @v1[-1])
• assert_equal(nil, @v1[3])
• end
• def test_size
• assert_equal(3, @v1.size)
• end
• def test_each2
• a = []
• @v1.each2(@v4) {|x, y| a << [x, y] }
• assert_equal([[1,1.0],[2,2.0],[3,3.0]], a)
• end
• def test_collect
• a = @v1.collect {|x| x + 1 }
• assert_equal(Vector[2,3,4], a)
• end
• def test_collect2
• a = @v1.collect2(@v4) {|x, y| x + y }
• assert_equal([2.0,4.0,6.0], a)
• end
• def test_map2
• a = @v1.map2(@v4) {|x, y| x + y }
• assert_equal(Vector[2.0,4.0,6.0], a)
• end
• def test_compare_by
• assert(@v1.compare_by([1,2,3], :==))
• assert(!@v1.compare_by([1,2,3], :equal?))
• end
• def test_mul
• assert_equal(Vector[2,4,6], @v1 * 2)
• assert_equal(Matrix[[1, 4, 9], [2, 8, 18], [3, 12, 27]], @v1 *
Matrix[[1,4,9]])
• assert_raise(Matrix::ErrOperationNotDefined) { @v1 * Vector[1,4,9]
}
• o = Object.new
• def o.coerce(x)
• `````` [1, 1]
``````
• end
• assert_equal(1, Vector[1, 2, 3] * o)
• end
• assert_equal(Vector[2,4,6], @v1 + @v1)
• assert_equal(Matrix[[2],[6],[12]], @v1 + Matrix[[1],[4],[9]])
• o = Object.new
• def o.coerce(x)
• `````` [1, 1]
``````
• end
• assert_equal(2, Vector[1, 2, 3] + o)
• end
• def test_sub
• assert_equal(Vector[0,0,0], @v1 - @v1)
• assert_equal(Matrix[[0],[-2],[-6]], @v1 - Matrix[[1],[4],[9]])
• o = Object.new
• def o.coerce(x)
• `````` [1, 1]
``````
• end
• assert_equal(0, Vector[1, 2, 3] - o)
• end
• def test_inner_product
• assert_equal(1+4+9, @v1.inner_product(@v1))
• end
• def test_r
• assert_equal(5, Vector[3, 4].r)
• end
• def test_covector
• assert_equal(Matrix[[1,2,3]], @v1.covector)
• end
• def test_elements_to_f
• assert_equal(Vector[0.5,1.0,1.5], @v1.elements_to_f * Rational(1,
2))
• end
• def test_elements_to_i
• assert_equal(Vector[0,1,1], (@v1.elements_to_f * Rational(1,
2)).elements_to_i)
• end
• def test_elements_to_r
• assert_equal(@v1.collect {|x| Rational(x, 2) }, @v1.elements_to_r
• Rational(1, 2))
• end
• def test_to_s
• assert_equal(“Vector[1, 2, 3]”, @v1.to_s)
• end
• def test_inspect
• assert_equal(“Vector[1, 2, 3]”, @v1.inspect)
• end

end

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:40191] Re: [Bug:trunk] three bugs of
Matrix::Scalar”
on Wed, 27 Jan 2010 23:35:01 +0900, [email protected]
(e\$B@PDM7=<ye(B) writes:

|>+ def test_compare_by_row_vectors
|>+ assert(@m1.compare_by_row_vectors([[1, 2, 3], [4, 5, 6]]))
|>+ end
|
|e\$B\$b\$H\$b\$He(B, Matrix#compare_by_row_vectors e\$B\$C\$Fe(B Matrixe\$BF1;N\$NHf3S\$N\$?\$a\$Je(B
|e\$B\$N\$Ge(B, e\$B\$3\$&8@\$C\$?\$3\$H\$OA[Dj\$7\$F\$\$\$J\$+\$C\$?\$s\$G\$9\$h\$M\$'e(B…

e\$B\$=\$l\$C\$Fe(Bcompare_by_row_vectorse\$B\$OFbIt<BAuMQ\$G!"%F%9%H\$NBP>]30\$Ce(B
e\$B\$F\$3\$H\$G\$9\$+!)e(B e\$B\$=\$l\$H\$b!"0z?t\$Oe(BMatrixe\$B\$K8B\$k\$C\$F\$3\$H!)e(B

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

In [ruby-dev:40224] the message: “[ruby-dev:40224] Re: [Bug:trunk]
three bugs of Matrix::Scalar”, on Jan/29 01:49(JST) Yukihiro M.
writes:

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

|e\$B\$b\$H\$b\$He(B, Matrix#compare_by_row_vectors e\$B\$C\$Fe(B Matrixe\$BF1;N\$NHf3S\$N\$?\$a\$Je(B
|e\$B\$N\$Ge(B, e\$B\$3\$&8@\$C\$?\$3\$H\$OA[Dj\$7\$F\$\$\$J\$+\$C\$?\$s\$G\$9\$h\$M\$'e(B…
e\$B\$=\$l\$C\$Fe(Bcompare_by_row_vectorse\$B\$OFbIt<BAuMQ\$G!"%F%9%H\$NBP>]30\$Ce(B
e\$B\$F\$3\$H\$G\$9\$+!)e(B e\$B\$=\$l\$H\$b!"0z?t\$Oe(BMatrixe\$B\$K8B\$k\$C\$F\$3\$H!)e(B

e\$B\$&!<\$se(B. e\$BNr;KE*\$K\$Oe(B, e\$BA0<TMQES\$Ge(B ==
e\$B\$H\$+\$NFbIt\$N%5%V%k!<%A%sE*\$JMQES\$,e(B
e\$B<g\$Ge(B, Matirixe\$BF1;N\$NHf3S\$7\$+9M\$(\$F\$\$\$^\$;\$s\$G\$7\$?e(B.

e\$B\$=\$l\$+\$ie(B, == e\$B\$H\$+\$,JL<BAu\$K\$J\$C\$?\$s\$G\$9\$,e(B,
e\$BB>\$K\$bMQES\$,\$"\$k\$+\$J\$H;W\$Ce(B
e\$B\$FJLESFHN)\$5\$;\$?\$N\$G\$9\$,e(B…

e\$B\$?\$@e(B, e\$B@5D>8@\$C\$F\$"\$^\$j9M\$(\$F\$J\$/\$Fe(B,
e\$B\$[\$H\$s\$I@N\$N\$^\$^\$N<BAu\$J\$N\$Ge(B,
Matrixe\$B0J30\$N%/%i%9\$,Mh\$?>l9g\$K\$I\$&\$9\$k\$Y\$-\$+9M\$(\$F\$J\$+\$C\$?\$s\$G\$9\$h\$Me(B…

__
---------------------------------------------------->> e\$B@PDMe(B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:40229] Re: [Bug:trunk] three bugs of
Matrix::Scalar”
on Fri, 29 Jan 2010 04:56:48 +0900, [email protected]
(e\$B@PDM7=<ye(B) writes:

|e\$B\$&!<\$se(B. e\$BNr;KE*\$K\$Oe(B, e\$BA0<TMQES\$Ge(B == e\$B\$H\$+\$NFbIt\$N%5%V%k!<%A%sE*\$JMQES\$,e(B
|e\$B<g\$Ge(B, Matirixe\$BF1;N\$NHf3S\$7\$+9M\$(\$F\$\$\$^\$;\$s\$G\$7\$?e(B.
|
|e\$B\$=\$l\$+\$ie(B, == e\$B\$H\$+\$,JL<BAu\$K\$J\$C\$?\$s\$G\$9\$,e(B, e\$BB>\$K\$bMQES\$,\$"\$k\$+\$J\$H;W\$Ce(B
|e\$B\$FJLESFHN)\$5\$;\$?\$N\$G\$9\$,e(B…
|
|e\$B\$?\$@e(B, e\$B@5D>8@\$C\$F\$"\$^\$j9M\$(\$F\$J\$/\$Fe(B, e\$B\$[\$H\$s\$I@N\$N\$^\$^\$N<BAu\$J\$N\$Ge(B,
|Matrixe\$B0J30\$N%/%i%9\$,Mh\$?>l9g\$K\$I\$&\$9\$k\$Y\$-\$+9M\$(\$F\$J\$+\$C\$?\$s\$G\$9\$h\$Me(B…

e\$B\$=\$&\$\$\$&\$3\$H\$G\$"\$l\$P!“EvLL!VFbIt<BAu\$G\$”\$k!W\$HL@5-\$7\$F!"%F%9e(B
e\$B%HBP>]30\$K\$7\$?J}\$,\$h\$\$\$N\$G\$O\$J\$\$\$+\$H;W\$\$\$^\$9!#e(B

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

In [ruby-dev:40231] the message: “[ruby-dev:40231] Re: [Bug:trunk]
three bugs of Matrix::Scalar”, on Jan/29 08:37(JST) Yusuke ENDOH
writes:

e\$B1sF#\$G\$9!#e(B

e\$B\$=\$&\$\$\$&\$3\$H\$G\$"\$l\$P!“EvLL!VFbIt<BAu\$G\$”\$k!W\$HL@5-\$7\$F!"%F%9e(B
e\$B%HBP>]30\$K\$7\$?J}\$,\$h\$\$\$N\$G\$O\$J\$\$\$+\$H;W\$\$\$^\$9!#e(B

e\$B\$b\$7\$=\$&\$9\$k\$J\$i!"\$O\$C\$-\$j\$He(B private e\$B\$K\$7\$F\$*\$\$\$F\$/\$@\$5\$\$!#e(B

e\$B\$?\$@!"\$?\$H\$(FbIt<BAu\$G\$b!"<BAu\$KIUB0\$9\$k%F%9%He(B (test/matrix/*) e\$B\$G\$O!"e(B
e\$B\$J\$k\$Y\$/%F%9%HBP>]\$K\$7\$?\$\$\$H;W\$\$\$^\$9!#%+%P%l%C%8\$N\$?\$a\$K\$b!#e(B
e\$BJL\$Ke(B spec e\$B\$8\$c\$J\$\$\$N\$G%[%o%\$%H%F%9%H\$r\$7\$F\$b\$\$\$\$\$G\$9\$h\$M!#e(B

e\$B\$=\$l\$G\$Oe(B, Matrixe\$BF1;N\$NHf3S\$K\$7\$F\$b\$i\$(\$^\$9\$+e(B?

__
---------------------------------------------------->> e\$B@PDMe(B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e\$B1sF#\$G\$9!#e(B

2010e\$BG/e(B1e\$B7ne(B29e\$BF|e(B13:44 e\$B@PDM7=<ye(B
[email protected]:

e\$B\$=\$l\$G\$Oe(B, Matrixe\$BF1;N\$NHf3S\$K\$7\$F\$b\$i\$(\$^\$9\$+e(B?

e\$B8+\$F\$\$?\$N\$G\$9\$,!"8=:\$N<BAu\$G\$O!“e(Bcompare_by_row_vectors
e\$B\$OHf3S\$Ge(B
e\$B;H\$o\$l\$F\$\$\$J\$\$e(B (e\$B\$H\$\$\$&\$+!”\$I\$3\$G\$b;H\$o\$l\$F\$\$\$J\$\$e(B)
e\$B5\$\$,\$7\$^\$9!#e(B
e\$B\$J\$N\$G!"Hf3S\$G\$Oe(B compare_by_row_vectors
e\$B\$N%F%9%H\$K\$O\$J\$i\$J\$=\$&\$G\$9!#e(B

e\$B\$“\$H!”\$3\$N%A%1%C%H\$H4X78\$J\$\$\$G\$9\$,!"e(B[ruby-core:27901]
e\$B\$r8+\$F\$b\$i\$(\$k\$He(B
e\$B=u\$+\$j\$^\$9e(B > e\$B\$\$\$7\$D\$+\$5\$se(B

e\$B1sF#\$G\$9!#e(B

2010e\$BG/e(B1e\$B7ne(B29e\$BF|e(B7:36 Yukihiro M.
[email protected]:

e\$B%HBP>]30\$K\$7\$?J}\$,\$h\$\$\$N\$G\$O\$J\$\$\$+\$H;W\$\$\$^\$9!#e(B
e\$B\$b\$7\$=\$&\$9\$k\$J\$i!"\$O\$C\$-\$j\$He(B private e\$B\$K\$7\$F\$*\$\$\$F\$/\$@\$5\$\$!#e(B

e\$B\$?\$@!“\$?\$H\$(FbIt<BAu\$G\$b!”<BAu\$KIUB0\$9\$k%F%9%He(B (test/matrix/*)
e\$B\$G\$O!"e(B
e\$B\$J\$k\$Y\$/%F%9%HBP>]\$K\$7\$?\$\$\$H;W\$\$\$^\$9!#%+%P%l%C%8\$N\$?\$a\$K\$b!#e(B
e\$BJL\$Ke(B spec e\$B\$8\$c\$J\$\$\$N\$G%[%o%\$%H%F%9%H\$r\$7\$F\$b\$\$\$\$\$G\$9\$h\$M!#e(B

e\$B1sF#\$G\$9!#e(B

2010e\$BG/e(B1e\$B7ne(B29e\$BF|e(B19:24 e\$B@PDM7=<ye(B
[email protected]:

e\$B\$H8@\$&0UL#\$G8@\$C\$?\$s\$G\$9\$,e(B?
e\$B\$“\$”!<\$J\$k\$[\$I!#e(Bcompare_by_row_vectors e\$B\$Oe(B Matrix#==
e\$B\$NHf3S\$NFbIt<BAu\$H\$7\$Fe(B
e\$BB8:_\$9\$k!"\$H\$\$\$&0UL#\$@\$HM}2r\$7\$F\$^\$7\$?!#\$=\$&\$7\$F\$*\$-\$^\$9!#e(B

e\$B\$\$\$:\$l\$K\$7\$F\$b!“e(Bvectors e\$B\$H\$\$\$&L>A0\$K\$O\$”\$o\$J\$\$\$G\$9\$M!#e(B

e\$B\$“\$H!”\$3\$N%A%1%C%H\$H4X78\$J\$\$\$G\$9\$,!"e(B[ruby-core:27901] e\$B\$r8+\$F\$b\$i\$(\$k\$He(B
e\$B=u\$+\$j\$^\$9e(B > e\$B\$\$\$7\$D\$+\$5\$se(B

e\$B\$3\$l\$M\$'e(B…

Integer#[], Integer#size

e\$B\$NL>A0\$rJQ\$(\$?J}\$,\$h\$\$\$s\$8\$c\$J\$\$e(B? e\$B\$C\$F8@\$\$\$?\$\$\$H\$3\$m\$G\$9\$,e(B…

Integer#[] e\$B\$O\$?\$^\$KJXMx\$G\$9\$,e(B #size
e\$B\$K\$D\$\$\$F\$O40A4\$KF10U\$7\$^\$9!#e(B
e\$BL5\$/\$F\$b\$\$\$\$!"\$H\$\$\$&\$+L5\$\$\$[\$&\$,\$\$\$\$\$H\$9\$i;W\$\$\$^\$9!#e(B

e\$B\$I\$&8+\$F\$bB>\$N%/%i%9\$Ne(B[], sizee\$B\$H?6\$kIq\$\$\$,0c\$\$\$^\$9\$7\$M\$'e(B, duck type e\$BE*e(B
e\$B\$K\$b%\$%^%\$%A\$J5\$\$,\$7\$^\$9e(B.

e\$B\$=\$l\$O\$H\$b\$+\$/e(B, NArraye\$B\$Ne(BNVector e\$B\$J\$I\$Ne(BVectore\$B\$NJL<BAu\$,<B:]\$K\$"\$j\$^\$9\$7e(B,
Vector, Arraye\$B\$K8BDj\$9\$k\$N\$Oe(B, e\$B\$d\$O\$je(B duck type e\$BE*e(B e\$B\$K%\$%^%\$%A\$G\$7\$g\$&e(B.

e\$BJL\$K!Ve(Bduck typing e\$BE*\$K\$=\$&\$\$\$&\$b\$N!W\$H\$\$\$C\$Fe(B reject
e\$B\$7\$F\$b\$i\$C\$F\$b9=\$o\$J\$\$e(B
e\$B\$H;W\$\$\$^\$9!#\$9\$G\$Ke(B rubyspec
e\$B\$K:\$C\$F\$k\$N\$G!"8+2r\$r<(\$7\$F\$b\$i\$(\$k\$H=\$@5\$9\$ke(B
e\$B:,5r\$K\$J\$k\$N\$G=u\$+\$j\$^\$9!#e(B

e\$B1sF#\$G\$9!#e(B
e\$B2?EY\$b\$9\$_\$^\$;\$s!#e(B

2010e\$BG/e(B1e\$B7ne(B29e\$BF|e(B19:54 Yusuke ENDOH [email protected]:

e\$B\$H8@\$&0UL#\$G8@\$C\$?\$s\$G\$9\$,e(B?

e\$B\$“\$”!<\$J\$k\$[\$I!#e(Bcompare_by_row_vectors e\$B\$Oe(B Matrix#== e\$B\$NHf3S\$NFbIt<BAu\$H\$7\$Fe(B
e\$BB8:_\$9\$k!"\$H\$\$\$&0UL#\$@\$HM}2r\$7\$F\$^\$7\$?!#\$=\$&\$7\$F\$*\$-\$^\$9!#e(B

e\$B\$d\$C\$F\$_\$?\$iNc30\$K\$J\$j\$^\$7\$?!D!D!#e(B

\$ ./ruby -rmatrix -e
‘Matrix[[1,2,3],[4,5,6]].compare_by_row_vectors(Matrix[[1, 2, 3], [4,
5, 6]])’
/home/mame/work/ruby-trunk-local/lib/ruby/1.9.1/matrix.rb:427:in
`compare_by_row_vectors': undefined method `size’ for Matrix[[1, 2,
3], [4, 5, 6]]:Matrix (NoMethodError)
from -e:1:in `’

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

In [ruby-dev:40236] the message: “[ruby-dev:40236] Re: [Bug:trunk]
three bugs of Matrix::Scalar”, on Jan/29 17:33(JST) Yusuke ENDOH
writes:

e\$B1sF#\$G\$9!#e(B

e\$B8+\$F\$\$?\$N\$G\$9\$,!"8=:\$N<BAu\$G\$O!“e(Bcompare_by_row_vectors e\$B\$OHf3S\$Ge(B
e\$B;H\$o\$l\$F\$\$\$J\$\$e(B (e\$B\$H\$\$\$&\$+!”\$I\$3\$G\$b;H\$o\$l\$F\$\$\$J\$\$e(B) e\$B5\$\$,\$7\$^\$9!#e(B
e\$B\$J\$N\$G!"Hf3S\$G\$Oe(B compare_by_row_vectors e\$B\$N%F%9%H\$K\$O\$J\$i\$J\$=\$&\$G\$9!#e(B

e\$B\$se(B?

def test_compare_by_row_vectors
assert(@m1.compare_by_row_vectors(Matrix[[1, 2, 3], [4, 5, 6]]))
end

e\$B\$H8@\$&0UL#\$G8@\$C\$?\$s\$G\$9\$,e(B?

e\$B\$"\$H!"\$3\$N%A%1%C%H\$H4X78\$J\$\$\$G\$9\$,!"e(B[ruby-core:27901] e\$B\$r8+\$F\$b\$i\$(\$k\$He(B
e\$B=u\$+\$j\$^\$9e(B > e\$B\$\$\$7\$D\$+\$5\$se(B

e\$B\$3\$l\$M\$'e(B…

Integer#[], Integer#size

e\$B\$NL>A0\$rJQ\$(\$?J}\$,\$h\$\$\$s\$8\$c\$J\$\$e(B?
e\$B\$C\$F8@\$\$\$?\$\$\$H\$3\$m\$G\$9\$,e(B…
e\$B\$I\$&8+\$F\$bB>\$N%/%i%9\$Ne(B[], sizee\$B\$H?6\$kIq\$\$\$,0c\$\$\$^\$9\$7\$M\$'e(B,
duck type e\$BE*e(B
e\$B\$K\$b%\$%^%\$%A\$J5\$\$,\$7\$^\$9e(B.

e\$B\$=\$l\$O\$H\$b\$+\$/e(B, NArraye\$B\$Ne(BNVector
e\$B\$J\$I\$Ne(BVectore\$B\$NJL<BAu\$,<B:]\$K\$"\$j\$^\$9\$7e(B,
Vector, Arraye\$B\$K8BDj\$9\$k\$N\$Oe(B, e\$B\$d\$O\$je(B duck type e\$BE*e(B
e\$B\$K%\$%^%\$%A\$G\$7\$g\$&e(B.

e\$B;d\$H\$7\$F\$Oe(B, e\$B%A%’%C%/\$7\$J\$/\$FNI\$\$5\$\$,\$7\$^\$9\$,e(B,
e\$B\$I\$&\$7\$F\$b%A%’%C%/\$7\$?\$\$e(B
e\$B\$J\$ie(B, each2e\$B\$C\$Fe(B Enumerable#zip &block e\$B\$H;w\$F\$\$\$k\$N\$Ge(B,
to_ae\$B\$r;}\$C\$F\$\$\$ke(B
e\$B\$+\$I\$&\$+\$GH=CG\$9\$k\$H\$\$\$&\$N\$O\$I\$&\$G\$9\$+\$Me(B?

__
---------------------------------------------------->> e\$B@PDMe(B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:40237] Re: [Bug:trunk] three bugs of
Matrix::Scalar”
on Fri, 29 Jan 2010 19:24:35 +0900, [email protected]
(e\$B@PDM7=<ye(B) writes:

| Integer#[], Integer#size
|
|e\$B\$NL>A0\$rJQ\$(\$?J}\$,\$h\$\$\$s\$8\$c\$J\$\$e(B? e\$B\$C\$F8@\$\$\$?\$\$\$H\$3\$m\$G\$9\$,e(B…
|e\$B\$I\$&8+\$F\$bB>\$N%/%i%9\$Ne(B[], sizee\$B\$H?6\$kIq\$\$\$,0c\$\$\$^\$9\$7\$M\$'e(B, duck type e\$BE*e(B
|e\$B\$K\$b%\$%^%\$%A\$J5\$\$,\$7\$^\$9e(B.

e\$B\$3\$l\$i\$Oe(Bduck typinge\$B\$H\$\$\$&35G0\$h\$j\$b8E\$\$\$G\$9\$+\$i\$M\$(!#:#\$5\$ie(B
e\$BJQ\$(\$i\$l\$J\$\$\$H\$b;W\$\$\$^\$9!#e(B

e\$B\$5\$i\$K\$\$\$(\$P!"e(Bduck
typinge\$BE*\$H\$\$\$&\$J\$i\$P!"7?%A%’%C%/\$J\$I\$7\$F\$Oe(B
e\$B\$\$\$1\$J\$/\$F!"e(B[ruby-core:27901]e\$B\$N\$h\$&\$J%(%i!<\$O5vMF\$9\$Y\$-\$J\$s\$8\$ce(B
e\$B\$J\$\$\$+\$H;W\$\$\$^\$9!#e(B

e\$B1sF#\$G\$9!#e(B

2010e\$BG/e(B1e\$B7ne(B31e\$BF|e(B0:51 Yukihiro M.
[email protected]:

e\$B\$5\$i\$K\$\$\$(\$P!"e(Bduck typinge\$BE*\$H\$\$\$&\$J\$i\$P!"7?%A%'%C%/\$J\$I\$7\$F\$Oe(B
e\$B\$\$\$1\$J\$/\$F!"e(B[ruby-core:27901]e\$B\$N\$h\$&\$J%(%i!<\$O5vMF\$9\$Y\$-\$J\$s\$8\$ce(B
e\$B\$J\$\$\$+\$H;W\$\$\$^\$9!#e(B

e\$B\$\$\$7\$D\$+\$5\$s\$b\$^\$D\$b\$H\$5\$s\$bH?BP\$H\$\$\$&\$3\$H\$G!">!<j\$Ke(B reject
e\$B\$5\$;\$Fe(B
e\$BD:\$-\$^\$7\$?!#e(B

http://redmine.ruby-lang.org/issues/show/2495

e\$B\$b\$7LdBj\$,\$"\$C\$?\$ie(B reopen e\$B\$7\$F\$/\$@\$5\$\$!#e(B

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

In [ruby-dev:40240] the message: “[ruby-dev:40240] Re: [Bug:trunk]
three bugs of Matrix::Scalar”, on Jan/29 21:44(JST) Yusuke ENDOH
writes:

e\$B1sF#\$G\$9!#e(B
e\$B2?EY\$b\$9\$_\$^\$;\$s!#e(B

def test_compare_by_row_vectors
assert(@m1.compare_by_row_vectors(Matrix[[1, 2, 3], [4, 5, 6]]))

e\$B\$d\$C\$F\$_\$?\$iNc30\$K\$J\$j\$^\$7\$?!D!D!#e(B

\$ ./ruby -rmatrix -e
‘Matrix[[1,2,3],[4,5,6]].compare_by_row_vectors(Matrix[[1, 2, 3], [4,
5, 6]])’
/home/mame/work/ruby-trunk-local/lib/ruby/1.9.1/matrix.rb:427:in
`compare_by_row_vectors': undefined method`size’ for Matrix[[1, 2,
3], [4, 5, 6]]:Matrix (NoMethodError)
from -e:1:in `’

e\$B?=\$7Lu\$J\$\$e(B.

e\$B0z?t\$Oe(B, e\$BG[Nse(B(e\$B\$NG[Nse(B)e\$B\$r5a\$a\$F\$\$\$^\$7\$?e(B…

e\$B\$3\$N\$^\$^\$G\$Oe(B, e\$B\$"\$^\$j;H\$\$>!<j\$,NI\$/\$J\$\$\$N\$Ge(B,
trunke\$B\$+\$i\$O\$b\$&:o=|\$7\$?J}e(B
e\$B\$,NI\$\$\$+\$J\$!e(B…

__
---------------------------------------------------->> e\$B@PDMe(B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e\$B\$1\$\$\$8\$e!w\$\$\$7\$D\$+\$G\$9e(B.

In [ruby-dev:40270] the message: “[ruby-dev:40270] Re: [Bug:trunk]
three bugs of Matrix::Scalar”, on Jan/31 18:15(JST) Yusuke ENDOH
writes:

e\$B1sF#\$G\$9!#e(B

e\$B\$\$\$7\$D\$+\$5\$s\$b\$^\$D\$b\$H\$5\$s\$bH?BP\$H\$\$\$&\$3\$H\$G!">!<j\$Ke(B reject e\$B\$5\$;\$Fe(B
e\$BD:\$-\$^\$7\$?!#e(B

http://redmine.ruby-lang.org/issues/show/2495

e\$B\$b\$7LdBj\$,\$"\$C\$?\$ie(B reopen e\$B\$7\$F\$/\$@\$5\$\$!#e(B

e\$BN;2r\$G\$9e(B.
e\$B\$*<j?t\$*3]\$1\$7\$^\$7\$?e(B.

__
---------------------------------------------------->> e\$B@PDMe(B
e\$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e\$B%A%1%C%He(B #2652 e\$B\$,99?7\$5\$l\$^\$7\$?!#e(B (by Yusuke E.)

e\$B%9%F!<%?%9e(B Opene\$B\$+\$ie(BClosede\$B\$KJQ99e(B

e\$B1sF#\$G\$9!#e(B

e\$BK\7o\$Oe(B r26448 e\$B\$G=\$@5:Q\$_\$G\$9\$N\$Ge(B close e\$B\$7\$^\$9!#e(B

## – Yusuke E. [email protected]

http://redmine.ruby-lang.org/issues/show/2652