Class: JBLAS::ReversedArithmetic

Inherits:
Object
  • Object
show all
Defined in:
lib/jblas/arith.rb

Overview

When arguments to arithmetic operators are promoted via coerce, they change their order. This class is a wrapper for the promoted self which has - and / overloaded to call rsub and rdiv instead of div and sub

Instance Method Summary collapse

Constructor Details

#initialize(o) ⇒ ReversedArithmetic

Returns a new instance of ReversedArithmetic.



42
43
44
# File 'lib/jblas/arith.rb', line 42

def initialize(o)
  @value = o;
end

Instance Method Details

#*(o) ⇒ Object



50
51
52
# File 'lib/jblas/arith.rb', line 50

def *(o)
  @value.mul o
end

#+(o) ⇒ Object



46
47
48
# File 'lib/jblas/arith.rb', line 46

def +(o)
  @value.add o
end

#-(o) ⇒ Object



54
55
56
# File 'lib/jblas/arith.rb', line 54

def -(o)
  @value.rsub o
end

#/(o) ⇒ Object



58
59
60
# File 'lib/jblas/arith.rb', line 58

def /(o)
  @value.rdiv o
end