tract_libcli/
display_params.rs1use crate::model::Model;
2use tract_core::prelude::*;
3
4#[derive(Debug, Clone, PartialEq, Eq, Default)]
5pub enum Io {
6 None,
7 #[default]
8 Short,
9 Long,
10}
11
12#[derive(Debug, Clone, Default, PartialEq, Eq)]
13pub struct DisplayParams {
14 pub konst: bool,
15 pub invariants: bool,
16 pub quiet: bool,
17 pub natural_order: bool,
18 pub opt_ram_order: bool,
19 pub debug_op: bool,
20 pub cost: bool,
21 pub tmp_mem_usage: bool,
22 pub profile: bool,
23 pub folded: bool,
24 pub node_ids: Option<Vec<TVec<(usize, String)>>>,
25 pub op_name: Option<String>,
26 pub node_name: Option<String>,
27 pub expect_core: bool,
28 pub outlet_labels: bool,
29 pub io: Io,
30 pub json: bool,
31 pub info: bool,
32 pub left_column_width: usize,
33 pub mm: bool,
34 pub summary: bool,
35 pub audit_json: bool,
36}
37
38impl DisplayParams {
39 pub fn filter(
40 &self,
41 model: &dyn Model,
42 scope: &[(usize, String)],
43 node_id: usize,
44 ) -> TractResult<bool> {
45 if let Some(nodes) = self.node_ids.as_ref() {
46 return Ok(nodes.iter().any(|n| {
47 n.len() == scope.len() + 1
48 && &n[0..scope.len()] == scope
49 && n.last().unwrap().0 == node_id
50 }));
51 }
52 if let Some(node_name) = self.node_name.as_ref() {
53 return Ok(model.node_name(node_id).starts_with(node_name));
54 }
55 if let Some(op_name) = self.op_name.as_ref() {
56 return Ok(model.node_op_name(node_id).starts_with(op_name));
57 }
58 Ok(!model.node_const(node_id) || self.konst)
64 }
65
66 pub fn should_draw(&self) -> bool {
67 !self.natural_order
68 }
69
70 pub fn order(&self, model: &dyn Model) -> TractResult<Vec<usize>> {
71 if self.natural_order {
72 Ok((0..model.nodes_len()).collect())
73 } else if self.opt_ram_order {
74 model.eval_order_opt_ram()
75 } else {
76 model.eval_order()
77 }
78 }
79}