Function

Trait Function 

Source
pub trait Function:
    Send
    + Sync
    + Clone {
    type Trace: Clone + Eq + Send + Sync + Trace;
    type Storage: Default + Send;
    type Workspace: Default + Send;
    type TapeStorage: Default + Send;
    type PointEval: TracingEvaluator<Data = f32, Trace = Self::Trace, TapeStorage = Self::TapeStorage> + Send + Sync;
    type IntervalEval: TracingEvaluator<Data = Interval, Trace = Self::Trace, TapeStorage = Self::TapeStorage> + Send + Sync;
    type FloatSliceEval: BulkEvaluator<Data = f32, TapeStorage = Self::TapeStorage> + Send + Sync;
    type GradSliceEval: BulkEvaluator<Data = Grad, TapeStorage = Self::TapeStorage> + Send + Sync;

Show 13 methods // Required methods fn point_tape( &self, storage: Self::TapeStorage, ) -> <Self::PointEval as TracingEvaluator>::Tape; fn interval_tape( &self, storage: Self::TapeStorage, ) -> <Self::IntervalEval as TracingEvaluator>::Tape; fn float_slice_tape( &self, storage: Self::TapeStorage, ) -> <Self::FloatSliceEval as BulkEvaluator>::Tape; fn grad_slice_tape( &self, storage: Self::TapeStorage, ) -> <Self::GradSliceEval as BulkEvaluator>::Tape; fn simplify( &self, trace: &Self::Trace, storage: Self::Storage, workspace: &mut Self::Workspace, ) -> Result<Self, Error> where Self: Sized; fn recycle(self) -> Option<Self::Storage>; fn size(&self) -> usize; fn vars(&self) -> &VarMap; fn can_simplify(&self) -> bool; // Provided methods fn new_point_eval() -> Self::PointEval { ... } fn new_interval_eval() -> Self::IntervalEval { ... } fn new_float_slice_eval() -> Self::FloatSliceEval { ... } fn new_grad_slice_eval() -> Self::GradSliceEval { ... }
}
Expand description

A function represents something that can be evaluated

It is mostly agnostic to how that something is represented; we simply require that it can generate evaluators of various kinds.

Inputs to the function should be represented as Var values; the vars() function returns the mapping from Var to position in the input slice.

Functions are shared between threads, so they should be cheap to clone. In most cases, they’re a thin wrapper around an Arc<..>.

Required Associated Types§

Source

type Trace: Clone + Eq + Send + Sync + Trace

Associated type traces collected during tracing evaluation

This type must implement Eq so that traces can be compared; calling Function::simplify with traces that compare equal should produce an identical result and may be cached.

Source

type Storage: Default + Send

Associated type for storage used by the function itself

Source

type Workspace: Default + Send

Associated type for workspace used during function simplification

Source

type TapeStorage: Default + Send

Associated type for storage used by tapes

For simplicity, we require that every tape use the same type for storage. This could change in the future!

Source

type PointEval: TracingEvaluator<Data = f32, Trace = Self::Trace, TapeStorage = Self::TapeStorage> + Send + Sync

Associated type for single-point tracing evaluation

Source

type IntervalEval: TracingEvaluator<Data = Interval, Trace = Self::Trace, TapeStorage = Self::TapeStorage> + Send + Sync

Associated type for single interval tracing evaluation

Source

type FloatSliceEval: BulkEvaluator<Data = f32, TapeStorage = Self::TapeStorage> + Send + Sync

Associated type for evaluating many points in one call

Source

type GradSliceEval: BulkEvaluator<Data = Grad, TapeStorage = Self::TapeStorage> + Send + Sync

Associated type for evaluating many gradients in one call

Required Methods§

Source

fn point_tape( &self, storage: Self::TapeStorage, ) -> <Self::PointEval as TracingEvaluator>::Tape

Returns an evaluation tape for a point evaluator

Source

fn interval_tape( &self, storage: Self::TapeStorage, ) -> <Self::IntervalEval as TracingEvaluator>::Tape

Returns an evaluation tape for an interval evaluator

Source

fn float_slice_tape( &self, storage: Self::TapeStorage, ) -> <Self::FloatSliceEval as BulkEvaluator>::Tape

Returns an evaluation tape for a float slice evaluator

Source

fn grad_slice_tape( &self, storage: Self::TapeStorage, ) -> <Self::GradSliceEval as BulkEvaluator>::Tape

Returns an evaluation tape for a float slice evaluator

Source

fn simplify( &self, trace: &Self::Trace, storage: Self::Storage, workspace: &mut Self::Workspace, ) -> Result<Self, Error>
where Self: Sized,

Computes a simplified tape using the given trace, and reusing storage

Source

fn recycle(self) -> Option<Self::Storage>

Attempt to reclaim storage from this function

This may fail, because functions are Clone and are often implemented using an Arc around a heavier data structure.

Source

fn size(&self) -> usize

Returns a size associated with this function

This is underspecified and only used for unit testing; for tape-based functions, it’s typically the length of the tape,

Source

fn vars(&self) -> &VarMap

Returns the map from Var to input index

Source

fn can_simplify(&self) -> bool

Checks to see whether this function can ever be simplified

Provided Methods§

Source

fn new_point_eval() -> Self::PointEval

Builds a new point evaluator

Source

fn new_interval_eval() -> Self::IntervalEval

Builds a new interval evaluator

Source

fn new_float_slice_eval() -> Self::FloatSliceEval

Builds a new float slice evaluator

Source

fn new_grad_slice_eval() -> Self::GradSliceEval

Builds a new gradient slice evaluator

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§