This is an automated email from the ASF dual-hosted git repository. mboehm7 pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/systemds.git
commit 70fca954ff78ac7efa1b458c0cb6fde90d777150 Author: baunsgaard <[email protected]> AuthorDate: Tue May 17 15:39:03 2022 +0200 [SYSTEMDS-3343] Various tests for eval w/ boolean function arguments Closes #1575. --- .../test/functions/mlcontext/MLContextTest.java | 62 +++++++++++++++++----- .../mlcontext/eval5-bool-allFalse-list-2.dml | 34 ++++++++++++ .../mlcontext/eval5-bool-allFalse-list.dml | 34 ++++++++++++ .../functions/mlcontext/eval5-bool-not-false.dml | 30 +++++++++++ .../functions/mlcontext/eval5-bool-not-true.dml | 29 ++++++++++ .../functions/mlcontext/eval6-gridSearch-1.dml | 52 ++++++++++++++++++ .../functions/mlcontext/eval6-gridSearch-2.dml | 54 +++++++++++++++++++ .../functions/mlcontext/eval6-gridSearch-3.dml | 54 +++++++++++++++++++ 8 files changed, 337 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/apache/sysds/test/functions/mlcontext/MLContextTest.java b/src/test/java/org/apache/sysds/test/functions/mlcontext/MLContextTest.java index c4b1e44e6a..147b450fbc 100644 --- a/src/test/java/org/apache/sysds/test/functions/mlcontext/MLContextTest.java +++ b/src/test/java/org/apache/sysds/test/functions/mlcontext/MLContextTest.java @@ -114,22 +114,60 @@ public class MLContextTest extends MLContextTestBase { @Test public void testExecuteEvalBuiltinTest() { - LOG.debug("MLContextTest - eval builtin test"); - Script script = dmlFromFile(baseDirectory + File.separator + "eval3-builtin-test.dml"); - ml.setExplain(true); - String out = executeAndCaptureStdOut( script).getRight(); - assertTrue(out.contains("TRUE")); - ml.setExplain(false); + runEvalTest("eval3-builtin-test.dml", "TRUE"); } @Test public void testExecuteEvalNestedBuiltinTest() { - LOG.debug("MLContextTest - eval builtin test"); - Script script = dmlFromFile(baseDirectory + File.separator + "eval4-nested_builtin-test.dml"); - ml.setExplain(true); - String out = executeAndCaptureStdOut( script).getRight(); - assertTrue(out.contains("TRUE")); - ml.setExplain(false); + runEvalTest("eval4-nested_builtin-test.dml", "TRUE"); + } + + @Test + public void testExecuteEvalBooleanArgument_01(){ + runEvalTest("eval5-bool-not-true.dml", "FALSE"); + } + + @Test + public void testExecuteEvalBooleanArgument_02(){ + runEvalTest("eval5-bool-not-false.dml", "TRUE"); + } + + @Test + public void testExecuteEvalBooleanArgument_03(){ + runEvalTest("eval5-bool-allFalse-list.dml", "FALSE"); + } + + @Test + public void testExecuteEvalBooleanArgument_04(){ + runEvalTest("eval5-bool-allFalse-list-2.dml", "TRUE"); + } + + @Test + public void testExecuteEvalGridSearchNoDefault(){ + // grid search where all parameters are defined in parameter ranges + runEvalTest("eval6-gridSearch-1.dml", "You Found Me! TRUE"); + } + + @Test + public void testExecuteEvalGridSearchWithDefault(){ + // grid search where all but one boolean parameter is defined in parameter ranges + runEvalTest("eval6-gridSearch-2.dml", "You Found Me Also! TRUE"); + } + + @Test + public void testExecuteEvalGridSearchWithTwoDefault(){ + // grid search where two boolean parameters are not defined in parameter ranges. + runEvalTest("eval6-gridSearch-3.dml", "Find Me! TRUE"); + } + + private void runEvalTest(String name, String outputContains){ + LOG.debug("MLContextTest - eval builtin test " + name); + final Script script = dmlFromFile(baseDirectory + File.separator + name); + // ml.setExplain(true); + final String out = executeAndCaptureStdOut(script).getRight(); + // LOG.error(out); + assertTrue(out, out.contains(outputContains)); + // ml.setExplain(false); } @Test diff --git a/src/test/scripts/functions/mlcontext/eval5-bool-allFalse-list-2.dml b/src/test/scripts/functions/mlcontext/eval5-bool-allFalse-list-2.dml new file mode 100644 index 0000000000..773e7c5d1f --- /dev/null +++ b/src/test/scripts/functions/mlcontext/eval5-bool-allFalse-list-2.dml @@ -0,0 +1,34 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +allFalse = function( + Boolean a=FALSE, + Boolean b=FALSE, + Boolean c=FALSE, + Boolean d=FALSE) + return (Boolean e) { + e = !a & !b & !c & !d + print(e) +} + +b = eval("allFalse", list(FALSE,FALSE,FALSE,FALSE)) + +print(toString(b)) diff --git a/src/test/scripts/functions/mlcontext/eval5-bool-allFalse-list.dml b/src/test/scripts/functions/mlcontext/eval5-bool-allFalse-list.dml new file mode 100644 index 0000000000..e53f7a6327 --- /dev/null +++ b/src/test/scripts/functions/mlcontext/eval5-bool-allFalse-list.dml @@ -0,0 +1,34 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +allFalse = function( + Boolean a=FALSE, + Boolean b=FALSE, + Boolean c=FALSE, + Boolean d=FALSE) + return (Boolean e) { + e = !a & !b & !c & !d + print(e) +} + +b = eval("allFalse", list(TRUE,TRUE,FALSE,FALSE)) + +print(toString(b)) diff --git a/src/test/scripts/functions/mlcontext/eval5-bool-not-false.dml b/src/test/scripts/functions/mlcontext/eval5-bool-not-false.dml new file mode 100644 index 0000000000..23a2160782 --- /dev/null +++ b/src/test/scripts/functions/mlcontext/eval5-bool-not-false.dml @@ -0,0 +1,30 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +not = function (Boolean b=FALSE) return (Boolean c) { + c = ! b + print(c) +} + + +b = eval("not", FALSE) + +print(toString(b)) diff --git a/src/test/scripts/functions/mlcontext/eval5-bool-not-true.dml b/src/test/scripts/functions/mlcontext/eval5-bool-not-true.dml new file mode 100644 index 0000000000..28b0a3d3ab --- /dev/null +++ b/src/test/scripts/functions/mlcontext/eval5-bool-not-true.dml @@ -0,0 +1,29 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +not = function (Boolean b=FALSE) return (Boolean c) { + c = ! b + print(c) +} + +b = eval("not", TRUE) + +print(toString(b)) diff --git a/src/test/scripts/functions/mlcontext/eval6-gridSearch-1.dml b/src/test/scripts/functions/mlcontext/eval6-gridSearch-1.dml new file mode 100644 index 0000000000..296ee14433 --- /dev/null +++ b/src/test/scripts/functions/mlcontext/eval6-gridSearch-1.dml @@ -0,0 +1,52 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +m = function( + Boolean a, + Boolean b, + Boolean c, + Boolean d) + return (Matrix[Double] m) { + # No default values. + e = !a & b & !c & d + if (e) + # test parses if this is printed + print("You Found Me! "+d) + m = matrix(e,1,1) +} + +p = function(boolean a, Matrix[Double] b) return(Matrix[double] loss){ + loss = rand(rows=1,cols=1,min=0,max=1) +} + +X = matrix(1,1,1) +Y = matrix(1,1,1) + +params = list("a", "b", "c", "d") +paramRanges=list(seq(0,1), seq(0,1), seq(0,1), seq(0,1)) +trainArgs = list(a=TRUE,b=TRUE,c=TRUE,d=TRUE) +predictArgs= list(TRUE) + +[b, opt] = gridSearch(X=X, y=Y, train="m", predict="p", numB = 1, params = params, + paramValues = paramRanges, trainArgs=trainArgs, predictArgs=predictArgs, + verbose=FALSE ) + +print(toString(b)) diff --git a/src/test/scripts/functions/mlcontext/eval6-gridSearch-2.dml b/src/test/scripts/functions/mlcontext/eval6-gridSearch-2.dml new file mode 100644 index 0000000000..ab2dc51b7d --- /dev/null +++ b/src/test/scripts/functions/mlcontext/eval6-gridSearch-2.dml @@ -0,0 +1,54 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +m = function( + Boolean a, + Boolean b, + Boolean c, + Boolean d, + Boolean e) + return (Matrix[Double] m) { + # e is using a default value of TRUE + f = !a & b & !c & d & e + if (f) + # test parses if this is printed + print("You Found Me Also! " + d) + m = matrix(f,1,1) +} + +p = function(boolean a, Matrix[Double] b) return(Matrix[double] loss){ + loss = rand(rows=1,cols=1,min=0,max=1) +} + +X = matrix(1,1,1) +Y = matrix(1,1,1) + +params = list("a", "b", "c", "d") +paramRanges=list(seq(0,1), seq(0,1), seq(0,1), seq(0,1)) +# E have a default value of True +trainArgs = list(a=TRUE, b=TRUE, c=TRUE, d=TRUE, e=TRUE) +predictArgs= list(TRUE) + +[b, opt] = gridSearch(X=X, y=Y, train="m", predict="p", numB = 1, params = params, + paramValues = paramRanges, trainArgs=trainArgs, predictArgs=predictArgs, + verbose=FALSE) + +print(toString(b)) diff --git a/src/test/scripts/functions/mlcontext/eval6-gridSearch-3.dml b/src/test/scripts/functions/mlcontext/eval6-gridSearch-3.dml new file mode 100644 index 0000000000..6b1168f1d0 --- /dev/null +++ b/src/test/scripts/functions/mlcontext/eval6-gridSearch-3.dml @@ -0,0 +1,54 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +m = function( + Boolean a, + Boolean b, + Boolean c, + Boolean d, + Boolean e) + return (Matrix[Double] m) { + # d and e is using a default value of TRUE + f = !a & b & !c & !d & e + if (f) + # test parses if this is printed + print("Find Me! " + e) + m = matrix(f,1,1) +} + +p = function(boolean a, Matrix[Double] b) return(Matrix[double] loss){ + loss = rand(rows=1,cols=1,min=0,max=1) +} + +X = matrix(1,1,1) +Y = matrix(1,1,1) + +params = list("a", "b", "c") +paramRanges=list(seq(0,1), seq(0,1), seq(0,1)) +# D and E have default values of False and True +trainArgs = list(a=TRUE, b=TRUE, c=TRUE, d=FALSE, e=TRUE) +predictArgs= list(TRUE) + +[b, opt] = gridSearch(X=X, y=Y, train="m", predict="p", numB = 1, params = params, + paramValues = paramRanges, trainArgs=trainArgs, predictArgs=predictArgs, + verbose=FALSE) + +print(toString(b))
