Vector

Struct Vector 

Source
pub struct Vector<T> {
    pub data: Vec<T>,
}
Expand description

A vector of elements of type T

Fields§

§data: Vec<T>

Implementations§

Source§

impl<T: Copy> Vector<T>

Source

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

Creates a new vector from a Vec<T>.

Source

pub fn len(&self) -> usize

Returns the length of the vector.

Source

pub fn dot(&self, other: &Self) -> T
where T: Add<Output = T> + Mul<Output = T> + Default,

Computes the dot product with another vector.

§Example
use rusticle::Vector;
let v1 = Vector::new(vec![1.0, 2.0]);
let v2 = Vector::new(vec![3.0, 4.0]);
let result = v1.dot(&v2);
assert_eq!(result, 11.0);
Source

pub fn norm(&self) -> f64
where T: Copy + Into<f64> + Mul<Output = T> + Add<Output = T> + Default,

Computes the norm (magnitude) of the vector.

§Example
use rusticle::Vector;
let v = Vector::new(vec![3.0, 4.0]);
let result = v.norm();
assert_eq!(result, 5.0);
Source

pub fn normalize(&self) -> Self
where T: Copy + Into<f64> + From<f64> + Mul<Output = T> + Add<Output = T> + Default,

Returns a normalized version of the vector.

§Example
use rusticle::Vector;
let v = Vector::new(vec![3.0, 4.0]);
let result = v.normalize();
assert!((result.norm() - 1.0).abs() < 1e-10);
Source

pub fn scale(&self, scalar: T) -> Self
where T: Mul<Output = T>,

Returns a new vector scaled by a scalar.

§Example
use rusticle::Vector;
let v = Vector::new(vec![1.0, 2.0]);
let result = v.scale(2.0);
assert_eq!(result, Vector::new(vec![2.0, 4.0]));
Source

pub fn tensor(&self, other: &Self) -> Self
where T: Copy + Mul<Output = T>,

Computes the tensor product of two vectors.

§Example
use rusticle::Vector;
let v1 = Vector::new(vec![1.0, 2.0]);
let v2 = Vector::new(vec![3.0, 4.0]);
let result = v1.tensor(&v2);
assert_eq!(result, Vector::new(vec![3.0, 4.0, 6.0, 8.0]));

Trait Implementations§

Source§

impl<T: Add<Output = T> + Copy> Add for Vector<T>

Source§

type Output = Vector<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

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

Source§

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
Source§

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

Source§

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

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

impl<T: Display> Display for Vector<T>

Source§

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

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

impl<T> From<Vec<T>> for Vector<T>

Source§

fn from(data: Vec<T>) -> Self

Converts to this type from the input type.
Source§

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

Source§

type Output = T

The returned type after indexing.
Source§

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

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

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

Source§

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

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

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

Source§

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.
Source§

impl<T: Sub<Output = T> + Copy> Sub for Vector<T>

Source§

type Output = Vector<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.