pub struct Machine<D: Discretization> { /* private fields */ }Expand description
Interval evaluation machine with persistent state and discretization.
A machine is compiled from a list of real-number expressions via
MachineBuilder::build, and can then be evaluated at specific input
points using Machine::apply. Returns an opaque machine that can
be passed to Machine::apply to evaluate the compiled real expression
on a specific point.
Internally, a machine converts expressions into a simple register machine. Compilation is fairly slow, so the ideal use case is to compile a function once and then apply it to multiple points.
If more than one expression is provided, common subexpressions will be identified and eliminated during compilation. This makes Rival ideal for evaluating large families of related expressions, a feature that is heavily used in Herbie. Note that each expression can use a different discretization.
Implementations§
Source§impl<D: Discretization> Machine<D>
impl<D: Discretization> Machine<D>
Sourcepub fn instruction_count(&self) -> usize
pub fn instruction_count(&self) -> usize
Return the total number of instructions in the compiled machine.
Sourcepub fn argument_count(&self) -> usize
pub fn argument_count(&self) -> usize
Return the number of input arguments expected by this machine.
Sourcepub fn target_precision(&self) -> u32
pub fn target_precision(&self) -> u32
Return the discretization’s target precision in bits.
Sourcepub fn min_precision(&self) -> u32
pub fn min_precision(&self) -> u32
Return the minimum working precision in bits.
Sourcepub fn max_precision(&self) -> u32
pub fn max_precision(&self) -> u32
Return the maximum working precision in bits.
Sourcepub fn argument_precision(&self) -> u32
pub fn argument_precision(&self) -> u32
Return the precision used for input arguments.
Sourcepub fn set_max_precision(&mut self, bits: u32)
pub fn set_max_precision(&mut self, bits: u32)
Set the maximum working precision in bits.
Sourcepub fn iterations(&self) -> usize
pub fn iterations(&self) -> usize
Return the number of iterations needed for the most recent call to Machine::apply.
Sourcepub fn bumps(&self) -> usize
pub fn bumps(&self) -> usize
Return the number of bumps detected during the most recent call to Machine::apply.
Sourcepub fn set_profiling_enabled(&mut self, enabled: bool)
pub fn set_profiling_enabled(&mut self, enabled: bool)
Enable or disable per-instruction profiling.
Sourcepub fn profiling_enabled(&self) -> bool
pub fn profiling_enabled(&self) -> bool
Returns whether per-instruction profiling is enabled.
Sourcepub fn execution_records(&self) -> &[Execution]
pub fn execution_records(&self) -> &[Execution]
Return a slice of recorded Execution records from the profiling buffer.
Sourcepub fn clear_executions(&mut self)
pub fn clear_executions(&mut self)
Reset the profiling buffer, discarding all recorded executions.
Sourcepub fn instruction_names(&self) -> Vec<&'static str>
pub fn instruction_names(&self) -> Vec<&'static str>
Return the operation name for each instruction in the machine.
Sourcepub fn configure_baseline(&mut self)
pub fn configure_baseline(&mut self)
Reconfigure the machine to use the baseline strategy.
The baseline strategy uses a single global precision for all instructions, doubling it each iteration. This is simpler but less efficient than the default adaptive precision tuning.
Sourcepub fn take_executions(&mut self) -> Vec<Execution>
pub fn take_executions(&mut self) -> Vec<Execution>
Return a snapshot of recorded Execution records and reset
the internal buffer pointer.
Source§impl<D: Discretization> Machine<D>
impl<D: Discretization> Machine<D>
Sourcepub fn apply(
&mut self,
args: &[Ival],
hint: Option<&[Hint]>,
max_iterations: usize,
) -> Result<Vec<Ival>, RivalError>
pub fn apply( &mut self, args: &[Ival], hint: Option<&[Hint]>, max_iterations: usize, ) -> Result<Vec<Ival>, RivalError>
Evaluate the compiled real expressions on an input point represented as a slice of intervals.
args must be the same length as the vars passed to
MachineBuilder::build. The output is a vector of output
values of the same length as the exprs passed to
MachineBuilder::build.
hint can be provided from a previous call to
Machine::analyze_with_hints to speed up evaluation.
Pass None for default behavior.
max_iterations sets the maximum number of re-evaluation
iterations before giving up.
§Errors
Returns RivalError::InvalidInput if the point is an
invalid input to at least one of the compiled expressions.
Returns RivalError::Unsamplable if Rival is unable to
evaluate at least one expression.
Note that apply will only return Ok if it can prove
that it has correctly-rounded the output. It will only
return InvalidInput if it can prove that at least one
output expression in the machine throws on the given input.
Sourcepub fn apply_baseline(
&mut self,
args: &[Ival],
hint: Option<&[Hint]>,
) -> Result<Vec<Ival>, RivalError>
pub fn apply_baseline( &mut self, args: &[Ival], hint: Option<&[Hint]>, ) -> Result<Vec<Ival>, RivalError>
Evaluate the machine using the baseline strategy.
The baseline strategy uses a single global precision for all
instructions, doubling it each iteration. This is simpler but
less efficient than Machine::apply, which uses adaptive
per-instruction precision tuning.
Call Machine::configure_baseline before using this method
to set up the machine for baseline evaluation.
Sourcepub fn analyze_baseline_with_hints(
&mut self,
rect: &[Ival],
hint: Option<&[Hint]>,
) -> (Ival, Vec<Hint>, bool)
pub fn analyze_baseline_with_hints( &mut self, rect: &[Ival], hint: Option<&[Hint]>, ) -> (Ival, Vec<Hint>, bool)
Analyze an input rectangle using the baseline strategy, returning status, next hints, and a convergence flag.
See Machine::analyze_with_hints for details on the
return values.
Sourcepub fn analyze_baseline(&mut self, rect: &[Ival]) -> Ival
pub fn analyze_baseline(&mut self, rect: &[Ival]) -> Ival
Analyze a hyper-rectangle using the baseline strategy and return only the boolean interval status.
See Machine::analyze for details on the return value.
Sourcepub fn analyze_with_hints(
&mut self,
rect: &[Ival],
hint: Option<&[Hint]>,
) -> (Ival, Vec<Hint>, bool)
pub fn analyze_with_hints( &mut self, rect: &[Ival], hint: Option<&[Hint]>, ) -> (Ival, Vec<Hint>, bool)
Analyze an input rectangle using adaptive precision tuning.
Returns a (status, hints, converged) tuple:
-
statusis a boolean interval indicating whether a call toMachine::applywith inputs in the suppliedrectis guaranteed to raise an error. If false is returned, there is no point callingapplywith any point in the input range. If uncertain, some points may raise errors while others may not, though nothing is guaranteed. If true is returned,InvalidInputwill not be raised for any point in the range; however,Unsamplablemay still be raised. -
hintsis a vector ofHints that can be passed to subsequent calls toMachine::applyto skip unnecessary computation. -
convergedindicates whether the analysis has converged.
Sourcepub fn analyze(&mut self, rect: &[Ival]) -> Ival
pub fn analyze(&mut self, rect: &[Ival]) -> Ival
Analyze a hyper-rectangle and return only the boolean interval status.
Returns a boolean interval which indicates whether a call to
Machine::apply, with inputs in the supplied rect, is
guaranteed to raise an error.
In other words, if false is returned, there is no point calling
apply with any point in the input range. If uncertain, some
points in the range may raise errors, while others may not,
though nothing is guaranteed. If true is returned,
RivalError::InvalidInput will not be raised for any point
in the range. However, RivalError::Unsamplable may still
be raised.
The advantage of analyze over apply is that it applies to
whole ranges of input points and is much faster.
Auto Trait Implementations§
impl<D> Freeze for Machine<D>where
D: Freeze,
impl<D> RefUnwindSafe for Machine<D>where
D: RefUnwindSafe,
impl<D> Send for Machine<D>where
D: Send,
impl<D> Sync for Machine<D>where
D: Sync,
impl<D> Unpin for Machine<D>where
D: Unpin,
impl<D> UnsafeUnpin for Machine<D>where
D: UnsafeUnpin,
impl<D> UnwindSafe for Machine<D>where
D: UnwindSafe,
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
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>
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>
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