@@ -43,7 +43,22 @@ class PlotRequest:
4343 log_y : bool
4444
4545
46- Row = tuple [int , float , float , float , float , float , float , float , float , float ]
46+ @dataclass (frozen = True , slots = True )
47+ class Row :
48+ dim : int
49+ la_time : float
50+ la_lo : float
51+ la_hi : float
52+ na_time : float
53+ na_lo : float
54+ na_hi : float
55+ fa_time : float
56+ fa_lo : float
57+ fa_hi : float
58+
59+
60+ class ReadmeMarkerError (ValueError ):
61+ """Raised when README markers are missing, duplicated, or out of order."""
4762
4863
4964METRICS : Final [dict [str , Metric ]] = {
@@ -143,8 +158,8 @@ def _write_csv(out_csv: Path, rows: list[Row]) -> None:
143158 out_csv .parent .mkdir (parents = True , exist_ok = True )
144159 with out_csv .open ("w" , encoding = "utf-8" ) as f :
145160 f .write ("D,la_stack,la_lo,la_hi,nalgebra,na_lo,na_hi,faer,fa_lo,fa_hi\n " )
146- for d , la , la_lo , la_hi , na , na_lo , na_hi , fa , fa_lo , fa_hi in rows :
147- f .write (f"{ d } ,{ la } ,{ la_lo } ,{ la_hi } ,{ na } ,{ na_lo } ,{ na_hi } ,{ fa } ,{ fa_lo } ,{ fa_hi } \n " )
161+ for row in rows :
162+ f .write (f"{ row . dim } ,{ row . la_time } ,{ row . la_lo } ,{ row . la_hi } ,{ row . na_time } ,{ row . na_lo } ,{ row . na_hi } ,{ row . fa_time } ,{ row . fa_lo } ,{ row . fa_hi } \n " )
148163
149164
150165def _pct_reduction (baseline : float , value : float ) -> str :
@@ -161,10 +176,10 @@ def _markdown_table(rows: list[Row], stat: str) -> str:
161176 "|---:|--------------------:|--------------------:|----------------:|---------------------:|----------------:|" ,
162177 ]
163178
164- for d , la , _la_lo , _la_hi , na , _na_lo , _na_hi , fa , _fa_lo , _fa_hi in rows :
165- pct_vs_na = _pct_reduction (na , la )
166- pct_vs_fa = _pct_reduction (fa , la )
167- lines .append (f"| { d } | { la :,.3f} | { na :,.3f} | { fa :,.3f} | { pct_vs_na } | { pct_vs_fa } |" )
179+ for row in rows :
180+ pct_vs_na = _pct_reduction (row . na_time , row . la_time )
181+ pct_vs_fa = _pct_reduction (row . fa_time , row . la_time )
182+ lines .append (f"| { row . dim } | { row . la_time :,.3f} | { row . na_time :,.3f} | { row . fa_time :,.3f} | { pct_vs_na } | { pct_vs_fa } |" )
168183
169184 return "\n " .join (lines )
170185
@@ -181,13 +196,13 @@ def _update_readme_table(readme_path: Path, marker_begin: str, marker_end: str,
181196 end_indices = [i for i , line in enumerate (lines ) if line .strip () == marker_end ]
182197
183198 if len (begin_indices ) != 1 or len (end_indices ) != 1 :
184- raise ValueError (f"README markers not found or not unique. Expected exactly one of each:\n { marker_begin } \n { marker_end } \n " )
199+ raise ReadmeMarkerError (f"README markers not found or not unique. Expected exactly one of each:\n { marker_begin } \n { marker_end } \n " )
185200
186201 begin_idx = begin_indices [0 ]
187202 end_idx = end_indices [0 ]
188203 if begin_idx >= end_idx :
189204 msg = "README markers are out of order."
190- raise ValueError (msg )
205+ raise ReadmeMarkerError (msg )
191206
192207 table_lines = [line + "\n " for line in table_md .strip ("\n " ).splitlines ()]
193208 new_lines = [
@@ -347,7 +362,20 @@ def _collect_rows(criterion_dir: Path, dims: list[int], metric: Metric, stat: st
347362 la , la_lo , la_hi = _read_estimate (la_est , stat )
348363 na , na_lo , na_hi = _read_estimate (na_est , stat )
349364 fa , fa_lo , fa_hi = _read_estimate (fa_est , stat )
350- rows .append ((d , la , la_lo , la_hi , na , na_lo , na_hi , fa , fa_lo , fa_hi ))
365+ rows .append (
366+ Row (
367+ dim = d ,
368+ la_time = la ,
369+ la_lo = la_lo ,
370+ la_hi = la_hi ,
371+ na_time = na ,
372+ na_lo = na_lo ,
373+ na_hi = na_hi ,
374+ fa_time = fa ,
375+ fa_lo = fa_lo ,
376+ fa_hi = fa_hi ,
377+ )
378+ )
351379
352380 return (rows , skipped )
353381
@@ -431,7 +459,7 @@ def main(argv: list[str] | None = None) -> int:
431459 if rc != 0 :
432460 return rc
433461
434- dims_present = [d for ( d , * _rest ) in rows ]
462+ dims_present = [row . dim for row in rows ]
435463
436464 title = f"{ metric .title } : { args .stat } time vs dimension"
437465 req = PlotRequest (
0 commit comments