pub struct FaerVec<T: FaerScalar> { /* private fields */ }Expand description
A batched vector, stored as one column per batch.
Invariant: data.ncols() == context.nbatch() and data.nrows() == len(). Note that
faer pads its column stride for alignment, so the batches are not contiguous with each
other; only a single column is.
Implementations§
Source§impl<T: FaerScalar> FaerVec<T>
impl<T: FaerScalar> FaerVec<T>
pub fn check_for_nan(&self, label: &str) -> bool
Trait Implementations§
Source§impl<T: FaerScalar> Add for FaerVec<T>
impl<T: FaerScalar> Add for FaerVec<T>
Source§impl<T: FaerScalar> Add<&FaerVec<T>> for FaerVecRef<'_, T>
impl<T: FaerScalar> Add<&FaerVec<T>> for FaerVecRef<'_, T>
Source§impl<T: FaerScalar> Add<&FaerVecRef<'_, T>> for FaerVec<T>
impl<T: FaerScalar> Add<&FaerVecRef<'_, T>> for FaerVec<T>
Source§impl<T: FaerScalar> Add<&FaerVecRef<'_, T>> for &FaerVec<T>
impl<T: FaerScalar> Add<&FaerVecRef<'_, T>> for &FaerVec<T>
Source§impl<T: FaerScalar> Add<FaerVec<T>> for FaerVecRef<'_, T>
impl<T: FaerScalar> Add<FaerVec<T>> for FaerVecRef<'_, T>
Source§impl<T: FaerScalar> Add<FaerVecRef<'_, T>> for FaerVec<T>
impl<T: FaerScalar> Add<FaerVecRef<'_, T>> for FaerVec<T>
Source§impl<T: FaerScalar> Add<FaerVecRef<'_, T>> for &FaerVec<T>
impl<T: FaerScalar> Add<FaerVecRef<'_, T>> for &FaerVec<T>
Source§impl<T: FaerScalar> AddAssign for FaerVec<T>
impl<T: FaerScalar> AddAssign for FaerVec<T>
Source§fn add_assign(&mut self, rhs: FaerVec<T>)
fn add_assign(&mut self, rhs: FaerVec<T>)
Performs the
+= operation. Read moreSource§impl<T: FaerScalar> AddAssign<&FaerVec<T>> for FaerVec<T>
impl<T: FaerScalar> AddAssign<&FaerVec<T>> for FaerVec<T>
Source§fn add_assign(&mut self, rhs: &FaerVec<T>)
fn add_assign(&mut self, rhs: &FaerVec<T>)
Performs the
+= operation. Read moreSource§impl<T: FaerScalar> AddAssign<&FaerVec<T>> for FaerVecMut<'_, T>
impl<T: FaerScalar> AddAssign<&FaerVec<T>> for FaerVecMut<'_, T>
Source§fn add_assign(&mut self, rhs: &FaerVec<T>)
fn add_assign(&mut self, rhs: &FaerVec<T>)
Performs the
+= operation. Read moreSource§impl<T: FaerScalar> AddAssign<&FaerVecRef<'_, T>> for FaerVec<T>
impl<T: FaerScalar> AddAssign<&FaerVecRef<'_, T>> for FaerVec<T>
Source§fn add_assign(&mut self, rhs: &FaerVecRef<'_, T>)
fn add_assign(&mut self, rhs: &FaerVecRef<'_, T>)
Performs the
+= operation. Read moreSource§impl<T: FaerScalar> AddAssign<FaerVec<T>> for FaerVecMut<'_, T>
impl<T: FaerScalar> AddAssign<FaerVec<T>> for FaerVecMut<'_, T>
Source§fn add_assign(&mut self, rhs: FaerVec<T>)
fn add_assign(&mut self, rhs: FaerVec<T>)
Performs the
+= operation. Read moreSource§impl<T: FaerScalar> AddAssign<FaerVecRef<'_, T>> for FaerVec<T>
impl<T: FaerScalar> AddAssign<FaerVecRef<'_, T>> for FaerVec<T>
Source§fn add_assign(&mut self, rhs: FaerVecRef<'_, T>)
fn add_assign(&mut self, rhs: FaerVecRef<'_, T>)
Performs the
+= operation. Read moreSource§impl<T: FaerScalar> DefaultDenseMatrix for FaerVec<T>
impl<T: FaerScalar> DefaultDenseMatrix for FaerVec<T>
Source§impl<T: FaerScalar> MulAssign<Scale<T>> for FaerVec<T>
impl<T: FaerScalar> MulAssign<Scale<T>> for FaerVec<T>
Source§fn mul_assign(&mut self, rhs: Scale<T>)
fn mul_assign(&mut self, rhs: Scale<T>)
Performs the
*= operation. Read moreimpl<T: PartialEq + FaerScalar> StructuralPartialEq for FaerVec<T>
Source§impl<T: FaerScalar> Sub for FaerVec<T>
impl<T: FaerScalar> Sub for FaerVec<T>
Source§impl<T: FaerScalar> Sub<&FaerVec<T>> for FaerVecRef<'_, T>
impl<T: FaerScalar> Sub<&FaerVec<T>> for FaerVecRef<'_, T>
Source§impl<T: FaerScalar> Sub<&FaerVecRef<'_, T>> for FaerVec<T>
impl<T: FaerScalar> Sub<&FaerVecRef<'_, T>> for FaerVec<T>
Source§impl<T: FaerScalar> Sub<&FaerVecRef<'_, T>> for &FaerVec<T>
impl<T: FaerScalar> Sub<&FaerVecRef<'_, T>> for &FaerVec<T>
Source§impl<T: FaerScalar> Sub<FaerVec<T>> for FaerVecRef<'_, T>
impl<T: FaerScalar> Sub<FaerVec<T>> for FaerVecRef<'_, T>
Source§impl<T: FaerScalar> Sub<FaerVecRef<'_, T>> for FaerVec<T>
impl<T: FaerScalar> Sub<FaerVecRef<'_, T>> for FaerVec<T>
Source§impl<T: FaerScalar> Sub<FaerVecRef<'_, T>> for &FaerVec<T>
impl<T: FaerScalar> Sub<FaerVecRef<'_, T>> for &FaerVec<T>
Source§impl<T: FaerScalar> SubAssign for FaerVec<T>
impl<T: FaerScalar> SubAssign for FaerVec<T>
Source§fn sub_assign(&mut self, rhs: FaerVec<T>)
fn sub_assign(&mut self, rhs: FaerVec<T>)
Performs the
-= operation. Read moreSource§impl<T: FaerScalar> SubAssign<&FaerVec<T>> for FaerVec<T>
impl<T: FaerScalar> SubAssign<&FaerVec<T>> for FaerVec<T>
Source§fn sub_assign(&mut self, rhs: &FaerVec<T>)
fn sub_assign(&mut self, rhs: &FaerVec<T>)
Performs the
-= operation. Read moreSource§impl<T: FaerScalar> SubAssign<&FaerVec<T>> for FaerVecMut<'_, T>
impl<T: FaerScalar> SubAssign<&FaerVec<T>> for FaerVecMut<'_, T>
Source§fn sub_assign(&mut self, rhs: &FaerVec<T>)
fn sub_assign(&mut self, rhs: &FaerVec<T>)
Performs the
-= operation. Read moreSource§impl<T: FaerScalar> SubAssign<&FaerVecRef<'_, T>> for FaerVec<T>
impl<T: FaerScalar> SubAssign<&FaerVecRef<'_, T>> for FaerVec<T>
Source§fn sub_assign(&mut self, rhs: &FaerVecRef<'_, T>)
fn sub_assign(&mut self, rhs: &FaerVecRef<'_, T>)
Performs the
-= operation. Read moreSource§impl<T: FaerScalar> SubAssign<FaerVec<T>> for FaerVecMut<'_, T>
impl<T: FaerScalar> SubAssign<FaerVec<T>> for FaerVecMut<'_, T>
Source§fn sub_assign(&mut self, rhs: FaerVec<T>)
fn sub_assign(&mut self, rhs: FaerVec<T>)
Performs the
-= operation. Read moreSource§impl<T: FaerScalar> SubAssign<FaerVecRef<'_, T>> for FaerVec<T>
impl<T: FaerScalar> SubAssign<FaerVecRef<'_, T>> for FaerVec<T>
Source§fn sub_assign(&mut self, rhs: FaerVecRef<'_, T>)
fn sub_assign(&mut self, rhs: FaerVecRef<'_, T>)
Performs the
-= operation. Read moreSource§impl<T: FaerScalar> Vector for FaerVec<T>
impl<T: FaerScalar> Vector for FaerVec<T>
type View<'a> = FaerVecRef<'a, T>
type ViewMut<'a> = FaerVecMut<'a, T>
type Index = FaerVecIndex
Source§fn 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.Source§fn 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.
Source§fn context(&self) -> &Self::C
fn context(&self) -> &Self::C
Get the context associated with this vector (for device placement, threading, etc.).
Source§fn get_index(&self, i: IndexType) -> T
fn get_index(&self, i: IndexType) -> T
Get the value at the specified index. Panics unless
nbatch == 1; for a batched vector read
one lane with Self::get_batch.Source§fn set_index(&mut self, i: IndexType, v: T)
fn set_index(&mut self, i: IndexType, v: T)
Set the value at the specified index to
value. Panics unless nbatch == 1; to write the
same value into every batch use Self::fill_index.Source§fn fill_index(&mut self, i: IndexType, v: T)
fn fill_index(&mut self, i: IndexType, v: T)
Set the value at the specified index to
value in every batch. Read moreSource§fn squared_norm(&self, y: &Self, atol: &Self, rtol: T) -> T
fn squared_norm(&self, y: &Self, atol: &Self, rtol: T) -> T
Compute the squared weighted norm for error control: $\sum_i (x_i / (|y_i| \cdot \text{rtol} + \text{atol}_i))^2$ Read more
Source§fn as_view_mut(&mut self) -> Self::ViewMut<'_>
fn as_view_mut(&mut self) -> Self::ViewMut<'_>
Create a mutable view of this vector.
Source§fn get_batch(&self, b: usize) -> Self::View<'_>
fn get_batch(&self, b: usize) -> Self::View<'_>
Get an immutable view of a single batch (with nbatch=1 context).
Source§fn get_batch_mut(&mut self, b: usize) -> Self::ViewMut<'_>
fn get_batch_mut(&mut self, b: usize) -> Self::ViewMut<'_>
Get a mutable view of a single batch (with nbatch=1 context).
Source§fn for_each_batch_mut_host<const M: usize, const N: usize>(
mut_args: [&mut Self; M],
args: [&Self; N],
f: impl FnMut([&mut [T]; M], [&[T]; N], usize),
)
fn for_each_batch_mut_host<const M: usize, const N: usize>( mut_args: [&mut Self; M], args: [&Self; N], f: impl FnMut([&mut [T]; M], [&[T]; N], usize), )
Run
f once per batch lane on the host. Read moreSource§fn copy_from_view(&mut self, o: &Self::View<'_>)
fn copy_from_view(&mut self, o: &Self::View<'_>)
Copy all values from a vector view into this vector.
Source§fn from_element(n: usize, v: T, ctx: Self::C) -> Self
fn from_element(n: usize, v: T, ctx: Self::C) -> Self
Create a vector of length
nstates with all elements initialized to value.Source§fn from_slice(v: &[T], ctx: Self::C) -> Self
fn from_slice(v: &[T], ctx: Self::C) -> Self
Create a vector from a slice.
Source§fn clone_as_vec(&self) -> Vec<T>
fn clone_as_vec(&self) -> Vec<T>
Clone this vector as a Rust
Vec.Source§fn zeros(n: usize, ctx: Self::C) -> Self
fn zeros(n: usize, ctx: Self::C) -> Self
Create a vector of length
nstates with all elements set to zero.Source§fn axpy(&mut self, a: T, x: &Self, beta: T)
fn axpy(&mut self, a: T, x: &Self, beta: T)
Compute the AXPY operation: self = alpha * x + beta * self
Source§fn axpy_v(&mut self, a: T, x: &Self::View<'_>, beta: T)
fn axpy_v(&mut self, a: T, x: &Self::View<'_>, beta: T)
Compute the AXPY operation with a vector view: self = alpha * x + beta * self
Source§fn batched_axpy(&mut self, a: &Self, x: &Self, beta: T)
fn batched_axpy(&mut self, a: &Self, x: &Self, beta: T)
Per-batch AXPY:
self[i]_b = alpha_b * x[i]_b + beta * self[i]_b Read moreSource§fn component_div_assign(&mut self, o: &Self)
fn component_div_assign(&mut self, o: &Self)
Element-wise division: self_i /= other_i
Source§fn component_mul_assign(&mut self, o: &Self)
fn component_mul_assign(&mut self, o: &Self)
Element-wise multiplication: self_i *= other_i
Source§fn root_finding(&self, g1: &Self) -> (bool, T, i32)
fn root_finding(&self, g1: &Self) -> (bool, T, i32)
Detect roots (zero crossings) between this vector (as g0) and another vector (g1). Read more
Source§fn assign_at_indices(&mut self, idx: &Self::Index, v: T)
fn assign_at_indices(&mut self, idx: &Self::Index, v: T)
Assign
value to all elements at the specified indices.Source§fn copy_from_indices(&mut self, o: &Self, idx: &Self::Index)
fn copy_from_indices(&mut self, o: &Self, idx: &Self::Index)
Copy values from
other at the specified indices: self[indices[i]] = other[indices[i]]Source§fn gather(&mut self, o: &Self, idx: &Self::Index)
fn gather(&mut self, o: &Self, idx: &Self::Index)
Gather values from
other at indices: self[i] = other[indices[i]]Source§fn scatter(&self, idx: &Self::Index, o: &mut Self)
fn scatter(&self, idx: &Self::Index, o: &mut Self)
Scatter values to
other at indices: other[indices[i]] = self[i]Source§fn 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().Source§fn for_each_batch_host<const N: usize>(
&mut self,
args: [&Self; N],
f: impl FnMut(&mut [Self::T], [&[Self::T]; N], usize),
)
fn for_each_batch_host<const N: usize>( &mut self, args: [&Self; N], f: impl FnMut(&mut [Self::T], [&[Self::T]; N], usize), )
Run
f once per batch lane of self on the host, passing that lane of self as a
mutable slice and the corresponding lane of each operand in args as an immutable slice. Read moreSource§fn for_each_batch_mut<const M: usize, const N: usize>(
mut_args: [&mut Self; M],
args: [&Self; N],
f: impl Fn([&mut [Self::T]; M], [&[Self::T]; N], usize) + Copy + Send,
)
fn for_each_batch_mut<const M: usize, const N: usize>( mut_args: [&mut Self; M], args: [&Self; N], f: impl Fn([&mut [Self::T]; M], [&[Self::T]; N], usize) + Copy + Send, )
Run
f once per batch lane on the device where the backend has one, falling back to
Self::for_each_batch_mut_host otherwise. Read moreSource§fn for_each_batch<const N: usize>(
&mut self,
args: [&Self; N],
f: impl Fn(&mut [Self::T], [&[Self::T]; N], usize) + Copy + Send,
)
fn for_each_batch<const N: usize>( &mut self, args: [&Self; N], f: impl Fn(&mut [Self::T], [&[Self::T]; N], usize) + Copy + Send, )
Source§fn for_each_elem_mut<const M: usize, const N: usize>(
mut_args: [&mut Self; M],
args: [&Self; N],
f: impl Fn([&mut Self::T; M], [&[Self::T]; N], usize, usize) + Copy + Send,
)
fn for_each_elem_mut<const M: usize, const N: usize>( mut_args: [&mut Self; M], args: [&Self; N], f: impl Fn([&mut Self::T; M], [&[Self::T]; N], usize, usize) + Copy + Send, )
Run
f once per element of every batch lane on the device where the backend has one,
falling back to a host loop otherwise. Read moreSource§fn for_each_elem<const N: usize>(
&mut self,
args: [&Self; N],
f: impl Fn(&mut Self::T, [&[Self::T]; N], usize, usize) + Copy + Send,
)
fn for_each_elem<const N: usize>( &mut self, args: [&Self; N], f: impl Fn(&mut Self::T, [&[Self::T]; N], usize, usize) + Copy + Send, )
Run
f once per element of every batch lane of self on the device where the backend
has one. Read moreSource§fn reduce_batch_host<const N: usize>(
dest: &mut Self,
args: [&Self; N],
init: Self::T,
map: impl FnMut([&[Self::T]; N], usize, usize) -> Self::T,
combine: impl FnMut(Self::T, Self::T) -> Self::T,
)
fn reduce_batch_host<const N: usize>( dest: &mut Self, args: [&Self; N], init: Self::T, map: impl FnMut([&[Self::T]; N], usize, usize) -> Self::T, combine: impl FnMut(Self::T, Self::T) -> Self::T, )
Reduce
args over the batch dimension, elementwise, on the host. Read moreSource§fn reduce_batch<const N: usize>(
dest: &mut Self,
args: [&Self; N],
init: Self::T,
map: impl Fn([&[Self::T]; N], usize, usize) -> Self::T + Copy + Send,
combine: impl Fn(Self::T, Self::T) -> Self::T + Copy + Send,
)
fn reduce_batch<const N: usize>( dest: &mut Self, args: [&Self; N], init: Self::T, map: impl Fn([&[Self::T]; N], usize, usize) -> Self::T + Copy + Send, combine: impl Fn(Self::T, Self::T) -> Self::T + Copy + Send, )
Reduce
args over the batch dimension, elementwise, on the device where the backend
has one, falling back to Self::reduce_batch_host otherwise. Read moreSource§fn reduce_elem_host<const N: usize>(
dest: &mut Self,
args: [&Self; N],
init: Self::T,
map: impl FnMut([&[Self::T]; N], usize, usize) -> Self::T,
combine: impl FnMut(Self::T, Self::T) -> Self::T,
)
fn reduce_elem_host<const N: usize>( dest: &mut Self, args: [&Self; N], init: Self::T, map: impl FnMut([&[Self::T]; N], usize, usize) -> Self::T, combine: impl FnMut(Self::T, Self::T) -> Self::T, )
Reduce each batch lane of
args over its elements, on the host. Read moreSource§fn reduce_elem<const N: usize>(
dest: &mut Self,
args: [&Self; N],
init: Self::T,
map: impl Fn([&[Self::T]; N], usize, usize) -> Self::T + Copy + Send,
combine: impl Fn(Self::T, Self::T) -> Self::T + Copy + Send,
)
fn reduce_elem<const N: usize>( dest: &mut Self, args: [&Self; N], init: Self::T, map: impl Fn([&[Self::T]; N], usize, usize) -> Self::T + Copy + Send, combine: impl Fn(Self::T, Self::T) -> Self::T + Copy + Send, )
Reduce each batch lane of
args over its elements, on the device where the backend
has one, falling back to Self::reduce_elem_host otherwise. Read moreSource§fn dot(&self, other: &Self) -> Self::T
fn dot(&self, other: &Self) -> Self::T
The dot product with
other, summed over every element of every batch lane. other
broadcasts into this vector’s lanes, as in Self::reduce_elem. The per-lane sums are
added on the host, which on a device backend means a copy back to the host each call:
meant for tests and checks rather than inner loops.Source§fn rand(nstates: usize, seed: f64, ctx: Self::C) -> Self
fn rand(nstates: usize, seed: f64, ctx: Self::C) -> Self
A deterministic pseudo-random vector of length
nstates with the lanes of ctx, for
tests: element i of lane b is sin((b * nstates + i + 1) * seed). The values are
irregular, so a dot test can’t pass by symmetry, and different seeds give different
vectors.Source§fn 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.Source§fn assert_eq_eps(&self, other: &Self, factor: f64)
fn assert_eq_eps(&self, other: &Self, factor: f64)
Assert that this vector equals
other within factor machine epsilons of Self::T.Source§fn 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). Read moreSource§fn 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>)
Auto Trait Implementations§
impl<T> Freeze for FaerVec<T>
impl<T> RefUnwindSafe for FaerVec<T>where
Mat<Own<T>>: RefUnwindSafe,
impl<T> Send for FaerVec<T>
impl<T> Sync for FaerVec<T>
impl<T> Unpin for FaerVec<T>
impl<T> UnsafeUnpin for FaerVec<T>where
Mat<Own<T>>: UnsafeUnpin,
impl<T> UnwindSafe for FaerVec<T>where
Mat<Own<T>>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, Right> ClosedAdd<Right> for T
impl<T, Right> ClosedAddAssign<Right> for T
impl<T, Right> ClosedMul<Right> for T
impl<T, Right> ClosedMulAssign<Right> for T
impl<T, Right> ClosedSub<Right> for T
impl<T, Right> ClosedSubAssign<Right> for T
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.