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>
impl<'rules> Solver<'rules>
sourcepub fn take_rules(self) -> Vec<Box<dyn Rule<'rules> + 'rules>>
pub fn take_rules(self) -> Vec<Box<dyn Rule<'rules> + 'rules>>
Consumes the solver and returns the rules that it uses.
sourcepub 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.
sourcepub fn equals<T, A, B>(&mut self, left: A, right: B) -> InferenceResult
pub fn equals<T, A, B>(&mut self, left: A, right: B) -> InferenceResult
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);
sourcepub fn equals_all<T>(&mut self, items: Vec<Exp<T>>) -> InferenceResult
pub fn equals_all<T>(&mut self, items: Vec<Exp<T>>) -> InferenceResult
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(),
]);
sourcepub fn equals_zero<F>(&mut self, items: Exp<F>) -> InferenceResult
pub fn equals_zero<F>(&mut self, items: Exp<F>) -> InferenceResult
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(),
]);
sourcepub fn with<T, A, F>(&mut self, item: A, closure: F) -> InferenceResult
pub fn with<T, A, F>(&mut self, item: A, closure: F) -> InferenceResult
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))
);
sourcepub fn given<T, A, F>(&mut self, item: A, closure: F) -> InferenceResult
pub fn given<T, A, F>(&mut self, item: A, closure: F) -> InferenceResult
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))
);
sourcepub fn given_all<T, I, A, F>(&mut self, items: I, closure: F) -> InferenceResultwhere
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) -> InferenceResultwhere
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>
impl<'rules> Solver<'rules>
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
source§impl<'rules> Solver<'rules>
impl<'rules> Solver<'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
) -> InferenceResultwhere
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> 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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