This is an automated email from the ASF dual-hosted git repository.
baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/main by this push:
new 6b3a6ced88 [SYSTEMDS-3610] BuiltinSwitch Aggregate Skip
6b3a6ced88 is described below
commit 6b3a6ced8804757feaf244963275b6aef4f3f71d
Author: baunsgaard <[email protected]>
AuthorDate: Mon Aug 7 13:44:37 2023 +0200
[SYSTEMDS-3610] BuiltinSwitch Aggregate Skip
This commit provide a minor minor change to the Builtin instructions
to include min and max. The difference in performance is negligible
but there, so we include the improvement.
Closes #1875
---
.../sysds/runtime/functionobjects/Builtin.java | 6 ++-
.../apache/sysds/runtime/functionobjects/Max.java | 52 ++++++++++++++++++++++
.../apache/sysds/runtime/functionobjects/Min.java | 52 ++++++++++++++++++++++
3 files changed, 109 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/apache/sysds/runtime/functionobjects/Builtin.java
b/src/main/java/org/apache/sysds/runtime/functionobjects/Builtin.java
index 724f057a73..48d6518edf 100644
--- a/src/main/java/org/apache/sysds/runtime/functionobjects/Builtin.java
+++ b/src/main/java/org/apache/sysds/runtime/functionobjects/Builtin.java
@@ -115,7 +115,7 @@ public class Builtin extends ValueFunction
String2BuiltinCode.put( "applySchema",
BuiltinCode.APPLY_SCHEMA);
}
- private Builtin(BuiltinCode bf) {
+ protected Builtin(BuiltinCode bf) {
bFunc = bf;
}
@@ -142,6 +142,10 @@ public class Builtin extends ValueFunction
public static Builtin getBuiltinFnObject(BuiltinCode code) {
if ( code == null )
return null;
+ if(code == BuiltinCode.MAX)
+ return Max.getMaxFnObject();
+ else if (code == BuiltinCode.MIN)
+ return Min.getMinFnObject();
return new Builtin(code);
}
diff --git a/src/main/java/org/apache/sysds/runtime/functionobjects/Max.java
b/src/main/java/org/apache/sysds/runtime/functionobjects/Max.java
new file mode 100644
index 0000000000..4c61479bdf
--- /dev/null
+++ b/src/main/java/org/apache/sysds/runtime/functionobjects/Max.java
@@ -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.
+ */
+
+package org.apache.sysds.runtime.functionobjects;
+
+public class Max extends Builtin {
+ private static Max singleObj = null;
+
+ private Max() {
+ super(BuiltinCode.MAX);
+ // nothing to do here.
+ }
+
+ private static final long serialVersionUID = 6529946102263905602L;
+
+ public static Max getMaxFnObject() {
+ if(singleObj == null)
+ singleObj = new Max();
+ return singleObj;
+ }
+
+ @Override
+ public boolean execute(boolean in1, boolean in2) {
+ return in1 || in2;
+ }
+
+ @Override
+ public double execute(long in1, long in2) {
+ return Math.max(in1, in2);
+ }
+
+ @Override
+ public double execute(double in1, double in2) {
+ return Math.max(in1, in2);
+ }
+}
diff --git a/src/main/java/org/apache/sysds/runtime/functionobjects/Min.java
b/src/main/java/org/apache/sysds/runtime/functionobjects/Min.java
new file mode 100644
index 0000000000..35cf226605
--- /dev/null
+++ b/src/main/java/org/apache/sysds/runtime/functionobjects/Min.java
@@ -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.
+ */
+
+package org.apache.sysds.runtime.functionobjects;
+
+public class Min extends Builtin {
+ private static Min singleObj = null;
+
+ private Min() {
+ super(BuiltinCode.MIN);
+ // nothing to do here.
+ }
+
+ private static final long serialVersionUID = 6529946102263905602L;
+
+ public static Min getMinFnObject() {
+ if(singleObj == null)
+ singleObj = new Min();
+ return singleObj;
+ }
+
+ @Override
+ public boolean execute(boolean in1, boolean in2) {
+ return !(!in1 || !in2);
+ }
+
+ @Override
+ public double execute(long in1, long in2) {
+ return Math.min(in1, in2);
+ }
+
+ @Override
+ public double execute(double in1, double in2) {
+ return Math.min(in1, in2);
+ }
+}