[][src]Struct mathru::algebra::linear::vector::vector::Vector

pub struct Vector<T> { /* fields omitted */ }

Methods

impl<T> Vector<T>[src]

Important traits for VectorIterator<'a, T>
pub fn iter(&self) -> VectorIterator<T>[src]

Important traits for VectorIteratorMut<'a, T>
pub fn iter_mut(&mut self) -> VectorIteratorMut<T>[src]

impl<T> Vector<T> where
    T: AddAssign + Mul<T, Output = T> + Zero + One + Clone + Exponential + Div<T, Output = T> + Power + PartialOrd
[src]

pub fn p_norm<'a, 'b>(&'a self, p: &'b T) -> T[src]

Computes the p norm

Arguments

p >= 1.0

Panics

p < 1.0

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 0.0, 3.0, -2.0]);
let p: f64 = 2.0;
let norm_ref: f64 = a.eucl_norm();
let norm: f64 = a.p_norm(&p);

assert_eq!(norm_ref, norm);

impl<T> Vector<T>[src]

pub fn convert_to_vec(self) -> Vec<T>[src]

impl<T> Vector<T> where
    T: Power + Zero + One + Exponential + AddAssign + Add<T, Output = T> + Clone + Copy + FromPrimitive + Div<T, Output = T> + PartialOrd
[src]

pub fn eucl_norm<'a, 'b>(&'a self) -> T[src]

Computes the euclidean norm

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 0.0, 3.0, -2.0]);
let norm_ref: f64 = 3.7416573867739413;
let norm: f64 = a.eucl_norm();

assert_eq!(norm_ref, norm);

impl<T> Vector<T> where
    T: Clone + Copy + Zero + One
[src]

pub fn new_row<'a, 'b>(n: usize, data: Vec<T>) -> Self[src]

Returns a row vector

Panics

n != data.len()

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_row(4, vec![1.0, 0.0, 3.0, -2.0]);

pub fn new_column(m: usize, data: Vec<T>) -> Self[src]

Returns a column vector

Panics

m != data.len()

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 0.0, 3.0, -2.0]);

pub fn apply(self: Vector<T>, f: &dyn Fn(&T) -> T) -> Self[src]

impl<T> Vector<T> where
    T: Scalar + Clone + Copy + Zero + One
[src]

pub fn new_row_random(n: usize) -> Self[src]

Returns a row vector initialized with random numbers

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_row_random(4);

pub fn new_column_random(m: usize) -> Self[src]

Returns a column vector initialized with random numbers

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column_random(4);

impl<T> Vector<T> where
    T: Real
[src]

pub fn transpose(self) -> Self[src]

Returns the transposed vector

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 0.0, 3.0, -2.0]);
let b: Vector<f64> = a.transpose();

impl<T> Vector<T> where
    T: Real
[src]

pub fn dotp<'a, 'b>(&'a self, rhs: &'b Self) -> T[src]

Computes the dot product of two vectors

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 0.0, 3.0, -2.0]);
let b: Vector<f64> = Vector::new_column(4, vec![-1.0, 2.0, 3.0, 5.0]);
let dotp_ref: f64 = -2.0;

let dotp: f64 = a.dotp(&b);

assert_eq!(dotp_ref, dotp);

pub fn argmax(&self) -> usize[src]

Find the argmax of the vector.

Returns the index of the largest value in the vector.

Examples

use mathru::algebra::linear::Vector;

let a = Vector::new_column(4, vec![1.0, 2.0, -3.0, 5.0]);
let idx = a.argmax();
assert_eq!(idx, 3);

pub fn argmin(&self) -> usize[src]

Find the argmin of the vector.

Returns the index of the smallest value in the vector.

Examples

use mathru::algebra::linear::Vector;

let a = Vector::new_column(4, vec![1.0, -2.0, -6.0, 75.0]);
let b = a.argmin();
assert_eq!(b, 2);

impl<T> Vector<T> where
    T: Zero + Mul<T, Output = T> + Clone + One + Display
[src]

pub fn dyadp<'a, 'b>(&'a self, rhs: &'b Self) -> Matrix<T>[src]

Computes the dyadic product of two vectors

Example

use mathru::algebra::linear::{Vector, Matrix};

let a: Vector<f64> = Vector::new_row(4, vec![1.0, 0.0, 3.0, -2.0]);
let b: Vector<f64> = Vector::new_column(4, vec![-1.0, 2.0, 3.0, 5.0]);

let m: Matrix<f64> = a.dyadp(&b);

impl<T> Vector<T>[src]

pub fn get_mut<'a>(&'a mut self, i: usize) -> &'a mut T[src]

Returns the mutual component

Arguments

Panics

if i out of bounds

Example

use mathru::algebra::linear::{Vector};

let mut a: Vector<f64> = Vector::new_row(4, vec![1.0, 0.0, 3.0, -2.0]);

*a.get_mut(1) = -4.0;

impl<T> Vector<T>[src]

pub fn get<'a>(&'a self, i: usize) -> &'a T[src]

Returns the component

Panics

if i out of bounds

Example

use mathru::algebra::linear::{Vector};

let mut a: Vector<f64> = Vector::new_row(4, vec![1.0, 0.0, 3.0, -2.0]);

assert_eq!(-2.0, *a.get_mut(3))

impl<T> Vector<T> where
    T: Real
[src]

pub fn reflector(&self) -> Vector<T>[src]

impl<T> Vector<T> where
    T: Zero + Clone + Copy
[src]

pub fn zero(m: usize) -> Self[src]

Returns the zero vector

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![0.0, 0.0, 0.0, 0.0]);
let b: Vector<f64> = Vector::zero(4);

assert_eq!(a, b)

impl<T> Vector<T>[src]

pub fn dim(&self) -> (usize, usize)[src]

Returns the vector dimension

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let (m, n): (usize, usize) = a.dim();
assert_eq!(4, m);
assert_eq!(1, n);

impl<T> Vector<T> where
    T: Real
[src]

pub fn get_slice(&self, s: usize, e: usize) -> Vector<T>[src]

Returns a slice of the vector

Arugments

0 <= s < m
0 <= e < m

s: start
e: end

Panics

iff s and e are out of bounds

Example

use mathru::algebra::linear::{Vector};

let mut a: Vector<f64> = Vector::new_column(4, vec![1.0, -2.0, 3.0, -7.0]);
a = a.get_slice(1, 2);

let a_ref: Vector<f64> = Vector::new_column(2, vec![-2.0, 3.0]);

assert_eq!(a_ref, a);

pub fn set_slice<'a>(&mut self, rhs: &Self, s: usize)[src]

Overwrite a slice of the vector with the given values

Arugments

0 <= s < m

s: start

Example

use mathru::algebra::linear::{Vector};

let mut a: Vector<f64> = Vector::new_column(4, vec![1.0, -2.0, 3.0, -7.0]);
let b: Vector<f64> = Vector::new_column(2, vec![-5.0, 4.0]);
a.set_slice(&b, 1);

let a_ref: Vector<f64> = Vector::new_column(4, vec![1.0, -5.0, 4.0, -7.0]);

assert_eq!(a_ref, a);

Trait Implementations

impl<T> Sign for Vector<T> where
    T: Real
[src]

impl Discrete<Vector<u32>, Vector<f64>> for Multinomial[src]

fn pmf<'a>(&'a self, x: Vector<u32>) -> f64[src]

Probability mass function

Arguments

  • x Random variable x &isin ࡃ

Example

use mathru::*;
use mathru::statistics::distrib::{Discrete, Multinomial};
use mathru::algebra::linear::Vector;

let p: Vector<f64> = vector![0.3; 0.7];
let distrib: Multinomial = Multinomial::new(p);
let x: Vector<u32> = vector![1; 2];
let p: f64 = distrib.pmf(x);

fn cdf<'a>(&'a self, _x: Vector<f64>) -> f64[src]

Cumulative distribution function

Arguments

  • x Random variable

Example

use mathru::statistics::distrib::{Discrete, Binomial};

let distrib: Binomial = Binomial::new(&5, &0.3);
let x: f64 = 0.4;
let p: f64 = distrib.cdf(x);

fn mean<'a>(&'a self) -> f64[src]

Expected value

Example

use mathru::statistics::distrib::{Discrete, Binomial};

let distrib: Binomial = Binomial::new(&5, &0.3);
let mean: f64 = distrib.mean();

fn variance<'a>(&'a self) -> f64[src]

Variance

Example

use mathru::statistics::distrib::{Discrete, Binomial};

let distrib: Binomial = Binomial::new(&5, &0.3);
let var: f64 = distrib.variance();

impl<T> IntoIterator for Vector<T> where
    T: Real
[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = VectorIntoIterator<T>

Which kind of iterator are we turning this into?

impl<T: Clone> Clone for Vector<T>[src]

impl<T> PartialEq<Vector<T>> for Vector<T> where
    T: Scalar
[src]

fn eq<'a, 'b>(&'a self, other: &'b Self) -> bool[src]

Compares if two vectors are equal

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![0.0, 0.0, 0.0, 0.0]);
let b: Vector<f64> = Vector::zero(4);

assert_eq!(true, a.eq(&b))

impl<T> Display for Vector<T> where
    T: Display
[src]

impl<T: Debug> Debug for Vector<T>[src]

impl<T> Div<T> for Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the / operator.

fn div(self, rhs: T) -> Self::Output[src]

Divides the vector elements with scalar values

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![-5.0, -10.0, -15.0, -20.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);

assert_eq!(res_ref, a / -5.0)

impl<'a, '_, T> Div<&'_ T> for &'a Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the / operator.

fn div(self, rhs: &T) -> Self::Output[src]

Divides the elements of a vector with the scalar value

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![5.0, 10.0, 15.0, 20.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);

assert_eq!(res_ref, a / 5.0)

impl<T> Sub<T> for Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the - operator.

fn sub(self, rhs: T) -> Self::Output[src]

Subtracts a scalar value from all vector elements

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![6.0, 7.0, 8.0, 9.0]);

assert_eq!(res_ref, a - -5.0)

impl<'a, '_, T> Sub<&'_ T> for &'a Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the - operator.

fn sub(self, rhs: &T) -> Self::Output[src]

Subtract a scalar from vector elements

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![-4.0, -3.0, -2.0, -1.0]);

assert_eq!(res_ref, a - 5.0)

impl<T> Sub<Vector<T>> for Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the - operator.

fn sub(self, rhs: Vector<T>) -> Self::Output[src]

Subtracts two vectors

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let b: Vector<f64> = Vector::new_column(4, vec![3.0, -4.0, 5.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![-2.0, 6.0, -2.0, 0.0]);

assert_eq!(res_ref, a - b)

impl<'a, 'b, T> Sub<&'b Vector<T>> for &'a Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the - operator.

fn sub(self, rhs: &'b Vector<T>) -> Self::Output[src]

Subtracts two vectors

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let b: Vector<f64> = Vector::new_column(4, vec![3.0, -4.0, 5.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![-2.0, 6.0, -2.0, 0.0]);

assert_eq!(res_ref, &a - &b)

impl<T> Add<Vector<T>> for Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the + operator.

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

Adds two vectors

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let b: Vector<f64> = Vector::new_column(4, vec![3.0, -4.0, 5.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![4.0, -2.0, 8.0, 8.0]);

assert_eq!(res_ref, a + b)

impl<T> Add<T> for Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the + operator.

fn add(self, rhs: T) -> Self::Output[src]

Adds a scalar to the vector

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![-4.0, -3.0, -2.0, -1.0]);

assert_eq!(res_ref, a + -5.0)

impl<'a, '_, T> Add<&'_ T> for &'a Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the + operator.

fn add(self, rhs: &T) -> Self::Output[src]

Adds a scalar to the vector

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![-4.0, -3.0, -2.0, -1.0]);

assert_eq!(res_ref, a + -5.0)

impl<'a, 'b, T> Add<&'b Vector<T>> for &'a Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the + operator.

fn add(self, rhs: &'b Vector<T>) -> Self::Output[src]

Adds two vectors

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let b: Vector<f64> = Vector::new_column(4, vec![3.0, -4.0, 5.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![4.0, -2.0, 8.0, 8.0]);

assert_eq!(res_ref, &a + &b)

impl<T> Mul<T> for Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the * operator.

fn mul(self, rhs: T) -> Self::Output[src]

Multiplies the vector elements with a scalar value

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![-5.0, -10.0, -15.0, -20.0]);

assert_eq!(res_ref, a * -5.0)

impl<'a, '_, T> Mul<&'_ T> for &'a Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the * operator.

fn mul(self, rhs: &T) -> Self::Output[src]

Multiplies the vector elements with the scalar value

Example

use mathru::algebra::linear::{Vector};

let a: Vector<f64> = Vector::new_column(4, vec![1.0, 2.0, 3.0, 4.0]);
let res_ref: Vector<f64> = Vector::new_column(4, vec![5.0, 10.0, 15.0, 20.0]);

assert_eq!(res_ref, a * 5.0)

impl<T> Mul<Matrix<T>> for Vector<T> where
    T: Copy + Zero + Mul<T, Output = T> + Add<T, Output = T> + One + Display
[src]

type Output = Vector<T>

The resulting type after applying the * operator.

impl<'a, 'b, T> Mul<&'b Matrix<T>> for &'a Vector<T> where
    T: Copy + Zero + Mul<T, Output = T> + Add<T, Output = T> + One + Display
[src]

type Output = Vector<T>

The resulting type after applying the * operator.

impl<'a, 'b, T> Mul<&'b Vector<T>> for &'a Matrix<T> where
    T: Copy + Zero + Mul<T, Output = T> + Add<T, Output = T> + One + AddAssign
[src]

Multiplies matrix by vector.

type Output = Vector<T>

The resulting type after applying the * operator.

impl<T> Mul<Vector<T>> for Matrix<T> where
    T: Copy + Zero + Mul<T, Output = T> + Add<T, Output = T> + One + AddAssign
[src]

type Output = Vector<T>

The resulting type after applying the * operator.

impl<T> Neg for Vector<T> where
    T: Real
[src]

type Output = Vector<T>

The resulting type after applying the - operator.

impl<T> Serialize for Vector<T> where
    T: Serialize
[src]

impl<'de, T> Deserialize<'de> for Vector<T> where
    T: Deserialize<'de>, 
[src]

Auto Trait Implementations

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

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

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]