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.
873 874 875 |
# File 'lib/matrix.rb', line 873 def initialize(value) @value = value end |
Instance Method Details
#*(other) ⇒ Object
906 907 908 909 910 911 912 913 914 915 916 |
# File 'lib/matrix.rb', line 906 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
932 933 934 935 936 937 938 939 940 941 942 943 944 |
# File 'lib/matrix.rb', line 932 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
878 879 880 881 882 883 884 885 886 887 888 889 890 |
# File 'lib/matrix.rb', line 878 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
892 893 894 895 896 897 898 899 900 901 902 903 904 |
# File 'lib/matrix.rb', line 892 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
918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'lib/matrix.rb', line 918 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 |