pub trait Context: Clone + Default {
// Required method
fn clone_with_nbatch(&self, nbatch: usize) -> Result<Self, DiffsolError>;
// Provided methods
fn nbatch(&self) -> usize { ... }
fn assert_compatible_nbatch(&self, other_nbatch: usize, op: &str) { ... }
fn vector_from_element<V: Vector<C = Self>>(
&self,
len: usize,
value: V::T,
) -> V { ... }
fn vector_from_vec<V: Vector<C = Self>>(&self, vec: Vec<V::T>) -> V { ... }
fn vector_zeros<V: Vector<C = Self>>(&self, len: usize) -> V { ... }
fn dense_mat_zeros<V: Vector<C = Self> + DefaultDenseMatrix>(
&self,
rows: usize,
cols: usize,
) -> <V as DefaultDenseMatrix>::M { ... }
}Expand description
defines the current execution and allocation context of an operator / vector / matrix for example:
- threading model (e.g. single-threaded, multi-threaded, GPU)
- custom allocators, host/device memory
- etc.
It will generally be the case that all the operators / vectors / matrices for the current ode problem share the same context
Required Methods§
Sourcefn clone_with_nbatch(&self, nbatch: usize) -> Result<Self, DiffsolError>
fn clone_with_nbatch(&self, nbatch: usize) -> Result<Self, DiffsolError>
Creates a new context with the given batch count.
Other properties of the context (e.g. CUDA stream, faer parallelism) are preserved.
Returns an error if the backend does not support batching (i.e.
nbatch > 1 for CPU backends such as faer and nalgebra).
Provided Methods§
Sourcefn nbatch(&self) -> usize
fn nbatch(&self) -> usize
Returns the batch count for this context.
When nbatch > 1, vectors and matrices store data for nbatch
independent ODE systems simultaneously. Operations between operands
with different batch counts use broadcast semantics: an operand with
nbatch == 1 is applied to all batches of the other operand.
Sourcefn assert_compatible_nbatch(&self, other_nbatch: usize, op: &str)
fn assert_compatible_nbatch(&self, other_nbatch: usize, op: &str)
Panics if the two batch counts are incompatible.
Compatibility rule: two batches are compatible if they are equal, or
if either one is 1 (broadcast). Only panics when both are > 1
and differ.
fn vector_from_element<V: Vector<C = Self>>(&self, len: usize, value: V::T) -> V
fn vector_from_vec<V: Vector<C = Self>>(&self, vec: Vec<V::T>) -> V
fn vector_zeros<V: Vector<C = Self>>(&self, len: usize) -> V
fn dense_mat_zeros<V: Vector<C = Self> + DefaultDenseMatrix>( &self, rows: usize, cols: usize, ) -> <V as DefaultDenseMatrix>::M
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".