Three bugs of Matrix::Scalar

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$,!"[email protected]$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

[email protected]$NDj5AK:[email protected]$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 methodpowered_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 [email protected]$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$B$1$$$8$e!w$$$7$D$+$G$9e(B.

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

   from -e:1:in `<main>'

[email protected]$NDj5AK:[email protected]$H;W$$$^$9!#e(B

e$BN;2re(B. e$B$=$NDL$j$G$9e(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 methodpowered_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 [email protected]$C$?$iNc30$K$9$Y$-$G$O$J$$$G$7$g$&$+!#e(B

exp(M) e$B$,Dj5A$G$-$k$N$Ge(B, 2**Me$B$bDj5A$G$-$k$H;W$$$^$9$,e(B?
[email protected](B, e$B<B:]$K7We(B
e$B;;$9$k$H$J$k$H$+$J$jLLE]$Ge(B, e$B:#$Ne(B matrix.rb
e$B$K$O2Y$,=E$$$G$9$,e(B…

e$B$H$$$&$3$H$Ge(B, e$BNc30$rJQ$($k$J$ie(B NoImplimentError e$B$H$+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

e$B$&!<$se(B. e$B3N$+$K$=$N$H$*[email protected]$H;W$$$^$9e(B.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs