Module: JBLAS::MatrixArithMixin
- Included in:
- MatrixMixin
- Defined in:
- lib/jblas/mixin_arith.rb
Overview
Mixin for syntactic sugar for arithmetic operations.
Collected in MatrixMixin.
Roughly defines the following types of operators:
-
arithmetic (+,-,*,/,…)
-
logical operations (|,&,…)
-
logical tests (==,>,<,…)
-
arithmetic operations with column and row vectors (add_column_vector, …)
Instance Method Summary collapse
-
#&(o) ⇒ Object
Element-wise logical and.
-
#*(o) ⇒ Object
Multiply this matrix with o.
-
#**(o) ⇒ Object
Compute self to the power of o.
-
#+(o) ⇒ Object
Add o to this matrix.
-
#-(o) ⇒ Object
Subtract o from this matrix.
-
#-@ ⇒ Object
Negating a matrix.
-
#/(o) ⇒ Object
Divide this matrix by o.
-
#<(o) ⇒ Object
Element-wise test on less-than with o.
-
#<=(o) ⇒ Object
Element-wise test on less-than-or-equal with o.
-
#==(o) ⇒ Object
Test on equality.
-
#===(o) ⇒ Object
Element-wise test on equality with o.
-
#>(o) ⇒ Object
Element-wise test on greater-than with o.
-
#>=(o) ⇒ Object
Element-wise test on greater-than-or-equal with o.
-
#^(o) ⇒ Object
Element-wise logical exclusive-or.
-
#add!(s) ⇒ Object
Add matrices in-place.
-
#add_column_vector!(s) ⇒ Object
Add column vector to matrix in-place.
-
#add_row_vector!(s) ⇒ Object
Add row vector to matrix in-place.
-
#and!(s) ⇒ Object
Element-wise logical “and” in-place.
-
#coerce(o) ⇒ Object
:nodoc:.
-
#div!(s) ⇒ Object
Divide matrices element-wise in-place.
-
#div_column_vector!(s) ⇒ Object
Multiply row vector element-wise with matrix in-place.
-
#div_row_vector!(s) ⇒ Object
Divide matrix element-wise by row vector in-place.
-
#eq!(s) ⇒ Object
Element-wise test for equality in-place.
-
#ge!(s) ⇒ Object
Element-wise test for greater-than-or-equal in-place.
-
#gt!(s) ⇒ Object
Element-wise test for greater-than in-place.
-
#le!(s) ⇒ Object
Element-wise test for less-than-or-equal in-place.
-
#lt!(s) ⇒ Object
Element-wise test for less-than in-place.
-
#mmul!(s) ⇒ Object
Matrix multiply matrices in-place.
-
#mul!(s) ⇒ Object
Multiply matrices element-wise in-place.
-
#mul_column_vector!(s) ⇒ Object
Multiply row vector element-wise with matrix in-place.
-
#mul_row_vector!(s) ⇒ Object
Divide matrix element-wise by column vector in-place.
-
#ne!(s) ⇒ Object
Element-wise test for inequality in-place.
-
#or!(s) ⇒ Object
Element-wise logical “or” in-place.
-
#sub!(s) ⇒ Object
Subtract matrices in-place.
-
#sub_column_vector!(s) ⇒ Object
Subtract column vector from matrix in-place.
-
#sub_row_vector!(s) ⇒ Object
Subtract column vector from matrix in-place.
-
#xor!(s) ⇒ Object
Element-wise logical exclusive-or in-place.
-
#|(o) ⇒ Object
Element-wise logical or.
Instance Method Details
#&(o) ⇒ Object
Element-wise logical and.
124 |
# File 'lib/jblas/mixin_arith.rb', line 124 def &(o); self.and(o); end |
#*(o) ⇒ Object
Multiply this matrix with o. If o is a matrix, this matrix-matrix multiplication. If you want element-wise multiplication, you must use emul
54 |
# File 'lib/jblas/mixin_arith.rb', line 54 def *(o); mmul(o); end |
#**(o) ⇒ Object
Compute self to the power of o.
131 |
# File 'lib/jblas/mixin_arith.rb', line 131 def **(o); MatrixFunctions.pow(self, o); end |
#+(o) ⇒ Object
Add o to this matrix. Works with matrices and scalars.
48 |
# File 'lib/jblas/mixin_arith.rb', line 48 def +(o); add(o); end |
#-(o) ⇒ Object
Subtract o from this matrix. Works with matrices and scalars.
50 |
# File 'lib/jblas/mixin_arith.rb', line 50 def -(o); sub(o); end |
#/(o) ⇒ Object
Divide this matrix by o.
56 |
# File 'lib/jblas/mixin_arith.rb', line 56 def /(o); div(o); end |
#<(o) ⇒ Object
Element-wise test on less-than with o.
61 |
# File 'lib/jblas/mixin_arith.rb', line 61 def <(o); lt(o); end |
#<=(o) ⇒ Object
Element-wise test on less-than-or-equal with o.
63 |
# File 'lib/jblas/mixin_arith.rb', line 63 def <=(o); le(o); end |
#==(o) ⇒ Object
Test on equality.
118 119 120 121 |
# File 'lib/jblas/mixin_arith.rb', line 118 def ==(o) #puts "== called with self = #{self.inspect}, o = #{o.inspect}" equals(o) end |
#===(o) ⇒ Object
Element-wise test on equality with o.
69 |
# File 'lib/jblas/mixin_arith.rb', line 69 def ===(o); eq(o); end |
#>(o) ⇒ Object
Element-wise test on greater-than with o.
65 |
# File 'lib/jblas/mixin_arith.rb', line 65 def >(o); gt(o); end |
#>=(o) ⇒ Object
Element-wise test on greater-than-or-equal with o.
67 |
# File 'lib/jblas/mixin_arith.rb', line 67 def >=(o); ge(o); end |
#^(o) ⇒ Object
Element-wise logical exclusive-or.
128 |
# File 'lib/jblas/mixin_arith.rb', line 128 def ^(o); self.xor(o); end |
#add!(s) ⇒ Object
Add matrices in-place.
72 |
# File 'lib/jblas/mixin_arith.rb', line 72 def add!(s); addi(s); end |
#add_column_vector!(s) ⇒ Object
Add column vector to matrix in-place.
101 |
# File 'lib/jblas/mixin_arith.rb', line 101 def add_column_vector!(s); addi_column_vector(s); end |
#add_row_vector!(s) ⇒ Object
Add row vector to matrix in-place.
103 |
# File 'lib/jblas/mixin_arith.rb', line 103 def add_row_vector!(s); addi_row_vector(s); end |
#and!(s) ⇒ Object
Element-wise logical “and” in-place.
94 |
# File 'lib/jblas/mixin_arith.rb', line 94 def and!(s); andi(s); end |
#coerce(o) ⇒ Object
:nodoc:
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/jblas/mixin_arith.rb', line 133 def coerce(o) # :nodoc: case o when Numeric return ReversedArithmetic.new(self), o else return self, o end #unless self.class === o # [ReversedArithmetic.new(self), o] #end end |
#div!(s) ⇒ Object
Divide matrices element-wise in-place.
80 |
# File 'lib/jblas/mixin_arith.rb', line 80 def div!(s); divi(s); end |
#div_column_vector!(s) ⇒ Object
Multiply row vector element-wise with matrix in-place.
113 |
# File 'lib/jblas/mixin_arith.rb', line 113 def div_column_vector!(s); divi_column_vector(s); end |
#div_row_vector!(s) ⇒ Object
Divide matrix element-wise by row vector in-place.
115 |
# File 'lib/jblas/mixin_arith.rb', line 115 def div_row_vector!(s); divi_row_vector(s); end |
#eq!(s) ⇒ Object
Element-wise test for equality in-place.
82 |
# File 'lib/jblas/mixin_arith.rb', line 82 def eq!(s); eqi(s); end |
#ge!(s) ⇒ Object
Element-wise test for greater-than-or-equal in-place.
92 |
# File 'lib/jblas/mixin_arith.rb', line 92 def ge!(s); gei(s); end |
#gt!(s) ⇒ Object
Element-wise test for greater-than in-place.
90 |
# File 'lib/jblas/mixin_arith.rb', line 90 def gt!(s); gti(s); end |
#le!(s) ⇒ Object
Element-wise test for less-than-or-equal in-place.
88 |
# File 'lib/jblas/mixin_arith.rb', line 88 def le!(s); lei(s); end |
#lt!(s) ⇒ Object
Element-wise test for less-than in-place.
86 |
# File 'lib/jblas/mixin_arith.rb', line 86 def lt!(s); lti(s); end |
#mmul!(s) ⇒ Object
Matrix multiply matrices in-place.
78 |
# File 'lib/jblas/mixin_arith.rb', line 78 def mmul!(s); mmuli(s); end |
#mul!(s) ⇒ Object
Multiply matrices element-wise in-place.
76 |
# File 'lib/jblas/mixin_arith.rb', line 76 def mul!(s); muli(s); end |
#mul_column_vector!(s) ⇒ Object
Multiply row vector element-wise with matrix in-place.
109 |
# File 'lib/jblas/mixin_arith.rb', line 109 def mul_column_vector!(s); muli_column_vector(s); end |
#mul_row_vector!(s) ⇒ Object
Divide matrix element-wise by column vector in-place.
111 |
# File 'lib/jblas/mixin_arith.rb', line 111 def mul_row_vector!(s); muli_row_vector(s); end |
#ne!(s) ⇒ Object
Element-wise test for inequality in-place.
84 |
# File 'lib/jblas/mixin_arith.rb', line 84 def ne!(s); nei(s); end |
#or!(s) ⇒ Object
Element-wise logical “or” in-place.
96 |
# File 'lib/jblas/mixin_arith.rb', line 96 def or!(s); ori(s); end |
#sub!(s) ⇒ Object
Subtract matrices in-place.
74 |
# File 'lib/jblas/mixin_arith.rb', line 74 def sub!(s); subi(s); end |
#sub_column_vector!(s) ⇒ Object
Subtract column vector from matrix in-place.
105 |
# File 'lib/jblas/mixin_arith.rb', line 105 def sub_column_vector!(s); subi_column_vector(s); end |
#sub_row_vector!(s) ⇒ Object
Subtract column vector from matrix in-place.
107 |
# File 'lib/jblas/mixin_arith.rb', line 107 def sub_row_vector!(s); subi_row_vector(s); end |
#xor!(s) ⇒ Object
Element-wise logical exclusive-or in-place.
98 |
# File 'lib/jblas/mixin_arith.rb', line 98 def xor!(s); xori(s); end |
#|(o) ⇒ Object
Element-wise logical or.
126 |
# File 'lib/jblas/mixin_arith.rb', line 126 def |(o); self.or(o); end |