—— NVector ——
# File nmatrix.rb, line 188 def *(other) case other when NMatrix NVector.mul_add( NArray.refer(self).newdim!(0), other, 1 ) when NVector NArray.mul_add( NArray.refer(self), other, 0 ) # inner product when NArray if other.instance_of?(NArray) NVector.mul( NArray.refer(self), other.newdim(0) ) else other.coerce_rev( self, :* ) end when Numeric NVector.mul( NArray.refer(self), other ) else raise TypeError,"Illegal operation: NVector * %s" % other.class end end
# File nmatrix.rb, line 226 def **(n) if n==2 self*self else raise ArgumentError,"Only v**2 is implemented" end end
# File nmatrix.rb, line 164 def +(other) case other when NVector return super(NArray.refer(other)) when NArray unless other.instance_of?(NArray) return other.coerce_rev( self, :+ ) end end raise TypeError,"Illegal operation: NVector + %s" % other.class end
# File nmatrix.rb, line 176 def -(other) case other when NVector return super(NArray.refer(other)) when NArray unless other.instance_of?(NArray) return other.coerce_rev( self, :- ) end end raise TypeError,"Illegal operation: NVector - %s" % other.class end
# File nmatrix.rb, line 207 def /(other) case other when NMatrix other.lu.solve(self) when NVector raise TypeError,"Illegal operation: NVector / %s" % other.class when NArray if other.instance_of?(NArray) NVector.div( NArray.refer(self), other.newdim(0) ) else other.coerce_rev( self, :/ ) end when Numeric NVector.div( NArray.refer(self), other ) else raise TypeError,"Illegal operation: NVector / %s" % other.class end end
# File nmatrix.rb, line 234 def coerce_rev(other,id) case id when :* if other.instance_of?(NArray) return NVector.mul( other.newdim(0), self ) end if other.instance_of?(NArrayScalar) return NVector.mul( other, self ) end end raise TypeError,"Illegal operation: %s %s NVector" % [other.class, id.id2name] end