Class: Stick::Matrix::Scalar
Overview
Instance Method Summary
collapse
Methods inherited from Numeric
#method_missing, #to_value
Constructor Details
#initialize(value) ⇒ Scalar
986
987
988
|
# File 'lib/stick/matrix/core.rb', line 986
def initialize(value)
@value = value
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Numeric
Instance Method Details
#*(other) ⇒ Object
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
|
# File 'lib/stick/matrix/core.rb', line 1019
def *(other)
case other
when Numeric
Scalar.new(@value * other)
when Vector, Matrix
other.collect{|e| @value * e}
else
x, y = other.coerce(self)
x * y
end
end
|
#**(other) ⇒ Object
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
|
# File 'lib/stick/matrix/core.rb', line 1045
def ** (other)
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)
else
x, y = other.coerce(self)
x ** y
end
end
|
#+(other) ⇒ Object
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
|
# File 'lib/stick/matrix/core.rb', line 991
def +(other)
case other
when Numeric
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
end
end
|
#-(other) ⇒ Object
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
|
# File 'lib/stick/matrix/core.rb', line 1005
def -(other)
case other
when Numeric
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
end
end
|
#/(other) ⇒ Object
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
|
# File 'lib/stick/matrix/core.rb', line 1031
def / (other)
case other
when Numeric
Scalar.new(@value / other)
when Vector
Scalar.Raise WrongArgType, other.class, "Numeric or Scalar or Matrix"
when Matrix
self * other.inverse
else
x, y = other.coerce(self)
x.quo(y)
end
end
|