Class: Matrix::Scalar
- Inherits:
-
Numeric
- Object
- Numeric
- Matrix::Scalar
- Includes:
- ExceptionForMatrix, CoercionHelper
- Defined in:
- lib/rubysl/matrix/matrix.rb
Overview
Private CLASS
Instance Method Summary collapse
- #*(other) ⇒ Object
- #**(other) ⇒ Object
-
#+(other) ⇒ Object
ARITHMETIC.
- #-(other) ⇒ Object
- #/(other) ⇒ Object
-
#initialize(value) ⇒ Scalar
constructor
A new instance of Scalar.
Methods included from CoercionHelper
Constructor Details
#initialize(value) ⇒ Scalar
Returns a new instance of Scalar.
1116 1117 1118 |
# File 'lib/rubysl/matrix/matrix.rb', line 1116 def initialize(value) @value = value end |
Instance Method Details
#*(other) ⇒ Object
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 |
# File 'lib/rubysl/matrix/matrix.rb', line 1143 def *(other) case other when Numeric Scalar.new(@value * other) when Vector, Matrix other.collect{|e| @value * e} else apply_through_coercion(other, __method__) end end |
#**(other) ⇒ Object
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 |
# File 'lib/rubysl/matrix/matrix.rb', line 1167 def ** (other) case other when Numeric Scalar.new(@value ** other) when Vector Scalar.Raise ErrOperationNotDefined, "**", @value.class, other.class when Matrix #other.powered_by(self) Scalar.Raise ErrOperationNotImplemented, "**", @value.class, other.class else apply_through_coercion(other, __method__) end end |
#+(other) ⇒ Object
ARITHMETIC
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 |
# File 'lib/rubysl/matrix/matrix.rb', line 1121 def +(other) case other when Numeric Scalar.new(@value + other) when Vector, Matrix Scalar.Raise ErrOperationNotDefined, "+", @value.class, other.class else apply_through_coercion(other, __method__) end end |
#-(other) ⇒ Object
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 |
# File 'lib/rubysl/matrix/matrix.rb', line 1132 def -(other) case other when Numeric Scalar.new(@value - other) when Vector, Matrix Scalar.Raise ErrOperationNotDefined, "-", @value.class, other.class else apply_through_coercion(other, __method__) end end |
#/(other) ⇒ Object
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 |
# File 'lib/rubysl/matrix/matrix.rb', line 1154 def / (other) case other when Numeric Scalar.new(@value / other) when Vector Scalar.Raise ErrOperationNotDefined, "/", @value.class, other.class when Matrix self * other.inverse else apply_through_coercion(other, __method__) end end |