pub trait Vector {
// Required methods
fn as_slice(&self) -> &[f64];
fn as_mut_slice(&mut self) -> &mut [f64];
fn zeros(len: usize) -> Self;
fn len(&self) -> usize;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
A trait for vector-like types that can be used with the JIT compiler.
This trait provides a common interface for different vector implementations, allowing them to be used interchangeably in JIT-compiled functions. It defines core vector operations needed for JIT compilation, including accessing raw data and creating zero-initialized vectors.
§Examples
use evalexpr_jit::prelude::Vector;
// Create a zero vector
let vec: Vec<f64> = Vector::zeros(5);
assert_eq!(vec.len(), 5);
// Access elements
let mut vec = vec![1.0, 2.0, 3.0];
let slice = vec.as_slice();
assert_eq!(slice[0], 1.0);Required Methods§
Sourcefn as_mut_slice(&mut self) -> &mut [f64]
fn as_mut_slice(&mut self) -> &mut [f64]
Returns a mutable reference to the vector’s data as a slice.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Vector for Vec<f64>
Implementation of Vector trait for standard Vec.
impl Vector for Vec<f64>
Implementation of Vector trait for standard Vec
This implementation provides an interface between the Vector trait and Rust’s
standard vector type. Vec
§Examples
use evalexpr_jit::prelude::Vector;
let mut vec = Vec::<f64>::zeros(3);
let slice = vec.as_mut_slice();
slice[0] = 1.0;
assert_eq!(vec[0], 1.0);Source§impl<const N: usize> Vector for [f64; N]
Implementation of Vector trait for fixed-size arrays.
impl<const N: usize> Vector for [f64; N]
Implementation of Vector trait for fixed-size arrays.
This implementation allows fixed-size arrays to be used with the JIT compiler. The array size is specified through the const generic parameter N.
§Type Parameters
N- The fixed size of the array
§Examples
use evalexpr_jit::prelude::Vector;
let mut arr = <[f64; 3]>::zeros(3);
let slice = arr.as_mut_slice();
slice[0] = 1.0;
assert_eq!(arr[0], 1.0);