Repository: systemml Updated Branches: refs/heads/master 43b573dfb -> 6a75104e5
[SYSTEMML-1426] Support both ceil and ceiling built-in functions Added support for ceiling built-in function while keeping existing ceil function with same internal compiler/runtime constants and opcode. Also included unit tests for ceiling. Closes #674. Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/6a75104e Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/6a75104e Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/6a75104e Branch: refs/heads/master Commit: 6a75104e5e870b3dd69bcad493bd4fe9fadd7c98 Parents: 43b573d Author: Glenn Weidner <gweid...@us.ibm.com> Authored: Fri Sep 29 10:28:15 2017 -0700 Committer: Glenn Weidner <gweid...@us.ibm.com> Committed: Fri Sep 29 10:28:15 2017 -0700 ---------------------------------------------------------------------- docs/dml-language-reference.md | 2 +- .../RewriteAlgebraicSimplificationStatic.java | 4 +- .../sysml/parser/BuiltinFunctionExpression.java | 2 +- src/main/python/systemml/defmatrix.py | 5 +- .../functions/unary/matrix/RoundTest.java | 64 +++++++++++++++++++- .../scripts/functions/unary/matrix/Ceiling.R | 33 ++++++++++ .../scripts/functions/unary/matrix/Ceiling.dml | 25 ++++++++ 7 files changed, 129 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/6a75104e/docs/dml-language-reference.md ---------------------------------------------------------------------- diff --git a/docs/dml-language-reference.md b/docs/dml-language-reference.md index c402acc..58ca306 100644 --- a/docs/dml-language-reference.md +++ b/docs/dml-language-reference.md @@ -821,7 +821,7 @@ is same as Function | Description | Parameters | Example -------- | ----------- | ---------- | ------- -exp(), log(), abs(), sqrt(), round(), floor(), ceil() | Apply mathematical function on input (cell wise if input is matrix) | Input: (<matrix>), or (<scalar>) <br/> Output: <matrix>, or <scalar> | sqrt(X) <br/> log(X,y) <br/> round(X) <br/> floor(X) <br/> ceil(X) +exp(), log(), abs(), sqrt(), round(), floor(), ceil(), ceiling() | Apply mathematical function on input (cell wise if input is matrix) | Input: (<matrix>), or (<scalar>) <br/> Output: <matrix>, or <scalar> | sqrt(X) <br/> log(X,y) <br/> round(X) <br/> floor(X) <br/> ceil(X) <br/> ceiling(X) sin(), cos(), tan(), sinh(), cosh(), tanh(), asin(), acos(), atan() | Apply trigonometric function on input (cell wise if input is matrix) | Input: (<matrix>), or (<scalar>) <br/> Output: <matrix>, or <scalar> | sin(X) sign() | Returns a matrix representing the signs of the input matrix elements, where 1 represents positive, 0 represents zero, and -1 represents negative | Input : (A <matrix>) <br/> Output : <matrix> | <span style="white-space: nowrap;">A = matrix("-5 0 3 -3",</span> rows=2, cols=2) <br/>signA = sign(A)<br/>Matrix signA: [[-1, 0], [1, -1]] http://git-wip-us.apache.org/repos/asf/systemml/blob/6a75104e/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java index eadf492..d100989 100644 --- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java +++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java @@ -170,7 +170,7 @@ public class RewriteAlgebraicSimplificationStatic extends HopRewriteRule hi = simplifyOrderedSort(hop, hi, i); //e.g., order(matrix())->seq; hi = removeUnnecessaryReorgOperation(hop, hi, i); //e.g., t(t(X))->X; rev(rev(X))->X potentially introduced by other rewrites hi = simplifyTransposeAggBinBinaryChains(hop, hi, i);//e.g., t(t(A)%*%t(B)+C) -> B%*%A+t(C) - hi = removeUnnecessaryMinus(hop, hi, i); //e.g., -(-X)->X; potentially introduced by simplfiy binary or dyn rewrites + hi = removeUnnecessaryMinus(hop, hi, i); //e.g., -(-X)->X; potentially introduced by simplify binary or dyn rewrites hi = simplifyGroupedAggregate(hi); //e.g., aggregate(target=X,groups=y,fn="count") -> aggregate(target=y,groups=y,fn="count") if(OptimizerUtils.ALLOW_OPERATOR_FUSION) { hi = fuseMinusNzBinaryOperation(hop, hi, i); //e.g., X-mean*ppred(X,0,!=) -> X -nz mean @@ -340,7 +340,7 @@ public class RewriteAlgebraicSimplificationStatic extends HopRewriteRule * rand*7 -> rand(min*7,max*7); rand+7 -> rand(min+7,max+7); rand-7 -> rand(min+(-7),max+(-7)) * 7*rand -> rand(min*7,max*7); 7+rand -> rand(min+7,max+7); * - * @param hi high-order operaton + * @param hi high-order operation * @return high-level operator * @throws HopsException if HopsException occurs */ http://git-wip-us.apache.org/repos/asf/systemml/blob/6a75104e/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java index 1e54251..d5fa65d 100644 --- a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java +++ b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java @@ -1708,7 +1708,7 @@ public class BuiltinFunctionExpression extends DataIdentifier bifop = Expression.BuiltinFunctionOp.AVG_POOL; else if (functionName.equals("solve")) bifop = Expression.BuiltinFunctionOp.SOLVE; - else if (functionName.equals("ceil")) + else if (functionName.equals("ceil") || functionName.equals("ceiling")) bifop = Expression.BuiltinFunctionOp.CEIL; else if (functionName.equals("floor")) bifop = Expression.BuiltinFunctionOp.FLOOR; http://git-wip-us.apache.org/repos/asf/systemml/blob/6a75104e/src/main/python/systemml/defmatrix.py ---------------------------------------------------------------------- diff --git a/src/main/python/systemml/defmatrix.py b/src/main/python/systemml/defmatrix.py index 576e300..c177a05 100644 --- a/src/main/python/systemml/defmatrix.py +++ b/src/main/python/systemml/defmatrix.py @@ -356,7 +356,7 @@ class matrix(object): 1. transpose 2. Aggregation functions: sum, mean, var, sd, max, min, argmin, argmax, cumsum - 3. Global statistical built-In functions: exp, log, abs, sqrt, round, floor, ceil, sin, cos, tan, asin, acos, atan, sign, solve + 3. Global statistical built-In functions: exp, log, abs, sqrt, round, floor, ceil, ceiling, sin, cos, tan, asin, acos, atan, sign, solve For all the above functions, we always return a two dimensional matrix, especially for aggregation functions with axis. For example: Assuming m1 is a matrix of (3, n), NumPy returns a 1d vector of dimension (3,) for operation m1.sum(axis=1) @@ -822,6 +822,9 @@ class matrix(object): def ceil(self): return unaryMatrixFunction(self, 'ceil') + def ceiling(self): + return unaryMatrixFunction(self, 'ceiling') + def sin(self): return unaryMatrixFunction(self, 'sin') http://git-wip-us.apache.org/repos/asf/systemml/blob/6a75104e/src/test/java/org/apache/sysml/test/integration/functions/unary/matrix/RoundTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/unary/matrix/RoundTest.java b/src/test/java/org/apache/sysml/test/integration/functions/unary/matrix/RoundTest.java index eb51303..f1c899c 100644 --- a/src/test/java/org/apache/sysml/test/integration/functions/unary/matrix/RoundTest.java +++ b/src/test/java/org/apache/sysml/test/integration/functions/unary/matrix/RoundTest.java @@ -34,7 +34,8 @@ public class RoundTest extends AutomatedTestBase private enum TEST_TYPE { ROUND ("RoundTest"), FLOOR ("Floor"), - CEIL ("Ceil"); + CEIL ("Ceil"), + CEILING ("Ceiling"); String scriptName = null; TEST_TYPE(String name) { @@ -58,6 +59,7 @@ public class RoundTest extends AutomatedTestBase addTestConfiguration(TEST_TYPE.ROUND.scriptName, new TestConfiguration(TEST_CLASS_DIR, TEST_TYPE.ROUND.scriptName, new String[] { "R" })); addTestConfiguration(TEST_TYPE.FLOOR.scriptName, new TestConfiguration(TEST_CLASS_DIR, TEST_TYPE.FLOOR.scriptName, new String[] { "R" })); addTestConfiguration(TEST_TYPE.CEIL.scriptName, new TestConfiguration(TEST_CLASS_DIR, TEST_TYPE.CEIL.scriptName, new String[] { "R" })); + addTestConfiguration(TEST_TYPE.CEILING.scriptName, new TestConfiguration(TEST_CLASS_DIR, TEST_TYPE.CEILING.scriptName, new String[] { "R" })); } @Test @@ -151,6 +153,36 @@ public class RoundTest extends AutomatedTestBase } @Test + public void testCeiling1() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows1, cols1, sparsity1); + } + + @Test + public void testCeiling2() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows1, cols1, sparsity2); + } + + @Test + public void testCeiling3() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows1, cols1, sparsity3); + } + + @Test + public void testCeiling4() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows2, cols2, sparsity1); + } + + @Test + public void testCeiling5() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows2, cols2, sparsity2); + } + + @Test + public void testCeiling6() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows2, cols2, sparsity3); + } + + @Test public void testRoundMR1() { runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.ROUND, rows1, cols1, sparsity1); } @@ -240,6 +272,36 @@ public class RoundTest extends AutomatedTestBase runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEIL, rows2, cols2, sparsity3); } + @Test + public void testCeilingMR1() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows1, cols1, sparsity1); + } + + @Test + public void testCeilingMR2() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows1, cols1, sparsity2); + } + + @Test + public void testCeilingMR3() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows1, cols1, sparsity3); + } + + @Test + public void testCeilingMR4() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows2, cols2, sparsity1); + } + + @Test + public void testCeilingMR5() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows2, cols2, sparsity2); + } + + @Test + public void testCeilingMR6() { + runTest(RUNTIME_PLATFORM.HYBRID, TEST_TYPE.CEILING, rows2, cols2, sparsity3); + } + // ----------------------------------------------------------------------------- @Test http://git-wip-us.apache.org/repos/asf/systemml/blob/6a75104e/src/test/scripts/functions/unary/matrix/Ceiling.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/unary/matrix/Ceiling.R b/src/test/scripts/functions/unary/matrix/Ceiling.R new file mode 100644 index 0000000..3dcef39 --- /dev/null +++ b/src/test/scripts/functions/unary/matrix/Ceiling.R @@ -0,0 +1,33 @@ +#------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#------------------------------------------------------------- + + +args <- commandArgs(TRUE) +options(digits=22) + +library("Matrix") + +A <- as.matrix(readMM(paste(args[1], "math.mtx", sep=""))) + +R = ceiling(A); + +writeMM(as(R, "CsparseMatrix"), paste(args[2], "R", sep="")); + http://git-wip-us.apache.org/repos/asf/systemml/blob/6a75104e/src/test/scripts/functions/unary/matrix/Ceiling.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/unary/matrix/Ceiling.dml b/src/test/scripts/functions/unary/matrix/Ceiling.dml new file mode 100644 index 0000000..38c1876 --- /dev/null +++ b/src/test/scripts/functions/unary/matrix/Ceiling.dml @@ -0,0 +1,25 @@ +#------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#------------------------------------------------------------- + +V = read($1); +R = ceiling(V); +write(R, $2); +