Skip to main content

DynVector

Struct DynVector 

Source
pub struct DynVector<T> { /* private fields */ }
Expand description

Dynamically-sized vector (wraps a 1×N DynMatrix).

Enforces single-row constraint and provides single-index access v[i].

§Examples

use numeris::DynVector;

let v = DynVector::from_slice(&[1.0_f64, 2.0, 3.0]);
assert_eq!(v[0], 1.0);
assert_eq!(v.len(), 3);
assert!((v.dot(&v) - 14.0).abs() < 1e-12);

Implementations§

Source§

impl<T: Scalar> DynVector<T>

Source

pub fn norm_squared(&self) -> T

Squared L2 norm (dot product with self).

use numeris::DynVector;
let v = DynVector::from_slice(&[3.0, 4.0]);
assert_eq!(v.norm_squared(), 25.0);
Source§

impl<T: LinalgScalar> DynVector<T>

Source

pub fn norm(&self) -> T::Real

L2 (Euclidean) norm.

use numeris::DynVector;
let v = DynVector::from_slice(&[3.0_f64, 4.0]);
assert!((v.norm() - 5.0).abs() < 1e-12);
Source

pub fn norm_l1(&self) -> T::Real

L1 norm (sum of absolute values / moduli).

use numeris::DynVector;
let v = DynVector::from_slice(&[1.0_f64, -2.0, 3.0]);
assert!((v.norm_l1() - 6.0).abs() < 1e-12);
Source

pub fn normalize(&self) -> Self

Return a unit vector in the same direction.

Panics if the norm is zero.

use numeris::DynVector;
let v = DynVector::from_slice(&[3.0_f64, 4.0]);
let u = v.normalize();
assert!((u.norm() - 1.0).abs() < 1e-12);
assert!((u[0] - 0.6).abs() < 1e-12);
Source§

impl<T: Scalar> DynVector<T>

Source

pub fn from_slice(data: &[T]) -> Self

Create a vector from a flat slice.

use numeris::DynVector;
let v = DynVector::from_slice(&[1.0, 2.0, 3.0]);
assert_eq!(v[0], 1.0);
assert_eq!(v.len(), 3);
Source

pub fn from_vec(data: Vec<T>) -> Self

Create a vector from an owned Vec.

use numeris::DynVector;
let v = DynVector::from_vec(vec![1.0, 2.0, 3.0]);
assert_eq!(v[2], 3.0);
Source

pub fn zeros(n: usize, _zero: T) -> Self

Create a zero vector of length n.

use numeris::DynVector;
let v = DynVector::zeros(4, 0.0_f64);
assert_eq!(v.len(), 4);
assert_eq!(v[3], 0.0);
Source

pub fn fill(n: usize, value: T) -> Self

Create a vector filled with a value.

Source

pub fn len(&self) -> usize

Number of elements.

Source

pub fn is_empty(&self) -> bool

Whether the vector is empty.

Source

pub fn dot(&self, rhs: &Self) -> T

Dot product.

use numeris::DynVector;
let a = DynVector::from_slice(&[1.0, 2.0, 3.0]);
let b = DynVector::from_slice(&[4.0, 5.0, 6.0]);
assert_eq!(a.dot(&b), 32.0);
Source

pub fn cast<U: Scalar + NumCast>(&self) -> DynVector<U>
where T: ToPrimitive,

Cast every element to a different numeric type.

use numeris::DynVector;
let v = DynVector::from_slice(&[1.0_f64, 2.0, 3.0]);
let v32: DynVector<f32> = v.cast();
assert_eq!(v32[0], 1.0_f32);
Source

pub fn as_slice(&self) -> &[T]

View the vector data as a slice.

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

View the vector data as a mutable slice.

Trait Implementations§

Source§

impl<T: Clone> Clone for DynVector<T>

Source§

fn clone(&self) -> DynVector<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for DynVector<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Scalar> From<&DynVector<T>> for DynMatrix<T>

Source§

fn from(v: &DynVector<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar, const N: usize> From<&Matrix<T, 1, N>> for DynVector<T>

Source§

fn from(v: &Vector<T, N>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar> From<DynVector<T>> for DynMatrix<T>

Source§

fn from(v: DynVector<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar, const N: usize> From<Matrix<T, 1, N>> for DynVector<T>

Source§

fn from(v: Vector<T, N>) -> Self

Convert a fixed-size Vector into a DynVector.

use numeris::{Vector, DynVector};
let v = Vector::from_array([1.0, 2.0, 3.0]);
let dv: DynVector<f64> = v.into();
assert_eq!(dv.len(), 3);
assert_eq!(dv[0], 1.0);
Source§

impl<T> Index<usize> for DynVector<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, i: usize) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<usize> for DynVector<T>

Source§

fn index_mut(&mut self, i: usize) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<T> MatrixMut<T> for DynVector<T>

Source§

fn get_mut(&mut self, row: usize, col: usize) -> &mut T

Mutable reference to the element at (row, col).
Source§

fn col_as_mut_slice(&mut self, col: usize, row_start: usize) -> &mut [T]

Mutable contiguous slice of column col from row row_start to end.
Source§

impl<T> MatrixRef<T> for DynVector<T>

Source§

fn nrows(&self) -> usize

Number of rows.
Source§

fn ncols(&self) -> usize

Number of columns.
Source§

fn get(&self, row: usize, col: usize) -> &T

Reference to the element at (row, col).
Source§

fn col_as_slice(&self, col: usize, row_start: usize) -> &[T]

Contiguous slice of column col from row row_start to end. Read more
Source§

impl<T: PartialEq> PartialEq for DynVector<T>

Source§

fn eq(&self, other: &DynVector<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> StructuralPartialEq for DynVector<T>

Auto Trait Implementations§

§

impl<T> Freeze for DynVector<T>

§

impl<T> RefUnwindSafe for DynVector<T>
where T: RefUnwindSafe,

§

impl<T> Send for DynVector<T>
where T: Send,

§

impl<T> Sync for DynVector<T>
where T: Sync,

§

impl<T> Unpin for DynVector<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for DynVector<T>

§

impl<T> UnwindSafe for DynVector<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.