Struct Vector

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

Represents a vector.

Implementations§

§

impl<T> Vector<T>
where T: Clone,

pub fn new(size: usize, init: T) -> Vector<T>

pub fn to_row_vector(&self) -> Vector<T>

pub fn to_col_vector(&self) -> Vector<T>

pub fn get_size(&self) -> usize

Trait Implementations§

§

impl<T> Add for &Vector<T>
where T: Add<Output = T> + Clone + Copy,

Vectors can be added by adding their references.

§Example

let vec_a = vector![1, 2, 3];
let vec_b = vector![3, 2, 1];
assert_eq!(&vec_a + &vec_b, Vector::new(3, 4));
§

type Output = Vector<T>

The resulting type after applying the + operator.
§

fn add(self, vector: &Vector<T>) -> Self::Output

Performs the + operation. Read more
§

impl<T> AddAssign<&Vector<T>> for Vector<T>
where T: Add<Output = T> + Clone + Copy,

§

fn add_assign(&mut self, vector: &Vector<T>)

Performs the += operation. Read more
§

impl<T: Clone> Clone for Vector<T>

§

fn clone(&self) -> Vector<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
§

impl<T: Debug> Debug for Vector<T>

§

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

Formats the value using the given formatter. Read more
§

impl<T> Div<T> for &Vector<T>
where T: Div<Output = T> + Mul<Output = T> + Clone + Zero + Copy + One,

Dividing a vector by a number is the same a multiplying by its inverse.

§Example

let vec_a = Vector::new(3, 1_f32);
assert_eq!(&vec_a / 2.0, Vector::new(3, 0.5));
§

type Output = Vector<T>

The resulting type after applying the / operator.
§

fn div(self, divisor: T) -> Self::Output

Performs the / operation. Read more
§

impl<T> From<Matrix<T>> for Vector<T>

§

fn from(mat: Matrix<T>) -> Vector<T>

Converts to this type from the input type.
§

impl<T> From<Vec<T>> for Vector<T>
where T: Clone,

§

fn from(vec: Vec<T>) -> Vector<T>

Converts to this type from the input type.
§

impl<T> Index<usize> for Vector<T>

Indexing a vectors returns the corresponding entry.

§Example

let vec_a = vector![1, 2, 3];
assert_eq!(vec_a[0], 1);
assert_eq!(vec_a[1], 2);
assert_eq!(vec_a[2], 3);
§

type Output = T

The returned type after indexing.
§

fn index(&self, idx: usize) -> &Self::Output

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

impl<T> IndexMut<usize> for Vector<T>

Single entries of a vector can be manipulated by mutating an indexed vector.

§Example

let mut vec_a = Vector::new(3, 1);
vec_a[1] = 2;
vec_a[2] = 3;
assert_eq!(vec_a[0], 1);
assert_eq!(vec_a[1], 2);
assert_eq!(vec_a[2], 3);
assert_eq!(vec_a, vector![1, 2, 3]);
§

fn index_mut(&mut self, idx: usize) -> &mut Self::Output

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

impl<T> Into<Matrix<T>> for Vector<T>
where T: Zero + One + Copy,

§

fn into(self) -> Matrix<T>

Converts this type into the (usually inferred) input type.
§

impl<T> Mul<&Matrix<T>> for &Vector<T>
where T: One + Zero + Copy + Clone,

Vectors can also be multiplied with matrices. The result will be a vector.

§Example

let mat_a = Matrix::<u32>::one(4);
let mat_b = matrix!{1, 2, 3; 4, 4, 3; 2, 1, 3; 4, 1, 2};
let vec_a = vector![4, 5, 6, 7].to_row_vector();
let vec_b = vector![64, 41, 59].to_row_vector();
assert_eq!(&vec_a * &mat_a, vec_a);
assert_eq!(&vec_a * &mat_b, vec_b);
§

type Output = Vector<T>

The resulting type after applying the * operator.
§

fn mul(self, mat: &Matrix<T>) -> Self::Output

Performs the * operation. Read more
§

impl<T> Mul<&Vector<T>> for &Matrix<T>
where T: One + Zero + Copy + Clone,

Matrices can be multiplied with Vectors by multiplying their references. The dimensions of the two objects need to match like with matrix multiplication.

§Example

let v_a = vector![1, 2, 3];
let mat_a = matrix!{1, 2, 3; 4, 5, 6; 7, 8, 9};
let v_b = vector![30, 36, 42].to_row_vector();
assert_eq!(&v_a.to_row_vector() * &mat_a, v_b);
§

type Output = Vector<T>

The resulting type after applying the * operator.
§

fn mul(self, vec: &Vector<T>) -> Self::Output

Performs the * operation. Read more
§

impl<T> Mul<T> for &Vector<T>
where T: Mul<Output = T> + Clone + Zero + Copy,

Vectors can be scaled by scaling a reference to a vector.

§Example

let vec_a = Vector::new(3, 1);
assert_eq!(&vec_a * 2, Vector::new(3, 2));
§

type Output = Vector<T>

The resulting type after applying the * operator.
§

fn mul(self, scalar: T) -> Self::Output

Performs the * operation. Read more
§

impl<T> Mul for &Vector<T>
where T: Mul<Output = T> + Clone + Copy + Zero,

Vectors can be multpilied by multiplying their references.

§Example

let vec_a = Vector::new(4, 3);
let vec_b = vector![5, 6, 7, 8];
assert_eq!(&vec_a * &vec_b, 78);
assert_eq!(&vec_b * &vec_a, 78);
§

type Output = T

The resulting type after applying the * operator.
§

fn mul(self, vec: &Vector<T>) -> Self::Output

Performs the * operation. Read more
§

impl<T> Neg for &Vector<T>
where T: Sub<Output = T> + One + Zero + Clone + Copy,

§

type Output = Vector<T>

The resulting type after applying the - operator.
§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
§

impl<T: PartialEq> PartialEq for Vector<T>

§

fn eq(&self, other: &Vector<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.
§

impl<T> Sub for &Vector<T>
where T: Sub<Output = T> + Zero + One + Copy + Clone,

Vectors can be subtracted by subtracting theri references.

§Example

let vec_a = vector![1_i32, 2, 3];
let vec_b = vector![3_i32, 2, 1];
assert_eq!(&vec_a - &vec_b, vector![-2, 0, 2]);
§

type Output = Vector<T>

The resulting type after applying the - operator.
§

fn sub(self, vector: &Vector<T>) -> Self::Output

Performs the - operation. Read more
§

impl<T> SubAssign<&Vector<T>> for Vector<T>
where T: Sub<Output = T> + Zero + One + Copy + Clone,

§

fn sub_assign(&mut self, vector: &Vector<T>)

Performs the -= operation. Read more
§

impl<T> StructuralPartialEq for Vector<T>

Auto Trait Implementations§

§

impl<T> Freeze for Vector<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Vector<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.