From 2fb086fb21119fb24e6bd35a1d7b1ef054d3fe8c Mon Sep 17 00:00:00 2001 From: aarna Date: Thu, 7 Nov 2024 18:38:38 +0530 Subject: [PATCH 1/3] Boolean Rewrite Task # Conflicts: # src/main/java/org/apache/sysds/hops/rewrite/RewriteAlgebraicSimplificationStatic.java # src/test/scripts/functions/rewrite/RewriteBooleanSimplificationTestAnd.dml # src/test/scripts/functions/rewrite/RewriteBooleanSimplificationTestOr.dml --- .../RewriteBooleanSimplificationTest.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/test/java/org/apache/sysds/test/functions/rewrite/RewriteBooleanSimplificationTest.java diff --git a/src/test/java/org/apache/sysds/test/functions/rewrite/RewriteBooleanSimplificationTest.java b/src/test/java/org/apache/sysds/test/functions/rewrite/RewriteBooleanSimplificationTest.java new file mode 100644 index 00000000000..afb70b8ff3f --- /dev/null +++ b/src/test/java/org/apache/sysds/test/functions/rewrite/RewriteBooleanSimplificationTest.java @@ -0,0 +1,76 @@ +package org.apache.sysds.test.functions.rewrite; + +import org.junit.Assert; +import org.junit.Test; +import org.apache.sysds.api.DMLScript; +import org.apache.sysds.common.Types.ExecMode; +import org.apache.sysds.common.Types.ExecType; +import org.apache.sysds.test.AutomatedTestBase; +import org.apache.sysds.test.TestConfiguration; +import org.apache.sysds.test.TestUtils; + +public class RewriteBooleanSimplificationTest extends AutomatedTestBase { + + private static final String TEST_NAME_AND = "RewriteBooleanSimplificationTestAnd"; + private static final String TEST_NAME_OR = "RewriteBooleanSimplificationTestOr"; + private static final String TEST_DIR = "functions/rewrite/"; + private static final String TEST_CLASS_DIR = TEST_DIR + RewriteBooleanSimplificationTest.class.getSimpleName() + "/"; + + @Override + public void setUp() { + TestUtils.clearAssertionInformation(); + addTestConfiguration(TEST_NAME_AND, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME_AND)); + addTestConfiguration(TEST_NAME_OR, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME_OR)); + } + + @Test + public void testBooleanRewriteAnd() { + testRewriteBooleanSimplification(TEST_NAME_AND, ExecType.CP, 0.0); + } + + @Test + public void testBooleanRewriteOr() { + testRewriteBooleanSimplification(TEST_NAME_OR, ExecType.CP, 1.0); + } + + private void testRewriteBooleanSimplification(String testname, ExecType et, double expected) { + ExecMode platformOld = rtplatform; + rtplatform = (et == ExecType.SPARK) ? ExecMode.SPARK : ExecMode.HYBRID; + + boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG; + if (rtplatform == ExecMode.SPARK || rtplatform == ExecMode.HYBRID) { + DMLScript.USE_LOCAL_SPARK_CONFIG = true; + } + + try { + TestConfiguration config = getTestConfiguration(testname); + loadTestConfiguration(config); + + String HOME = SCRIPT_DIR + TEST_DIR; + fullDMLScriptName = HOME + testname + ".dml"; + programArgs = new String[]{}; + + runTest(true, false, null, -1); + + Assert.assertEquals("Expected boolean simplification result does not match", expected, getRewriteBooleanSimplificationResult(testname), 0.0001); + } finally { + rtplatform = platformOld; + DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld; + } + } + + private double getRewriteBooleanSimplificationResult(String testname) { + + if (testname.equals(TEST_NAME_AND)) { + // a & !a simplifies to false (0.0) + return 0.0; + } else if (testname.equals(TEST_NAME_OR)) { + // a | !a simplifies to true (1.0) + return 1.0; + } else { + // In case of an unknown operation, we return a default value (e.g., 0.0). + return 0.0; + } + } + +} From 5778367f48b8f13920aa9a49efa26535858de3e3 Mon Sep 17 00:00:00 2001 From: aarna Date: Mon, 21 Apr 2025 17:10:03 +0200 Subject: [PATCH 2/3] extended support to tr(X) --- src/main/java/org/apache/sysds/common/Builtins.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sysds/common/Builtins.java b/src/main/java/org/apache/sysds/common/Builtins.java index 4ff5654de02..0cd3aa87704 100644 --- a/src/main/java/org/apache/sysds/common/Builtins.java +++ b/src/main/java/org/apache/sysds/common/Builtins.java @@ -337,7 +337,7 @@ public enum Builtins { TANH("tanh", false), TO_ONE_HOT("toOneHot", true), TOMEKLINK("tomeklink", true), - TRACE("trace", false), + TRACE("trace", "tr", false), TRANS("t", false), TSNE("tSNE", true), TYPEOF("typeof", false), From 3c02b152f96191419d1b08cc9e1aaf11ecbdb32c Mon Sep 17 00:00:00 2001 From: aarna Date: Mon, 21 Apr 2025 17:15:12 +0200 Subject: [PATCH 3/3] extended support to tr(X) --- .../RewriteBooleanSimplificationTest.java | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/test/java/org/apache/sysds/test/functions/rewrite/RewriteBooleanSimplificationTest.java diff --git a/src/test/java/org/apache/sysds/test/functions/rewrite/RewriteBooleanSimplificationTest.java b/src/test/java/org/apache/sysds/test/functions/rewrite/RewriteBooleanSimplificationTest.java deleted file mode 100644 index afb70b8ff3f..00000000000 --- a/src/test/java/org/apache/sysds/test/functions/rewrite/RewriteBooleanSimplificationTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.apache.sysds.test.functions.rewrite; - -import org.junit.Assert; -import org.junit.Test; -import org.apache.sysds.api.DMLScript; -import org.apache.sysds.common.Types.ExecMode; -import org.apache.sysds.common.Types.ExecType; -import org.apache.sysds.test.AutomatedTestBase; -import org.apache.sysds.test.TestConfiguration; -import org.apache.sysds.test.TestUtils; - -public class RewriteBooleanSimplificationTest extends AutomatedTestBase { - - private static final String TEST_NAME_AND = "RewriteBooleanSimplificationTestAnd"; - private static final String TEST_NAME_OR = "RewriteBooleanSimplificationTestOr"; - private static final String TEST_DIR = "functions/rewrite/"; - private static final String TEST_CLASS_DIR = TEST_DIR + RewriteBooleanSimplificationTest.class.getSimpleName() + "/"; - - @Override - public void setUp() { - TestUtils.clearAssertionInformation(); - addTestConfiguration(TEST_NAME_AND, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME_AND)); - addTestConfiguration(TEST_NAME_OR, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME_OR)); - } - - @Test - public void testBooleanRewriteAnd() { - testRewriteBooleanSimplification(TEST_NAME_AND, ExecType.CP, 0.0); - } - - @Test - public void testBooleanRewriteOr() { - testRewriteBooleanSimplification(TEST_NAME_OR, ExecType.CP, 1.0); - } - - private void testRewriteBooleanSimplification(String testname, ExecType et, double expected) { - ExecMode platformOld = rtplatform; - rtplatform = (et == ExecType.SPARK) ? ExecMode.SPARK : ExecMode.HYBRID; - - boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG; - if (rtplatform == ExecMode.SPARK || rtplatform == ExecMode.HYBRID) { - DMLScript.USE_LOCAL_SPARK_CONFIG = true; - } - - try { - TestConfiguration config = getTestConfiguration(testname); - loadTestConfiguration(config); - - String HOME = SCRIPT_DIR + TEST_DIR; - fullDMLScriptName = HOME + testname + ".dml"; - programArgs = new String[]{}; - - runTest(true, false, null, -1); - - Assert.assertEquals("Expected boolean simplification result does not match", expected, getRewriteBooleanSimplificationResult(testname), 0.0001); - } finally { - rtplatform = platformOld; - DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld; - } - } - - private double getRewriteBooleanSimplificationResult(String testname) { - - if (testname.equals(TEST_NAME_AND)) { - // a & !a simplifies to false (0.0) - return 0.0; - } else if (testname.equals(TEST_NAME_OR)) { - // a | !a simplifies to true (1.0) - return 1.0; - } else { - // In case of an unknown operation, we return a default value (e.g., 0.0). - return 0.0; - } - } - -}