Skip to main content

Vector

Trait Vector 

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

Source

type View<'a>: VectorView<'a, T = Self::T, Owned = Self> where Self: 'a

Source

type ViewMut<'a>: VectorViewMut<'a, T = Self::T, Owned = Self, View = Self::View<'a>> where Self: 'a

Source

type Index: VectorIndex

Required Methods§

Source

fn context(&self) -> &Self::C

Get the context associated with this vector (for device placement, threading, etc.).

Source

fn inner_mut(&mut self) -> &mut Self::Inner

Get a mutable reference to the inner representation of the vector.

Source

fn set_index(&mut self, index: IndexType, value: Self::T)

Set the value at the specified index to value.

Source

fn get_index(&self, index: IndexType) -> Self::T

Get the value at the specified index.

Source

fn norm(&self, k: i32) -> Self::T

Compute the $\ell_k$ norm: $(\sum_i |x_i|^k)^{1/k}$

Source

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.

Source

fn len(&self) -> IndexType

Get the per-batch length (number of states) in this vector. For batched vectors, this returns nstates, not nstates * nbatch.

Source

fn from_element(nstates: usize, value: Self::T, ctx: Self::C) -> Self

Create a vector of length nstates with all elements initialized to value.

Source

fn fill(&mut self, value: Self::T)

Fill all elements of this vector with value.

Source

fn as_view(&self) -> Self::View<'_>

Create an immutable view of this vector.

Source

fn as_view_mut(&mut self) -> Self::ViewMut<'_>

Create a mutable view of this vector.

Source

fn get_batch(&self, batch: usize) -> Self::View<'_>

Get an immutable view of a single batch (with nbatch=1 context).

Source

fn get_batch_mut(&mut self, batch: usize) -> Self::ViewMut<'_>

Get a mutable view of a single batch (with nbatch=1 context).

Source

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

Copy all values from other into this vector.

Source

fn copy_from_view(&mut self, other: &Self::View<'_>)

Copy all values from a vector view into this vector.

Source

fn from_vec(vec: Vec<Self::T>, ctx: Self::C) -> Self

Create a vector from a Rust Vec.

Source

fn from_slice(slice: &[Self::T], ctx: Self::C) -> Self

Create a vector from a slice.

Source

fn clone_as_vec(&self) -> Vec<Self::T>

Clone this vector as a Rust Vec.

Source

fn axpy(&mut self, alpha: Self::T, x: &Self, beta: Self::T)

Compute the AXPY operation: self = alpha * x + beta * self

Source

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

Source

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.

Source

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

Element-wise multiplication: self_i *= other_i

Source

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

Element-wise division: self_i /= other_i

Source

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

fn assign_at_indices(&mut self, indices: &Self::Index, value: Self::T)

Assign value to all elements at the specified indices.

Source

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

Source

fn gather(&mut self, other: &Self, indices: &Self::Index)

Gather values from other at indices: self[i] = other[indices[i]]

Source

fn scatter(&self, indices: &Self::Index, other: &mut Self)

Scatter values to other at indices: other[indices[i]] = self[i]

Provided Methods§

Source

fn total_len(&self) -> IndexType

Get the total number of elements stored, including all batches. Returns self.len() * self.context().nbatch().

Source

fn is_empty(&self) -> bool

Check if the vector is empty.

Source

fn zeros(nstates: usize, ctx: Self::C) -> Self

Create a vector of length nstates with all elements set to zero.

Source

fn assert_eq_st(&self, other: &Self, tol: Self::T)

Assert that this vector equals other within a scalar tolerance tol.

Source

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.

Source

fn assert_eq(&self, other: &Self, tol: &Self)

Assert that this vector equals other using a vector of per-element tolerances.

Source

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".

Implementors§