[][src]Struct crabsformer::Vector

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

Vector elements structure

TODO: add overview about vector here.

  1. how to create a vector
  2. Vector operation
  3. Indexing, etc.

Methods

impl<T> Vector<T>[src]

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

The total number of elements of the numeric vector.

Examples

let v = vector![3.0, 1.0, 4.0, 1.0, 5.0];
assert_eq!(v.len(), 5);

impl<T> Vector<T> where
    T: FromPrimitive + Num + Copy
[src]

pub fn full(len: usize, value: T) -> Vector<T>[src]

Create a new numeric vector of given length len and type T, filled with value.

Examples

let v = Vector::full(5, 2.5);

pub fn full_like(v: &Vector<T>, value: T) -> Vector<T>[src]

Create a new numeric vector that have the same length and type as vector v, filled with value.

Examples

let v1 = vector![3.0, 1.0, 4.0, 1.0, 5.0];
let v2 = Vector::full_like(&v1, 3.1415);

pub fn zeros(len: usize) -> Vector<T>[src]

Create a new numeric vector of given length len and type T, filled with zeros. You need to explicitly annotate the numeric type.

Examples

let v: Vector<i32> = Vector::zeros(5);

pub fn zeros_like(v: &Vector<T>) -> Vector<T>[src]

Create a new numeric vector that have the same length and type as vector v, filled with zeros.

Examples

let v1 = vector![3, 1, 4, 1, 5];
let v2 = Vector::zeros_like(&v1);

pub fn ones(len: usize) -> Vector<T>[src]

Create a new numeric vector of given length len and type T, filled with ones. You need to explicitly annotate the numeric type.

Examples

let v: Vector<i32> = Vector::ones(10);

pub fn ones_like(v: &Vector<T>) -> Vector<T>[src]

Create a new numeric vector that have the same length and type as vector v, filled with ones.

Examples

let v1 = vector![3, 1, 4, 1, 5];
let v2 = Vector::ones_like(&v1);

pub fn power(&self, exp: usize) -> Vector<T>[src]

Raises each elements of vector to the power of exp, using exponentiation by squaring.

Examples

let x = vector![3, 1, 4, 1];
let y = x.power(2);
assert_eq!(y, vector![9, 1, 16, 1]);

pub fn filter(&self, criteria: impl Fn(T) -> bool) -> Vector<T>[src]

Filter out the elements that doesn't match the criteria.

Examples

let x = vector![3, 1, 4, 1];
let y = x.filter(|x| x >= 2);
assert_eq!(y, vector![3, 4]);

impl<U> Vector<U> where
    U: SampleUniform
[src]

pub fn uniform(len: usize, low: U, high: U) -> Vector<U>[src]

Create a new numeric vector of the given length len and populate it with random samples from a uniform distribution over the half-open interval [low, high) (includes low, but excludes high).

Examples

let v = Vector::uniform(5, 0.0, 1.0);

impl Vector<f64>[src]

pub fn normal(len: usize, mean: f64, std_dev: f64) -> Vector<f64>[src]

Create a new numeric vector of the given length len and populate it with random samples from a normal distribution N(mean, std_dev**2).

Examples

let v = Vector::normal(5, 0.0, 1.0); // Gaussian mean=0.0 std_dev=1.0

impl<T> Vector<T> where
    T: Num + FromPrimitive + Copy + PartialOrd + AddAssign + Display
[src]

pub fn range(start: T, stop: T, step: T) -> Vector<T>[src]

Create a new numeric vector of evenly spaced values within a given half-open interval [start, stop) and spacing value step. Values are generated within the half-open interval [start, stop) (in other words, the interval including start but excluding stop).

Examples

let v = Vector::range(0.0, 3.0, 0.5);
// v = vector![0.0, 0.5, 1.0, 1.5, 2.0, 2.5]

Panics

Panics if start >= stop.

impl<F> Vector<F> where
    F: Float + FromPrimitive + Copy + PartialOrd + AddAssign + Display
[src]

pub fn linspace(len: usize, start: F, stop: F) -> Vector<F>[src]

Create a new numeric vector of the given length len and populate it with linearly spaced values within a given closed interval [start, stop].

Examples

let a = Vector::linspace(5, 1.0, 10.0); // vector![1.0, 3.25, 5.5, 7.75, 10.0]

Panics

Panics if start >= stop.

Trait Implementations

impl<T> PartialEq<Vector<T>> for Vector<T> where
    T: Num + Copy
[src]

impl<T> From<Vec<T>> for Vector<T> where
    T: Num + Copy
[src]

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

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

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

impl<T> Add<Vector<T>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The resulting type after applying the + operator.

impl<T> Add<T> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The resulting type after applying the + operator.

impl Add<Vector<usize>> for usize[src]

type Output = Vector<usize>

The resulting type after applying the + operator.

impl Add<Vector<i8>> for i8[src]

type Output = Vector<i8>

The resulting type after applying the + operator.

impl Add<Vector<i16>> for i16[src]

type Output = Vector<i16>

The resulting type after applying the + operator.

impl Add<Vector<i32>> for i32[src]

type Output = Vector<i32>

The resulting type after applying the + operator.

impl Add<Vector<i64>> for i64[src]

type Output = Vector<i64>

The resulting type after applying the + operator.

impl Add<Vector<i128>> for i128[src]

type Output = Vector<i128>

The resulting type after applying the + operator.

impl Add<Vector<u8>> for u8[src]

type Output = Vector<u8>

The resulting type after applying the + operator.

impl Add<Vector<u16>> for u16[src]

type Output = Vector<u16>

The resulting type after applying the + operator.

impl Add<Vector<u32>> for u32[src]

type Output = Vector<u32>

The resulting type after applying the + operator.

impl Add<Vector<u64>> for u64[src]

type Output = Vector<u64>

The resulting type after applying the + operator.

impl Add<Vector<u128>> for u128[src]

type Output = Vector<u128>

The resulting type after applying the + operator.

impl Add<Vector<f32>> for f32[src]

type Output = Vector<f32>

The resulting type after applying the + operator.

impl Add<Vector<f64>> for f64[src]

type Output = Vector<f64>

The resulting type after applying the + operator.

impl<T> Sub<Vector<T>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The resulting type after applying the - operator.

impl<T> Sub<T> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The resulting type after applying the - operator.

impl Sub<Vector<usize>> for usize[src]

type Output = Vector<usize>

The resulting type after applying the - operator.

impl Sub<Vector<i8>> for i8[src]

type Output = Vector<i8>

The resulting type after applying the - operator.

impl Sub<Vector<i16>> for i16[src]

type Output = Vector<i16>

The resulting type after applying the - operator.

impl Sub<Vector<i32>> for i32[src]

type Output = Vector<i32>

The resulting type after applying the - operator.

impl Sub<Vector<i64>> for i64[src]

type Output = Vector<i64>

The resulting type after applying the - operator.

impl Sub<Vector<i128>> for i128[src]

type Output = Vector<i128>

The resulting type after applying the - operator.

impl Sub<Vector<u8>> for u8[src]

type Output = Vector<u8>

The resulting type after applying the - operator.

impl Sub<Vector<u16>> for u16[src]

type Output = Vector<u16>

The resulting type after applying the - operator.

impl Sub<Vector<u32>> for u32[src]

type Output = Vector<u32>

The resulting type after applying the - operator.

impl Sub<Vector<u64>> for u64[src]

type Output = Vector<u64>

The resulting type after applying the - operator.

impl Sub<Vector<u128>> for u128[src]

type Output = Vector<u128>

The resulting type after applying the - operator.

impl Sub<Vector<f32>> for f32[src]

type Output = Vector<f32>

The resulting type after applying the - operator.

impl Sub<Vector<f64>> for f64[src]

type Output = Vector<f64>

The resulting type after applying the - operator.

impl<T> Mul<Vector<T>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The resulting type after applying the * operator.

impl<T> Mul<T> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The resulting type after applying the * operator.

impl Mul<Vector<usize>> for usize[src]

type Output = Vector<usize>

The resulting type after applying the * operator.

impl Mul<Vector<i8>> for i8[src]

type Output = Vector<i8>

The resulting type after applying the * operator.

impl Mul<Vector<i16>> for i16[src]

type Output = Vector<i16>

The resulting type after applying the * operator.

impl Mul<Vector<i32>> for i32[src]

type Output = Vector<i32>

The resulting type after applying the * operator.

impl Mul<Vector<i64>> for i64[src]

type Output = Vector<i64>

The resulting type after applying the * operator.

impl Mul<Vector<i128>> for i128[src]

type Output = Vector<i128>

The resulting type after applying the * operator.

impl Mul<Vector<u8>> for u8[src]

type Output = Vector<u8>

The resulting type after applying the * operator.

impl Mul<Vector<u16>> for u16[src]

type Output = Vector<u16>

The resulting type after applying the * operator.

impl Mul<Vector<u32>> for u32[src]

type Output = Vector<u32>

The resulting type after applying the * operator.

impl Mul<Vector<u64>> for u64[src]

type Output = Vector<u64>

The resulting type after applying the * operator.

impl Mul<Vector<u128>> for u128[src]

type Output = Vector<u128>

The resulting type after applying the * operator.

impl Mul<Vector<f32>> for f32[src]

type Output = Vector<f32>

The resulting type after applying the * operator.

impl Mul<Vector<f64>> for f64[src]

type Output = Vector<f64>

The resulting type after applying the * operator.

impl<T> AddAssign<Vector<T>> for Vector<T> where
    T: Num + Copy + AddAssign
[src]

impl<T> AddAssign<T> for Vector<T> where
    T: Num + Copy + AddAssign
[src]

impl<T> SubAssign<Vector<T>> for Vector<T> where
    T: Num + Copy + SubAssign
[src]

impl<T> SubAssign<T> for Vector<T> where
    T: Num + Copy + SubAssign
[src]

impl<T> MulAssign<Vector<T>> for Vector<T> where
    T: Num + Copy + MulAssign
[src]

impl<T> MulAssign<T> for Vector<T> where
    T: Num + Copy + MulAssign
[src]

impl<T> Index<usize> for Vector<T>[src]

type Output = T

The returned type after indexing.

Auto Trait Implementations

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

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

Blanket Implementations

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

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

type Owned = T

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

impl<T, U> TryInto 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> Any for T where
    T: 'static + ?Sized
[src]