liblisa::semantics

Trait Computation

pub trait Computation: Debug + Clone {
    // Required methods
    fn evaluate<V: AsValue>(&self, inputs: &[V]) -> OwnedValue;
    fn display<'a, S: AsRef<str>>(
        &'a self,
        input_names: &'a [S],
    ) -> impl Display + Debug + 'a;
    fn used_input_indices(&self) -> Vec<usize>;
    fn remap_inputs(&mut self, map: &[Option<usize>]);
    fn is_identity(&self) -> bool;

    // Provided method
    fn compare_eq<V: AsValue>(&self, inputs: &[V], expected: Value<'_>) -> bool { ... }
}
Expand description

Implements the semantics of a single dataflow.

Required Methods§

fn evaluate<V: AsValue>(&self, inputs: &[V]) -> OwnedValue

Computes the output of the semantics, given inputs.

fn display<'a, S: AsRef<str>>( &'a self, input_names: &'a [S], ) -> impl Display + Debug + 'a

Returns a struct that is suitable for printing, which uses input_names in place of the inputs.

fn used_input_indices(&self) -> Vec<usize>

The indices of all inputs used in the computation.

fn remap_inputs(&mut self, map: &[Option<usize>])

Remaps the input indices, such that new_index = map[old_index].unwrap_or(old_index).

fn is_identity(&self) -> bool

Returns true when the computation is the identity function. This function may under-approximate: it does not necessarily have to return true in all cases.

For example, this function might return true for f(x) = x, but return false for f(x) = (x + 5) - 5.

Provided Methods§

fn compare_eq<V: AsValue>(&self, inputs: &[V], expected: Value<'_>) -> bool

Returns true if expected matches the output of the computation. This function can be more efficient than manually comparing the result of self.evaluate(..). For example, we can avoid allocating a Vec for OwnedValue::Bytes results.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl Computation for ()

§

fn evaluate<V: AsValue>(&self, _inputs: &[V]) -> OwnedValue

§

fn display<'a, S: AsRef<str>>( &'a self, _input_names: &'a [S], ) -> impl Display + Debug + 'a

§

fn used_input_indices(&self) -> Vec<usize>

§

fn remap_inputs(&mut self, _map: &[Option<usize>])

§

fn is_identity(&self) -> bool

Implementors§