Struct tract_hir::infer::rules::Solver

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

A declarative constraint solver for tensors.

Fields§

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

Implementations§

source§

impl<'rules> Solver<'rules>

source

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

Consumes the solver and returns the rules that it uses.

source

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

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.
source

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

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);
source

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

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(),
]);
source

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,

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(),
]);
source

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,

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))
);
source

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,

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))
);
source

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,

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))
);
source§

impl<'rules> Solver<'rules>

source

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,

source§

impl<'rules> Solver<'rules>

source

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,

source§

impl<'rules> Solver<'rules>

source

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,

Trait Implementations§

source§

impl<'rules> Default for Solver<'rules>

source§

fn default() -> Solver<'rules>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'rules> Freeze for Solver<'rules>

§

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§

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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.