Skip to main content

RecordedGraph

Struct RecordedGraph 

Source
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>

Source

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"]);
Source

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);
Source

pub fn as_graph(&self) -> &Graph<Op>

Borrow the recorded graph.

Source

pub fn input_keys(&self) -> &[Op::InputKey]

Graph input keys aligned with eager input edges.

Source

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>
where <Op as GraphOperation>::InputKey: UnwindSafe + RefUnwindSafe, Op: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.