Struct tract_hir::infer::Solver [−][src]
Expand description
A declarative constraint solver for tensors.
Fields
rules: Vec<Box<dyn Rule<'rules> + 'rules>>
Implementations
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>)>
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.
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,
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(),
]);
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,
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))
);
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,
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))
);
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,
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))
);
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,
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
Auto Trait Implementations
impl<'rules> !RefUnwindSafe for Solver<'rules>
impl<'rules> !UnwindSafe for Solver<'rules>
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>ⓘimpl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
impl<W> Write for Box<W, Global> where
W: Write + ?Sized, impl<R> Read for Box<R, Global> where
R: Read + ?Sized, impl<F, A> Future for Box<F, A> where
F: Future + Unpin + ?Sized,
A: Allocator + 'static, type Output = <F as Future>::Output;impl<I, A> Iterator for Box<I, A> where
I: Iterator + ?Sized,
A: Allocator, type Item = <I as Iterator>::Item;
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
. Read more
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more