Skip to main content

PrimitiveRuleBuilder

Trait PrimitiveRuleBuilder 

Source
pub trait PrimitiveRuleBuilder {
    // Required method
    fn add_operation(
        &mut self,
        operation: StdTensorOp,
        inputs: Vec<ValueRef<StdTensorOp>>,
        role: OperationRole,
    ) -> Vec<LocalValueId> ;
}
Expand description

Builder interface used by tenferro AD rules.

§Examples

use computegraph::graph::GraphBuilder;
use computegraph::{OperationRole, ValueRef};
use tenferro_ops::ad::PrimitiveRuleBuilder;
use tenferro_ops::input_key::TensorInputKey;
use tenferro_ops::std_tensor_op::StdTensorOp;

let mut builder = GraphBuilder::<StdTensorOp>::new();
let x = builder.add_input(TensorInputKey::User { id: 1 });
let out = PrimitiveRuleBuilder::add_operation(
    &mut builder,
    StdTensorOp::Neg,
    vec![ValueRef::Local(x)],
    OperationRole::Primary,
);
assert_eq!(out.len(), 1);

Required Methods§

Source

fn add_operation( &mut self, operation: StdTensorOp, inputs: Vec<ValueRef<StdTensorOp>>, role: OperationRole, ) -> Vec<LocalValueId>

Add one primitive graph operation and return local ids for its outputs.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl PrimitiveRuleBuilder for GraphBuilder<StdTensorOp>

Available on crate feature autodiff only.
Source§

fn add_operation( &mut self, operation: StdTensorOp, inputs: Vec<ValueRef<StdTensorOp>>, role: OperationRole, ) -> Vec<LocalValueId>

Implementors§