[−][src]Struct ml_rust_cuda::math::linear::Vector
A representation of a 32-bit float mathematical vector.
A vector is simply a wrapper around a Matrix with additional and/or vector-specific operations. Don't confuse this with Rust's Vec data type.
use ml_rust_cuda::math::linear::Vector; let elements = vec![1_f32, 3_f32, 4_f32]; let vector = Vector::new(elements); // "Vector { matrix: Matrix { elements: [ 1.0, 3.0, 4.0 ], dims: (3, 1) } } println!("{:?}", vector);
Implementations
impl Vector
[src]
pub fn new(elements: Vec<f32>) -> Self
[src]
Returns a mathematical vector representation from a supplied f32 vector.
Arguments
elements
- A vector off32
s for the mathematical vector.
Examples
use ml_rust_cuda::math::linear::Vector; let vec = vec![9_f32, 5_f32, 8_f32, 3_f32, 4_f32, 0_f32]; let vector = Vector::new(vec); println!("{}", vector);
pub fn from_matrix(matrix: Matrix) -> Self
[src]
Returns a mathematical vector around a given Matrix.
Arguments
matrix
- The matrix to contain in the resulting vector.
Examples
use ml_rust_cuda::math::linear::{ Matrix, Vector }; let matrix = Matrix::new(vec![vec![1_f32, 2_f32, 5_f32, 3_f32]]); let vector = Vector::from_matrix(matrix); println!("{}", vector);
pub fn zero(n_elements: usize) -> Self
[src]
Returns a mathematical vector of specified dimension filled with zeros.
Arguments
n_elements
- The dimension of the resulting vector.
Examples
use ml_rust_cuda::math::linear::Vector; let vector = Vector::zero(6); println!("{}", vector);
pub fn get(&self, i: usize) -> Option<f32>
[src]
Returns the element of the vector at a given position, or None
if the
index is out of bounds of the vector.
Arguments
i
- The target element's index.
Examples
use ml_rust_cuda::math::linear::Vector; let vec = vec![9_f32, 5_f32, 8_f32, 3_f32, 4_f32, 0_f32]; let vector = Vector::new(vec); assert_eq!(vector.get(2), Some(8_f32)); assert!(vector.get(8).is_none());
pub fn set(&mut self, i: usize, val: f32)
[src]
Replaces the element of the vector at a given position with a given value. Does nothing if the position is out of bounds of the vector.
Arguments
i
- The target element's position.val
- The value with which to replace the target element.
Examples
use ml_rust_cuda::math::linear::Vector; let vec = vec![9_f32, 5_f32, 8_f32, 3_f32, 4_f32, 0_f32]; let mut vector = Vector::new(vec); vector.set(2, 5_f32); assert_eq!(vector.get(2), Some(5_f32));
pub fn matrix(&self) -> &Matrix
[src]
Returns a reference to the interal matrix ofthe vector.
pub fn dim(&self) -> usize
[src]
Returns the dimension of the vector.
pub fn dot(&self, other: &Self) -> f32
[src]
Returns the dot product of the vector with another vector.
Uses a CUDA kernel under the hood.
Arguments
other
- A reference to another vector operand.
Examples
use ml_rust_cuda::math::{ f32_eq, linear::Vector }; let v1 = Vector::new(vec![9_f32, 5_f32, 8_f32, 3_f32, 4_f32, 0_f32]); let v2 = Vector::new(vec![8_f32, 1_f32, 2_f32, 4_f32, 0_f32, 1_f32]); let dot = v1.dot(&v2); assert!(f32_eq(dot, 105_f32));
Panics
Panics if the dimensions of both vectors are not equal.
pub fn p_norm(&self, p: f32) -> f32
[src]
Returns the p-norm of the vector.
The p-norm of a vector v
of dimension n
is defined as
||v||p = (|v_1|^p + ... |v_n|^p)^(1/p)
for any real number p >= 0
.
The infinity norm (i.e. the limit of ||v||p
as p
tends to infinity)
is the same as max(v_i)
for each element v_i
of v
.
Uses a CUDA kernel under the hood.
Arguments
p
- A positive 32-bit float.
Examples
use ml_rust_cuda::math::{ f32_eq, linear::Vector }; let v = Vector::new(vec![9_f32, 5_f32, 8_f32, 3_f32, 4_f32, 0_f32]); let p = 2_f32; let p_norm = v.p_norm(p); let inf_norm = v.p_norm(f32::INFINITY); assert!(f32_eq(p_norm, 195_f32.sqrt())); assert!(f32_eq(inf_norm, 9_f32));
Panics
Panics if p
is less than or equal to 0.
pub fn transposed(&self) -> Self
[src]
Returns the vector transposed. See Matrix::transposed.
Uses a CUDA kernel under the hood.
Trait Implementations
impl<'_> Add<&'_ Vector> for &'_ Vector
[src]
type Output = Vector
The resulting type after applying the +
operator.
fn add(self, other: Self) -> Self::Output
[src]
See Matrix.
impl Clone for Vector
[src]
impl Debug for Vector
[src]
impl Display for Vector
[src]
impl<'_, '_> Mul<&'_ Vector> for &'_ Matrix
[src]
type Output = Vector
The resulting type after applying the *
operator.
fn mul(self, other: &Vector) -> Self::Output
[src]
Uses the same CUDA kernel as matrix multiplication.
Panics
Panics if the number of columns in the matrix is not equal to the dimension of the vector.
impl<'_> Mul<&'_ Vector> for f32
[src]
type Output = Vector
The resulting type after applying the *
operator.
fn mul(self, other: &Vector) -> Self::Output
[src]
See Matrix.
impl PartialEq<Vector> for Vector
[src]
fn eq(&self, other: &Self) -> bool
[src]
See Matrix.
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'_> Sub<&'_ Vector> for &'_ Vector
[src]
Auto Trait Implementations
impl RefUnwindSafe for Vector
impl Send for Vector
impl Sync for Vector
impl Unpin for Vector
impl UnwindSafe for Vector
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> 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, U> TryInto<U> 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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,