[][src]Struct crabsformer::Vector

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

Numeric vector.

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);

pub fn full(len: usize, value: T) -> Vector<T> where
    T: FromPrimitive + Num + Copy
[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> where
    T: FromPrimitive + Num + Copy
[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> where
    T: FromPrimitive + Num + Copy
[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> where
    T: FromPrimitive + Num + Copy
[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> where
    T: FromPrimitive + Num + Copy
[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> where
    T: FromPrimitive + Num + Copy
[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> where
    T: FromPrimitive + Num + Copy
[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> where
    T: Copy
[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]);

pub fn sum(&self) -> T where
    T: FromPrimitive + Num + Copy
[src]

Sum of numeric vector elements.

Examples

let x = Vector::uniform(5, -1.0, 1.0);
let sum = x.sum();
println!("sum = {}", sum);

pub fn max(&self) -> T where
    T: Integer + Copy
[src]

Returns the maximum element of a numeric vector.

Note that, it's only work for numeric vector of integer due too the trait std::cmp::Ord is not implemented for f32 and f64 in Rust standard library. This may change in the future.

Examples

let x = Vector::uniform(5, -10, 10);
let max = x.max();
println!("max = {}", max);

pub fn min(&self) -> T where
    T: Integer + Copy
[src]

Returns the minimum element of a numeric vector.

Note that, it's only work for numeric vector of integer due too the trait std::cmp::Ord is not implemented for f32 and f64 in Rust standard library. This may change in the future.

Examples

let x = Vector::uniform(5, -10, 10);
let min = x.min();
println!("min = {}", min);

pub fn uniform(len: usize, low: T, high: T) -> Vector<T> where
    T: SampleUniform
[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);

pub fn range(start: T, stop: T, step: T) -> Vector<T> where
    T: Num + FromPrimitive + Copy + PartialOrd + AddAssign + Display
[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.

pub fn linspace(len: usize, start: T, stop: T) -> Vector<T> where
    T: Float + FromPrimitive + Copy + PartialOrd + AddAssign + Display
[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.

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

Trait Implementations

impl<T> Slice<Range<usize>> for Vector<T> where
    T: Num + Copy
[src]

Implements sub-numeric vector slicing with syntax x.slice(begin .. end).

Returns a new numeric content that have elements of the given numeric vector from the range [begin..end).

This operation is O(1).

Panics

Requires that begin <= end and end <= len where len is the length of the numeric vector. Otherwise it will panic.

Examples

let x = vector![3, 1, 2, 3];
// Range
assert_eq!(x.slice(0..1), vector![3]);
// RangeTo
assert_eq!(x.slice(..2), vector![3, 1]);
// RangeFrom
assert_eq!(x.slice(2..), vector![2, 3]);
// RangeFull
assert_eq!(x.slice(..), vector![3, 1, 2, 3]);
// RangeInclusive
assert_eq!(x.slice(0..=1), vector![3, 1]);
// RangeToInclusive
assert_eq!(x.slice(..=2), vector![3, 1, 2]);

type Output = Vector<T>

The returned type after indexing.

impl<T> Slice<RangeFrom<usize>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The returned type after indexing.

impl<T> Slice<RangeTo<usize>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The returned type after indexing.

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

type Output = Vector<T>

The returned type after indexing.

impl<T> Slice<RangeInclusive<usize>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The returned type after indexing.

impl<T> Slice<RangeToInclusive<usize>> for Vector<T> where
    T: Num + Copy
[src]

type Output = Vector<T>

The returned type after indexing.

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> PartialEq<Vector<T>> for Vector<T> where
    T: Num + Copy
[src]

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<T> IntoIterator for Vector<T>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<T> From<Vec<T>> for Vector<T> where
    T: Num + Copy
[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.

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

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

Auto Trait Implementations

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

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

Blanket Implementations

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, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

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

type Owned = T

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, 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> BorrowMut for T where
    T: ?Sized
[src]

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