Skip to main content

Vector

Trait Vector 

Source
pub trait Vector<S>: Sized + Clone
where S: Scalar,
{
Show 26 methods // Required methods fn zeros(len: usize) -> Self; fn fill(len: usize, value: S) -> Self; fn from_slice(data: &[S]) -> Self; fn len(&self) -> usize; fn get(&self, i: usize) -> S; fn set(&mut self, i: usize, value: S); fn get_mut(&mut self, i: usize) -> &mut S; fn as_slice(&self) -> &[S]; fn as_mut_slice(&mut self) -> &mut [S]; fn copy_from(&mut self, other: &Self); fn axpy(&mut self, a: S, x: &Self); fn axpby(&mut self, a: S, x: &Self, b: S); fn dot(&self, other: &Self) -> S; fn scale(&mut self, a: S); fn norm_inf(&self) -> S; fn norm1(&self) -> S; fn abs_inplace(&mut self); fn max_elementwise(&mut self, other: &Self); fn min_elementwise(&mut self, other: &Self); fn sum(&self) -> S; fn max_element(&self) -> S; fn min_element(&self) -> S; fn map_inplace<F>(&mut self, f: F) where F: Fn(S) -> S; // Provided methods fn is_empty(&self) -> bool { ... } fn norm2(&self) -> S { ... } fn weighted_rms_norm(&self, weights: &Self) -> S { ... }
}
Expand description

A vector type for numerical computation.

This trait provides the essential operations needed by ODE/SDE solvers and other numerical algorithms.

§Example

use numra_core::Vector;

fn compute_weighted_sum<V: Vector<f64>>(a: f64, x: &V, b: f64, y: &V) -> V {
    let mut result = x.clone();
    result.scale(a);
    result.axpy(b, y);
    result
}

Required Methods§

Source

fn zeros(len: usize) -> Self

Create a zero vector of given length.

Source

fn fill(len: usize, value: S) -> Self

Create a vector filled with a constant value.

Source

fn from_slice(data: &[S]) -> Self

Create from a slice.

Source

fn len(&self) -> usize

Length of the vector.

Source

fn get(&self, i: usize) -> S

Get element at index (panics if out of bounds).

Source

fn set(&mut self, i: usize, value: S)

Set element at index.

Source

fn get_mut(&mut self, i: usize) -> &mut S

Get mutable reference to element.

Source

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

Return as a slice.

Source

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

Return as mutable slice.

Source

fn copy_from(&mut self, other: &Self)

Copy elements from another vector.

Source

fn axpy(&mut self, a: S, x: &Self)

AXPY: y = a*x + y (fundamental BLAS operation)

This is the most important operation for numerical algorithms.

Source

fn axpby(&mut self, a: S, x: &Self, b: S)

Scaled add: y = ax + by

Source

fn dot(&self, other: &Self) -> S

Dot product: x·y

Source

fn scale(&mut self, a: S)

Scale in place: x *= a

Source

fn norm_inf(&self) -> S

Infinity norm: ||x||_∞ = max|x_i|

Source

fn norm1(&self) -> S

1-norm: ||x||_1 = Σ|x_i|

Source

fn abs_inplace(&mut self)

Element-wise absolute value in place.

Source

fn max_elementwise(&mut self, other: &Self)

Element-wise maximum: self[i] = max(self[i], other[i])

Source

fn min_elementwise(&mut self, other: &Self)

Element-wise minimum: self[i] = min(self[i], other[i])

Source

fn sum(&self) -> S

Sum of all elements.

Source

fn max_element(&self) -> S

Maximum element.

Source

fn min_element(&self) -> S

Minimum element.

Source

fn map_inplace<F>(&mut self, f: F)
where F: Fn(S) -> S,

Apply a function to each element.

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if empty.

Source

fn norm2(&self) -> S

Euclidean norm: ||x||_2 = sqrt(x·x)

Source

fn weighted_rms_norm(&self, weights: &Self) -> S

Weighted RMS norm: sqrt(mean((x/w)²)) Used for error control in ODE solvers.

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<S> Vector<S> for Vec<S>
where S: Scalar,

Source§

fn zeros(len: usize) -> Vec<S>

Source§

fn fill(len: usize, value: S) -> Vec<S>

Source§

fn from_slice(data: &[S]) -> Vec<S>

Source§

fn len(&self) -> usize

Source§

fn get(&self, i: usize) -> S

Source§

fn set(&mut self, i: usize, value: S)

Source§

fn get_mut(&mut self, i: usize) -> &mut S

Source§

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

Source§

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

Source§

fn copy_from(&mut self, other: &Vec<S>)

Source§

fn axpy(&mut self, a: S, x: &Vec<S>)

Source§

fn axpby(&mut self, a: S, x: &Vec<S>, b: S)

Source§

fn dot(&self, other: &Vec<S>) -> S

Source§

fn scale(&mut self, a: S)

Source§

fn norm_inf(&self) -> S

Source§

fn norm1(&self) -> S

Source§

fn abs_inplace(&mut self)

Source§

fn max_elementwise(&mut self, other: &Vec<S>)

Source§

fn min_elementwise(&mut self, other: &Vec<S>)

Source§

fn sum(&self) -> S

Source§

fn max_element(&self) -> S

Source§

fn min_element(&self) -> S

Source§

fn map_inplace<F>(&mut self, f: F)
where F: Fn(S) -> S,

Implementors§