pub trait Vector<S: Scalar>: Clone + Sized {
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: Fn(S) -> S>(&mut self, f: F);
// 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§
Sourcefn from_slice(data: &[S]) -> Self
fn from_slice(data: &[S]) -> Self
Create from a slice.
Sourcefn as_mut_slice(&mut self) -> &mut [S]
fn as_mut_slice(&mut self) -> &mut [S]
Return as mutable slice.
Sourcefn axpy(&mut self, a: S, x: &Self)
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.
Sourcefn abs_inplace(&mut self)
fn abs_inplace(&mut self)
Element-wise absolute value in place.
Sourcefn max_elementwise(&mut self, other: &Self)
fn max_elementwise(&mut self, other: &Self)
Element-wise maximum: self[i] = max(self[i], other[i])
Sourcefn min_elementwise(&mut self, other: &Self)
fn min_elementwise(&mut self, other: &Self)
Element-wise minimum: self[i] = min(self[i], other[i])
Sourcefn max_element(&self) -> S
fn max_element(&self) -> S
Maximum element.
Sourcefn min_element(&self) -> S
fn min_element(&self) -> S
Minimum element.
Sourcefn map_inplace<F: Fn(S) -> S>(&mut self, f: F)
fn map_inplace<F: Fn(S) -> S>(&mut self, f: F)
Apply a function to each element.
Provided Methods§
Sourcefn weighted_rms_norm(&self, weights: &Self) -> S
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.