Class: Matrix::Scalar
- Inherits:
-
Numeric
- Object
- Numeric
- Matrix::Scalar
- Includes:
- ExceptionForMatrix, CoercionHelper
- 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.
Methods included from CoercionHelper
Constructor Details
#initialize(value) ⇒ Scalar
Returns a new instance of Scalar.
1607 1608 1609 |
# File 'lib/matrix.rb', line 1607 def initialize(value) @value = value end |
Instance Method Details
#*(other) ⇒ Object
1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 |
# File 'lib/matrix.rb', line 1634 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
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 |
# File 'lib/matrix.rb', line 1658 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
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
# File 'lib/matrix.rb', line 1612 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
1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 |
# File 'lib/matrix.rb', line 1623 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
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 |
# File 'lib/matrix.rb', line 1645 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 |