Class: Matrix::Scalar
- Inherits:
-
Numeric
- Object
- Numeric
- Matrix::Scalar
- Includes:
- ExceptionForMatrix
- Defined in:
- lib/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.
Constructor Details
#initialize(value) ⇒ Scalar
Returns a new instance of Scalar.
879 880 881 |
# File 'lib/matrix.rb', line 879 def initialize(value) @value = value end |
Instance Method Details
#*(other) ⇒ Object
912 913 914 915 916 917 918 919 920 921 922 |
# File 'lib/matrix.rb', line 912 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
938 939 940 941 942 943 944 945 946 947 948 949 950 |
# File 'lib/matrix.rb', line 938 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
ARITHMETIC
884 885 886 887 888 889 890 891 892 893 894 895 896 |
# File 'lib/matrix.rb', line 884 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
898 899 900 901 902 903 904 905 906 907 908 909 910 |
# File 'lib/matrix.rb', line 898 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
924 925 926 927 928 929 930 931 932 933 934 935 936 |
# File 'lib/matrix.rb', line 924 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 * _M.inverse else x, y = other.coerce(self) x / y end end |