Expose more printer options. (#1817)

This commit is contained in:
Laurent Mazare
2024-03-08 15:04:18 +01:00
committed by GitHub
parent 9634583781
commit ea984d0421

View File

@ -65,12 +65,13 @@ impl std::fmt::Debug for Tensor {
} }
/// Options for Tensor pretty printing /// Options for Tensor pretty printing
#[derive(Debug, Clone)]
pub struct PrinterOptions { pub struct PrinterOptions {
precision: usize, pub precision: usize,
threshold: usize, pub threshold: usize,
edge_items: usize, pub edge_items: usize,
line_width: usize, pub line_width: usize,
sci_mode: Option<bool>, pub sci_mode: Option<bool>,
} }
static PRINT_OPTS: std::sync::Mutex<PrinterOptions> = static PRINT_OPTS: std::sync::Mutex<PrinterOptions> =
@ -89,6 +90,10 @@ impl PrinterOptions {
} }
} }
pub fn print_options() -> &'static std::sync::Mutex<PrinterOptions> {
&PRINT_OPTS
}
pub fn set_print_options(options: PrinterOptions) { pub fn set_print_options(options: PrinterOptions) {
*PRINT_OPTS.lock().unwrap() = options *PRINT_OPTS.lock().unwrap() = options
} }
@ -117,6 +122,26 @@ pub fn set_print_options_full() {
} }
} }
pub fn set_line_width(line_width: usize) {
PRINT_OPTS.lock().unwrap().line_width = line_width
}
pub fn set_precision(precision: usize) {
PRINT_OPTS.lock().unwrap().precision = precision
}
pub fn set_edge_items(edge_items: usize) {
PRINT_OPTS.lock().unwrap().edge_items = edge_items
}
pub fn set_threshold(threshold: usize) {
PRINT_OPTS.lock().unwrap().threshold = threshold
}
pub fn set_sci_mode(sci_mode: Option<bool>) {
PRINT_OPTS.lock().unwrap().sci_mode = sci_mode
}
struct FmtSize { struct FmtSize {
current_size: usize, current_size: usize,
} }