@@ -293,6 +293,36 @@ impl QuantConfig {
293293 }
294294}
295295
296+ impl std:: fmt:: Display for QuantConfig {
297+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
298+ match self {
299+ Self :: Spherical {
300+ seed,
301+ transform_kind,
302+ num_bits,
303+ pre_scale,
304+ quant_store_config,
305+ } => {
306+ write_field ! ( f, "quantization" , "spherical" ) ?;
307+ write_field ! ( f, "num_bits" , num_bits) ?;
308+ write_field ! ( f, "seed" , seed) ?;
309+ write_field ! ( f, "transform_kind" , transform_kind) ?;
310+ if let Some ( pre_scale) = pre_scale {
311+ write_field ! ( f, "pre_scale" , pre_scale) ?;
312+ }
313+ if let Some ( cfg) = quant_store_config {
314+ writeln ! ( f, "\n Quant Store:" ) ?;
315+ write ! ( f, "{}" , cfg) ?;
316+ }
317+ }
318+ Self :: None => {
319+ write_field ! ( f, "quantization" , "none" ) ?;
320+ }
321+ }
322+ Ok ( ( ) )
323+ }
324+ }
325+
296326#[ derive( Debug , Serialize , Deserialize ) ]
297327pub ( crate ) struct BfTreeBuild {
298328 build : IndexBuild ,
@@ -388,20 +418,7 @@ impl std::fmt::Display for BfTreeBuild {
388418 }
389419 write_field ! ( f, "tag" , Self :: tag( ) ) ?;
390420
391- if let QuantConfig :: Spherical {
392- seed,
393- transform_kind,
394- num_bits,
395- ..
396- } = & self . quantization
397- {
398- write_field ! ( f, "quantization" , "spherical" ) ?;
399- write_field ! ( f, "num_bits" , num_bits) ?;
400- write_field ! ( f, "seed" , seed) ?;
401- write_field ! ( f, "transform_kind" , transform_kind) ?;
402- } else {
403- write_field ! ( f, "quantization" , "none" ) ?;
404- }
421+ write ! ( f, "{}" , self . quantization) ?;
405422
406423 writeln ! ( f) ?;
407424 self . build . summarize_fields ( f) ?;
@@ -414,14 +431,6 @@ impl std::fmt::Display for BfTreeBuild {
414431 writeln ! ( f, "\n Neighbor Store:" ) ?;
415432 write ! ( f, "{}" , cfg) ?;
416433 }
417- if let QuantConfig :: Spherical {
418- quant_store_config : Some ( ref cfg) ,
419- ..
420- } = self . quantization
421- {
422- writeln ! ( f, "\n Quant Store:" ) ?;
423- write ! ( f, "{}" , cfg) ?;
424- }
425434
426435 Ok ( ( ) )
427436 }
@@ -530,20 +539,7 @@ impl std::fmt::Display for BfTreeStreamingRun {
530539 }
531540 write_field ! ( f, "tag" , Self :: tag( ) ) ?;
532541
533- if let QuantConfig :: Spherical {
534- seed,
535- transform_kind,
536- num_bits,
537- ..
538- } = & self . quantization
539- {
540- write_field ! ( f, "quantization" , "spherical" ) ?;
541- write_field ! ( f, "num_bits" , num_bits) ?;
542- write_field ! ( f, "seed" , seed) ?;
543- write_field ! ( f, "transform_kind" , transform_kind) ?;
544- } else {
545- write_field ! ( f, "quantization" , "none" ) ?;
546- }
542+ write ! ( f, "{}" , self . quantization) ?;
547543
548544 writeln ! ( f) ?;
549545 self . build . summarize_fields ( f) ?;
@@ -556,14 +552,6 @@ impl std::fmt::Display for BfTreeStreamingRun {
556552 writeln ! ( f, "\n Neighbor Store:" ) ?;
557553 write ! ( f, "{}" , cfg) ?;
558554 }
559- if let QuantConfig :: Spherical {
560- quant_store_config : Some ( ref cfg) ,
561- ..
562- } = self . quantization
563- {
564- writeln ! ( f, "\n Quant Store:" ) ?;
565- write ! ( f, "{}" , cfg) ?;
566- }
567555
568556 Ok ( ( ) )
569557 }
0 commit comments