Repository: incubator-systemml
Updated Branches:
  refs/heads/master 020403466 -> 31d2cda55


[SYSTEMML-1186] Adding Python3-style Division of Scalar By Matrix

This adds the right-hand side Python3-style division to the `matrix`
class by overriding `__rtruediv__`.  I.e. `3 / X` will now work.

Closes #348.


Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/31d2cda5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/31d2cda5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/31d2cda5

Branch: refs/heads/master
Commit: 31d2cda55a5dd48b279d2e8f187339822c3a4647
Parents: 0204034
Author: Imran Younus <imranyou...@gmail.com>
Authored: Wed Jan 18 10:48:50 2017 -0800
Committer: Mike Dusenberry <mwdus...@us.ibm.com>
Committed: Wed Jan 18 10:48:50 2017 -0800

----------------------------------------------------------------------
 src/main/python/systemml/defmatrix.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/31d2cda5/src/main/python/systemml/defmatrix.py
----------------------------------------------------------------------
diff --git a/src/main/python/systemml/defmatrix.py 
b/src/main/python/systemml/defmatrix.py
index 6a56690..5f973f6 100644
--- a/src/main/python/systemml/defmatrix.py
+++ b/src/main/python/systemml/defmatrix.py
@@ -915,6 +915,12 @@ class matrix(object):
     def __rdiv__(self, other):
         return binary_op(other, self, ' / ')
 
+    def __rtruediv__(self, other):
+        """
+        Performs division (Python 3 way).
+        """
+        return binary_op(other, self, ' / ')
+
     def __rmod__(self, other):
         return binary_op(other, self, ' % ')
 
@@ -1225,4 +1231,4 @@ class matrix(object):
         self.op.dml = self.op.dml + [ '\n', self.ID ] + getIndexingDML(index) 
+ [ ' = ',  getValue(value), '\n']
 
     # Not implemented: conj, hyperbolic/inverse-hyperbolic functions(i.e. 
sinh, arcsinh, cosh, ...), bitwise operator, xor operator, isreal, iscomplex, 
isfinite, isinf, isnan, copysign, nextafter, modf, frexp, trunc  
-    _numpy_to_systeml_mapping = {np.add: __add__, np.subtract: __sub__, 
np.multiply: __mul__, np.divide: __div__, np.logaddexp: logaddexp, 
np.true_divide: __truediv__, np.floor_divide: __floordiv__, np.negative: 
negative, np.power: __pow__, np.remainder: remainder, np.mod: mod, np.fmod: 
__mod__, np.absolute: abs, np.rint: round, np.sign: sign, np.exp: exp, np.exp2: 
exp2, np.log: log, np.log2: log2, np.log10: log10, np.expm1: expm1, np.log1p: 
log1p, np.sqrt: sqrt, np.square: square, np.reciprocal: reciprocal, 
np.ones_like: ones_like, np.zeros_like: zeros_like, np.sin: sin, np.cos: cos, 
np.tan: tan, np.arcsin: arcsin, np.arccos: arccos, np.arctan: arctan, 
np.deg2rad: deg2rad, np.rad2deg: rad2deg, np.greater: __gt__, np.greater_equal: 
__ge__, np.less: __lt__, np.less_equal: __le__, np.not_equal: __ne__, np.equal: 
__eq__, np.logical_not: logical_not, np.logical_and: __and__, np.logical_or: 
__or__, np.maximum: max, np.minimum: min, np.signbit: sign, np.ldexp: ldexp, 
np.dot:dot}
\ No newline at end of file
+    _numpy_to_systeml_mapping = {np.add: __add__, np.subtract: __sub__, 
np.multiply: __mul__, np.divide: __div__, np.logaddexp: logaddexp, 
np.true_divide: __truediv__, np.floor_divide: __floordiv__, np.negative: 
negative, np.power: __pow__, np.remainder: remainder, np.mod: mod, np.fmod: 
__mod__, np.absolute: abs, np.rint: round, np.sign: sign, np.exp: exp, np.exp2: 
exp2, np.log: log, np.log2: log2, np.log10: log10, np.expm1: expm1, np.log1p: 
log1p, np.sqrt: sqrt, np.square: square, np.reciprocal: reciprocal, 
np.ones_like: ones_like, np.zeros_like: zeros_like, np.sin: sin, np.cos: cos, 
np.tan: tan, np.arcsin: arcsin, np.arccos: arccos, np.arctan: arctan, 
np.deg2rad: deg2rad, np.rad2deg: rad2deg, np.greater: __gt__, np.greater_equal: 
__ge__, np.less: __lt__, np.less_equal: __le__, np.not_equal: __ne__, np.equal: 
__eq__, np.logical_not: logical_not, np.logical_and: __and__, np.logical_or: 
__or__, np.maximum: max, np.minimum: min, np.signbit: sign, np.ldexp: ldexp, 
np.dot:dot}

Reply via email to