Skip to main content

Application

Struct Application 

Source
#[repr(C)]
pub struct Application {
Show 18 fields pub compiled: Option<MachineCode<f64>>, pub compiled_simd: Option<MachineCode<f64>>, pub use_simd: bool, pub use_threads: bool, pub count_states: usize, pub count_params: usize, pub count_obs: usize, pub count_diffs: usize, pub config: Config, pub prog: Program, pub compiled_fast: Option<MachineCode<f64>>, pub bytecode: CompiledMir, pub params: Vec<f64>, pub can_fast: bool, pub first_state: usize, pub first_param: usize, pub first_obs: usize, pub first_diff: usize,
}

Fields§

§compiled: Option<MachineCode<f64>>§compiled_simd: Option<MachineCode<f64>>§use_simd: bool§use_threads: bool§count_states: usize§count_params: usize§count_obs: usize§count_diffs: usize§config: Config§prog: Program§compiled_fast: Option<MachineCode<f64>>§bytecode: CompiledMir§params: Vec<f64>§can_fast: bool§first_state: usize§first_param: usize§first_obs: usize§first_diff: usize

Implementations§

Source§

impl Application

Source

pub fn call(&mut self, args: &[f64]) -> Vec<f64>

Calls the compiled function.

args is a slice of f64 values, corresponding to the states.

The output is a Vec<f64>, corresponding to the observables (the expressions passed to compile).

Source

pub fn call_params(&mut self, args: &[f64], params: &[f64]) -> Vec<f64>

Sets the params and calls the compiled function.

args is a slice of f64 values, corresponding to the states. params is a slice of f64 values, corresponding to the params.

The output is a Vec<f64>, corresponding to the observables (the expressions passed to compile).

Source

pub fn interpret<T>(&mut self, args: &[T], outs: &mut [T])
where T: Element,

Source

pub fn interpret_matrix(&mut self, args: &[f64], outs: &mut [f64], n: usize)

Source

pub fn evaluate<T>(&self, args: &[T], outs: &mut [T])
where T: Element,

Generic evaluate function for compiled Symbolica expressions

Source

pub fn evaluate_single<T>(&self, args: &[T]) -> T
where T: Element + Copy,

Generic evaluate_single function for compiled Symbolica expressions

Source

pub fn evaluate_matrix<T>(&self, args: &[T], outs: &mut [T], n: usize)
where T: Element,

Generic evaluate function for compiled Symbolica expressions The main entry point to compute matrices. The actual dispatched method depends on the configuration and the type of the arguments.

Source

pub fn fast_func(&mut self) -> Result<FastFunc<'_>>

Returns a fast function.

Application call functions need to copy the input argument slice into the function memory area and then copy the output to a Vec. This process is acceptable for large and complex functions but incurs a penalty for small functions. Therefore, for a certain subset of applications, Symjit can compile a fast funcction and return a function pointer. Examples:

fn test_fast() -> Result<()> {
    let x = Expr::var("x");
    let y = Expr::var("y");
    let z = Expr::var("z");
    let u = &x * &(&y - &z).pow(&Expr::from(2));

    let mut comp = Compiler::new();
    let mut app = comp.compile(&[x, y, z], &[u])?;
    let f = app.fast_func()?;

    if let FastFunc::F3(f, _) = f {
        let res = f(3.0, 5.0, 9.0);
        println!("fast\t{:?}", &res);
    }

    Ok(())
}

The conditions for a fast function are:

  • A fast function can have 1 to 8 arguments.
  • No SIMD and no parameters.
  • It returns only a single value.

If these conditions are met, you can generate a fast functin by calling app.fast_func(), with a return type of Result<FastFunc>. FastFunc is an enum with eight variants F1, F2, ..., F8`, corresponding to functions with 1 to 8 arguments.

Source§

impl Application

Source

pub fn new(prog: Program, reals: HashSet<Loc>) -> Result<Application>

Source

pub fn with_mir( prog: Program, reals: HashSet<Loc>, mir: Mir, ) -> Result<Application>

Source

pub fn seal(self) -> Result<Applet>

Source

pub fn as_applet(&self) -> &Applet

Source

pub fn exec(&mut self)

Source

pub fn exec_callable(&mut self, xx: &[f64]) -> f64

Source

pub fn prepare_simd(&mut self)

Source

pub fn get_fast( &mut self, ) -> Option<fn(*const f64, *const &mut [f64], usize, *const f64) -> i32>

Source

pub fn exec_vectorized(&mut self, states: &mut Matrix<'_>, obs: &mut Matrix<'_>)

Source

pub fn exec_vectorized_simple( &mut self, states: &Matrix<'_>, obs: &mut Matrix<'_>, )

Source

pub fn exec_vectorized_scalar( &mut self, states: &mut Matrix<'_>, obs: &mut Matrix<'_>, threads: bool, )

Source

pub fn exec_vectorized_simd( &mut self, states: &mut Matrix<'_>, obs: &mut Matrix<'_>, threads: bool, l: usize, )

Source

pub fn dump(&mut self, name: &str, what: &str) -> bool

Source

pub fn dumps(&self) -> Vec<u8>

Trait Implementations§

Source§

impl Storage for Application

Source§

fn save(&self, stream: &mut impl Write) -> Result<()>

Source§

fn load(stream: &mut impl Read) -> Result<Self>

Auto Trait Implementations§

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> 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

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

Source§

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.