pub trait Vector:
VectorOpsByValue<Self>
+ for<'b> VectorOpsByValue<&'b Self>
+ for<'a> VectorOpsByValue<Self::View<'a>>
+ for<'a, 'b> VectorOpsByValue<&'b Self::View<'a>>
+ Mul<Scale<Self::T>, Output = Self>
+ Div<Scale<Self::T>, Output = Self>
+ VectorMutOpsByValue<Self>
+ for<'a> VectorMutOpsByValue<Self::View<'a>>
+ for<'b> VectorMutOpsByValue<&'b Self>
+ for<'a, 'b> VectorMutOpsByValue<&'b Self::View<'a>>
+ MulAssign<Scale<Self::T>>
+ Clone
+ Send {
type View<'a>: VectorView<'a, T = Self::T, Owned = Self>
where Self: 'a;
type ViewMut<'a>: VectorViewMut<'a, T = Self::T, Owned = Self, View = Self::View<'a>>
where Self: 'a;
type Index: VectorIndex;
Show 35 methods
// Required methods
fn context(&self) -> &Self::C;
fn inner_mut(&mut self) -> &mut Self::Inner;
fn set_index(&mut self, index: IndexType, value: Self::T);
fn get_index(&self, index: IndexType) -> Self::T;
fn norm(&self, k: i32) -> Self::T;
fn squared_norm(&self, y: &Self, atol: &Self, rtol: Self::T) -> Self::T;
fn len(&self) -> IndexType;
fn from_element(nstates: usize, value: Self::T, ctx: Self::C) -> Self;
fn fill(&mut self, value: Self::T);
fn as_view(&self) -> Self::View<'_>;
fn as_view_mut(&mut self) -> Self::ViewMut<'_>;
fn get_batch(&self, batch: usize) -> Self::View<'_>;
fn get_batch_mut(&mut self, batch: usize) -> Self::ViewMut<'_>;
fn copy_from(&mut self, other: &Self);
fn copy_from_view(&mut self, other: &Self::View<'_>);
fn from_vec(vec: Vec<Self::T>, ctx: Self::C) -> Self;
fn from_slice(slice: &[Self::T], ctx: Self::C) -> Self;
fn clone_as_vec(&self) -> Vec<Self::T>;
fn axpy(&mut self, alpha: Self::T, x: &Self, beta: Self::T);
fn axpy_v(&mut self, alpha: Self::T, x: &Self::View<'_>, beta: Self::T);
fn batched_axpy(&mut self, alpha: &[Self::T], x: &Self, beta: Self::T);
fn component_mul_assign(&mut self, other: &Self);
fn component_div_assign(&mut self, other: &Self);
fn root_finding(&self, g1: &Self) -> (bool, Self::T, i32);
fn assign_at_indices(&mut self, indices: &Self::Index, value: Self::T);
fn copy_from_indices(&mut self, other: &Self, indices: &Self::Index);
fn gather(&mut self, other: &Self, indices: &Self::Index);
fn scatter(&self, indices: &Self::Index, other: &mut Self);
// Provided methods
fn total_len(&self) -> IndexType { ... }
fn is_empty(&self) -> bool { ... }
fn zeros(nstates: usize, ctx: Self::C) -> Self { ... }
fn assert_eq_st(&self, other: &Self, tol: Self::T) { ... }
fn assert_eq_norm(
&self,
other: &Self,
atol: &Self,
rtol: Self::T,
factor: Self::T,
) { ... }
fn assert_eq(&self, other: &Self, tol: &Self) { ... }
fn assert_eq_vec(s: Vec<Self::T>, other: Vec<Self::T>, tol: Vec<Self::T>) { ... }
}Expand description
A complete vector abstraction supporting arithmetic operations, norms, and index operations.
This is the main vector trait used throughout diffsol. Implementing vectors can be hosted on CPU (see VectorHost) or GPU.
Users typically do not need to implement this trait; use provided implementations like
NalgebraVec or FaerVec.
Required Associated Types§
type View<'a>: VectorView<'a, T = Self::T, Owned = Self> where Self: 'a
type ViewMut<'a>: VectorViewMut<'a, T = Self::T, Owned = Self, View = Self::View<'a>> where Self: 'a
type Index: VectorIndex
Required Methods§
Sourcefn context(&self) -> &Self::C
fn context(&self) -> &Self::C
Get the context associated with this vector (for device placement, threading, etc.).
Sourcefn inner_mut(&mut self) -> &mut Self::Inner
fn inner_mut(&mut self) -> &mut Self::Inner
Get a mutable reference to the inner representation of the vector.
Sourcefn set_index(&mut self, index: IndexType, value: Self::T)
fn set_index(&mut self, index: IndexType, value: Self::T)
Set the value at the specified index to value.
Sourcefn squared_norm(&self, y: &Self, atol: &Self, rtol: Self::T) -> Self::T
fn squared_norm(&self, y: &Self, atol: &Self, rtol: Self::T) -> Self::T
Compute the squared weighted norm for error control: $\sum_i (x_i / (|y_i| \cdot \text{rtol} + \text{atol}_i))^2$
This norm is used by ODE solvers for adaptive error control.
Sourcefn len(&self) -> IndexType
fn len(&self) -> IndexType
Get the per-batch length (number of states) in this vector.
For batched vectors, this returns nstates, not nstates * nbatch.
Sourcefn from_element(nstates: usize, value: Self::T, ctx: Self::C) -> Self
fn from_element(nstates: usize, value: Self::T, ctx: Self::C) -> Self
Create a vector of length nstates with all elements initialized to value.
Sourcefn as_view_mut(&mut self) -> Self::ViewMut<'_>
fn as_view_mut(&mut self) -> Self::ViewMut<'_>
Create a mutable view of this vector.
Sourcefn get_batch(&self, batch: usize) -> Self::View<'_>
fn get_batch(&self, batch: usize) -> Self::View<'_>
Get an immutable view of a single batch (with nbatch=1 context).
Sourcefn get_batch_mut(&mut self, batch: usize) -> Self::ViewMut<'_>
fn get_batch_mut(&mut self, batch: usize) -> Self::ViewMut<'_>
Get a mutable view of a single batch (with nbatch=1 context).
Sourcefn copy_from_view(&mut self, other: &Self::View<'_>)
fn copy_from_view(&mut self, other: &Self::View<'_>)
Copy all values from a vector view into this vector.
Sourcefn from_slice(slice: &[Self::T], ctx: Self::C) -> Self
fn from_slice(slice: &[Self::T], ctx: Self::C) -> Self
Create a vector from a slice.
Sourcefn clone_as_vec(&self) -> Vec<Self::T>
fn clone_as_vec(&self) -> Vec<Self::T>
Clone this vector as a Rust Vec.
Sourcefn axpy(&mut self, alpha: Self::T, x: &Self, beta: Self::T)
fn axpy(&mut self, alpha: Self::T, x: &Self, beta: Self::T)
Compute the AXPY operation: self = alpha * x + beta * self
Sourcefn axpy_v(&mut self, alpha: Self::T, x: &Self::View<'_>, beta: Self::T)
fn axpy_v(&mut self, alpha: Self::T, x: &Self::View<'_>, beta: Self::T)
Compute the AXPY operation with a vector view: self = alpha * x + beta * self
Sourcefn batched_axpy(&mut self, alpha: &[Self::T], x: &Self, beta: Self::T)
fn batched_axpy(&mut self, alpha: &[Self::T], x: &Self, beta: Self::T)
Per-batch AXPY: self[i]_b = alpha[b] * x[i]_b + beta * self[i]_b
alpha must have length equal to self.context().nbatch().
Each batch uses its own scalar multiplier alpha[b].
The x operand may broadcast if its nbatch == 1.
Sourcefn component_mul_assign(&mut self, other: &Self)
fn component_mul_assign(&mut self, other: &Self)
Element-wise multiplication: self_i *= other_i
Sourcefn component_div_assign(&mut self, other: &Self)
fn component_div_assign(&mut self, other: &Self)
Element-wise division: self_i /= other_i
Sourcefn root_finding(&self, g1: &Self) -> (bool, Self::T, i32)
fn root_finding(&self, g1: &Self) -> (bool, Self::T, i32)
Detect roots (zero crossings) between this vector (as g0) and another vector (g1).
Returns a tuple of:
bool: true if a zero crossing is found (g1_i == 0 for some i)T: the interpolation factor at the maximum crossing (0 if none found) (given by maxmimum |g0_i / (g1_i - g0_i)|)i32: the index of the maximum crossing (-1 if none found)
Sourcefn assign_at_indices(&mut self, indices: &Self::Index, value: Self::T)
fn assign_at_indices(&mut self, indices: &Self::Index, value: Self::T)
Assign value to all elements at the specified indices.
Sourcefn copy_from_indices(&mut self, other: &Self, indices: &Self::Index)
fn copy_from_indices(&mut self, other: &Self, indices: &Self::Index)
Copy values from other at the specified indices: self[indices[i]] = other[indices[i]]
Provided Methods§
Sourcefn total_len(&self) -> IndexType
fn total_len(&self) -> IndexType
Get the total number of elements stored, including all batches.
Returns self.len() * self.context().nbatch().
Sourcefn zeros(nstates: usize, ctx: Self::C) -> Self
fn zeros(nstates: usize, ctx: Self::C) -> Self
Create a vector of length nstates with all elements set to zero.
Sourcefn assert_eq_st(&self, other: &Self, tol: Self::T)
fn assert_eq_st(&self, other: &Self, tol: Self::T)
Assert that this vector equals other within a scalar tolerance tol.
Sourcefn assert_eq_norm(
&self,
other: &Self,
atol: &Self,
rtol: Self::T,
factor: Self::T,
)
fn assert_eq_norm( &self, other: &Self, atol: &Self, rtol: Self::T, factor: Self::T, )
Assert that this vector equals other using a weighted norm (same as used by ODE solvers).
Uses squared_norm internally with the scaling factors, and asserts that the resulting
norm is less than factor.
Sourcefn assert_eq(&self, other: &Self, tol: &Self)
fn assert_eq(&self, other: &Self, tol: &Self)
Assert that this vector equals other using a vector of per-element tolerances.
fn assert_eq_vec(s: Vec<Self::T>, other: Vec<Self::T>, tol: Vec<Self::T>)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".