Skip to main content

Func

Struct Func 

Source
pub struct Func { /* private fields */ }
Expand description

A function of named inputs and parameters, traced into a graph. Unit of composition for the grad/vmap/ jvp/hvp transforms.

Inputs vs parameters. Declare per-call data with GraphScope::input and trainable weights with GraphScope::param. Bind weight values once with with_param; they are applied on every run and survive transforms — so f.grad(&["w"]) gives gradients w.r.t. the weights (training), runnable with just the inputs.

Implementations§

Source§

impl Func

Source

pub fn new( name: impl Into<String>, build: impl FnOnce(&mut GraphScope) -> Tensor, ) -> Self

Trace a single-output function. The closure builds the body from inputs declared via GraphScope::input; the returned tensor is the output.

Source

pub fn multi( name: impl Into<String>, build: impl FnOnce(&mut GraphScope) -> Vec<Tensor>, ) -> Self

Trace a multi-output function (the closure returns all outputs in order).

Source

pub fn from_graph(graph: Graph) -> Self

Wrap an already-built graph (its outputs are this function’s outputs).

Source

pub fn with_param( self, name: impl Into<String>, data: impl Into<Vec<f32>>, ) -> Self

Bind a parameter (weight) value by name. Overwrites any prior binding for that name. Builder-style: chain several, then run/grad/jit.

Source

pub fn graph(&self) -> &Graph

The underlying graph.

Source

pub fn output_count(&self) -> usize

Number of outputs this function produces.

Source

pub fn param_binding(&self, name: &str) -> Option<&[f32]>

The currently bound value of a parameter, if any. After train_step this is the updated weight.

Trait Implementations§

Source§

impl Clone for Func

Source§

fn clone(&self) -> Func

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Func

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Func

§

impl RefUnwindSafe for Func

§

impl Send for Func

§

impl Sync for Func

§

impl Unpin for Func

§

impl UnsafeUnpin for Func

§

impl UnwindSafe for Func

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.