pub trait IsVector<S, const ROWS: usize, const BATCH: usize, const DM: usize, const DN: usize>:
Clone
+ Copy
+ Neg<Output = Self>
+ Add<Output = Self>
+ Sub<Output = Self>
+ Debug
+ AbsDiffEq<Epsilon = f64, Epsilon = f64>
+ RelativeEqwhere
S: IsScalar<BATCH, DM, DN>,{
Show 22 methods
// Required methods
fn block_vec2<const R0: usize, const R1: usize>(
top_row: <S as IsScalar<BATCH, DM, DN>>::Vector<R0>,
bot_row: <S as IsScalar<BATCH, DM, DN>>::Vector<R1>,
) -> Self;
fn dot<V>(&self, rhs: V) -> S
where V: Borrow<Self>;
fn from_array<A>(vals: A) -> Self
where A: Borrow<[S; ROWS]>;
fn from_real_array<A>(vals: A) -> Self
where A: Borrow<[<S as IsScalar<BATCH, DM, DN>>::RealScalar; ROWS]>;
fn from_real_vector<A>(val: A) -> Self
where A: Borrow<<S as IsScalar<BATCH, DM, DN>>::RealVector<ROWS>>;
fn from_f64(val: f64) -> Self;
fn from_f64_array<A>(vals: A) -> Self
where A: Borrow<[f64; ROWS]>;
fn elem(&self, idx: usize) -> S;
fn elem_mut(&mut self, idx: usize) -> &mut S;
fn get_fixed_subvec<const R: usize>(
&self,
start_r: usize,
) -> <S as IsScalar<BATCH, DM, DN>>::Vector<R>;
fn from_scalar_array<A>(vals: A) -> Self
where A: Borrow<[S; ROWS]>;
fn norm(&self) -> S;
fn normalized(&self) -> Self;
fn outer<const R2: usize, V>(
&self,
rhs: V,
) -> <S as IsScalar<BATCH, DM, DN>>::Matrix<ROWS, R2>
where V: Borrow<<S as IsScalar<BATCH, DM, DN>>::Vector<R2>>;
fn real_vector(&self) -> <S as IsScalar<BATCH, DM, DN>>::RealVector<ROWS>;
fn select<O>(
&self,
mask: &<S as IsScalar<BATCH, DM, DN>>::Mask,
other: O,
) -> Self
where O: Borrow<Self>;
fn scaled<U>(&self, v: U) -> Self
where U: Borrow<S>;
fn squared_norm(&self) -> S;
fn to_dual_const<const M: usize, const N: usize>(
&self,
) -> <<S as IsScalar<BATCH, DM, DN>>::DualScalar<M, N> as IsScalar<BATCH, M, N>>::Vector<ROWS>;
fn to_mat(&self) -> <S as IsScalar<BATCH, DM, DN>>::Matrix<ROWS, 1>;
// Provided methods
fn ones() -> Self { ... }
fn zeros() -> Self { ... }
}
Expand description
A trait representing a fixed-size vector whose elements can be real scalars (f64
)
or dual numbers. This trait provides core vector operations such as dot products,
subvector extraction, scaling, normalization, and more. It also supports both
real-only and dual/simd-based implementations via generics.
§Generic parameters
S
: The scalar type, which might bef64
or a dual number implementingIsScalar
.ROWS
: The number of rows (dimension) of the vector.BATCH
: If using batch/simd, the number of lanes; otherwise typically 1.DM
,DN
: Shape parameters for dual-number derivatives (0 for real scalars).
Required Methods§
Sourcefn block_vec2<const R0: usize, const R1: usize>(
top_row: <S as IsScalar<BATCH, DM, DN>>::Vector<R0>,
bot_row: <S as IsScalar<BATCH, DM, DN>>::Vector<R1>,
) -> Self
fn block_vec2<const R0: usize, const R1: usize>( top_row: <S as IsScalar<BATCH, DM, DN>>::Vector<R0>, bot_row: <S as IsScalar<BATCH, DM, DN>>::Vector<R1>, ) -> Self
Creates a new vector by concatenating two smaller vectors top_row
and bot_row
.
The resulting vector has dimension R0 + R1
.
Sourcefn dot<V>(&self, rhs: V) -> Swhere
V: Borrow<Self>,
fn dot<V>(&self, rhs: V) -> Swhere
V: Borrow<Self>,
Computes the dot product (inner product) with another vector.
Sourcefn from_array<A>(vals: A) -> Self
fn from_array<A>(vals: A) -> Self
Creates a vector from an array of elements.
Sourcefn from_real_array<A>(vals: A) -> Self
fn from_real_array<A>(vals: A) -> Self
Creates a constant (non-dual) vector from an array of real scalars.
Sourcefn from_real_vector<A>(val: A) -> Self
fn from_real_vector<A>(val: A) -> Self
Creates a constant vector from a real vector type (e.g. VecF64<ROWS>
).
Sourcefn from_f64_array<A>(vals: A) -> Self
fn from_f64_array<A>(vals: A) -> Self
Creates a vector from an array of f64
.
Similar to from_real_array
but may serve a
different purpose in some dual or batch contexts.
Sourcefn elem_mut(&mut self, idx: usize) -> &mut S
fn elem_mut(&mut self, idx: usize) -> &mut S
Returns a mutable reference to the idx
-th element of the vector.
Sourcefn get_fixed_subvec<const R: usize>(
&self,
start_r: usize,
) -> <S as IsScalar<BATCH, DM, DN>>::Vector<R>
fn get_fixed_subvec<const R: usize>( &self, start_r: usize, ) -> <S as IsScalar<BATCH, DM, DN>>::Vector<R>
Extracts a subvector of length R
, starting from row index start_r
.
§Panics
May panic if start_r + R
exceeds the vector’s total size ROWS
.
Sourcefn from_scalar_array<A>(vals: A) -> Self
fn from_scalar_array<A>(vals: A) -> Self
Creates a vector from an array of S
scalars.
Sourcefn normalized(&self) -> Self
fn normalized(&self) -> Self
Returns a normalized version of this vector (self / self.norm()
).
§Note
May return a NaN or invalid value if the norm is zero.
Sourcefn outer<const R2: usize, V>(
&self,
rhs: V,
) -> <S as IsScalar<BATCH, DM, DN>>::Matrix<ROWS, R2>
fn outer<const R2: usize, V>( &self, rhs: V, ) -> <S as IsScalar<BATCH, DM, DN>>::Matrix<ROWS, R2>
Computes the outer product between self
(treated as ROWS×1) and rhs
(treated as 1×R2), yielding a ROWS×R2 matrix.
Sourcefn real_vector(&self) -> <S as IsScalar<BATCH, DM, DN>>::RealVector<ROWS>
fn real_vector(&self) -> <S as IsScalar<BATCH, DM, DN>>::RealVector<ROWS>
Returns the underlying real vector (e.g., VecF64<ROWS>
) if S
is a real type.
If S
is dual or simd, this method returns the “real part” of the vector’s elements.
Sourcefn select<O>(
&self,
mask: &<S as IsScalar<BATCH, DM, DN>>::Mask,
other: O,
) -> Selfwhere
O: Borrow<Self>,
fn select<O>(
&self,
mask: &<S as IsScalar<BATCH, DM, DN>>::Mask,
other: O,
) -> Selfwhere
O: Borrow<Self>,
Lane-wise select operation: for each element or lane, picks from self
if
mask
is true, otherwise picks from other
.
For non-batch usage (BATCH=1), mask
is just a simple boolean. For batch/simd usage,
mask
can represent per-lane boolean flags.
Sourcefn scaled<U>(&self, v: U) -> Selfwhere
U: Borrow<S>,
fn scaled<U>(&self, v: U) -> Selfwhere
U: Borrow<S>,
Scales the vector by a scalar v
(e.g., self * v
).
Sourcefn squared_norm(&self) -> S
fn squared_norm(&self) -> S
Returns the squared Euclidean norm of this vector.
Sourcefn to_dual_const<const M: usize, const N: usize>(
&self,
) -> <<S as IsScalar<BATCH, DM, DN>>::DualScalar<M, N> as IsScalar<BATCH, M, N>>::Vector<ROWS>
fn to_dual_const<const M: usize, const N: usize>( &self, ) -> <<S as IsScalar<BATCH, DM, DN>>::DualScalar<M, N> as IsScalar<BATCH, M, N>>::Vector<ROWS>
Converts this vector into a dual vector with zero infinitesimal part, if
S
is a real type. If it is already a dual type, it preserves or adapts
the dual content based on generics M
and N
.
Provided Methods§
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.