[−][src]Struct crabsformer::Vector
Numeric vector
TODO: add overview about vector here.
- how to create a vector
- Vector operation
- 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]
T: FromPrimitive + Num + Copy,
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]
T: FromPrimitive + Num + Copy,
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]
T: FromPrimitive + Num + Copy,
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]
T: FromPrimitive + Num + Copy,
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]
T: FromPrimitive + Num + Copy,
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]
T: FromPrimitive + Num + Copy,
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]
T: FromPrimitive + Num + Copy,
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]
T: Copy,
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]
T: FromPrimitive + Num + Copy,
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]
T: Integer + Copy,
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]
T: Integer + Copy,
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]
T: SampleUniform,
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]
T: Num + FromPrimitive + Copy + PartialOrd + AddAssign + Display,
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]
T: Float + FromPrimitive + Copy + PartialOrd + AddAssign + Display,
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]
T: Num + Copy,
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.
fn slice(&self, index: Range<usize>) -> Vector<T>
[src]
impl<T> Slice<RangeFrom<usize>> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The returned type after indexing.
fn slice(&self, index: RangeFrom<usize>) -> Vector<T>
[src]
impl<T> Slice<RangeTo<usize>> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The returned type after indexing.
fn slice(&self, index: RangeTo<usize>) -> Vector<T>
[src]
impl<T> Slice<RangeFull> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The returned type after indexing.
fn slice(&self, index: RangeFull) -> Vector<T>
[src]
impl<T> Slice<RangeInclusive<usize>> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The returned type after indexing.
fn slice(&self, index: RangeInclusive<usize>) -> Vector<T>
[src]
impl<T> Slice<RangeToInclusive<usize>> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The returned type after indexing.
fn slice(&self, index: RangeToInclusive<usize>) -> Vector<T>
[src]
impl<T> Clone for Vector<T> where
T: Copy,
[src]
T: Copy,
fn clone(&self) -> Vector<T>
[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]
T: Num + Copy,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T> From<Vec<T>> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
impl<T> Add<Vector<T>> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The resulting type after applying the +
operator.
fn add(self, other: Vector<T>) -> Vector<T>
[src]
impl<T> Add<T> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The resulting type after applying the +
operator.
fn add(self, value: T) -> Vector<T>
[src]
impl Add<Vector<usize>> for usize
[src]
type Output = Vector<usize>
The resulting type after applying the +
operator.
fn add(self, v: Vector<usize>) -> Vector<usize>
[src]
impl Add<Vector<i8>> for i8
[src]
type Output = Vector<i8>
The resulting type after applying the +
operator.
fn add(self, v: Vector<i8>) -> Vector<i8>
[src]
impl Add<Vector<i16>> for i16
[src]
type Output = Vector<i16>
The resulting type after applying the +
operator.
fn add(self, v: Vector<i16>) -> Vector<i16>
[src]
impl Add<Vector<i32>> for i32
[src]
type Output = Vector<i32>
The resulting type after applying the +
operator.
fn add(self, v: Vector<i32>) -> Vector<i32>
[src]
impl Add<Vector<i64>> for i64
[src]
type Output = Vector<i64>
The resulting type after applying the +
operator.
fn add(self, v: Vector<i64>) -> Vector<i64>
[src]
impl Add<Vector<i128>> for i128
[src]
type Output = Vector<i128>
The resulting type after applying the +
operator.
fn add(self, v: Vector<i128>) -> Vector<i128>
[src]
impl Add<Vector<u8>> for u8
[src]
type Output = Vector<u8>
The resulting type after applying the +
operator.
fn add(self, v: Vector<u8>) -> Vector<u8>
[src]
impl Add<Vector<u16>> for u16
[src]
type Output = Vector<u16>
The resulting type after applying the +
operator.
fn add(self, v: Vector<u16>) -> Vector<u16>
[src]
impl Add<Vector<u32>> for u32
[src]
type Output = Vector<u32>
The resulting type after applying the +
operator.
fn add(self, v: Vector<u32>) -> Vector<u32>
[src]
impl Add<Vector<u64>> for u64
[src]
type Output = Vector<u64>
The resulting type after applying the +
operator.
fn add(self, v: Vector<u64>) -> Vector<u64>
[src]
impl Add<Vector<u128>> for u128
[src]
type Output = Vector<u128>
The resulting type after applying the +
operator.
fn add(self, v: Vector<u128>) -> Vector<u128>
[src]
impl Add<Vector<f32>> for f32
[src]
type Output = Vector<f32>
The resulting type after applying the +
operator.
fn add(self, v: Vector<f32>) -> Vector<f32>
[src]
impl Add<Vector<f64>> for f64
[src]
type Output = Vector<f64>
The resulting type after applying the +
operator.
fn add(self, v: Vector<f64>) -> Vector<f64>
[src]
impl<T> Sub<Vector<T>> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The resulting type after applying the -
operator.
fn sub(self, other: Vector<T>) -> Vector<T>
[src]
impl<T> Sub<T> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The resulting type after applying the -
operator.
fn sub(self, value: T) -> Vector<T>
[src]
impl Sub<Vector<usize>> for usize
[src]
type Output = Vector<usize>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<usize>) -> Vector<usize>
[src]
impl Sub<Vector<i8>> for i8
[src]
type Output = Vector<i8>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<i8>) -> Vector<i8>
[src]
impl Sub<Vector<i16>> for i16
[src]
type Output = Vector<i16>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<i16>) -> Vector<i16>
[src]
impl Sub<Vector<i32>> for i32
[src]
type Output = Vector<i32>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<i32>) -> Vector<i32>
[src]
impl Sub<Vector<i64>> for i64
[src]
type Output = Vector<i64>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<i64>) -> Vector<i64>
[src]
impl Sub<Vector<i128>> for i128
[src]
type Output = Vector<i128>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<i128>) -> Vector<i128>
[src]
impl Sub<Vector<u8>> for u8
[src]
type Output = Vector<u8>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<u8>) -> Vector<u8>
[src]
impl Sub<Vector<u16>> for u16
[src]
type Output = Vector<u16>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<u16>) -> Vector<u16>
[src]
impl Sub<Vector<u32>> for u32
[src]
type Output = Vector<u32>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<u32>) -> Vector<u32>
[src]
impl Sub<Vector<u64>> for u64
[src]
type Output = Vector<u64>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<u64>) -> Vector<u64>
[src]
impl Sub<Vector<u128>> for u128
[src]
type Output = Vector<u128>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<u128>) -> Vector<u128>
[src]
impl Sub<Vector<f32>> for f32
[src]
type Output = Vector<f32>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<f32>) -> Vector<f32>
[src]
impl Sub<Vector<f64>> for f64
[src]
type Output = Vector<f64>
The resulting type after applying the -
operator.
fn sub(self, v: Vector<f64>) -> Vector<f64>
[src]
impl<T> Mul<Vector<T>> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The resulting type after applying the *
operator.
fn mul(self, other: Vector<T>) -> Vector<T>
[src]
impl<T> Mul<T> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
type Output = Vector<T>
The resulting type after applying the *
operator.
fn mul(self, value: T) -> Vector<T>
[src]
impl Mul<Vector<usize>> for usize
[src]
type Output = Vector<usize>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<usize>) -> Vector<usize>
[src]
impl Mul<Vector<i8>> for i8
[src]
type Output = Vector<i8>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<i8>) -> Vector<i8>
[src]
impl Mul<Vector<i16>> for i16
[src]
type Output = Vector<i16>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<i16>) -> Vector<i16>
[src]
impl Mul<Vector<i32>> for i32
[src]
type Output = Vector<i32>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<i32>) -> Vector<i32>
[src]
impl Mul<Vector<i64>> for i64
[src]
type Output = Vector<i64>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<i64>) -> Vector<i64>
[src]
impl Mul<Vector<i128>> for i128
[src]
type Output = Vector<i128>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<i128>) -> Vector<i128>
[src]
impl Mul<Vector<u8>> for u8
[src]
type Output = Vector<u8>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<u8>) -> Vector<u8>
[src]
impl Mul<Vector<u16>> for u16
[src]
type Output = Vector<u16>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<u16>) -> Vector<u16>
[src]
impl Mul<Vector<u32>> for u32
[src]
type Output = Vector<u32>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<u32>) -> Vector<u32>
[src]
impl Mul<Vector<u64>> for u64
[src]
type Output = Vector<u64>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<u64>) -> Vector<u64>
[src]
impl Mul<Vector<u128>> for u128
[src]
type Output = Vector<u128>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<u128>) -> Vector<u128>
[src]
impl Mul<Vector<f32>> for f32
[src]
type Output = Vector<f32>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<f32>) -> Vector<f32>
[src]
impl Mul<Vector<f64>> for f64
[src]
type Output = Vector<f64>
The resulting type after applying the *
operator.
fn mul(self, v: Vector<f64>) -> Vector<f64>
[src]
impl<T> AddAssign<Vector<T>> for Vector<T> where
T: Num + Copy + AddAssign,
[src]
T: Num + Copy + AddAssign,
fn add_assign(&mut self, other: Vector<T>)
[src]
impl<T> AddAssign<T> for Vector<T> where
T: Num + Copy + AddAssign,
[src]
T: Num + Copy + AddAssign,
fn add_assign(&mut self, value: T)
[src]
impl<T> SubAssign<Vector<T>> for Vector<T> where
T: Num + Copy + SubAssign,
[src]
T: Num + Copy + SubAssign,
fn sub_assign(&mut self, other: Vector<T>)
[src]
impl<T> SubAssign<T> for Vector<T> where
T: Num + Copy + SubAssign,
[src]
T: Num + Copy + SubAssign,
fn sub_assign(&mut self, value: T)
[src]
impl<T> MulAssign<Vector<T>> for Vector<T> where
T: Num + Copy + MulAssign,
[src]
T: Num + Copy + MulAssign,
fn mul_assign(&mut self, other: Vector<T>)
[src]
impl<T> MulAssign<T> for Vector<T> where
T: Num + Copy + MulAssign,
[src]
T: Num + Copy + MulAssign,
fn mul_assign(&mut self, value: T)
[src]
impl<T> Index<usize> for Vector<T>
[src]
impl<T> FromIterator<T> for Vector<T> where
T: Num + Copy,
[src]
T: Num + Copy,
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
[src]
impl<T> Debug for Vector<T> where
T: Debug,
[src]
T: Debug,
Auto Trait Implementations
Blanket Implementations
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,