pub struct DynVector<T> { /* private fields */ }Expand description
Dynamically-sized column vector (wraps an N×1 DynMatrix).
Matches the fixed-size Vector<T, N> = Matrix<T, N, 1> convention.
Provides single-index access v[i].
§Examples
use numeris::{DynVector, MatrixRef};
let v = DynVector::from_slice(&[1.0_f64, 2.0, 3.0]);
assert_eq!(v[0], 1.0);
assert_eq!(v.len(), 3);
assert_eq!(v.nrows(), 3);
assert_eq!(v.ncols(), 1);
assert!((v.dot(&v) - 14.0).abs() < 1e-12);Implementations§
Source§impl<T: Scalar> DynVector<T>
impl<T: Scalar> DynVector<T>
Sourcepub fn norm_squared(&self) -> T
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>
impl<T: LinalgScalar> DynVector<T>
Sourcepub fn norm(&self) -> T::Real
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§impl<T: Scalar> DynVector<T>
impl<T: Scalar> DynVector<T>
Sourcepub fn from_slice(data: &[T]) -> Self
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);Sourcepub fn from_vec(data: Vec<T>) -> Self
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);Sourcepub fn zeros(n: usize) -> Self
pub fn zeros(n: usize) -> Self
Create a zero vector of length n.
use numeris::DynVector;
let v = DynVector::<f64>::zeros(4);
assert_eq!(v.len(), 4);
assert_eq!(v[3], 0.0);Sourcepub fn dot(&self, rhs: &Self) -> T
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);Sourcepub fn cast<U: Scalar + NumCast>(&self) -> DynVector<U>where
T: ToPrimitive,
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);Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
View the vector data as a mutable slice.
Trait Implementations§
Source§impl<T: Scalar + Scalar> From<&Matrix<T, Dyn, Const<1>, VecStorage<T, Dyn, Const<1>>>> for DynVector<T>
impl<T: Scalar + Scalar> From<&Matrix<T, Dyn, Const<1>, VecStorage<T, Dyn, Const<1>>>> for DynVector<T>
Source§impl<T: Scalar + Scalar> From<Matrix<T, Dyn, Const<1>, VecStorage<T, Dyn, Const<1>>>> for DynVector<T>
impl<T: Scalar + Scalar> From<Matrix<T, Dyn, Const<1>, VecStorage<T, Dyn, Const<1>>>> for DynVector<T>
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> 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,
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.