Skip to main content

Application

Struct Application 

Source
pub struct Application {
Show 17 fields pub prog: Program, pub compiled: Option<MachineCode<f64>>, pub compiled_simd: Option<MachineCode<f64>>, pub compiled_fast: Option<MachineCode<f64>>, pub bytecode: CompiledMir, pub params: Vec<f64>, pub use_simd: bool, pub use_threads: bool, pub can_fast: bool, pub first_state: usize, pub first_param: usize, pub first_obs: usize, pub first_diff: usize, pub count_states: usize, pub count_params: usize, pub count_obs: usize, pub count_diffs: usize,
}

Fields§

§prog: Program§compiled: Option<MachineCode<f64>>§compiled_simd: Option<MachineCode<f64>>§compiled_fast: Option<MachineCode<f64>>§bytecode: CompiledMir§params: Vec<f64>§use_simd: bool§use_threads: bool§can_fast: bool§first_state: usize§first_param: usize§first_obs: usize§first_diff: usize§count_states: usize§count_params: usize§count_obs: usize§count_diffs: 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 evaluate<T: Sized + Copy>(&mut self, args: &[T], outs: &mut [T])

Generic evaluate function for compiled Symbolica expressions

Source

pub fn evaluate_single<T: Sized + Copy + Default>(&mut self, args: &[T]) -> T

Generic evaluate_single function for compiled Symbolica expressions

Source

pub fn evaluate_simd<T: Sized + Copy>(&self, args: &[T], outs: &mut [T])

Generic SIMD evaluate function for compiled Symbolica expressions

Source

pub fn evaluate_simd_single<T: Sized + Copy + Default>(&self, args: &[T]) -> T

Generic SIMD evaluate_single function for compiled Symbolica expressions

Source

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

Source

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

Generic evaluate function for compiled Symbolica expressions

Source

pub fn evaluate_complex_matrix( &mut self, args: &[Complex<f64>], outs: &mut [Complex<f64>], n: usize, )

Source

pub fn evaluate_simd_matrix<T: Sized + Copy>( &self, args: &[T], outs: &mut [T], n: usize, )

Generic evaluate function for compiled Symbolica expressions

Source

pub unsafe fn call_simd(&mut self, _args: &[[f64; 4]]) -> Result<Vec<[f64; 4]>>

Source

pub unsafe fn call_simd_params( &mut self, _args: &[[f64; 4]], _params: &[f64], ) -> Result<Vec<[f64; 4]>>

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>, df: &Defuns, ) -> Result<Application>

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 Clone for Application

Source§

fn clone(&self) -> Application

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.