Trait IsVector

Source
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>
    + RelativeEq
where 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 be f64 or a dual number implementing IsScalar.
  • 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§

Source

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.

Source

fn dot<V>(&self, rhs: V) -> S
where V: Borrow<Self>,

Computes the dot product (inner product) with another vector.

Source

fn from_array<A>(vals: A) -> Self
where A: Borrow<[S; ROWS]>,

Creates a vector from an array of elements.

Source

fn from_real_array<A>(vals: A) -> Self
where A: Borrow<[<S as IsScalar<BATCH, DM, DN>>::RealScalar; ROWS]>,

Creates a constant (non-dual) vector from an array of real scalars.

Source

fn from_real_vector<A>(val: A) -> Self
where A: Borrow<<S as IsScalar<BATCH, DM, DN>>::RealVector<ROWS>>,

Creates a constant vector from a real vector type (e.g. VecF64<ROWS>).

Source

fn from_f64(val: f64) -> Self

Creates a vector where all elements are set to the given f64.

Source

fn from_f64_array<A>(vals: A) -> Self
where A: Borrow<[f64; ROWS]>,

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.

Source

fn elem(&self, idx: usize) -> S

Returns the idx-th element of the vector.

Source

fn elem_mut(&mut self, idx: usize) -> &mut S

Returns a mutable reference to the idx-th element of the vector.

Source

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.

Source

fn from_scalar_array<A>(vals: A) -> Self
where A: Borrow<[S; ROWS]>,

Creates a vector from an array of S scalars.

Source

fn norm(&self) -> S

Computes the Euclidean norm (length) of this vector.

Source

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.

Source

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

Computes the outer product between self (treated as ROWS×1) and rhs (treated as 1×R2), yielding a ROWS×R2 matrix.

Source

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.

Source

fn select<O>( &self, mask: &<S as IsScalar<BATCH, DM, DN>>::Mask, other: O, ) -> Self
where 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.

Source

fn scaled<U>(&self, v: U) -> Self
where U: Borrow<S>,

Scales the vector by a scalar v (e.g., self * v).

Source

fn squared_norm(&self) -> S

Returns the squared Euclidean norm of this vector.

Source

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.

Source

fn to_mat(&self) -> <S as IsScalar<BATCH, DM, DN>>::Matrix<ROWS, 1>

Interprets self as a column vector and returns it in matrix form (ROWS×1).

Provided Methods§

Source

fn ones() -> Self

Creates a vector of all ones (1.0).

Source

fn zeros() -> Self

Creates a vector of all zeros (0.0).

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.

Implementations on Foreign Types§

Source§

impl<const ROWS: usize> IsVector<f64, ROWS, 1, 0, 0> for Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>

Source§

fn block_vec2<const R0: usize, const R1: usize>( top_row: Matrix<f64, Const<R0>, Const<1>, ArrayStorage<f64, R0, 1>>, bot_row: Matrix<f64, Const<R1>, Const<1>, ArrayStorage<f64, R1, 1>>, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>

Source§

fn from_array<A>( vals: A, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>
where A: Borrow<[f64; ROWS]>,

Source§

fn from_real_array<A>( vals: A, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>
where A: Borrow<[f64; ROWS]>,

Source§

fn from_real_vector<A>( val: A, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>
where A: Borrow<Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>>,

Source§

fn from_f64_array<A>( vals: A, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>
where A: Borrow<[f64; ROWS]>,

Source§

fn from_scalar_array<A>( vals: A, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>
where A: Borrow<[f64; ROWS]>,

Source§

fn elem(&self, idx: usize) -> f64

Source§

fn elem_mut(&mut self, idx: usize) -> &mut f64

Source§

fn norm(&self) -> f64

Source§

fn real_vector( &self, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>

Source§

fn squared_norm(&self) -> f64

Source§

fn to_mat( &self, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>

Source§

fn scaled<U>( &self, v: U, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>
where U: Borrow<f64>,

Source§

fn dot<V>(&self, rhs: V) -> f64
where V: Borrow<Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>>,

Source§

fn normalized( &self, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>

Source§

fn from_f64( val: f64, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>

Source§

fn to_dual_const<const M: usize, const N: usize>( &self, ) -> <f64 as IsScalar<1, 0, 0>>::DualVector<ROWS, M, N>

Source§

fn outer<const R2: usize, V>( &self, rhs: V, ) -> Matrix<f64, Const<ROWS>, Const<R2>, ArrayStorage<f64, ROWS, R2>>
where V: Borrow<Matrix<f64, Const<R2>, Const<1>, ArrayStorage<f64, R2, 1>>>,

Source§

fn select<Q>( &self, mask: &bool, other: Q, ) -> Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>
where Q: Borrow<Matrix<f64, Const<ROWS>, Const<1>, ArrayStorage<f64, ROWS, 1>>>,

Source§

fn get_fixed_subvec<const R: usize>( &self, start_r: usize, ) -> Matrix<f64, Const<R>, Const<1>, ArrayStorage<f64, R, 1>>

Implementors§

Source§

impl<const ROWS: usize, const DM: usize, const DN: usize> IsVector<DualScalar<DM, DN>, ROWS, 1, DM, DN> for DualVector<ROWS, DM, DN>