[][src]Struct tract_hir::infer::rules::Solver

pub struct Solver<'rules> {
    pub rules: Vec<Box<dyn Rule<'rules> + 'rules>>,
}

A declarative constraint solver for tensors.

Fields

rules: Vec<Box<dyn Rule<'rules> + 'rules>>

Methods

impl<'rules> Solver<'rules>[src]

pub fn take_rules(self) -> Vec<Box<dyn Rule<'rules> + 'rules>>[src]

Consumes the solver and returns the rules that it uses.

pub fn infer_facts(
    self,
    facts: (TVec<&InferenceFact>, TVec<&InferenceFact>)
) -> TractResult<(TVec<InferenceFact>, TVec<InferenceFact>)>
[src]

Runs the solver on a set of InferenceFacts.

This method returns:

  • Err(_) if a constraint couldn't be satisfied.
  • Ok(None) if no more information about tensors could be deduced.
  • Ok(Some(facts)) otherwise, with facts the new InferenceFacts.

pub fn equals<T, A, B>(&mut self, left: A, right: B) -> InferenceResult where
    T: Output + Factoid + 'static,
    A: IntoExp<T>,
    B: IntoExp<T>, 
[src]

Ensures that two expressions are equal.

For instance, one could write:

solver.equals(outputs[0].rank, inputs[1].shape[0]);
solver.equals(outputs[1].rank, 3);

pub fn equals_all<T>(&mut self, items: Vec<Exp<T>>) -> InferenceResult where
    T: Output + Factoid + 'static, 
[src]

Ensures that several expressions are equal.

For instance, one could write:

solver.equals_all(vec![
    outputs[0].rank.into(),
    inputs[1].shape[0].into(),
    3.into(),
]);

pub fn equals_zero<F>(&mut self, items: Exp<F>) -> InferenceResult where
    F: Factoid + Zero + Add<F, Output = F> + Neg<Output = F> + Clone + Debug + Output + 'rules, 
[src]

Ensures that the sum of several expressions equals zero.

For instance, one could write:

solver.equals_zero(vec![
    outputs[0].rank.into(),
    outputs[1].rank.into(),
    (-1, inputs[1].shape[0]).into(),
]);

pub fn with<T, A, F>(&mut self, item: A, closure: F) -> InferenceResult where
    T: Factoid + Output + 'static,
    A: IntoExp<T>,
    F: Fn(&mut Solver<'rules>, T) -> InferenceResult + 'rules, 
[src]

Adds rules to the solver with a partial value.

For instance, one could write:

solver.given(input.rank, |solver, ir|
    (0..ir).map(|i| solver.equals(input.shape[ir], 0))
);

pub fn given<T, A, F>(&mut self, item: A, closure: F) -> InferenceResult where
    T: Factoid + Output + 'static,
    A: IntoExp<T>,
    F: Fn(&mut Solver<'rules>, T::Concrete) -> InferenceResult + 'rules, 
[src]

Adds rules to the solver once the value of an expression is known.

For instance, one could write:

solver.given(input.rank, |solver, ir|
    (0..ir).map(|i| solver.equals(input.shape[ir], 0))
);

pub fn given_all<T, I, A, F>(&mut self, items: I, closure: F) -> InferenceResult where
    T: Factoid + Output + 'static,
    A: IntoExp<T>,
    I: IntoIterator<Item = A>,
    F: Fn(&mut Solver<'rules>, Vec<T::Concrete>) -> InferenceResult + 'rules, 
[src]

Adds rules to the solver once the value of all expressions are known.

For instance, one could write:

solver.given(input.rank, |solver, ir|
    (0..ir).map(|i| solver.equals(input.shape[ir], 0))
);

impl<'rules> Solver<'rules>[src]

pub fn given_2<T1, T2, A1, A2, F>(
    &mut self,
    item_1: A1,
    item_2: A2,
    closure: F
) -> InferenceResult where
    A1: IntoExp<T1>,
    T1: Factoid + Output + 'static,
    A2: IntoExp<T2>,
    T2: Factoid + Output + 'static,
    F: Fn(&mut Solver<'rules>, T1::Concrete, T2::Concrete) -> InferenceResult + 'rules, 
[src]

impl<'rules> Solver<'rules>[src]

pub fn given_3<T1, T2, T3, A1, A2, A3, F>(
    &mut self,
    item_1: A1,
    item_2: A2,
    item_3: A3,
    closure: F
) -> InferenceResult where
    A1: IntoExp<T1>,
    T1: Factoid + Output + 'static,
    A2: IntoExp<T2>,
    T2: Factoid + Output + 'static,
    A3: IntoExp<T3>,
    T3: Factoid + Output + 'static,
    F: Fn(&mut Solver<'rules>, T1::Concrete, T2::Concrete, T3::Concrete) -> InferenceResult + 'rules, 
[src]

impl<'rules> Solver<'rules>[src]

pub fn given_4<T1, T2, T3, T4, A1, A2, A3, A4, F>(
    &mut self,
    item_1: A1,
    item_2: A2,
    item_3: A3,
    item_4: A4,
    closure: F
) -> InferenceResult where
    A1: IntoExp<T1>,
    T1: Factoid + Output + 'static,
    A2: IntoExp<T2>,
    T2: Factoid + Output + 'static,
    A3: IntoExp<T3>,
    T3: Factoid + Output + 'static,
    A4: IntoExp<T4>,
    T4: Factoid + Output + 'static,
    F: Fn(&mut Solver<'rules>, T1::Concrete, T2::Concrete, T3::Concrete, T4::Concrete) -> InferenceResult + 'rules, 
[src]

Trait Implementations

impl<'rules> Default for Solver<'rules>[src]

Auto Trait Implementations

impl<'rules> !RefUnwindSafe for Solver<'rules>

impl<'rules> !Send for Solver<'rules>

impl<'rules> !Sync for Solver<'rules>

impl<'rules> Unpin for Solver<'rules>

impl<'rules> !UnwindSafe for Solver<'rules>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Downcast for T where
    T: Any

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.