1
1
#!/usr/bin/env python3
2
2
3
3
import argparse
4
+ from typing import Tuple
4
5
5
6
import analyze
6
7
from analyze import Block , Logs , utils
@@ -67,6 +68,25 @@ def is_improved(before: Block, after: Block):
67
68
return cost_for_blk (before ) > cost_for_blk (after )
68
69
69
70
71
+ def blk_relative_cost (nogt , gt ) -> Tuple [int , int ]:
72
+ no_sum = yes_sum = 0
73
+ for no , yes in zip (nogt , gt ):
74
+ no_cost = block_stats .block_cost (no )
75
+ yes_cost = block_stats .block_cost (yes )
76
+ no_lb = block_stats .block_cost_lower_bound (no )
77
+ yes_lb = block_stats .block_cost_lower_bound (yes )
78
+ assert no_lb <= yes_lb
79
+
80
+ # relative to the tightest LB we know
81
+ no_rel = no_cost - yes_lb
82
+ yes_rel = yes_cost - yes_lb
83
+
84
+ no_sum += no_rel
85
+ yes_sum += yes_rel
86
+
87
+ return no_sum , yes_sum
88
+
89
+
70
90
def compute_stats (nogt : Logs , gt : Logs , * , pass_num : int ):
71
91
TOTAL_BLOCKS = utils .count (nogt )
72
92
@@ -83,6 +103,8 @@ def compute_stats(nogt: Logs, gt: Logs, *, pass_num: int):
83
103
84
104
nogt_opt , gt_opt = utils .zipped_keep_blocks_if (nogt , gt , pred = lambda b : 'DagSolvedOptimally' in b )
85
105
106
+ nogt_rel , gt_rel = blk_relative_cost (nogt , gt )
107
+
86
108
result = {
87
109
'Total Blocks in Benchsuite' : TOTAL_BLOCKS ,
88
110
'Num Blocks enumerated with & without GT' : utils .count (nogt ),
@@ -101,8 +123,8 @@ def compute_stats(nogt: Logs, gt: Logs, *, pass_num: int):
101
123
'Enum Time (opt. blocks only) (No GT)' : utils .sum_stat_for_all (enum_time_for_blk , nogt_opt ),
102
124
'Enum Time (opt. blocks only) (GT)' : utils .sum_stat_for_all (enum_time_for_blk , gt_opt ),
103
125
104
- 'Block Cost - Relative (No GT)' : utils . sum_stat_for_all ( block_stats . block_relative_cost , nogt ) ,
105
- 'Block Cost - Relative (GT)' : utils . sum_stat_for_all ( block_stats . block_relative_cost , gt ) ,
126
+ 'Block Cost - Relative (No GT)' : nogt_rel ,
127
+ 'Block Cost - Relative (GT)' : gt_rel ,
106
128
'Block Cost (No GT)' : utils .sum_stat_for_all (block_stats .block_cost , nogt ),
107
129
'Block Cost (GT)' : utils .sum_stat_for_all (block_stats .block_cost , gt ),
108
130
0 commit comments