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.
1609 1610 1611 |
# File 'lib/matrix.rb', line 1609 def initialize(value) @value = value end |
Instance Method Details
#*(other) ⇒ Object
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 |
# File 'lib/matrix.rb', line 1636 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
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 |
# File 'lib/matrix.rb', line 1660 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
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 |
# File 'lib/matrix.rb', line 1614 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
1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 |
# File 'lib/matrix.rb', line 1625 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
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 |
# File 'lib/matrix.rb', line 1647 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 |