fn build_graph()

in crates/ratchet-core/src/plot.rs [113:147]


    fn build_graph(leaf: &Tensor) -> anyhow::Result<RenderableGraph> {
        log::warn!("Rendering plot");
        let mut g = RenderableGraph::new();

        let mut graph_index_map = HashMap::new();
        let leaf_cl = leaf.clone();
        let execution_order = leaf_cl.execution_order();
        for t in execution_order.iter() {
            let renderable_node = g.create_node(t.id(), Cow::Owned(t.op().name().to_string()));
            let can_inplace = t.op().supports_inplace() && Arc::strong_count(&t.inner) == 1;
            match t.op() {
                crate::LazyOp::Const => renderable_node.style_as_const(),
                _ => renderable_node.style_as_op(),
            }
            if can_inplace {
                renderable_node.style_as_inplace()
            }

            let node_graph_id = renderable_node.plot_id;
            graph_index_map.insert(t.id(), renderable_node.plot_id);
            t.op().srcs().iter().for_each(|src_t| {
                if let Some(src_id) = graph_index_map.get(&src_t.id()) {
                    let e = g.create_edge(Cow::Owned(src_t.plot_fmt()), *src_id, node_graph_id);
                } else {
                    panic!("Source tensor not found in graph index map");
                }
            });
        }

        let label = leaf.op().name().to_string();
        g.create_node(leaf.id(), Cow::Owned(label))
            .style_as_output();

        Ok(g)
    }