Class: Matrix::Scalar
Overview
Instance Method Summary
collapse
check_int, check_range, coerce_to, coerce_to_int, coerce_to_matrix
Constructor Details
#initialize(value) ⇒ Scalar
1754
1755
1756
|
# File 'lib/matrix.rb', line 1754
def initialize(value)
@value = value
end
|
Instance Method Details
#*(other) ⇒ Object
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
|
# File 'lib/matrix.rb', line 1781
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
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
|
# File 'lib/matrix.rb', line 1805
def **(other)
case other
when Numeric
Scalar.new(@value ** other)
when Vector
raise ErrOperationNotDefined, ["**", @value.class, other.class]
when Matrix
raise ErrOperationNotImplemented, ["**", @value.class, other.class]
else
apply_through_coercion(other, __method__)
end
end
|
#+(other) ⇒ Object
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
|
# File 'lib/matrix.rb', line 1759
def +(other)
case other
when Numeric
Scalar.new(@value + other)
when Vector, Matrix
raise ErrOperationNotDefined, ["+", @value.class, other.class]
else
apply_through_coercion(other, __method__)
end
end
|
#-(other) ⇒ Object
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
|
# File 'lib/matrix.rb', line 1770
def -(other)
case other
when Numeric
Scalar.new(@value - other)
when Vector, Matrix
raise ErrOperationNotDefined, ["-", @value.class, other.class]
else
apply_through_coercion(other, __method__)
end
end
|
#/(other) ⇒ Object
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
|
# File 'lib/matrix.rb', line 1792
def /(other)
case other
when Numeric
Scalar.new(@value / other)
when Vector
raise ErrOperationNotDefined, ["/", @value.class, other.class]
when Matrix
self * other.inverse
else
apply_through_coercion(other, __method__)
end
end
|