sebwrede commented on a change in pull request #1395:
URL: https://github.com/apache/systemds/pull/1395#discussion_r723267713



##########
File path: src/main/java/org/apache/sysds/hops/cost/FederatedCostEstimator.java
##########
@@ -196,6 +194,90 @@ private FederatedCost costEstimate(Hop root){
                }
        }
 
+       /**
+        * Return cost estimate in bytes of Hop DAG starting from given root 
HopRel.
+        * @param root HopRel of Hop DAG for which cost is estimated
+        * @param hopRelMemo memo table of HopRels for calculating input costs
+        * @return cost estimation of Hop DAG starting from given root HopRel
+        */
+       public FederatedCost costEstimate(HopRel root, Map<Long, List<HopRel>> 
hopRelMemo){
+               // Check if root is in memo table.
+               if ( hopRelMemo.containsKey(root.hopRef.getHopID())
+                       && 
hopRelMemo.get(root.hopRef.getHopID()).stream().anyMatch(h -> h.fedOut == 
root.fedOut) ){
+                       return root.getCostObject();
+               }
+               else {
+                       // If no input has FOUT, the root will be processed by 
the coordinator
+                       boolean hasFederatedInput = 
root.inputDependency.stream().anyMatch(in -> in.hopRef.hasFederatedOutput());
+                       //the input cost is included the first time the input 
hop is used
+                       //for additional usage, the additional cost is zero 
(disregarding potential read cost)
+                       double inputCosts = root.inputDependency.stream()
+                               .mapToDouble( in -> {
+                                       double inCost = 
in.existingCostPointer(root.hopRef.getHopID()) ?
+                                               0 : costEstimate(in, 
hopRelMemo).getTotal();
+                                       
in.addCostPointer(root.hopRef.getHopID());
+                                       return inCost;
+                               } )
+                               .sum();

Review comment:
       I decided to use streams because it is easy to work with. I could create 
a method instead, but I will wait with that until I am sure that this is the 
way I want to calculate it. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to