Vector

Trait Vector 

Source
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§

Source

fn as_slice(&self) -> &[f64]

Returns a reference to the vector’s data as a slice.

Source

fn as_mut_slice(&mut self) -> &mut [f64]

Returns a mutable reference to the vector’s data as a slice.

Source

fn zeros(len: usize) -> Self

Creates a new vector of the specified length filled with zeros.

§Arguments
  • len - The length of the vector to create
Source

fn len(&self) -> usize

Returns the length of the vector.

Provided Methods§

Source

fn is_empty(&self) -> bool

Checks if the vector is empty.

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.

This implementation provides an interface between the Vector trait and Rust’s standard vector type. Vec already provides slice access, making this implementation straightforward.

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

fn as_slice(&self) -> &[f64]

Source§

fn as_mut_slice(&mut self) -> &mut [f64]

Source§

fn zeros(len: usize) -> Self

Source§

fn len(&self) -> usize

Source§

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);
Source§

fn as_slice(&self) -> &[f64]

Source§

fn as_mut_slice(&mut self) -> &mut [f64]

Source§

fn zeros(len: usize) -> Self

Source§

fn len(&self) -> usize

Implementors§