|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.sysds.runtime.einsum; |
| 21 | + |
| 22 | +import org.apache.commons.logging.Log; |
| 23 | +import org.apache.sysds.runtime.matrix.data.MatrixBlock; |
| 24 | +import scala.Int; |
| 25 | + |
| 26 | +import java.util.ArrayList; |
| 27 | +import java.util.Arrays; |
| 28 | +import java.util.List; |
| 29 | + |
| 30 | +public abstract class EOpNode { |
| 31 | + public Character c1; |
| 32 | + public Character c2; |
| 33 | + public Integer dim1; |
| 34 | + public Integer dim2; |
| 35 | + public EOpNode(Character c1, Character c2, Integer dim1, Integer dim2) { |
| 36 | + this.c1 = c1; |
| 37 | + this.c2 = c2; |
| 38 | + this.dim1 = dim1; |
| 39 | + this.dim2 = dim2; |
| 40 | + } |
| 41 | + |
| 42 | + public String getOutputString() { |
| 43 | + if(c1 == null) return "''"; |
| 44 | + if(c2 == null) return c1.toString(); |
| 45 | + return c1.toString() + c2.toString(); |
| 46 | + } |
| 47 | + public abstract List<EOpNode> getChildren(); |
| 48 | + |
| 49 | + public String[] recursivePrintString(){ |
| 50 | + ArrayList<String[]> inpStrings = new ArrayList<>(); |
| 51 | + for (EOpNode node : getChildren()) { |
| 52 | + inpStrings.add(node.recursivePrintString()); |
| 53 | + } |
| 54 | + String[] inpRes = inpStrings.stream().flatMap(Arrays::stream).toArray(String[]::new); |
| 55 | + String[] res = new String[1 + inpRes.length]; |
| 56 | + |
| 57 | + res[0] = this.toString(); |
| 58 | + |
| 59 | + for (int i=0; i<inpRes.length; i++) { |
| 60 | + res[i+1] = (i==0 ? "┌ " : (i==inpRes.length-1 ? "└ " : "| "))+inpRes[i]; |
| 61 | + } |
| 62 | + return res; |
| 63 | + }; |
| 64 | + |
| 65 | + public abstract MatrixBlock computeEOpNode(ArrayList<MatrixBlock> inputs, int numOfThreads, Log LOG); |
| 66 | + |
| 67 | + public abstract EOpNode reorderChildrenAndOptimize(EOpNode parent, Character outChar1, Character outChar2); |
| 68 | +} |
| 69 | + |
0 commit comments