pub struct RecordedGraph<Op: GraphOperation> { /* private fields */ }Expand description
Graph invocation recorded as one eager reverse-mode trace node.
§Examples
use tidu::eager::RecordedGraph;
use computegraph::GraphOperation;
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
enum Op { Add }
impl GraphOperation for Op {
type Operand = f64;
type Context = ();
type InputKey = &'static str;
fn input_count(&self) -> usize { 2 }
fn output_count(&self) -> usize { 1 }
}
let recorded = RecordedGraph::from_primitive(Op::Add, vec!["x", "y"]);
assert_eq!(recorded.input_keys(), &["x", "y"]);
assert_eq!(recorded.output_keys().len(), 1);Implementations§
Source§impl<Op: GraphOperation> RecordedGraph<Op>
impl<Op: GraphOperation> RecordedGraph<Op>
Sourcepub fn new(
graph: Arc<Graph<Op>>,
input_keys: Vec<Op::InputKey>,
output_keys: Vec<ValueKey<Op>>,
) -> Self
pub fn new( graph: Arc<Graph<Op>>, input_keys: Vec<Op::InputKey>, output_keys: Vec<ValueKey<Op>>, ) -> Self
Create a recorded graph from an already-built graph and aligned keys.
§Examples
use std::sync::Arc;
use computegraph::graph::GraphBuilder;
use computegraph::{GraphOperation, OperationRole, ValueRef};
use tidu::eager::RecordedGraph;
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
enum Op { Id }
impl GraphOperation for Op {
type Operand = f64;
type Context = ();
type InputKey = &'static str;
fn input_count(&self) -> usize { 1 }
fn output_count(&self) -> usize { 1 }
}
let mut builder = GraphBuilder::new();
let x = builder.add_input("x");
let y = builder.add_operation(Op::Id, vec![ValueRef::Local(x)], OperationRole::Primary);
builder.set_outputs(y.clone());
let graph = Arc::new(builder.build());
let output_keys = y.iter().map(|id| graph.values()[*id].key.clone()).collect();
let recorded = RecordedGraph::new(graph, vec!["x"], output_keys);
assert_eq!(recorded.input_keys(), &["x"]);Sourcepub fn from_primitive(op: Op, input_keys: Vec<Op::InputKey>) -> Self
pub fn from_primitive(op: Op, input_keys: Vec<Op::InputKey>) -> Self
Build a one-op recorded graph for an eager primitive invocation.
§Examples
use tidu::eager::RecordedGraph;
use computegraph::GraphOperation;
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
enum Op { Add }
impl GraphOperation for Op {
type Operand = f64;
type Context = ();
type InputKey = &'static str;
fn input_count(&self) -> usize { 2 }
fn output_count(&self) -> usize { 1 }
}
let recorded = RecordedGraph::from_primitive(Op::Add, vec!["x", "y"]);
assert_eq!(recorded.as_graph().operations().len(), 1);Sourcepub fn input_keys(&self) -> &[Op::InputKey]
pub fn input_keys(&self) -> &[Op::InputKey]
Graph input keys aligned with eager input edges.
Sourcepub fn output_keys(&self) -> &[ValueKey<Op>]
pub fn output_keys(&self) -> &[ValueKey<Op>]
Graph output keys aligned with eager output slots.
Auto Trait Implementations§
impl<Op> Freeze for RecordedGraph<Op>
impl<Op> RefUnwindSafe for RecordedGraph<Op>where
<Op as GraphOperation>::InputKey: RefUnwindSafe,
Op: RefUnwindSafe,
impl<Op> Send for RecordedGraph<Op>
impl<Op> Sync for RecordedGraph<Op>
impl<Op> Unpin for RecordedGraph<Op>where
<Op as GraphOperation>::InputKey: Unpin,
impl<Op> UnsafeUnpin for RecordedGraph<Op>
impl<Op> UnwindSafe for RecordedGraph<Op>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more