incubator-systemml git commit: [HOTFIX] Fixing broken `print out` Python syntax to be Python 3 friendly.
Repository: incubator-systemml Updated Branches: refs/heads/master e23acf71f -> 7279bf72a [HOTFIX] Fixing broken `print out` Python syntax to be Python 3 friendly. Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/7279bf72 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/7279bf72 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/7279bf72 Branch: refs/heads/master Commit: 7279bf72a48002f47e2b0a5d1fc4aeb4dfe47324 Parents: e23acf7 Author: Mike DusenberryAuthored: Wed Sep 7 16:15:47 2016 -0700 Committer: Mike Dusenberry Committed: Wed Sep 7 16:15:47 2016 -0700 -- src/main/python/systemml/defmatrix.py | 82 +++--- 1 file changed, 41 insertions(+), 41 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/7279bf72/src/main/python/systemml/defmatrix.py -- diff --git a/src/main/python/systemml/defmatrix.py b/src/main/python/systemml/defmatrix.py index 5092874..4d2781a 100644 --- a/src/main/python/systemml/defmatrix.py +++ b/src/main/python/systemml/defmatrix.py @@ -56,18 +56,18 @@ class DMLOp(object): self.dml = dml self.ID = None for m in self.inputs: -m.referenced = m.referenced + [ self ] +m.referenced = m.referenced + [ self ] def _visit(self, execute=True): matrix.dml = matrix.dml + self.dml - + # Don't use this method instead use matrix's printAST() def printAST(self, numSpaces): ret = [] for m in self.inputs: ret = [ m.printAST(numSpaces+2) ] return ''.join(ret) - + # Special object used internally to specify the placeholder which will be replaced by output ID # This helps to provide dml containing output ID in constructIntermediateNode OUTPUT_ID = '$$OutputID$$' @@ -75,11 +75,11 @@ OUTPUT_ID = '$$OutputID$$' def constructIntermediateNode(inputs, dml): """ Convenient utility to create an intermediate node of AST. - + Parameters -- inputs = list of input matrix objects and/or DMLOp -dml = list of DML string (which will be eventually joined before execution). To specify out.ID, please use the placeholder +dml = list of DML string (which will be eventually joined before execution). To specify out.ID, please use the placeholder """ dmlOp = DMLOp(inputs) out = matrix(None, op=dmlOp) @@ -215,7 +215,7 @@ def populateOutputs(outputs, results, outputDF): def exp(X): return unaryMatrixFunction(X, 'exp') - + def log(X, y=None): if y is None: return unaryMatrixFunction(X, 'log') @@ -224,10 +224,10 @@ def log(X, y=None): def abs(X): return unaryMatrixFunction(X, 'abs') - + def sqrt(X): return unaryMatrixFunction(X, 'sqrt') - + def round(X): return unaryMatrixFunction(X, 'round') @@ -236,7 +236,7 @@ def floor(X): def ceil(X): return unaryMatrixFunction(X, 'ceil') - + def sin(X): return unaryMatrixFunction(X, 'sin') @@ -257,7 +257,7 @@ def atan(X): def sign(X): return unaryMatrixFunction(X, 'sign') - + def solve(A, b): """ Computes the least squares solution for system of linear equations A %*% x = b @@ -305,20 +305,20 @@ def eval(outputs, outputDF=False, execute=True): results = matrix.ml.execute(matrix.script) populateOutputs(outputs, results, outputDF) resetOutputFlag(outputs) - + ### # DESIGN DECISIONS: # 1. Until eval() method is invoked, we create an AST (not exposed to the user) that consist of unevaluated operations and data required by those operations. -#As an anology, a spark user can treat eval() method similar to calling RDD.persist() followed by RDD.count(). +#As an anology, a spark user can treat eval() method similar to calling RDD.persist() followed by RDD.count(). # 2. The AST consist of two kinds of nodes: either of type matrix or of type DMLOp. #Both these classes expose _visit method, that helps in traversing the AST in DFS manner. -# 3. A matrix object can either be evaluated or not. +# 3. A matrix object can either be evaluated or not. #If evaluated, the attribute 'data' is set to one of the supported types (for example: NumPy array or DataFrame). In this case, the attribute 'op' is set to None. #If not evaluated, the attribute 'op' which refers to one of the intermediate node of AST and if of type DMLOp. In this case, the attribute 'data' is set to None. -# 5. DMLOp has an attribute 'inputs' which contains list of matrix
incubator-systemml git commit: [SYSTEMML-881] [WIP] Bug fixes in indexing operation and added debugging utility for development purposes
Repository: incubator-systemml Updated Branches: refs/heads/master f10fa2b8f -> e23acf71f [SYSTEMML-881] [WIP] Bug fixes in indexing operation and added debugging utility for development purposes Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/e23acf71 Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/e23acf71 Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/e23acf71 Branch: refs/heads/master Commit: e23acf71f3a31448f98ce78baffea23ccc69751c Parents: f10fa2b Author: Niketan PansareAuthored: Wed Sep 7 15:28:15 2016 -0700 Committer: Niketan Pansare Committed: Wed Sep 7 15:28:15 2016 -0700 -- src/main/python/systemml/defmatrix.py | 60 ++ 1 file changed, 52 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/e23acf71/src/main/python/systemml/defmatrix.py -- diff --git a/src/main/python/systemml/defmatrix.py b/src/main/python/systemml/defmatrix.py index e1bd3b9..5092874 100644 --- a/src/main/python/systemml/defmatrix.py +++ b/src/main/python/systemml/defmatrix.py @@ -54,10 +54,20 @@ class DMLOp(object): def __init__(self, inputs, dml=None): self.inputs = inputs self.dml = dml +self.ID = None +for m in self.inputs: +m.referenced = m.referenced + [ self ] def _visit(self, execute=True): matrix.dml = matrix.dml + self.dml +# Don't use this method instead use matrix's printAST() +def printAST(self, numSpaces): +ret = [] +for m in self.inputs: +ret = [ m.printAST(numSpaces+2) ] +return ''.join(ret) + # Special object used internally to specify the placeholder which will be replaced by output ID # This helps to provide dml containing output ID in constructIntermediateNode OUTPUT_ID = '$$OutputID$$' @@ -315,7 +325,21 @@ def eval(outputs, outputDF=False, execute=True): #To ensure the above property, we make deep copy of existing object and point any references to the left-indexed matrix to the newly created object. #Then the left-indexed matrix is set to be backed by DMLOp consisting of following pydml: #left-indexed-matrix = new-deep-copied-matrix -#left-indexed-matrix[index] = value +#left-indexed-matrix[index] = value +# 8. Please use m.printAST() and/or type `m` for debugging. Here is a sample session: +# >>> npm = np.ones((3,3)) +# >>> m1 = sml.matrix(npm + 3) +# >>> m2 = sml.matrix(npm + 5) +# >>> m3 = m1 + m2 +# >>> m3 +# mVar2 = load(" ", format="csv") +# mVar1 = load(" ", format="csv") +# mVar3 = mVar1 + mVar2 +# save(mVar3, " ") +# >>> m3.printAST() +# - [mVar3] (op). +# - [mVar1] (data). +# - [mVar2] (data). class matrix(object): """ matrix class is a python wrapper that implements basic matrix operator. @@ -395,8 +419,6 @@ class matrix(object): self.data = data if not (isinstance(data, SUPPORTED_TYPES) or hasattr(data, '_jdf') or (data is None and op is not None)): raise TypeError('Unsupported input type') -if op is not None: -self.referenced = self.referenced + [ op ] def eval(self, outputDF=False): """ @@ -479,6 +501,25 @@ class matrix(object): self._registerAsOutput(execute) return self +def printAST(self, numSpaces = 0): +""" +Used for debugging purposes +""" +head = ''.join([ ' ' ]*numSpaces + [ '- [', self.ID, '] ' ]) +if self.data is not None: +out = head + '(data).\n' +elif self.op is not None: +ret = [ head, '(op).\n' ] +for m in self.op.inputs: +ret = ret + [ m.printAST(numSpaces + 2) ] +out = ''.join(ret) +else: +raise ValueError('Either op or data needs to be set') +if numSpaces == 0: +print out +else: +return out + def __repr__(self): """ This function helps to debug matrix class and also examine the generated PyDML script @@ -639,18 +680,21 @@ class matrix(object): # Performs deep copy if the matrix is backed by data def _prepareForInPlaceUpdate(self): temp = matrix(self.data, op=self.op) -self.ID, temp.ID = temp.ID, self.ID # Copy even the IDs as the IDs might be used to create DML for op in self.referenced: -op.inputs.remove(self) #while self in op.inputs: -op.inputs = op.inputs + [ temp ] +op.inputs = [temp if x.ID==self.ID else x for x in op.inputs] +self.ID, temp.ID = temp.ID, self.ID #